0% found this document useful (0 votes)
8 views388 pages

# ASP Tutorial - To Use Pp1-78

The document provides an overview of Answer Set Programming (ASP), including its basic concepts, syntax, semantics, and applications in AI problem-solving. It discusses the modeling of problems through rules and the interpretation of solutions via answer sets, along with various extensions and algorithms related to ASP. Additionally, it highlights the relationship between ASP and other fields such as logic programming and nonmonotonic reasoning.

Uploaded by

Erhan Tiryaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views388 pages

# ASP Tutorial - To Use Pp1-78

The document provides an overview of Answer Set Programming (ASP), including its basic concepts, syntax, semantics, and applications in AI problem-solving. It discusses the modeling of problems through rules and the interpretation of solutions via answer sets, along with various extensions and algorithms related to ASP. Additionally, it highlights the relationship between ASP and other fields such as logic programming and nonmonotonic reasoning.

Uploaded by

Erhan Tiryaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 388

Answer Set Programming

• Christian Anger

• Kathrin Konczak

• Thomas Linke

• Torsten Schaub

1
Resources

Course material
• http://www.cs.uni-potsdam.de/wv/lehre/
• http://www.cs.uni-potsdam.de/~torsten/asp/

Systems
• dlv http://www.dbai.tuwien.ac.at/proj/dlv/
• noMoRe http://www.cs.uni-potsdam.de/~linke/nomore/
• smodels http://www.tcs.hut.fi/Software/smodels/

• plp http://www.cs.uni-potsdam.de/~torsten/plp/
• nlp http://www.cs.uni-potsdam.de/~torsten/nlp/

2
Roadmap

• Overview and Introduction

• Modeling

• Extensions: Disjunctive and Nested logic programs

• Extensions: Cardinality and Weight Constraints

• Algorithms and Systems: Smodels

• Algorithms and Systems: noMoRe

• Extensions: Negation and Preferences

• Applications: Configuration

• Applications: Actions and Planning

• Applications: Agents

• Miscellaneous: Dowling/Gallier Algorithm, Fitting’s and Well-founded Semantics,


Complexity. . .

3
Problem solving versus Programming

Problem Solution
6

Modeling Interpretation

?
Representation - Output
Computation

4
Wanted

An approach to modeling and solving AI problems!

For instance,

• Planning,

• Diagnosis,

• Configuration,

• Combinatorics,

• Puzzles and Games,

• ...

5
A solution

Answer Set Programming!

Basic Idea
• Encode problem (class+instance) as a set of rules
• Read off solutions from answer sets of the rules

6
Roots

• Algorithm = Logic + Control (Kowalski, 1979)

• Logic as a programming language


➥ Prolog (Colmerauer, Kowalski)

• Related fields
– Logic Programming (of course)
– Nonmonotonic Reasoning
– Deductive Databases
– Constraint Programming

• Current killer application


➥ NASA’s space shuttle

7
Motivation
Prolog (Programming in logic) is great, it’s almost declarative!

To see this, consider

above(X,Y) :- on(X,Y).
above(X,Y) :- on(X,Z),above(Z,Y).

and compare it to

above(X,Y) :- above(Z,Y),on(X,Z).
above(X,Y) :- on(X,Y).

An interpretation in classical logic amounts to

∀xy(on(x, y) ∨ ∃z(on(x, z) ∧ above(z, y)) → above(x, y))

8
Motivation (ctd)
Prolog offers negation as failure via operator not.

For instance,

info(a).
ask(X) :- not info(X).

cannot be captured by

info(a) ∧ ∀x(¬info(x) → ask (x))


but by appeal to Clark’s completion by

∀x(x = a ↔ info(x)) ∧ ∀x(¬info(x) ↔ ask (x))


⇐⇒ info(a) ∧ ∀x(x 6= a ↔ ask (x))

9
Motivation (ctd)

Clark’s completion is sometimes too syntactical.


Consider

• p :- p yields p ↔ p

• p :- not p yields p ↔ ¬p

• Or even more complex yet analogous situations!

10
Answer Set Programming

• Basic idea

• Syntax

• Semantics

• Examples

• Variables and grounding

• Integrity constraints

• An algorithm

11
Answer Set Programming: Basic idea
✘ View rules as constraints on models.
For instance, given a rule
c ← a, not b
then each model X must satisfy
if a ∈ X and b 6∈ X , then c ∈ X .
➥ Models are closed under rules (informally!).
✘ Circumscribe models.
For instance, prefer model
∅ to {a, c} to {a, c, d} .

➥ Consider only minimal models containing justifiable atoms


(informally!).
☞ Such models are called answer sets (or initially: stable models).

12
Problem solving in Answer Set Programming

Problem Solution(s)
6

Modeling Interpretation

?
Logic Program - Answer sets
Computation

13
Normal logic programs

• A (normal) rule, r , is an ordered pair of the form

A0 ← A1 , . . . , Am , not Am+1 , . . . , not An ,

where n ≥ m ≥ 0, and each Ai (0 ≤ i ≤ n) is a atom.

• A (normal) logic program is a finite set of rules.

• Notation
head (r) = A0
body(r) = {A1 , . . . , Am , not Am+1 , . . . , not An }
body + (r) = {A1 , . . . , Am }
body − (r) = {Am+1 , . . . , An }

• A program is called basic if body − (r) = ∅ for all its rules.

14
Answer sets

Basic programs
• A set of atoms X is closed under a basic program Π iff
for any r ∈ Π, head (r) ∈ X whenever body + (r) ⊆ X .
• The smallest set of atoms which is closed under a basic
program Π is denoted by Cn(Π).

Normal programs
• The reduct, ΠX , of a program Π relative to a set X of atoms is
defined by

ΠX = {head (r) ← body + (r) | r ∈ Π and body − (r) ∩ X = ∅}.

• A set X of atoms is an answer set of a program Π if Cn(ΠX ) = X

15
A closer look at ΠX

In other words, given a set of atoms X from Π,

ΠX is obtained from Π by deleting

1. each rule having a not A in its body with A ∈ X


and then

2. all negative atoms of the form not A


in the bodies of the remaining rules.

16
Some “logical” remarks

• Basic programs are also referred as definite clauses

• Definite clauses are disjunctions with exactly one positive atom


➥ A0 ∨ ¬A1 ∨ · · · ∨ ¬Am

• Horn clauses are clauses with at most one positive atom


➥ Every definite clause is a Horn clause but not vice versa

• Every set of Horn clauses has a (unique) smallest model.

• This smallest model is the intended semantics of a set of Horn


clauses.

☞ Given a basic program Π, Cn(Π) corresponds to the smallest model


of the set of definite clauses corresponding to Π.

17
Another “logical” remark

Answer sets versus (minimal) models

• Program {a ← not b} has answer set {a}.

• Clause a ∨ b (being equivalent to a ← ¬b)


– has models {a}, {b}, and {a, b},
– among which {a} and {b} are minimal.

☞ The negation-as-failure operator not makes a difference!

18
A first example

Π = {p ← p, q ← not p}

X Π ΠX Cn(ΠX )
∅ p ← p p ← p {q}
q ← not p q ←
{p} p ← p p ← p ∅
q ← not p
{q} p ← p p ← p {q}
q ← not p q ←
{p, q} p ← p p ← p ∅
q ← not p

19
A second example

Π = {p ← not q, q ← not p}

X Π ΠX Cn(ΠX )
∅ p ← not q p ← {p, q}
q ← not p q ←
{p} p ← not q p ← {p}
q ← not p
{q} p ← not q {q}
q ← not p q ←
{p, q} p ← not q ∅
q ← not p

20
A third example

Π = {p ← not p}

X Π ΠX Cn(ΠX )
∅ p ← not p p ← {p}
{p} p ← not p ∅

☞ A program may have zero, one, or multiple answer sets!

21
A closer look at Cn
Inductive characterization

Let Π be a basic program and X a set of atoms.

• The immediate consequence operator TΠ is defined as follows:

TΠ X = {head (r) | r ∈ Π and body(r) ⊆ X}

• Iterated applications of TΠ are written as TΠj for j ≥ 0,


where TΠ0 X = X and TΠi X = TΠ TΠi−1 X for i ≥ 1.

i
S
Theorem Cn(Π) = i≥0 Π ∅
T for any basic program Π.

Proposition X ⊆ Y implies TΠ X ⊆ TΠ Y for any basic program Π.


➥ In other words, TΠ is monotone.

22
Let’s iterate TΠ

Π = {p ←, q ←, r ← p, s ← q, t, t ← r, u ← v}

TΠ0 ∅ = ∅
TΠ1 ∅ = {p, q} = TΠ TΠ0 ∅ = TΠ (∅)
TΠ2 ∅ = {p, q, r} = TΠ TΠ1 ∅ = TΠ ({p, q})
TΠ3 ∅ = {p, q, r, t} = TΠ TΠ2 ∅ = TΠ ({p, q, r})
TΠ4 ∅ = {p, q, r, t, s} = TΠ TΠ3 ∅ = TΠ ({p, q, r, t})
TΠ5 ∅ = {p, q, r, t, s} = TΠ TΠ4 ∅ = TΠ ({p, q, r, t, s})
TΠ6 ∅ = {p, q, r, t, s} = TΠ TΠ5 ∅ = TΠ ({p, q, r, t, s})

In fact, Cn(Π) = {p, q, r, t, s} is the smallest fixpoint of TΠ . That is,


TΠ {p, q, r, t, s} = {p, q, r, t, s} and TΠ X 6= X for every X ⊆ {p, q, r, t, s}.
23
Programs with Variables
Let Π be a logic program.

Herbranduniverse U Π : Set of constants in Π

Herbrandbase B Π : Set of (variable-free) atoms constructible from U Π


☞ We usually denote this as A.
Ground Instances of r ∈ Π : Set of variable-free rules obtained by
replacing all variables in r by elements from U Π :

ground (r) = {rθ | θ : var (r) → U Π }

where var (r) stands for the set of all variables occuring in r ;
θ is a (ground) substitution.
Ground Instantiation of Π

ground (Π) = {ground (r) | r ∈ Π}

24
An example

Π = { r(a, b) ←, r(b, c) ←, t(X, Y ) ← r(X, Y ) }

UΠ = {a, b, c}
 
 r(a, a), r(a, b), r(a, c), r(b, a), r(b, b), r(b, c), r(c, a), r(c, b), r(c, c), 
BΠ =
 t(a, a), t(a, b), t(a, c), t(b, b), t(b, b), t(b, c), t(c, b), t(c, b), t(c, c) 

 


 r(a, b) ← , 



 

 r(b, c)


 ← , 



ground (Π) = t(a, a) ← r(a, a), t(b, a) ← r(b, a), t(c, a) ← r(c, a),

 

t(a, b) ← r(a, b), t(b, b) ← r(b, b), t(c, b) ← r(c, b), 

 

 


 

 t(a, c) ← r(a, c), t(b, c) ← r(b, c), t(c, c) ← r(c, c) 

25
Answer sets of programs with Variables

Let Π be a normal logic program with variables.

We define a set X of (ground) atoms as an answer set of Π


if Cn(ground (Π)X ) = X .

26
Programs with Integrity Constraints
Purpose Integrity constraints eliminate unwanted candidate solutions

Syntax An integrity constraints is of the form

← A1 , . . . , Am , not Am+1 , . . . , not An ,

where n ≥ m ≥ 1, and each Ai (1 ≤ i ≤ n) is a atom.

Example ← monitor(21in), graphics(evil)


Implementation For a new symbol x, map

← A1 , . . . , Am , not Am+1 , . . . , not An


7→ x ← A1 , . . . , Am , not Am+1 , . . . , not An , not x

Another example Π = {p ← not q, q ← not p}


versus Π′ = {p ← not q, q ← not p, ← p}
versus Π′′ = {p ← not q, q ← not p, ← not p}

27
A first glance at algorithmics
Global parameters: Logic program Π and its set of atoms A:
answersetΠ (X, Y )
1. (X, Y ) ← propagationΠ (X, Y )
2. if (X ∩ Y ) 6= ∅ then fail
3. if (X ∪ Y ) = A then return(X)
4. Select A ∈ A \ (X ∪ Y )
5. answersetΠ (X ∪ {A}, Y )
6. answersetΠ (X, Y ∪ {A})

• (X, Y ) is supposed to be a 3-valued model such that X ⊆ Z and


Y ∩ Z = ∅ for any answer set Z of Π.
• Key operations: propagationΠ (X, Y ) and ’Select A ∈ A \ (X ∪ Y )’
• Worst case complexity: O(2|A| )

28
Modeling and Interpreting

Problem Solution(s)
6

Modeling Interpretation

?
Logic Program - Answer sets
Computation

29
Problem 7→ Logic Program

For solving a problem class P for a problem instance I ,


encode

1. the problem instance I as a set of facts C(I) and

2. the problem class P as a set of rules C(P),

such that the solutions to P for I can be (polynomially) extracted


from the answer sets of C(P) ∪ C(I).

30
n-colorability of graphs

Problem instance A graph (V, E).

Problem class Assign each vertex in V one of n colors such that no


two vertexes in V connected by an edge in E have the same color.

31
3–colorability of graphs

C(I) vertex(1) ← edge(1,2) ←


vertex(2) ← edge(2,3) ←
vertex(3) ← edge(3,1) ←
C(P) colored(V,r) ← not colored(V,b), not colored(V,g),
vertex(V)
colored(V,b) ← not colored(V,r), not colored(V,g),
vertex(V)
colored(V,g) ← not colored(V,r), not colored(V,b),
vertex(V),color(C)
← edge(V,U),
colored(V,C),colored(U,C)
Answer set { colored(1,r), colored(2,b), colored(3,g), . . . }

32
n-colorability of graphs
with n = 3

C(I) vertex(1) ← edge(1,2) ←


vertex(2) ← edge(2,3) ←
vertex(3) ← edge(3,1) ←
C(P) color(r) ← color(b) ← color(g) ←
colored(V,C) ← not othercolor(V,C),
vertex(V),color(C)
othercolor(V,C) ← colored(V,C’), C6=C’,
vertex(V),color(C),color(C’)
← edge(V,U),color(C),
colored(V,C),colored(U,C)
Answer set { colored(1,r), colored(2,b), colored(3,g), . . . }

33
n–colorability of graphs
with n = 3

C(I) vertex(1). vertex(2). vertex(3).


edge(1,2). edge(2,3). edge(3,1).

C(P) color(r). color(b). color(g).

colored(V,C) :- not othercolor(V,C),


vertex(V),color(C).
othercolor(V,C) :- colored(V,C1), C != C1,
vertex(V),color(C),color(C1).
:- edge(V,U),color(C),
colored(V,C),colored(U,C).

34
Let it run!

torsten@belle-ile 507 > lparse 3color.lp | smodels 0

smodels version 2.25. Reading...done


Answer: 1
Stable Model: colored(3,g) othercolor(2,g) othercolor(1,g)
othercolor(3,b) colored(2,b) othercolor(1,b) othercolor(3,r)
othercolor(2,r) colored(1,r) color(g) color(b) color(r)
edge(3,1) edge(2,3) edge(1,2) vertex(3) vertex(2) vertex(1)

35
Here’s the rest!

Answer: 2
Stable Model: colored(3,g) othercolor(2,g) othercolor(1,g) othercolor(3,b)
othercolor(2,b) colored(1,b) othercolor(3,r) colored(2,r) othercolor(1,r)
color(g) color(b) color(r) edge(3,1) edge(2,3) edge(1,2) vertex(3) vertex(2)
vertex(1)
Answer: 3
Stable Model: othercolor(3,g) colored(2,g) othercolor(1,g) colored(3,b)
othercolor(2,b) othercolor(1,b) othercolor(3,r) othercolor(2,r) colored(1,r)
color(g) color(b) color(r) edge(3,1) edge(2,3) edge(1,2) vertex(3) vertex(2)
vertex(1)
Answer: 4
Stable Model: othercolor(3,g) othercolor(2,g) colored(1,g) colored(3,b)
othercolor(2,b) othercolor(1,b) othercolor(3,r) colored(2,r) othercolor(1,r)
color(g) color(b) color(r) edge(3,1) edge(2,3) edge(1,2) vertex(3) vertex(2)
vertex(1)
Answer: 5
Stable Model: othercolor(3,g) colored(2,g) othercolor(1,g) othercolor(3,b)
othercolor(2,b) colored(1,b) colored(3,r) othercolor(2,r) othercolor(1,r)
color(g) color(b) color(r) edge(3,1) edge(2,3) edge(1,2) vertex(3) vertex(2)
vertex(1)
Answer: 6
Stable Model: othercolor(3,g) othercolor(2,g) colored(1,g) othercolor(3,b)
colored(2,b) othercolor(1,b) colored(3,r) othercolor(2,r) othercolor(1,r)
color(g) color(b) color(r) edge(3,1) edge(2,3) edge(1,2) vertex(3) vertex(2)
vertex(1)
False

36
And finally some statistics!

Duration: 0.010
Number of choice points: 5
Number of wrong choices: 5
Number of atoms: 28
Number of rules: 45
Number of picked atoms: 42
Number of forced atoms: 0
Number of truth assignments: 347
Size of searchspace (removed): 9 (0)

37
Basic Methodology

Generate and Test (or: Guess and Check) approach

Generator Generate potential candidates answer sets


(typically through non-deterministic constructs)

Tester Eliminate non-valid Candidates


(typically through integrity constraints)

38
Satisfiability

Problem instance A propositional formula φ.

Problem class Is there an assigment of propositional variables to true


and false such that a given forumla φ is true.

39
Satisfiability

Consider formula (a ∨ ¬b) ∧ (¬a ∨ b).

Generator Tester Answer set


a ← not â ← not a, b A1 = {a, b}
â ← not a ← a, not b A2 = {â, b̂}
b ← not b̂
b̂ ← not b

40
n-Queens Problem

A solution to n = 4 :

Q
Q
Q
Q

41
n-Queens in answer set programming
q(X, Y ) gives the legal positions of the queensa

q(X, Y ) ← not¬q(X, Y )
¬q(X, Y ) ← not q(X, Y )

← q(X, Y ), q(X ′ , Y ), X 6= X ′
← q(X, Y ), q(X, Y ′ ), Y 6= Y ′
← q(X, Y ), q(X ′ , Y ′ ), |X − X ′ | = |Y − Y ′ |, X 6= X ′ , Y 6= Y ′

← not hasq(X)
hasq(X) ← q(X, Y )

a regard ¬q(X, Y ) as an indepenedant auxiliary atom


42
n-Queens
(in the smodels language)

q(X,Y) :- d(X), d(Y), not negq(X,Y).


negq(X,Y) :- d(X), d(Y), not q(X,Y).

:- d(X), d(Y), d(X1), q(X,Y), q(X1,Y), X1 != X.


:- d(X), d(Y), d(Y1), q(X,Y), q(X,Y1), Y1 != Y.
:- d(X), d(Y), d(X1), d(Y1), q(X,Y), q(X1,Y1),
X != X1, Y != Y1, abs(X - X1) == abs(Y - Y1).

:- d(X), not hasq(X).


hasq(X) :- d(X), d(Y), q(X,Y).

d(1..queens).

43
n-Queens in answer set programming
(in disjunctive logic programming)

q(X, Y ) ∨ ¬q(X, Y ) ←

← q(X, Y ), q(X ′ , Y ), X 6= X ′
← q(X, Y ), q(X, Y ′ ), Y 6= Y ′
← q(X, Y ), q(X ′ , Y ′ ), |X − X ′ | = |Y − Y ′ |, X 6= X ′ , Y 6= Y ′
← not hasq(X)
hasq(X) ← q(X, Y )

44
n-Queens in answer set programming
(in nested logic programming)

q(X, Y ) ∨ not q(X, Y ) ←

← q(X, Y ), q(X ′ , Y ), X 6= X ′
← q(X, Y ), q(X, Y ′ ), Y 6= Y ′
← q(X, Y ), q(X ′ , Y ′ ), |X − X ′ | = |Y − Y ′ |, X 6= X ′ , Y 6= Y ′
← not hasq(X)
hasq(X) ← q(X, Y )

45
n-Queens (ctd)
(in the smodels language with cardinality constraints)

1 { q(X, Y ) } 1 ← d(X)
1 { q(X, Y ) } 1 ← d(Y )

← q(X, Y ), q(X ′ , Y ′ ), |X − X ′ | = |Y − Y ′ |, X 6= X ′ , Y 6= Y ′

d(1) ←
..
.
d(n) ←

46
n-Queens (ctd)
(in the smodels language with cardinality constraints)

1 { q(X,Y) : d(Y) } 1 :- d(X).


1 { q(X,Y) : d(X) } 1 :- d(Y).

:- d(X), d(Y), d(X1), d(Y1), q(X,Y), q(X1,Y1), X!=X1, Y!=Y1,


abs(X-X1) == abs(Y-Y1).

d(1..queens).

47
And the Performance . . . ?

torsten@belle-ile 506 > lparse -c queens=20 queens2.lp | smodels


smodels version 2.25. Reading...done
Answer: 1
Stable Model: d(1) d(2) d(3) d(4) d(5) d(6) d(7) d(8) d(9) d(10) d(11) d(12)
d(13) d(14) d(15) d(16) d(17) d(18) d(19) d(20) q(1,16) q(2,13) q(3,6) q(4,3)
q(5,15) q(6,19) q(7,1) q(8,4) q(9,9) q(10,11) q(11,8) q(12,10) q(13,17)
q(14,2) q(15,20) q(16,18) q(17,7) q(18,5) q(19,14) q(20,12)
True
Duration: 37.810
Number of choice points: 1471
Number of wrong choices: 1464
Number of atoms: 501
Number of rules: 10100
Number of picked atoms: 304305
Number of forced atoms: 14604
Number of truth assignments: 3111768
Size of searchspace (removed): 400 (0)

48
Planning
in the Blocksworld

Initial situation Goal situation

3 6
1 3 5 2 5
2 4 6 1 4

49
Initial Situation

const grippers=2.
const lasttime=3.

block(1..6).

% DEFINE
on(1,2,0).
on(2,table,0).
on(3,4,0).
on(4,table,0).
on(5,6,0).
on(6,table,0).

50
Goal Situation

% TEST
:- not on(3,2,lasttime).
:- not on(2,1,lasttime).
:- not on(1,table,lasttime).
:- not on(6,5,lasttime).
:- not on(5,4,lasttime).
:- not on(4,table,lasttime).

51
Planning in the Blocksworld I
GENERATE

time(0..lasttime).

location(B) :- block(B).
location(table).

% GENERATE
{ move(B,L,T) : block(B) : location(L) } grippers :- time(T),
T<lasttime.

52
Planning in the Blocksworld II
DEFINE

% effect of moving a block


on(B,L,T+1) :- move(B,L,T),
block(B), location(L), time(T), T<lasttime.

% inertia
on(B,L,T+1) :- on(B,L,T), not neg_on(B,L,T+1),
location(L), block(B), time(T), T<lasttime.

% uniqueness of location
neg_on(B,L1,T) :- on(B,L,T), L!=L1,
block(B), location(L), location(L1), time(T).

53
Planning in the Blocksworld III
TEST

% neg_on is the negation of on


:- on(B,L,T), neg_on(B,L,T),
block(B), location(L), time(T).

% two blocks cannot be on top of the same block


:- 2 { on(B1,B,T) : block(B1) },
block(B), time(T).

% a block can’t be moved unless it is clear


:- move(B,L,T), on(B1,B,T),
block(B), block(B1), location(L), time(T), T<lasttime.

% a block can’t be moved onto a block that is being moved also


:- move(B,B1,T), move(B1,L,T),
block(B), block(B1), location(L), time(T), T<lasttime.

54
The Plan

torsten@hoedic 538 > lparse blocks.lp | smodels


smodels version 2.25. Reading...done
Answer: 1
Stable Model: move(1,table,0) move(3,table,0)
move(2,1,1) move(5,4,1)
move(3,2,2) move(6,5,2)
Duration: 0.050
Number of choice points: 0
Number of wrong choices: 0
Number of atoms: 507
Number of rules: 3026
Number of picked atoms: 24
Number of forced atoms: 13
Number of truth assignments: 944
Size of searchspace (removed): 0 (0)

55
Action description languages
zB. A (Gelfond & Lifschitz, 1990)

move(b,l) causes on(b,l)


inertial on(b,l)

represents

% effect of moving a block


on(B,L,T+1) :- move(B,L,T),
block(B), location(L), time(T), T<lasttime.

% inertia
on(B,L,T+1) :- on(B,L,T), not neg_on(B,L,T+1),
location(L), block(B), time(T), T<lasttime.

56
Configuration

computer(desktop) ←
{ hard-drive(ide), hard-drive(scsi) } ← computer(x)
keyboard(us) ∨ keyboard(german) ← computer(x)
controller(scsi) ← hard-drive(scsi)
← monitor(21in) ∧ graphics(evil)

(Syrjänen, 99) describes a Configurator for Corel Linux!

57
Disjunctive logic programs

• Syntax

• Semantics

• Examples

58
Disjunctive logic programs

• A disjunctive rule, r , is an ordered pair of the form

A1 ; . . . ; Am ← Am+1 , . . . , An , not An+1 , . . . , not Ao ,

where o ≥ n ≥ m ≥ 0, and each Ai (0 ≤ i ≤ o) is a atom.

• A disjunctive logic program is a finite set of disjunctive rules.

• (Generalized) Notation
head (r) = {A1 , . . . , Am }
body(r) = {Am+1 , . . . , An , not An+1 , . . . , not Ao }
body + (r) = {Am+1 , . . . , An }
body − (r) = {An+1 , . . . , Ao }

• A program is called positive if body − (r) = ∅ for all its rules.

59
Answer sets

Positive programs
• A set of atoms X is closed under a positive program Π iff
for any r ∈ Π, head (r) ∩ X 6= ∅ whenever body + (r) ⊆ X .
• The set of all ⊆-minimal sets of atoms being closed under a
positive program Π is denoted by min⊆ (Π).

Disjunctive programs
• The reduct, ΠX , of a disjunctive program Π relative to a set X
of atoms is defined by

ΠX = {head (r) ← body + (r) | r ∈ Π and body − (r) ∩ X = ∅}.

• A set X of atoms is an answer set of a disjunctive program Π if


X ∈ min⊆ (ΠX ).

60
A “positive” example

 
 a ← 
Π=
 b ;c ← a 

• The sets {a, b}, {a, c}, and {a, b, c} are closed under Π.

• We have min⊆ (Π) = { {a, b}, {a, c} }.

61
3-colorability revisited

C(I) vertex(1) ← edge(1,2) ←


vertex(2) ← edge(2,3) ←
vertex(3) ← edge(3,1) ←
C(P) colored(V,r); colored(V,b); colored(V,g) ← vertex(V)
← edge(V,U), colored(V,C), colored(U,C)
Answer set { colored(1,r), colored(2,b), colored(3,g), . . . }

62
An example with variables

 
 a(1, 2) ← 
Π =
 b(X) ; c(Y ) ← a(X, Y ), not c(Y ) 
 


 a(1, 2) ← 



 

 b(1) ; c(1)


 ← a(1, 1), not c(1) 



ground (Π) = b(1) ; c(2) ← a(1, 2), not c(2)

 

b(2) ; c(1) ← a(2, 1), not c(1)

 


 


 

 b(2) ; c(2) ← a(2, 2), not c(2) 

Clearly, for every answer set X of Π, we have a(1, 2) ∈ X


and {a(1, 1), a(2, 1), a(2, 2)} ∩ X = ∅.

63
An example with variables

 


 a(1, 2) ← 



 

 b(1) ; c(1)


 ← a(1, 1), not c(1) 



ground (Π)X = b(1) ; c(2) ← a(1, 2), not c(2)

 

b(2) ; c(1) ← a(2, 1), not c(1)

 


 


 

 b(2) ; c(2) ← a(2, 2), not c(2) 

• Consider X = {a(1, 2), b(1)}.

• We get min⊆ (ground (Π)X ) = { {a(1, 2), b(1)}, {a(1, 2), c(2)} }.

• X is an answer set of Π because X ∈ min⊆ (ground (Π)X )

64
An example with variables

 


 a(1, 2) ← 



 

 b(1) ; c(1)


 ← a(1, 1), not c(1) 



ground (Π)X = b(1) ; c(2) ← a(1, 2), not c(2)

 

b(2) ; c(1) ← a(2, 1), not c(1)

 


 


 

 b(2) ; c(2) ← a(2, 2), not c(2) 

• Consider X = {a(1, 2), c(2)}.

• We get min⊆ (ground (Π)X ) = { {a(1, 2)} }.

• X is no answer set of Π because X 6∈ min⊆ (ground (Π)X ).

65
Nested logic programs

• Syntax

• Semantics

• Examples

66
Nested logic programs

• Formulas are formed from


– propositional atoms and
– ⊤ and ⊥
using
– negation-as-failure (not),
– conjunction (,), and
– disjunction (;).

• A nested rule, r , is an ordered pair of the form F ← G


where F and G are formulas.

• A nested program is a finite set of rules.

• Notation: head (r) = F and body(r) = G.

67
Satisfaction relation
• The satisfaction relation X |= F between a set of atoms and a
formula F is defined recursively as follows:
– X |= F if F ∈ X for an atom F
– X |= ⊤,
– X 6|= ⊥,
– X |= (F, G) if X |= F and X |= G,
– X |= (F ; G) if X |= F or X |= G,
– X |= not F if X 6|= F .

• A set of atoms X satisfies a nested program Π, written X |= Π, iff


for any r ∈ Π, X |= head (r) whenever X |= body(r).
• The set of all ⊆-minimal sets of atoms satisfying program Π is
denoted by min⊆ (Π).

68
Reduct
• The reduct F X of a formula F relative to a set X of atoms is
defined recursively as follows:
– FX = F if F is an atom or ⊤ or ⊥,
– (F, G)X = (F X , GX ),
– (F ; G)X = (F X ; GX ),

 ⊥ if X |= F
– (not F )X =
 ⊤ otherwise

• The reduct, ΠX , of a nested program Π relative to a set X of


atoms is defined by
ΠX = {head (r)X ← body(r)X | r ∈ Π}.

• A set X of atoms is an answer set of a nested program Π if


X ∈ min⊆ (ΠX ).

69
Two examples

• Π1 = {(p ; not p) ←}
– For X = ∅, we get Π∅1 = {(p ; ⊤) ←} and min⊆ (Π∅1 ) = {∅}.
{p} {p}
– For X = {p}, we get Π1 = {(p ; ⊥) ←} and min⊆ (Π1 ) = {{p}}.

• Π2 = {p ← not not p}
– For X = ∅, we get Π∅2 = {p ← ⊥} and min⊆ (Π∅2 ) = {∅}.
{p} {p}
– For X = {p}, we get Π2 = {p ← ⊤} and min⊆ (Π2 ) = {{p}}.

• In general,
– F ← G, not not H is equivalent to F ; not H ← G
– F ; not not G ← H is equivalent to F ← not G, H
– not not not F is equivalent to not F
➥ Intuitionistic Logic HT (Heyting, 1930)

70
Some more examples

Π3 = {p ← (q, r) ; (not q, not s)}


Π4 = {(p ; not p), (q ; not q), (r ; not r) ←}
Π5 = {(p ; not p), (q ; not q), (r ; not r) ←, ⊥ ← p, q}

71
Implementation

nlp http://www.cs.uni-potsdam.de/~torsten/nlp

72
Language extensions

• Choice rules

• Cardinality constraints

• Weight constraints

• Semantics by embedding in Nested logic programs

73
Choice rules

Idea Choices over subsets

Syntax

{A1 , . . . , Am } ← Am+1 , . . . , An , not An+1 , . . . , not Ao ,

Informal meaning If the body is satisfied in an answer set,


then any subset of {A1 , . . . , Am } can be included in the answer set.

Example The program Π = { {a} ← b, b ←} has two answer sets: {b}


and {a, b}.

Implementation smodels

74
Cardinality constraints

Syntax A cardinality constraint is of the form l {A1 , . . . , Am } u

Informal meaning A cardinality constraint is satisfied in an answer set


X , if the number of atoms from {A1 , . . . , Am } satisfied in X is
between l and u (inclusive).
More formally, if l ≤ |{A1 , . . . , Am } ∩ X| ≤ u.

Conditions l {A1 , . . . , Am : Am+1 , . . . , An } u


where Am+1 , . . . , An are often used for type definitions of variables
occurring in A1 , . . . , Am .

Implementation smodels

75
n-colorability revisited
with n = 3

C(I) vertex(1) ← edge(1,2) ←


vertex(2) ← edge(2,3) ←
vertex(3) ← edge(3,1) ←
C(P) color(r) ← color(b) ← color(g) ←
1 {colored(V,C):color(C)} 1 ← vertex(V)
← edge(V,U),color(C),
colored(V,C),colored(U,C)
Answer set { colored(1,r), colored(2,b), colored(3,g), . . . }

76
Further extensions

Weight constraints
Syntax l {A1 : w1 , . . . , Am : wm } u
Informal meaning A weight constraint is satisfied in an answer set
X , if l ≤ ΣAi ∈X wi ≤ u.
Implementation smodels

Optimization
Syntax minimize {A1 : w1 , . . . , Am : wm }
Implementation smodels

77
Further extensions (cont’d)

Weak integrity constraints


Syntax :∼ A1 , . . . , Am , not Am+1 , . . . , not An [w : l]
Informal meaning
1. minimize the sum of weights of violated constraints in the
highest level;
2. minimize the sum of weights of violated constraints in the
next lower level;
3. etc
Implementation dlv

78
Embedding in nested logic programs

For formulas F, F1 , . . . , Fn , define

• ← F as ⊥ ← F

• {F1 . . . , Fn }c as (F1 ; not F1 ), . . . , (Fn ; not Fn )


➥ corresponds to choice over subsets (see above)

For example,
   
 {p, q}c ←   (p ; not p), (q ; not q) ← 
Π= stands for
 ← p, q   ⊥ ← p, q 

79
Embedding in nested logic programs (ctd)

For formulas F1 , . . . , Fn , define

• l {F1 , . . . , Fn } as
_
(Fi1 , . . . , Fil )
1≤i1 <...il ≤n

• {F1 , . . . , Fn } u as not (u + 1 {F1 , . . . , Fn })

• l {F1 , . . . , Fn } u as (l {F1 , . . . , Fn }), ({F1 , . . . , Fn } u)

80
An example

 
c


 {p, q, r} ← 


Π= ← 2 {p, q, r}

 

← {p, q, r} 0
 

 


 (p ; not p) ← 



 

 (q ; not


 q) ← 



stands for (r ; not r) ←

 

⊥ ← (p, q) ; (p, r) ; (q, r) 

 

 


 

 ⊥ ← not (p ; q ; r), 

Answer sets ? {p}, {q}, and {r} !


81
Embedding in nested logic programs (ctd)

For formulas F1 , . . . , Fn , define

• l {F1 , . . . , Fn }c as ({F1 , . . . , Fn }c , l {F1 , . . . , Fn } )

• {F1 , . . . , Fn }c u as ({F1 , . . . , Fn }c , {F1 , . . . , Fn } u)

• l {F1 , . . . , Fn }c u as ({F1 , . . . , Fn }c , l {F1 , . . . , Fn } u)


➥ corresponds to cardinality constraints (see above)

The program

1 {p, q, r}c 1 ←

has the same answer sets as the previous one.

82
A closer look

1 {p, q, r} 2 ← versus 1 {p, q, r}c 2 ←

1 {p, q, r} 2 ←
= (1 {p, q, r}), ({p, q, r} 2) ←
= (p ; q ; r), not (3 {p, q, r}) ←
= (p ; q ; r), not ( p, q, r ) ←

1 {p, q, r}c 2 ←
= 1 {p, q, r} 2, {p, q, r}c ←
= (p ; q ; r), not ( p, q, r ), ((p ; not p), (q ; not q), (r ; not r)) ←

83
A closer look (ctd)

(1 {p, q, r} 2 ←)X
= (1 {p, q, r} 2)X ←
= (p ; q ; r)X , (not ( p, q, r ))X ←
= (p ; q ; r), (not ( p, q, r ))X ←

(1 {p, q, r}c 2 ←)X


= (1 {p, q, r}c 2)X ←
= (1 {p, q, r} 2, {p, q, r}c )X ←
= (1 {p, q, r} 2)X , ({p, q, r}c )X ←
= (p ; q ; r), (not ( p, q, r ))X , ((p ; (not p)X ), (q ; (not q)X ), (r ; (not r)X )) ←

84
A closer look (ctd)
Consider X = {p, q}

(1 {p, q, r} 2 ←){p,q}
= (p ; q ; r), (not ( p, q, r )){p,q} ←
= (p ; q ; r), ⊤ ←
= (p ; q ; r) ←

(1 {p, q, r}c 2 ←){p,q}


= (p ; q ; r), (not ( p, q, r )){p,q} , ((p ; (not p){p,q} ),
(q ; (not q){p,q} ), (r ; (not r){p,q} )) ←
= (p ; q ; r), ⊤, ((p ; ⊥), (q ; ⊥), (r ; ⊤)) ←
= (p ; q ; r), (p, q) ←
= (p, q) ←

85
What about. . . ?

s ← 1 {p, q, r} 2 versus s ← 1 {p, q, r}c 2

Enjoy your exercise ⌣ !

86
Usage in lparse and smodels
In lparse and smodels,

• rule bodies may include


– l {F1 , . . . , Fn }
– {F1 , . . . , Fn } u
– l {F1 , . . . , Fn } u

• rule heads may include


– {F1 , . . . , Fn }c
– l {F1 , . . . , Fn }c
– {F1 , . . . , Fn }c u
– l {F1 , . . . , Fn }c u
c
– but dropping superscript

• For instance, ‘{p,q,r} :- {p,q,r} 2’ stands for {p, q, r}c ← {p, q, r} 2.

87
Algorithms & Systems: The Smodels approach

• Approximation

• Expansion

• Backtracking search

88
Approximating answer sets

First Idea Approximate an answer set X by two sets of atoms L and U


such that L ⊆ X ⊆ U .
➥ L and U constitute lower and upper bounds on X .
➥ L and (A \ U ) describe a 3-valued model of the program.

Properties Let X be an answer set of normal logic program Π.


• If L ⊆ X , then X ⊆ Cn(ΠL ).
• If X ⊆ U , then Cn(ΠU ) ⊆ X .
• If L ⊆ X ⊆ U , then L ∪ Cn(ΠU ) ⊆ X ⊆ U ∩ Cn(ΠL ).

89
Approximating answer sets (ctd)

Second Idea
Iterate
• Replace L by L ∪ Cn(ΠU )
• Replace U by U ∩ Cn(ΠL )
until L and U do not change anymore.

Observations
• At each iteration step
– L becomes larger (or equal)
– U becomes smaller (or equal)
• L ⊆ X ⊆ U is invariant for every answer set X of Π
• If L 6⊆ U , then Π has no answer set!
• If L = U , then L is an answer set of Π.

90
The basic expand algorithm

expand(L, U )
repeat
L′ ← L
U′ ← U

L ← L′ ∪ Cn(ΠU )
′ L′
U ← U ∩ Cn(Π )
if L 6⊆ U then return
until L = L′ and U = U ′

☞ Π is a global parameter!

91
Let’s expand!

 


 a← 


 
 b ← a, not c
 

Π=


 d ← b, not e 



 

 e ← not d 

′ ′
L′ Cn(ΠU ) L U′ Cn(ΠL ) U
1 ∅ {a} {a} {a, b, c, d, e} {a, b, d, e} {a, b, d, e}
2 {a} {a, b} {a, b} {a, b, d, e} {a, b, d, e} {a, b, d, e}
3 {a, b} {a, b} {a, b} {a, b, d, e} {a, b, d, e} {a, b, d, e}

➥ We have {a, b} ⊆ X and (A \ {a, b, d, e}) ∩ X = ({c} ∩ X) = ∅


for every answer set X of Π.

92
The basic expand algorithm (ctd)

expand

• tightens the approximation on answer sets

• is answer set preserving

• amounts to the well-founded semantics of a program


(see following lectures)

93
Let’s expand with d !
 


 a← 


 
 b ← a, not c
 

Π=


 d ← b, not e 



 

 e ← not d 

′ ′
L′ Cn(ΠU ) L U′ Cn(ΠL ) U
1 {d} {a} {a, d} {a, b, c, d, e} {a, b, d} {a, b, d}
2 {a, d} {a, b, d} {a, b, d} {a, b, d} {a, b, d} {a, b, d}
3 {a, b, d} {a, b, d} {a, b, d} {a, b, d} {a, b, d} {a, b, d}

➥ {a, b, d} is an answer set X of Π.

94
Let’s expand with “not d” !
 


 a← 


 
 b ← a, not c
 

Π=


 d ← b, not e 



 

 e ← not d 

′ ′
L′ Cn(ΠU ) L U′ Cn(ΠL ) U
1 ∅ {a, e} {a, e} {a, b, c, e} {a, b, d, e} {a, b, e}
2 {a, e} {a, b, e} {a, b, e} {a, b, e} {a, b, e} {a, b, e}
3 {a, b, e} {a, b, e} {a, b, e} {a, b, e} {a, b, e} {a, b, e}

➥ {a, b, e} is an answer set X of Π.

95
The basic smodels algorithm

smodels(L, U )
expand(L, U )
if L 6⊆ U then return
if L = U then exit with L
A ← select(U \ L)
smodels(L ∪ {A}, U )
smodels(L, U \ {A})

Call: smodels(∅, A) where A is the set of all atoms in Π

96
The basic smodels algorithm (ctd)

• Backtracking search building a binary search tree

• Choice points on atoms

• A node in the search tree corresponds to a 3-valued model

• The search space is pruned by


– making one choice at a time by appeal to a heuristics (select)
– the set of remaining choices is reduced and conflicts are
detected (expand)

• Low level implementation using Dowling-Gallier-type data


structures (see following lectures)

97
Outer system architecture

Two-phase implementation

1. lparse: Grounding (and handling of “special definitions”)

2. smodels: Answer set computation for ground programs

Running smodels:

UNIX> lparse demo.lp | smodels

More info:

• http://www.tcs.hut.fi/Software/smodels/

• lparse --help or smodels --help

• Try in particular lparse -t and smodels 0

98
What’s inside real smodels?

expand in smodels

• is based on propagation rules

• uses furthermore back-propagation

• generalizes the well-founded semantics

• ...

smodels in smodels

• is enhanced by lookahead (see next slide)

• uses smart heuristics

• ...

99
Lookahead
• Given a program Π, an atom A, and sets of atoms L and U
– if expand(L ∪ {A}, U ) yields a conflict, then delete A from U
– if expand(L, U \ {A}) yields a conflict, then add A to L

• Moreover, lookahead is used for determining the next atom A to


select (from U \ L in the smodels algorithm).
That is, provided that
– u+ = |U \ L| after expand(L ∪ {A}, U ) and
– u− = |U \ L| after expand(L, U \ {A})
then
u+ u−
h(A) = 2 +2

☞ Select an atom A with a minimal value of h(A)

100
Some remarks on lparse

• lparse accepts only domain-restricted programs

• In a program, predicates are (automatically) partitioned into


– domain predicates
∗ no choices
∗ no recursion “through” negation-as-failure
– non-domain predicates
∗ all others

• A rule is domain-restricted if each of its variables appears in a


positive domain predicate in its body.

• A program is domain-restricted if every rule is domain-restricted.

101
Examples for domain predicates

• Facts
– vertex(1). vertex(2). vertex(3).
– edge(1,2). edge(2,3). edge(3,1).
– color(1). color(2). color(3).

• Non-recursive rules
– two-edge(X,Y) :- edge(X,Z), edge(Z,Y), not edge(X,Y).

• Recursive rules
– path(X,Y) :- edge(X,Y).
– path(X,Y) :- edge(X,Z), path(Z,Y), vertex(Z).

102
Examples for domain-restricted rules

colored(V,r) :- not colored(V,b), not colored(V,g),


vertex(V)
colored(V,b) :- not colored(V,r), not colored(V,g),
vertex(V)
colored(V,g) :- not colored(V,r), not colored(V,b),
vertex(V)
:- edge(V,U), colored(V,C),colored(U,C),
color(C).

103
Domain-restricted programs
• Rules defining domain predicates have a single answer set.
This answer set can be computed very efficiently through database
techniques.
• Domain-restricted programs are grounded in two-steps:
1. Evaluate domain predicates;
2. Generate for each rule with variables a set of ground instances
that are compatible with the evaluation of domain predicates.
• Also, certain built-ins are supported. For instance,
– d(0..n)
– odd(X+1) :- d(X), X<n, not odd(X).
where n is either explicitly provided in the program by means of
const n=n or supplied through the command line option -c n=n to
lparse.

104
Algorithms & Systems: The noMoRe approach

• Exemplary proceeding

• Formal devices

• Coloring sequences

105
Motivation

Goal Characterize the computation of answer sets of logic programs.

Approach Use rule dependency graphs (RDGs) and their colorings.

Inspiration Proof theory, in particular, SLD derivations.

Outcome A series of operational characterizations of answer sets


in terms of operators on partial colorings.

106
Examplary proceeding

r1 : penguin(tweety) ←
r2 : bird(tweety) ←
r3 : f lies(tweety) ← bird(tweety), not ¬f lies(tweety)
r4 : ¬f lies(tweety) ← penguin(tweety), not f lies(tweety).

 
Propagation r~
1 r~
2 Propagation
 

?
 ?
Propagation r~
4  - r~
3 Choice
 
Buildingset
Coloring
Answer
X1 = {penguin(tweety), bird(tweety), f lies(tweety)} extraction
the graph

107
Examplary proceeding

r1 : penguin(tweety) ←
r2 : bird(tweety) ←
r3 : f lies(tweety) ← bird(tweety), not ¬f lies(tweety)
r4 : ¬f lies(tweety) ← penguin(tweety), not f lies(tweety).

 
r~
1 r~
2
 

?
 ?
r~
4  - r~
3
 
X2 = {penguin(tweety), bird(tweety), ¬f lies(tweety)}

108
Formal devices in a nutshell
Graphs The rule dependency graph (Π, E0 , E1 ) of program Π is a
labeled directed graph with
E0 = {(r, r ′ ) | r, r ′ ∈ Π, head (r) ∈ body + (r ′ )} (0-edges);
E1 = {(r, r ′ ) | r, r ′ ∈ Π, head (r) ∈ body − (r ′ )} (1-edges);

Colorings are partial functions C : Π → {⊕, ⊖};


➥ Admissible colorings are colorings characterizing answer sets;
Operators are partial functions O : C → C ;

Coloring sequences (C i )0≤i≤n ;


➥ Successful coloring sequences enjoy
• C 0 is the “empty” coloring
• O : C i 7→ C i+1 for 0 ≤ i ≤ n and some operator O
• C n is some admissible coloring

109
Rule dependency graph

• The rule dependency graph (RDG )

(Π, E0 , E1 )

of program Π, also written as ΓΠ , is a labeled directed graph with


E0 = {(r, r ′ ) | r, r ′ ∈ Π, head (r) ∈ body + (r ′ )} (0-edges);
E1 = {(r, r ′ ) | r, r ′ ∈ Π, head (r) ∈ body − (r ′ )} (1-edges).

110
An example

• Consider Π = {r1 , . . . , r6 }, where

r1 : p ←
r2 : b ← p
r3 : f ← b, not f ′
r4 : f ′ ← p, not f
r5 : b ← m
r6 : x ← f, f ′ , not x

• The RDG of Π is given as follows:


   
 (r , r ), (r , r ), (r , r ), 
1 2 1 4 2 3
ΓΠ =  Π, , {(r3 , r4 ), (r4 , r3 ), (r6 , r6 )} 
 (r3 , r6 ), (r4 , r6 ), (r5 , r3 ) 

111
An example (ctd)

 0 
r1 - r2
• Consider Π = {r1 , . . . , r6 }, where  

r1 : p ← 0 0

r2 : b ← p
?
 1 ?
r3 : f ← b, not f ′ r4  - r3
 
r4 : f ′ ← p, not f 6
r5 : b ← m 0 0 0
r6 : x ← f, f ′ , not x
?
 
r6  r5
 1 
• The RDG of Π is graphically given as: 

112
Coloring

• A coloring C of ΓΠ is a mapping C : Π → {⊕, ⊖}.

• Define

C⊕ = {r | C(r) = ⊕} and C⊖ = {r | C(r) = ⊖} .

We often identify a coloring C with the pair (C⊕ , C⊖ ).

• If C is total, (C⊕ , C⊖ ) is a binary partition of Π.


That is, Π = C⊕ ∪ C⊖ and C⊕ ∩ C⊖ = ∅.

• A partial coloring C induces a pair (C⊕ , C⊖ ) of sets such that


C⊕ ∪ C⊖ ⊆ Π and C⊕ ∩ C⊖ = ∅.

113
Coloring (ctd)

• For comparing partial colorings, C and C ′ , define

C ⊑ C′ if C⊕ ⊆ C⊕ ′ and C⊖ ⊆ C⊖ ′ .

• The “empty” coloring (∅, ∅) is the ⊑-smallest coloring.

• Accordingly, define

C ⊔ C′ as (C⊕ ∪ C⊕ ′ , C⊖ ∪ C⊖ ′ ) .

• We denote the set of all partial colorings of a RDG ΓΠ by CΓΠ .


☞ Or simply C if ΓΠ is clear from the context.

114
An example

 0 
r1~ - r~
2
 

0 0
• If C is a coloring of ΓΠ ,
we call the pair (ΓΠ , C) a colored RDG . ?
 ?
1
r4  - r3
 
6
• For example, “coloring” the RDG
0 0 0
of the previous program Π with
? 
C = ({r1 , r2 }, {r6 }) = (C⊕ , C⊖ )
r6~ r5
 1 
yields the following colored graph. 

115
Colorings representing answer sets

Given a logic program Π along with its RDG Γ .


Then, for every answer set X of Π, define a unique admissible coloring
C of Γ as

C = (RΠ (X), Π \ RΠ (X))

where

RΠ (X) = {r ∈ Π | body + (r) ⊆ X and body − (r) ∩ X = ∅} .

116
Auxiliary concepts

Let Γ = (Π, E0 , E1 ) be the RDG of logic program Π and C be a partial


coloring of Γ .
For r ∈ Π, define:

1. r is supported in (Γ, C), if body + (r) ⊆ {head (r ′ ) | (r ′ , r) ∈ E0 , r ′ ∈ C⊕ };

2. r is unsupported in (Γ, C), if {r ′ | (r ′ , r) ∈ E0 , head (r ′ ) = q} ⊆ C⊖ for


some q ∈ body + (r);

3. r is blocked in (Γ, C), if r ′ ∈ C⊕ for some (r ′ , r) ∈ E1 ;

4. r is unblocked in (Γ, C), if r ′ ∈ C⊖ for all (r ′ , r) ∈ E1 .

Whenever C is total, a rule is unsupported (or unblocked) iff it is not


supported (or not blocked, respectively).

117
Auxiliary concepts (ctd)

Let Γ be the RDG of program Π and C be a partial coloring of Γ .


We define

1. S(Γ, C) = {r ∈ Π | r is supported in (Γ, C)};

2. S(Γ, C) = {r ∈ Π | r is unsupported in (Γ, C)};

3. B(Γ, C) = {r ∈ Π | r is blocked in (Γ, C)};

4. B(Γ, C) = {r ∈ Π | r is unblocked in (Γ, C)}.

118
An example (ctd)

• Consider the sets obtained regarding the above colored RDG .


 0 
• We get:
r~
1 - r~
2
– S(ΓΠ , C) = {r1 , r2 , r3 , r4 }  
– S(ΓΠ , C) = {r5 } 0 0
– B(ΓΠ , C) = ∅
?
 1 ?
– B(ΓΠ , C) = {r1 , r2 , r5 , r6 }
r4  - r3
 
6
0 0 0
☞ Rules like r1 = p ← or r5 = b ← m
must be distinguished through
?
 
r~
6  r5
their “inner” structure!  1 


119
Relation to answer sets

Let C be the admissible coloring of Γ corresponding to answer set X of


Π.
For r ∈ Π, we have

1. r ∈ S(Γ, C) iff body + (r) ⊆ X ;

2. r ∈ S(Γ, C) iff body + (r) 6⊆ X ;

3. r ∈ B(Γ, C) iff body − (r) ∩ X 6= ∅;

4. r ∈ B(Γ, C) iff body − (r) ∩ X = ∅.

120
Relation to answer sets (ctd)
Let Γ be the RDG of logic program Π and C be a partial coloring of Γ .

If C is admissible, we have for the corresponding answer set X of Π that

1. S(Γ, C) ∩ B(Γ, C) = RΠ (X);

2. S(Γ, C) ∪ B(Γ, C) = Π \ RΠ (X).

For every answer set X of Π with

C⊕ ⊆ RΠ (X) and C⊖ ⊆ Π \ RΠ (X)

we have that

1. S(Γ, C) ∩ B(Γ, C) ⊆ RΠ (X);

2. S(Γ, C) ∪ B(Γ, C) ⊆ Π \ RΠ (X).

121
Propagation operator P

Let Γ be the RDG of logic program Π and C be a partial coloring of Γ .

• Define

PΓ : C → C

as

PΓ (C) = C ⊔ (S(Γ, C) ∩ B(Γ, C), S(Γ, C) ∪ B(Γ, C)) .

• A partial coloring C is closed under PΓ , if C = PΓ (C).

122
Propagation operator P (ctd)
• Define
PΓ∗ : C → C
where PΓ∗ (C) is
– the ⊑-smallest partial coloring
– containing C and
– being closed under PΓ .

• Alternatively, we have
G

PΓ (C) = P i (C)
i<ω

where
1. P 0 (C) = C and
2. P i+1 (C) = PΓ (P i (C)) for i < ω .

123
An example

r1 : p ← r3 : f ← b, not f ′ r5 : b ← m
r2 : b ← p r4 : f ′ ← p, not f r6 : x ← f, f ′ , not x

PΓ ((∅, ∅)) = (∅, ∅) ⊔ ({r1 } ∩ {r1 , r2 , r5 }, {r5 } ∪ ∅)


= ({r1 }, {r5 })
PΓ (({r1 }, {r5 })) = ({r1 }, {r5 }) ⊔ ({r1 , r2 , r4 } ∩ {r1 , r2 , r5 }, {r5 } ∪ ∅)
= ({r1 , r2 }, {r5 })
PΓ (({r1 , r2 }, {r5 })) = ({r1 , r2 }, {r5 }) ⊔ ({r1 , r2 , r3 , r4 } ∩ {r1 , r2 , r5 }, {r5 } ∪ ∅)
= ({r1 , r2 }, {r5 })
Hence, we obtain PΓ∗ ((∅, ∅)) = ({r1 , r2 }, {r5 }).

124
Propagation operator U

• Originally, U is defined in graph-theoretical terms by means of the


so-called “support graph”.a

• Alternative definition:
Define UΓ : C → C as

UΓ (C) = (C⊕ , C⊖ ∪ {r | body + (r) 6⊆ Cn((Π \ C⊖ )∅ )}) .

• For instance, for Π = {p ← q, q ← p}, we obtain

UΓ ((∅, ∅)) = (∅, {p ← q, q ← p}) ,

which is not obtainable through PΓ .

a Intuitively, support graphs constitute the graph-theoretical counterpart of Cn.

125
Choice operators

Let Γ be the RDG of logic program Π and C be a partial coloring of Γ .

• For ◦ ∈ {⊕, ⊖}, define CΓ◦ : C → C as


1. CΓ⊕ (C) = (C⊕ ∪ {r}, C⊖ ) for some r ∈ Π \ (C⊕ ∪ C⊖ );
2. CΓ⊖ (C) = (C⊕ , C⊖ ∪ {r}) for some r ∈ Π \ (C⊕ ∪ C⊖ ).

• For ◦ ∈ {⊕, ⊖}, define DΓ◦ : C → C as


1. DΓ⊕ (C) = (C⊕ ∪ {r}, C⊖ ) for some r ∈ S(Γ, C) \ (C⊕ ∪ C⊖ );
2. DΓ⊖ (C) = (C⊕ , C⊖ ∪ {r}) for some r ∈ S(Γ, C) \ (C⊕ ∪ C⊖ ).

126
All operators at a glance
• P and P ∗ :
– deterministic
– provide basic forward propagation
– P ∗ computes the closure under P
– P ∗ amounts to closure under Fitting’s operator (see below)
– P is reflexive, monotonic, and answer set preserving

• U and V :
– deterministic
– allow for detecting unsupported rules
– V is an incremental variant of U
– (PU)∗ amounts to well-founded semantics (see below)
– U is reflexive, idempotent, monotonic, and answer set preserving

127
All operators at a glance (ctd)

• N :
– deterministic
– colors all uncolored rules with ⊖
– Formally: NΓ (C) = (C⊕ , Π \ C⊕ ).

• C ◦ and D ◦ for ◦ ∈ {⊕, ⊖} :


– nondeterministic
– choose a rule and color it, either with ⊕ or ⊖
– D ◦ is restricted to choosing supported rules only

128
Operational answer set characterization I

Let Γ be the RDG of logic program Π and let C be a total coloring of Γ .


Then, C is an admissible coloring of Γ
iff
there exists a sequence (C i )0≤i≤n with the following properties:

1. C 0 = (∅, ∅);

2. C i+1 = CΓ◦ (C i ) for some ◦ ∈ {⊕, ⊖} and 0 ≤ i < n;

3. C n = PΓ (C n );

4. C n = UΓ (C n );

5. C n = C .

129
Operational answer set characterization II

Let Γ be the RDG of logic program Π and let C be a total coloring of Γ .


Then, C is an admissible coloring of Γ
iff
there exists a sequence (C i )0≤i≤n with the following properties:

1. C 0 = (PU)∗Γ ((∅, ∅));

2. C i+1 = (PU)∗Γ (CΓ◦ (C i )) for some ◦ ∈ {⊕, ⊖} and 0 ≤ i < n;

3. C n = C .

130
A coloring sequence according to II

r1 : p ← r3 : f ← b, not f ′ r5 : b ← m
r2 : b ← p r4 : f ′ ← p, not f r6 : x ← f, f ′ , not x

r1j r2j j
x j
x j
x j
x j
x j
x
0- 0- 0- 0-

0 0 0 0 0 0 0 0
? 1 ? ? 1 ? ? 1 ? ? 1 ?
j
r4  - j
r3 j
r4  - r3j j
r4  - j
x j
x - x
j
0 0 6
0 0 0 6
0 0 0 6
0 0 0 6
0
? ? ? ?
r6j r5j (PU)∗
r6j j
x ⊕
CΓ r6j j
x (PU)∗
j
x j
x
 1  1  1 1
Γ Γ
7−→ 7−→ 7−→

131
Operational answer set characterization V

Let Γ be the RDG of logic program Π and let C be a total coloring of Γ .


Then, C is an admissible coloring of Γ
iff
there exists a sequence (C i )0≤i≤n with the following properties:

1. C 0 = PΓ∗ ((∅, ∅));

2. C i+1 = PΓ∗ (DΓ◦ (C i )) where ◦ ∈ {⊕, ⊖} and 0 ≤ i < n − 1;

3. C n = NΓ (C n−1 );

4. C n = PΓ (C n );

5. C n = C .

☞ This is the basic strategy of the noMoRe system!


132
Summary of operational characterizations

Formation Check Properties Properties


Process Prefix sequences
I ◦ ]k
[CΓ PΓ , UΓ 1–5 1–3
II ◦ ]k ◦ (PU)∗
[(PU)∗Γ ◦ CΓ Γ − 1–7 1–3,5–7
⊕ k
II+ [(PU)∗Γ ◦ CΓ ] ◦ (PU)∗Γ − 1–7 1–3,5–7
⊖ k
II− [(PU)∗Γ ◦ CΓ ] ◦ (PU)∗Γ − 1–7 1–3,5–7
⊕ k
III+ UΓ ◦ PΓ∗ ◦ [CΓ ] − 1–5 1–3,5
⊖ k
III− PΓ∗ ◦ [CΓ ] − 1–5 1–3,5
IV ◦ ]k
NΓ ◦ [DΓ PΓ 1–5,8 1–3,5,8
⊕ k
IV+ NΓ ◦ [DΓ ] PΓ 1–5,8–9 1–3,5,8–9
V NΓ ◦ [PΓ∗ ◦ DΓ
◦ ]k ◦ P ∗
Γ PΓ 1–8 1–3,5–8
⊕ k
V+ NΓ ◦ [PΓ∗ ◦ DΓ ] ◦ PΓ∗ PΓ 1–9 1–3,5–9
VI [(PV)∗Γ ◦ DΓ
◦ ]k ◦ (PV)∗
Γ − 1–8 1–3,5–8
⊕ k
VI+ [(PV)∗Γ ◦ DΓ ] ◦ (PV)∗Γ − 1–9 1–3,5–9
⊖ k
VI− [(PV)∗Γ ◦ DΓ ] ◦ (PV)∗Γ − 1–8 1–3,5–8

133
The noMoRe system

• System architecture

• Coloring strategy and algorithm

• Visualizing color sequences

• Extensions

• Future development

134
System architecture

input parser . transformations . coloring output


.. ..
visualizer

grounder daVinci

System architecture of the non-monotonic reasoning system noMoRe.

135
Computing answer sets

Computation of answer sets (in general) consists of

1. deterministic part: extends a partial (answer set) graph coloring in


a reasonable way as much as possible. Only consistent operations
are performed. For example, facts have to be in the answer set.

2. non-deterministic part: extends a partial (answer set) graph


coloring, which cannot be extended deterministicly, in a systematic
(possibly inconsistent) way. For example, a rule (a ← not a ) must be
considered as applied and non-applied.

☞ see definitions of the different operators and results on coloring


sequences
☞ the non-deterministic part is subject of heuristics
☞ see the smodels algorithm including expand

136
The basic coloring strategy of noMoRe
☞ Recall the basic strategy of the noMoRe system:
Let Γ be the RDG of logic program Π and let C be a total coloring of Γ .
Then, C is an admissible coloring of Γ
iff
there exists a sequence (C i )0≤i≤n with the following properties:

1. C 0 = PΓ∗ ((∅, ∅));

2. C i+1 = PΓ∗ (DΓ◦ (C i )) where ◦ ∈ {⊕, ⊖} and 0 ≤ i < n − 1;

3. C n = NΓ (C n−1 );

4. C n = PΓ (C n );

5. C n = C .

☞ How to implement this strategy?


137
Implementation: Main algorithm I

☞ code simplified, but very close to the implementation

a_color( Col ) :- % Col is modified during computation


pre_color(Col,CP),
!,
color_cp(CP,Col),
color_rest(Col).

pre_color( Col, CP ) :-
facts(Fs),q_facts(QF),
color_all_1(Fs,Col,QF,CP1),
loops_1(L1),
color_all_0(L1,Col,CP1,CP).

138
Implementation: Main algorithm II

color_cp( CP, Col ) :-


heuristic_choose(Node,CP,CP1,Col),!,
( Node = no -> true;
( cp(Node,Col,[],NewCPs),
ord_union(NewCPs,CP1,CP2),
color_cp(CP2,Col)
)).

cp( Node, Col, CP1, CP2 ) :-


col_1(Node,Col,CP1,CP2).
cp( Node, Col, CP1, CP2 ) :-
col_0(Node,Col,CP1,CP2).

139
Implementation: Main algorithm III
☞ Missing predicates
• color_rest(Col) is true iff
all uncolored nodes can be colored ⊖ wrt Col and we obtain an
admissible coloring (see operator-NΓ ).
• color_all_1(Set,Col,InCP,OutCP) is true iff
all nodes in Set can be colored ⊕ wrt Col where OutCP is InCP plus
new possible choices (color_all_0\4 analog).
• facts\1, q_facts\1 and loop_1\1 give the respective rules.
Examples
– q_facts(h :- not b) is true (no positive body)
– loop_1(h :- a, not, b, not h) is true (self-blocking)
• heuristic_choose(Node,InCP,OutCP,Col) is true iff
Node is some heuristically chosen rule out of InCP;
OutCP contains remaining possible choices.
140
• col_1\1 and col_0\1 color a node ⊕ or ⊖, respectively, and
propagate the new coloring. If propagation fails col_1/0 fails!!

141
Implementation: Main algorithm IV

col_1( Node, Col, CP1, CP2 ) :-


arg(Node,Col,C),
((C == 1) -> CP1=CP2;
(C == u ->
(
setarg(Node,Col,1),
prop_1(Node,Col,CP1,CP2),
show(Node,1,Col)
);fail
)).

☞ How to compute prop_1/4 and prop_0/4?

142
Implementation: Propagation I

☞ Recall coloring sequence formation: C i+1 = PΓ∗ (DΓ◦ (C i )) where


◦ ∈ {⊕, ⊖}.
• For efficiency operators P and D are mixed together in the actual
implementation.

• Propagation is performed as local as possible. That is, whenever a


node is colored, its color is propagated to the direct successors of
that node.

• No need for global computation of S(Γ, C), S(Γ, C), B(Γ, C) and
B(Γ, C).
• Next possible choices are computed online during propagation.
• Propagation is performed recursively until no more nodes can be
colored by propagation.

143
Implementation: Propagation II

Let C be a partial coloring of ΓΠ (Π logic program) and let u ∈ Π be


some uncolored node wrt C . We have the following (local) forward
propagation cases:
1 1
1. prop (⊕ → u) 7→ (⊕ → ⊖) no condition
0 0
2. prop (⊕ → u) 7→ (⊕ → ⊕) if u ∈ S(Γ, C) ∪ B(Γ, C)
1 1
3. prop (⊖ → u) 7→ (⊖ → ⊕) if u ∈ S(Γ, C) ∪ B(Γ, C)
0 0
4. prop (⊖ → u) 7→ (⊖ → ⊖) if u ∈ S(Γ, C)

☞ prop_1\4 calls cases 1. and 2. whereas prop_0\4 calls cases 3. and 4.


0 0
☞ if prop (⊕ → u) 7→ (⊕ → ⊕) fails since u ∈ S(Γ, C) but u 6∈ B(Γ, C), then
u is collected as a new choice.

144
1 1
Propagation: prop(⊕ → u) 7→ (⊕ → ⊖)

Condition: no

1 r ⊖

⊕ r′

1 r ⊖

145
0 0
Propagation: prop(⊕ → u) 7→ (⊕ → ⊕)

Condition: r ∈ S(Γ, C) ∪ B(Γ, C)

1 r ′′ ⊖
⊕ ⊕
0
r ′ r 1

r ′′ ⊖

⊕ 1
0
r ′ r

r is new possible choice!!

146
1 1
Propagation: prop(⊖ → u) 7→ (⊖ → ⊕)

Condition: r ∈ S(Γ, C) ∪ B(Γ, C)

r ′′ ⊕
r ′′ ⊖
⊖ 0 1
1
r′ r ⊕ 1

1 r r ′′ ⊖

147
0 0
Propagation: prop(⊖ → u) 7→ (⊖ → ⊖)

Condition: r ∈ S(Γ, C)

r ′′ ⊖
⊖ ⊖ 0
0
r′ r 0

r ′′ ⊖

148
Implementation: Backward propagation I

Let C be a partial coloring of ΓΠ (Π logic program) and let u ∈ Π be


some uncolored node wrt C . We have the following (local) backward
propagation cases:
1 1
1. bprop (⊕ ← u) 7→ (⊕ ← ⊖) no condition
0 0
2. bprop (⊕ ← u) 7→ (⊕ ← ⊕) if first node is in B(Γ, C) and only u is
responsible for supporting the first one
1 1
3. bprop (⊖ ← u) 7→ (⊖ ← ⊕) if first node is in S(Γ, C) and only u is
responsible for blocking the first one
0 0
4. bprop (⊖ ← u) 7→ (⊖ ← ⊖) if first node is in B(Γ, C) and only u is
responsible for non-supporting the first one

☞ backward propagation is only necessary for choices and 1-loops and it


works recursively.
149
Backward propagation II

☞ For backward propagation we have to look at partial mappings


C : Π 7→ {⊖, ⊕, +} for graph coloring.
1 r ′′
0
1
r r′ 0

r ′′

☞ All + colored nodes have to be colored ⊕ in order to end with an


admissible coloring.

150
1 1
Backward propagation: bprop (⊕ ← u) 7→ (⊕ ← ⊖)

Condition: no

1 r ⊖

⊕ r′

1 r ⊖

151
0 0
Backward propagation: bprop (⊕ ← u) 7→ (⊕ ← ⊕)

Condition: r ′ ∈ B(Γ, C)

r ′′ ⊖
1 0
0
⊕ r ′ r + 0
0
1 r ′′
r ′′ ⊖

152
1 1
Backward propagation: bprop (⊖ ← u) 7→ (⊖ ← ⊕)

Condition: r ′ ∈ S(Γ, C)


r ′′ ⊖
0 1
1
⊖ r ′ r +
1

r ′′ ⊖

153
0 0
Backward propagation: bprop (⊖ ← u) 7→ (⊖ ← ⊖)

Condition: r ′ ∈ B(Γ, C)

⊖ 1 0 r ⊖

r′

⊖ 1 0 r ⊖

154
Backward propagation: Jumping

ra = a ← not a, not b, not d


rb = b ← not c
rc = c ← not b
rd = d ← not e
re = e ← not d 1
1 1
⊖ rb ra rd

1 1

rc re

155
Backward propagation: Experiments

noMoRe smodels
backprop no yes yes with (without)
jumping no no yes lookahead
ham k 7 14335 14335 2945 4814 (34077)
ham k 8 82200 82200 24240 688595 (86364)
ind cir 20 539 317 276 ∗ 276 (276)
ind cir 30 9266 5264 4609 ∗ 4609 (4609)
p1 step4 - 464 176 7 (69)
p2 step6 - 13654 3779 75 (3700)
col4x4 27680 27680 7811 7811 (102226)
col5x5 - - 580985 580985 (2.3 Mil)
queens4 84 84 5 1 (11)
queens5 326 326 13 9 (34)

156
Visualizing color sequences: An example

☞ noMoRe has an interface to the graph drawing tool daVinci, which


gives animated coloring sequences

r1 : b ← p
r2 : f ← b, not f ′
r3 : f′ ← p, not f
r4 : p ←
r5 : w ← b

157
daVinci V2.1 daVinci V2.1 daVinci V2.1

2
2
1

1
1
3

3
3
5
4

4
4

5
5
daVinci V2.1 daVinci V2.1 daVinci V2.1

2
2
2

1
1
1

3
3
3
5

4
4
4

5
5

158
daVinci V2.1 daVinci V2.1 daVinci V2.1

2
2
2

1
1
1

3
3
3
5

4
4
4

5
5

daVinci V2.1 daVinci V2.1 daVinci V2.1


2
2
2

1
1
1

3
3
3
5

4
4
4

5
5
Visualizing color sequences: An example
Extension: Transformations

☞ for dependency graphs

0 0
v v v v

159
Transformations: An example
r1 : a ← not b. r2 : b ← not a.
r3 : c ← a. r4 : c ← b. r5 : d ← c.

1 ⊕/⊖ ⊖/⊕
⊕/⊖ r1 r2 ⊖/⊕
1
r1 , r3 r2 , r4
0 0

⊕/⊖ r3 r4 ⊖/⊕ 0 0
r5
0 0 ⊕/⊕
r5

⊕/⊕
☞ no normal program with same answer sets corresponds to the
transformed graph.

160
Extension: Syntax

By suitable generalization of RDGs noMoRe is able to deal with


(ground) normal nested logic programs, that is, rule of the form

h1 , . . . , hk ← B1 ; . . . ; Bn (1)

where each Bi is a conjunction of default literals (“normal” body).

• p(a) and q(a, b) are propositional atoms


• conjunction and disjunction are allowed as in rule (1), for example
– a normal rule p(a) ← b, not c is represented by p(a) :- b, not c.
– a nested rule a, b ← (c, not d); (e) is represented by
a,b :- (c, not d);(e).
– a integrity constraint ← p, q is represented by :- p, q.

• lines beginning with a % are regarded as a comment lines

161
Extension: Transformations

☞ for logic programs

• all rules Πϕ ⊆ Π with head ϕ are transformed to one rule


ϕ ← B1 ; . . . ; Bn where body(Πϕ ) = {B1 , . . . , Bn }.

• all rules Πφ ⊆ Π with body φ are transformed to one rule


h1 , . . . , hn ← φ where head (Πφ ) = {h1 , . . . , hn }.

☞ Observe, that this program transformations can be applied since


noMoRe is able to deal with normal nested programs.

162
noMoRe ++

• C++ implementation

163
Extensions and future development

• heuristics for choices

• more transformations

• preferences between rules

• extension to disjunctive programs

164
Classical Negation ¬

• Motivation

• Semantics

• Translation

165
Motivation

• Given a set X , the difference among not a and ¬a amounts to:


a 6∈ X versus ¬a ∈ X

• Example

cross ← not train cross ← ¬ train


X = {cross} X=∅

• Two- versus Three-valued-interpretation of answer sets


For instance, given A = {a, b} and X = {a},
– b is false under a two-valued interpretation of X and
– b is undefined under a three-valued interpretation of X .

166
Literals

• A literal L is an atom A or its negation ¬A.

• Two literals A and ¬A are said to be complementary .

• A set of literals is inconsistent, if it contains a complementary pair


of literals, and consistent otherwise.

• A set of literals is logically closed if it is consistent or if it equals


the set of all literals.

167
Extended logic programs

• An extended rule, r , is an ordered pair of the form

L0 ← L1 , . . . , Lm , not Lm+1 , . . . , not Ln ,

where n ≥ m ≥ 0, and each Li (0 ≤ i ≤ n) is a literal.

• An extended logic program is a finite set of extended rules.

• Notations
head (r) = L0
body(r) = {L1 , . . . , Lm , not Lm+1 , . . . , not Ln }
body + (r) = {L1 , . . . , Lm }
body − (r) = {Lm+1 , . . . , Ln }

• A program is called basic if body − (r) = ∅ for all its rules.

168
Answer sets

• The smallest set of atoms which is logically closed and closed under
a basic program Π is denoted by Cn(Π).

• A set X of atoms is an answer set of a program Π if Cn(ΠX ) = X .

169
Back to normal logic programs

• Define A′ = {A′ | A ∈ A}.


• The mapping norm between extended and normal logic programs is
defined recursively as follows:
– norm(A) = A if A is an atom,
– norm(¬A) = A′ if A is an atom,
– norm(not L) = not norm(L) if L is a literal,
– norm(X) = {norm(L) | L ∈ X} if X is a set,
– norm(Π) = {norm(head (r)) ← norm(body(r)) | r ∈ Π}
plus the set Π⊥ of contradiction rules
– A ← B, B ′
– A′ ← B, B ′
for all distinct pairs A, B of atoms in A.

170
Properties of norm

• For any basic program Π,

norm(Cn(Π)) = Cn(norm(Π) ∪ Π⊥ )

• Let Π be an extended logic program and let X be a set of literals.


Then, we have that
X is an answer set of Π iff norm(X) is an answer set of norm(Π) ∪ Π⊥ .

• Let Π be an extended logic program and let X be a consistent set


of literals. Then, we have that
X is an answer set of Π iff norm(X) is an answer set of norm(Π).

171
An example

 

      p ← q, q 

 p ← not q  p ← not q 
   
 

  
  
  p′ ← q, q ′ 

Π= q ← not p norm(Π) ∪ Π⊥ = q ← not p ∪

     q ← p, p 
p′
     
¬p
      

 q ′ ← p, p′
 

• Π has answer set {q, ¬p}

• norm(Π) ∪ Π⊥ has answer set {q, p′ }

• norm(Π) has two answer sets {q, p′ } and {p, p′ }

172
Preferences

• Motivation

• Semantics

• Compilation

173
Motivation

The notion of preference in commonsense reasoning is pervasive.


For instance,

• in buying a car, one may prefer certain features over others;

• in scheduling, meeting some deadlines may be more important


than meeting others;

• in legal reasoning, laws are subject to higher principles, like


lex superior or lex posterior, which are themselves subject to
“higher higher” principles;

• etc etc . . .

174
Legal reasoning
The challenge!

“A person wants to find out if her security interest in a certain ship is perfected. She
currently has possession of the ship. According to the Uniform Commercial Code
(UCC, §9-305) a security interest in goods may be perfected by taking possession of
the collateral. However, there is a federal law called the Ship Mortgage Act (SMA)
according to which a security interest in a ship may only be perfected by filing a
financing statement. Such a statement has not been filed. Now the question is
whether the UCC or the SMA takes precedence in this case. There are two known
legal principles for resolving conflicts of this kind. The principle of Lex Posterior gives
precedence to newer laws. In our case the UCC is newer than the SMA. On the other
hand, the principle of Lex Superior gives precedence to laws supported by the higher
authority. In our case the SMA has higher authority since it is federal law.”

(Gordon, 1993)

175
Legal reasoning
Our solution in “ordered logic programming”

perfected :- name(ucc), possession, not neg perfected.


neg perfected :- name(sma), ship, neg finstatement, not perfected.

possession. ship. neg finstatement.

(Y < X) :- name(lex_posterior(X,Y)), newer(X,Y), not neg (Y < X).

(X < Y) :- name(lex_superior(X,Y)), state_law(X), federal_law(Y), not neg (X < Y).

newer(ucc,sma). federal_law(sma). state_law(ucc).

(lex_posterior(X,Y) < lex_superior(X,Y)).

176
What type of preference?

Different (often dependent) options:

• Preferences on rules
(versus preferences on literals
or preferences on answer sets)

• Selection function on the set of answer sets


(versus possible modification of answer sets)

• Complexity within NP
(versus complexity beyond NP)

177
How to express preferences?

Static preferences: Use an external order < .


Ordered logic program: (Π, <)
where Π is a logic program over L and
< is a strict partial order over Π ;

Dynamic preferences: Use a special-purpose predicate ≺ .


Ordered logic program: Π
where Π is a logic program over L ∪ {≺} containing
rules expressing that ≺ is a strict partial order.

Every statically ordered program can be expressed as a dynamically


ordered one.

178
An example

Consider the following ordered logic program (Π, <) with Π = {r1 , r2 , r3 }

r1 : ¬a ← and r3 < r2 .
r2 : b ← ¬a, not c
r3 : c ← not b

This program has two standard answer sets,

{¬a, b} and {¬a, c}

among which the green one is preferred.

179
How to define preferred answer sets?
for statically ordered logic programs

Let (Π, <) be an ordered program and let X be an answer set of Π.


Then, X is <-preserving, if X is either inconsistent, or else there exists
an enumeration hri ii∈I of RΠ (X) such that for all i, j ∈ I we have that:

1. body + (ri ) ⊆ {head (rj ) | j < i}; and

2. if ri < rj , then j < i; and

3. if ri < r ′ and r ′ ∈ Π \ RΠ (X), then


(a) body + (r ′ ) 6⊆ X or
(b) body − (r ′ ) ∩ {head (rj ) | j < i} =
6 ∅.

Recall: RΠ (X) = {r ∈ Π | body + (r) ⊆ X and body − (r) ∩ X = ∅}.


180
An example

Consider the statically ordered logic program

(Π, <) = ({r1 , r2 , r3 }, {r3 < r2 })

with

r1 = ¬a ←
r2 = b ← ¬a, not c
r3 = c ← not b

The (standard) program Π has two answer sets:

1. {¬a, b} is <-preserving; hr1 , r2 i satisfies (1) and (2).

2. {¬a, c} is not <-preserving, since hr1 , r3 i violates (3b).

181
Implementation
for dynamically ordered logic programs

Idea
Translate a logic program Π with preference information
into a regular logic program T (Π) such that
answers to T (Π) respect the preferences in Π.

Plan
1. Extend the language for expressing preference
2. Add axioms encoding specific preference handling strategies

182
(Dynamically) ordered logic programs
An ordered logic program is an extended logic program over a
propositional language L,
containing the following pairwise disjoint categories:
• a set N of terms serving as names for rules;
• a set A of regular (propositional) atoms of a program; and
• a set A≺ of preference atoms s ≺ t, where s, t ∈ N are names.

For each ordered program Π, we require a bijective function n(·)


assigning to each rule r ∈ Π a name n(r) ∈ N .
To simplify our notation, we write
• nr instead of n(r) or ni instead of nri and
• t : r instead of t = n(r).

183
Towards preferred answer sets

1. Introduce special purpose predicates controlling rule application:


ap(nr ) signifies that rule r is applicable wrt X , that is,
• body + (r) ⊆ X and
• body − (r) ∩ X = ∅.
bl(nr ) signifies that rule r is blocked wrt X , that is, either
• body + (r) 6⊆ X or
• body − (r) ∩ X 6= ∅.
ok(nr ) signifies that it is “ok” to consider rule r
2. Provide axioms that guarantee a consideration of rules that is in
accord with the underlying preference information, that is,
nr ≺ nr′ enforces that ok(nr′ ) is derivable “before” ok(nr )
3. Specify what it means that a rule “has been considered”

184
Translating ordered logic programs

Let Π = {r1 , . . . , rk } be an ordered logic program over L.


Let L⋆ be the language obtained from L by adding, for each r, r ′ ∈ Π,
new pairwise distinct propositional atoms

• ap(nr ),

• bl(nr ),

• ok(nr ), and

• rdy(nr , nr′ ).

Then, the logic program T (Π) over L⋆ contains the following rules,
(shown on the next slide)

185
Translating ordered logic programs (ctd)

For each r ∈ Π, where L+ ∈ body + (r), L− ∈ body − (r), and r ′ , r ′′ ∈ Π :

a1 (r) : head (r) ← ap(nr )


a2 (r) : ap(nr ) ← ok(nr ), body(r)
b1 (r, L) : bl(nr ) ← ok(nr ), not L+
b2 (r, L) : bl(nr ) ← ok(nr ), L−

c1 (r) : ok(nr ) ← rdy(nr , nr1 ), . . . , rdy(nr , nrk )


c2 (r, r ′ ) : rdy(nr , nr′ ) ← not(nr ≺ nr′ )
c3 (r, r ′ ) : rdy(nr , nr′ ) ← (nr ≺ nr′ ), ap(nr′ )
c4 (r, r ′ ) : rdy(nr , nr′ ) ← (nr ≺ nr′ ), bl(nr′ )

t(r, r ′ , r ′′ ) : nr ≺ nr′′ ← nr ≺ nr′ , nr′ ≺ nr′′


as(r, r ′ ) : ¬(nr′ ≺ nr ) ← nr ≺ nr′

186
An(other) example

Consider the following ordered logic program Π = {r1 , r2 , r3 , r4 }:

r1 = ¬a ←
r2 = b ← ¬a, not c
r3 = c ← not b
r4 = n3 ≺ n2 ← not d

where ni denotes the name of rule ri (i = 1, . . . , 4).


This program has two answer sets, {¬a, b, n3 ≺ n2 } and {¬a, c, n3 ≺ n2 }.

Only the first one, {¬a, b, n3 ≺ n2 }, preserves its contained preference,


given by n3 ≺ n2 .

187
Properties

Let (Π, <) be an ordered logic program and X a set of literals.

Soundness and correctness


X is a <-preserving answer set of Π
iff
X = Y ∩ L for some answer set Y of T (Π ∪ {(nr ≺ nr′ ) ←| r < r ′ }).
➥ One-to-one correspondence (actually holds).

Selection
If Y is an answer set of T (Π ∪ {(nr ≺ nr′ ) ←| r < r ′ }),
then Y ∩ L is an answer set of Π.

188
Implementation

plp http://www.cs.uni-potsdam.de/~torsten/plp

• Front-end to dlv and smodels

• Ordered logic programs


– with preferences (everywhere)
eg. n17 ≺ n42 ← n17 ≺ n34 , not (n42 ≺ n34 )
– with variables
eg. n1 (x) ≺ n2 (y) ← p(y), not (x = c)
– with disjunctive preferences
eg. (r2 ≺ r42 ) ∨ (r4 ≺ r42 ) ← ¬a

189
The example ran through plp

Ordered logic program Π = {r1 , r2 , r3 , r4 } :

r1 = ¬a ←
r2 = b ← ¬a, not c
r3 = c ← not b
r4 = n3 ≺ n2 ← not d

becomes

neg a.
b :- name(n2), neg a, not c.
c :- name(n3), not b.
(n3 < n2) :- not d.

190
The outcome
neg_a.
b :- ap(n2).
ap(n2) :- ok(n2), neg_a, not c.
bl(n2) :- ok(n2), not neg_a.
bl(n2) :- ok(n2), c.
c :- ap(n3).
ap(n3) :- ok(n3), not b.
bl(n3) :- ok(n3), b.
prec(n3, n2) :- not d.
ok(N) :- name(N), rdy(N, n2), rdy(N, n3).
rdy(N, M) :- name(N), name(M), not prec(N, M).
rdy(N, M) :- name(N), name(M), prec(N, M), ap(M).
rdy(N, M) :- name(N), name(M), prec(N, M), bl(M).
neg_prec(M, N) :- name(N), name(M), prec(N, M).
prec(N, M) :- name(N), name(M), name(O),
prec(N, O), prec(O, M).
false :- a, neg_a. false :- b, neg_b. false :- c, neg_c. false :- d, neg_d.
false :- name(N), name(M), prec(N, M), neg_prec(N, M).
name(n3). name(n2).

191
Computing preferred answer sets

?- lp2dlv(’Examples/example’).

yes
?- dlv(’Examples/example’).
dlv [build BEN/Apr 5 2000 gcc 2.95.2 19991024 (release)]

{name(n2), name(n3), neg_a, ok(n2), rdy(n2,n2), rdy(n2,n3), rdy(n3,n3),


prec(n3,n2), neg_prec(n2,n3), ap(n2), b, rdy(n3,n2), ok(n3), bl(n3)}

yes
?- dlv(’Examples/example’,nice).
dlv [build BEN/Apr 5 2000 gcc 2.95.2 19991024 (release)]

{neg_a, b}

yes
?-

192
Sokoban - Initial Information

• initial_at(X,Y)

• square(X,Y)

• initial_box(X,Y)

• target_square(X,Y)

193
Sokoban - Beginning and End

time(1..n).

at(X, Y, 1) :-
initial_at(X, Y).

has_box(X, Y, 1) :-
initial_box(X, Y).

% In the end, all target squares must have boxes:


compute { has_box(X, Y, n +1) : target_square(X, Y) }.

194
Sokoban - Has Box I

% A box ends where it is pushed to


has_box(X, Y, I+1) :-
move_to(X, Y, I),
move_square(X, Y),
time(I).

% A box moves away when pushed


-has_box(X, Y, I+1) :-
push(X, Y, Dir, I),
time(I),
has_neighbor(X, Y, Dir).

195
Sokoban - Has Box II

% A box stays at a place if not pushed


has_box(X, Y, I+1) :-
not -has_box(X, Y, I+1),
has_box(X, Y, I),
time(I),
move_square(X, Y).

% A box may not be pushed onto another


:- has_box(X, Y, I),
move_to(X, Y, I),
move_square(X, Y),
time(I).

196
Sokoban - Has Box III

% A box may not be pushed over another


:- has_box(X_2, Y_2, I),
push(X_1, Y_1, Dir, I),
move_to(X_3, Y_3, I),
time(I),
same_segment(X_1, Y_1, X_2, Y_2, Dir),
same_segment(X_2, Y_2, X_3, Y_3, Dir).

197
Sokoban - Move to

% A box ends at exactly one position along the push direction


1 { move_to(X_2, Y_2, I) : same_segment(X_1, Y_1, X_2, Y_2, Dir) } 1 :-
push(X_1, Y_1, Dir, I),
has_neighbor(X_1, Y_1, Dir),
time(I), I < n.

198
Sokoban - Pushing Boxes I

% A box may be pushed if it can be pushed:


{ push(X, Y, Dir, I) } :-
can_push(X, Y, Dir, I),
has_box(X, Y, I),
has_neighbor(X, Y, Dir),
possible_box(X, Y, I),
time(I).

% No two boxes may be pushed at one time


:- 2 { push(X, Y, Dir, I) :
move_square(X, Y) :
direction(Dir) },
time(I).

199
Sokoban - Pushing Boxes II

% A box can be pushed in a direction if the worker can reach it and


% there is space immediately behind the box
can_push(X, Y, east, I) :-
has_box(X, Y, I),
move_square(X, Y ; X+1, Y),
square(X-1, Y),
not has_box(X-1, Y, I),
not has_box(X+1, Y, I),
reachable(X-1, Y, I),
possible_box(X, Y, I),
time(I).

200
Sokoban - Moving Boxes

% We only try to move to places from where there is a route to a


% target location:
move_square(X, Y) :-
square(X, Y),
has_target_route(X, Y).

has_target_route(X, Y) :-
target_square(X, Y).

has_target_route(X, Y) :-
square(X, Y ; X+1, Y; X-1, Y),
has_target_route(X+1, Y).

usw.

201
Sokoban - Reachable

% The worker can reach all places that are not blocked.
reachable(X, Y, I) :-
square(X, Y),
time(I),
at(X, Y, I).

reachable(X+1, Y, I) :-
square(X, Y ; X+1, Y),
time(I),
reachable(X, Y, I),
not has_box(X+1, Y, I).

usw.

202
Sokoban - Has Neighbor

% When squares have neighbors:


has_neighbor(X, Y, east) :-
move_square(X, Y ; X +1, Y).
usw.

203
Sokoban - Improvements I

% Check if goal is reached:


goal(I) :-
{ not has_box(X, Y, I) : target_square(X, Y) } 0,
time(I).

% Do not push after goal is reached:


:- 1 { move_to(X, Y, I) : move_square(X, Y) },
time(I),
goal(I).

204
Sokoban - Improvements II

% The final move has to be to a target square:


1 { move_to(X_2, Y_2, n) : same_segment(X_1, Y_1, X_2, Y_2, Dir) :
target_square(X_2, Y_2) } 1 :-
push(X_1, Y_1, Dir, n),
has_neighbor(X_1, Y_1, Dir).

% A box may not be pushed twice to the same direction:


:- push_dir(Dir, I),
move_to(X, Y, I),
push(X, Y, Dir, I),
has_neighbor(X, Y, Dir),
time(I).

205
Sokoban - Improvements III

% no immediate undoing of a move, if reachable doesn’t change


:- push(X, Y, west, I),
push_dir(east, I),
move_to(X, Y, I+1),
time(I), I < n,
has_neighbor(X, Y, west),
reachable(X-2, Y, I).

usw.

206
Sokoban - Improvements IV

% Don’t push two boxes adjacent each other along the edge.
:- edge_pair(X_1, Y_1, X_2, Y_2),
time(I),
has_box(X_1, Y_1, I),
has_box(X_2, Y_2, I).

edge_pair(X, Y, X+1, Y) :-
move_square(X, Y ; X+1, Y),
not target_square(X, Y),
not target_square(X+1, Y),
not square(X, Y-1),
not square(X+1, Y-1).

usw.

207
Sokoban - Improvements V

% Don’t push three boxes into a L-turn:


:- { target_square(X_1, Y_1),
target_square(X_2, Y_2),
target_square(X_3, Y_3) } 2,
l_turn(X_1, Y_1, X_2, Y_2, X_3, Y_3),
time(I),
has_box(X_1, Y_1,I),
has_box(X_2, Y_2,I),
has_box(X_3, Y_3,I).

l_turn(X,Y, X+1, Y, X+1, Y+1) :-


move_square(X, Y ; X+1, Y ; X+1, Y+1),
not square(X+1, Y).

208
Sokoban - Improvements VI

% Don’t form a 4-box square:


:- move_square(X, Y),
move_square(X+1,Y),
move_square(X+1, Y+1),
move_square(X, Y+1),
time(I),
not target_square(X, Y),
not target_square(X+1,Y),
not target_square(X+1, Y+1),
not target_square(X, Y+1),
has_box(X, Y, I),
has_box(X+1, Y, I),
has_box(X+1, Y+1, I),
has_box(X, Y+1, I).

209
Sokoban - Improvements VII

% Treat first two moves special because we know what moves are possible:
possible_box(X, Y, 1) :- initial_box(X, Y).

possible_box(X_2, Y_2, 2) :-
same_segment(X_1, Y_1, X_2, Y_2, Dir),
move_square(X_2, Y_2),
initial_box(X_1, Y_1).

possible_box(X, Y, 2) :-
initial_box(X, Y).

possible_box(X, Y, I) :-
time(I), I >= 3,
move_square(X, Y).

210
What is a configuration problem?

Product: consists of different components (configuration objects) that


interact in complex ways

Configuration model: collection of objects and relationships between


them

Constraints: restrict allowed object combinations in the model

Configuration: set of objects of the configuration model

Configuration process: find a configuration that satisfies given user


requirements in a given configuration model

211
Classes of configurations

Valid configuration: satisfies all constraints of the configuration model

Suitable configuration: is a valid configuration satisfying all user


requirements

Optimal configuration: is a suitable configuration satisfying some


optimal criteria

212
Debian GNU/Linux System

The Debian configuration model can be divided in two parts:

1. a database that stores information about the packages and their


relations as facts;

2. a set of inference rules that construct the valid configurations


using the facts stored in the database.

213
Database

package(P) software package P

depends(P1 ,P2 ) package P1 depends on package P2 (package P1


cannot be used if P2 is not installed)

conflicts(P1 ,P2 ) package P1 will not operate if P2 is installed

recommends(P1 ,P2 ) package P2 enhances the functionality of package


P1 in a significant way

214
Debian GNU/Linux System
Database

package(mail-reader1 )
package(mail-reader2 )
package(mail-extension)
package(mail-transport-agent)
depends(mail-reader1 , mail-transport-agent)
depends(mail-reader2 , mail-transport-agent)
depends(mail-extension, mail-reader1 )
conf licts(mail-reader1 , mail-reader2 )
recommends(mail-reader1 , mail-extension)

215
Inference Rules

in(P) package P is chosen to be in the configuration

justified(P) package P has some reasons to be in the configuration

user-exclude(P), user-include(P) representation of user requirements

216
Debian GNU/Linux System
Inference Rules

{in(P )} ← package(P ), justif ied(P )


← in(P1 ), depends(P1 , P2 ), not in(P2 )
← conf licts(P1 , P2 ), in(P1 ), in(P2 )
← user -include(P ), not in(P )
← user -exclude(P ), in(P )
justif ied(P ) ← user -include(P )
justif ied(P2 ) ← depends(P1 , P2 ), in(P1 )
justif ied(P2 ) ← recommends(P1 , P2 ), in(P1 )

217
Suitable configurations

Given a Debian configuration model CM , a set U of user requirements,


and a stable model M of CM ∪ U , a Debian configuration CM is a set of
packages

CM = {P | in(P ) ∈ M }

218
Debian GNU/Linux System
Logic program

package(mailreader1). depends(mailreader1,mailtransportagent).
package(mailreader2). depends(mailreader2,mailtransportagent).
package(mailextension). depends(mailextension,mailreader1).
package(mailtransportagent). recommends(mailreader1,mailextension).
conflicts(mailreader1,mailreader2).

{ in(P) } :- package(P), justified(P).


:- in(P1), depends(P1,P2), not in(P2).
:- conflicts(P1,P2),in(P1),in(P2).
:- userinclude(P), not in(P).
:- userexclude(P), in(P).
justified(P) :- userinclude(P).
justified(P2) :- depends(P1,P2), in(P1).
justified(P2) :- recommends(P1,P2), in(P1).

userinclude(mailreader1).

hide. show in(X).

219
Debian GNU/Linux System
Stable models

smodels version 2.27. Reading...done


Answer: 1
Stable Model: in(mailtransportagent) in(mailreader1)
Answer: 2
Stable Model: in(mailtransportagent) in(mailextension) in(mailreader1)

220
Debian GNU/Linux System
Logic program

package(mailreader1). depends(mailreader1,mailtransportagent).
package(mailreader2). depends(mailreader2,mailtransportagent).
package(mailextension). depends(mailextension,mailreader1).
package(mailtransportagent). recommends(mailreader1,mailextension).
conflicts(mailreader1,mailreader2).

{ in(P) } :- package(P), justified(P).


:- in(P1), depends(P1,P2), not in(P2).
:- conflicts(P1,P2),in(P1),in(P2).
:- userinclude(P), not in(P).
:- userexclude(P), in(P).
justified(P) :- userinclude(P).
justified(P2) :- depends(P1,P2), in(P1).
justified(P2) :- recommends(P1,P2), in(P1).

userinclude(mailreader2).

hide. show in(X).

221
Debian GNU/Linux System
Stable models

smodels version 2.27. Reading...done


Answer: 1
Stable Model: in(mailtransportagent) in(mailreader2)

222
Debian GNU/Linux System
Logic program
package(mailreader1). depends(mailreader1,mailtransportagent).
package(mailreader2). depends(mailreader2,mailtransportagent).
package(mailextension). depends(mailextension,mailreader1).
package(mailtransportagent). recommends(mailreader1,mailextension).
conflicts(mailreader1,mailreader2).

{ in(P) } :- package(P), justified(P).


:- in(P1), depends(P1,P2), not in(P2).
:- conflicts(P1,P2),in(P1),in(P2).
:- userinclude(P), not in(P).
:- userexclude(P), in(P).
justified(P) :- userinclude(P).
justified(P2) :- depends(P1,P2), in(P1).
justified(P2) :- recommends(P1,P2), in(P1).

userinclude(mailextension).
userinclude(mailreader2).

No stable models!
223
Diagnostic Model

Unsatisfiable requirements are diagnosed using a diagnostic model.


The diagnostic model is constructed from the configuration model by
adding a new set of atoms that represent the possible error conditions.
The diagnostic output also explains why each problematic component
was included in the configuration.
The constraint are modified in such way that the diagnostic model will
always have at least one stable model.

224
Diagnostic Model
New atoms

missing(P), in-conflict(P1 ,P2 ) denote error conditions

needs-reason(P) mark the packages that are in some way part of the
problem and thus needs an explanation

user-selected(P), needs(P1 ,P2 ) explain why certain packages were


taken into the configuration

225
Diagnosis

Given a Debian configuration model DM and a set U of user


requirements, a diagnosis D is a four-tuple D = (M, EM , PM , RM ), where

1. M is a stable model of DM ∪ U ;

2. EM is the error set

EM = {missing(P ) ∈ M } ∪ {in-conf lict(P1 , P2 ) ∈ M };

3. PM is the problem set

PM = {P | needs-reason(P ) ∈ M }; and

4. RM is the explanation set

RM = {user -selected(P ) ∈ M } ∪ {needs(P1 , P2 ) ∈ M }.

226
Modifying configuration models

We want that the diagnosis contains only those packages that have to
be in there so that it will be as small as possible.
Thus, remove rule

{in(P )} ← package(P ), justif ied(P ).

In addition, this ensures that no false alarms are caused by adding


unnecessary recommended packages in the configuration.

227
Missing Packages
Error set

missing(P ) denote that some package in the configuration depends on P


but for some reason P is not in the configuration.
Rule ← in(P1 ), depends(P1 , P2 ), not in(P2 ) is replaced by:

in(P2 ) ← in(P1 ), depends(P1 , P2 ), package(P2 )


missing(P2 ) ← in(P1 ), depends(P1 , P2 ), not package(P2 )
The first rule ensures that existing packages are added to the model,
the second rule marks non-existing packages as missing.
In addition, it may be the case that a package the user included is not
available. Hence, rule ← user -include(P ), not in(P ) is replaced by:

in(P ) ← user -include(P ), package(P )


missing(P ) ← user -include(P ), not package(P )

228
Conflicts
Error set

in-conf lict(P1 , P2 ) is used to model conflicts. in-conf lict(P1 , P2 ) is true


when P1 and P2 conflict with each other and they both have to be in the
configuration.
We replace rule ← conf licts(P1 , P2 ), in(P1 ), in(P2 ) with

in-conf lict(P1 , P2 ) ← conf licts(P1 , P2 ), in(P1 ), in(P2 ).

To handle the case where the user wants to leave out a package that
some other package needs, we replace the rule ← in(P ), user -exclude(P )
with

in-conf lict(P, user -exclude) ← in(P ), user -exclude(P ).

229
Justifications
needs-reason(P ) marks the packages we want to justify.
We add the rules
needs-reason(P ) ← missing(P )
needs-reason(P1 ) ← in-conf lict(P1 , P2 ), package(P1 )
needs-reason(P2 ) ← in-conf lict(P1 , P2 ), package(P2 )
needs-reason(P1 ) ← depends(P1 , P2 ), needs-reason(P2 ), in(P1 )

user -selected(P ) is true when the user chose P to be in the configuration.


needs(P1 , P2 ) is true if P2 was included because P1 depends on it. The
justifications can be modeled with the following rules:
user -selected(P ) ← needs-reason(P ), user -include(P )
needs(P1 , P2 ) ← needs-reason(P2 ), depends(P1 , P2 ), in(P1 )

230
Debian GNU / Linux System

in(P2 ) ← in(P1 ), depends(P1 , P2 ), package(P2 )


missing(P2 ) ← in(P1 ), depends(P1 , P2 ), not package(P2 )
in-conf lict(P1 , P2 ) ← conf licts(P1 , P2 ), in(P1 ), in(P2 )
in-conf lict(P, user-exclude) ← in(P ), user-exclude(P )
in(P ) ← user-include(P ), package(P )
missing(P ) ← user-include(P ), not package(P )
justif ied(P ) ← user-include(P )
justif ied(P2 ) ← depends(P1 , P2 ), in(P1 )
justif ied(P2 ) ← recommends(P1 , P2 ), in(P1 )
needs-reason(P ) ← missing(P )
needs-reason(P1 ) ← in-conf lict(P1 , P2 ), package(P1 )
needs-reason(P2 ) ← in-conf lict(P1 , P2 ), package(P2 )
needs-reason(P1 ) ← depends(P1 , P2 ), needs-reason(P2 ), in(P1 )
user-selected(P ) ← needs-reason(P ), user-include(P )
needs(P1 , P2 ) ← needs-reason(P2 ), depends(P1 , P2 ), in(P1 )

231
Stable Models

User requirements:

userinclude(mailextension). userinclude(mailreader2).

package(mailreader1). depends(mailreader1,mailtransportagent).
package(mailreader2). depends(mailreader2,mailtransportagent).
package(mailextension). depends(mailextension,mailreader1).
package(mailtransportagent). recommends(mailreader1,mailextension).
conflicts(mailreader1,mailreader2).

232
Stable Models
User requirements:

userinclude(mailextension). userinclude(mailreader2).
Stable Model: userinclude(mailreader2) userinclude(mailextension)
needs(mailextension,mailreader1)
in(mailreader1)
in(mailextension)
in(mailtransportagent)
in(mailreader2)
needsreason(mailreader1)
needsreason(mailreader2)
needsreason(mailextension)
userselected(mailreader2)
userselected(mailextension)
inconflict(mailreader1,mailreader2)

233
Debian GNU / Linux System
Diagnosis

Error set:
E = {in-conf lict(mail-reader1 , mail-reader2 )}

Problem set:
P = {mail-reader1 , mail-reader2 , mail-extension}

Explanation
 set: 
 user -selected(mail-reader2 ),

 


R= user -selected(mail-extension), .

 

needs(mail-extension, mail-reader1 )
 

234
Stable Models

User requirements:

userinclude(mailreader2).

Stable Model: in(mailtransportagent)


in(mailreader2)

E=P =R=∅

235
Configuration of a PC
A computer is configured using the following configuration model:

• a mass-memory {IDEdisk, SCSIdisk, f loppydrive},


• a keyboard {GermanlayoutKB, U KlayoutKB},
• a processor {P II, P III},
• a motherboard {AT X, I820},
• a graphics card gcard.

The following dependencies must be respected:

• SCSI disk requires an SCSI controller {SCSIcontroller},


• {P II} is incompatible with I820 and {P III} with AT X ,
• graphics card is needed, if motherboard contains none, {AT X}
contains one, {I820} does not.

236
Configuration Rule Language (CRL)

Rules are of the form


a1 θ . . . θal ← b1 , . . . , bm , not c1 , . . . not cn
where θ ∈ {|, ⊕}, a1 , . . . , an , b1 , . . . bm , c1 , . . . cn are atoms.
We have two types of disjunction:

|: ”normal or”

⊕: exclusive or

237
Configuration model of a PC

computer ←
IDEdisk | SCSIdisk | f loppydrive ← computer
GermanlayoutKB ⊕ U KlayoutKB ← computer
P II ⊕ P III ← computer
AT X ⊕ I820 ← computer
SCSIcontroller ← SCSIdisk
← P II, I820
← P III, AT X
gcard ← not gcardinmb
gcardinmb ← AT X

238
Satisfaction

A configuration C satisfies a set of rules R in CRL (C |= R) iff

1. If a1 | . . . | al ← b1 , . . . , bm , not c1 , . . . not cn ,
{b1 , . . . , bm } ⊆ C and {c1 , . . . , cn } ∩ C = ∅,
then {a1 , . . . al } ∩ C 6= ∅.

2. If a1 ⊕ . . . ⊕ al ← b1 , . . . , bm , not c1 , . . . not cn ,
{b1 , . . . , bm } ⊆ C and {c1 , . . . , cn } ∩ C = ∅,
then for exactly one a ∈ {a1 , . . . al }, a ∈ C .

239
Computation of configurations

Given a configuration C and a set of rules R, we denote by RC the set


of rules

{ai ← b1 , . . . bm : a1 θ . . . θal ← b1 , . . . , bm , not c1 , . . . not cn ∈ R,


θ ∈ {|, ⊕}, ai ∈ C, 1 ≤ i ≤ l,
{c1 , . . . , cn } ∩ C = ∅} ∪
{a ← b1 , . . . bm : a ← b1 , . . . , bm , not c1 , . . . not cn ∈ R,
{c1 , . . . , cn } ∩ C = ∅}.

The least model of RC is denoted by M M (RC ).


The configuration is R-valid iff C = M M (RC ) and C |= R.

240
Configuration of a PC

computer ←
IDEdisk | SCSIdisk | f loppydrive ← computer
GermanlayoutKB ⊕ U KlayoutKB ← computer
P II ⊕ P III ← computer
AT X ⊕ I820 ← computer
SCSIcontroller ← SCSIdisk
← P II, I820
← P III, AT X
gcard ← not gcardinmb
gcardinmb ← AT X
GermanlayoutKB ←

C1 = {computer, SCSIdisk, U KlayoutKB, P II, P III, gcard}

Configuration C1 is not R-valid.

241
Configuration of a PC

computer ←
IDEdisk | SCSIdisk | f loppydrive ← computer
GermanlayoutKB ⊕ U KlayoutKB ← computer
P II ⊕ P III ← computer
AT X ⊕ I820 ← computer
SCSIcontroller ← SCSIdisk
← P II, I820
← P III, AT X
gcard ← not gcardinmb
gcardinmb ← AT X
GermanlayoutKB ←
 
 computer, IDEdisk, GermanlayoutKB, P III, AT X, 
C2 =
 SCSIcontroller, gcardinmb 
Configuration C2 is not R-valid.

242
Configuration of a PC

computer ←
IDEdisk | SCSIdisk | f loppydrive ← computer
GermanlayoutKB ⊕ U KlayoutKB ← computer
P II ⊕ P III ← computer
AT X ⊕ I820 ← computer
SCSIcontroller ← SCSIdisk
← P II, I820
← P III, AT X
gcard ← not gcardinmb
gcardinmb ← AT X
GermanlayoutKB ←
 
 computer, SCSIdisk, GermanlayboutKB, P II, AT X, 
C3 =
 SCSIcontroller, gcardinmb 

243
Configuration of a PC
C3 |= R
Reduct RC3 :
computer ←
SCSIdisk ← computer
GermanlayoutKB ← computer
P II ← computer
AT X ← computer
SCSIcontroller ← SCSIdisk
← P II, I820
← P III, AT X
gcardinmb ← AT X
GermanlayoutKB ←

M M (RC3 ) = C3 .
Configuration C3 is R-valid.

244
Relationship to logic programming semantics

Let R be a set of rules in CRL. Let f, f ′ be atoms not appearing in R.


Include f ′ ← not f ′ , f .
For each rule a1 | . . . | al ← b1 , . . . , bm , not c1 , . . . not cn we include a rule
f ← b1 , . . . , bm , not c1 , . . . not cn , aˆ1 , . . . , âl
and for all i = 1, . . . , l, two rules
ai ← not aˆi , b1 , . . . , bm , not c1 , . . . not cn and aˆi ← not ai
where aˆ1 , . . . , âl are new atoms.
For each rule a1 ⊕ . . . ⊕ al ← b1 , . . . , bm , not c1 , . . . not cn we additionally
include
f ← b1 , . . . , bm , not c1 , . . . not cn , a′ , a′′
where a′ = ai and a′′ = aj for some i, j, 1 ≤ i < j ≤ l.

245
Configuration of a PC
translation of the rules

computer ←
stays unchanged.

246
Configuration of a PC
translation of the rules

f ′ ← not f ′ , f

IDEdisk | SCSIdisk | f loppydrive ← computer

f ← computer, IDEdisk′ , SCSIdisk′ , f loppydrive′


IDEdisk ← not IDEdisk′ , computer
IDEdisk′ ← not IDEdisk
SCSIdisk ← not SCSIdisk′ , computer
SCSIdisk′ ← not SCSIdisk
f loppydrive ← not f loppydrive′ , computer
f loppydrive′ ← not f loppydrive

247
Configuration of a PC
translation of the rules

GermanlayoutKB ⊕ U KlayoutKB ← computer

f ← computer, GermanlayoutKB ′ , U KlayoutKB ′


GermanlayoutKB ← not GermanlayoutKB ′ , computer
GermanlayoutKB ′ ← not GermanlayoutKB
U KlayoutKB ← not U KlayoutKB ′ , computer
U KlayoutKB ′ ← not U KlayoutKB
f ← computer, GermanlayoutKB, U KlayoutKB

248
Configuration of a PC
computer.
fp :- not fp, f.
f :- computer, nidedisk, nscsidisk, nfloppydrive.
idedisk :- not nidedisk, computer.
nidedisk :- not idedisk.
scsidisk :- not nscsidisk, computer.
nscsidisk :- not scsidisk.
floppydrive :- not nfloppydrive, computer.
nfloppydrive :- not floppydrive.
f:- computer, ngermanlayoutKB, nuklayoutKB.
germanlayoutKB :- not ngermanlayoutKB, computer.
ngermanlayoutKB :- not germanlayoutKB.
uklayoutKB :- not nuklayoutKB, computer.
nuklayoutKB :- not uklayoutKB.
f :- computer, germanlayoutKB, uklayoutKB.
f:- computer, npII, npIII. f :- computer, natx, ni820.
pII :- not npII, computer. atx :- not natx, computer.
npII :- not pII. natx :- not atx.
pIII :- not npIII, computer. i820 :- not ni820, computer.
npIII :- not pIII. ni820 :- not i820.
f :- computer, pII, pIII. f :- computer, atx, i820.
scsicontroller :- scsidisk.
:- pII, i820.
:- pIII, atx.
gcard :- not gcardinmb.
gcardinmb :- atx.
germanlayoutKB.

hide.
show computer,
idedisk,scsidisk,floppydrive,germanlayoutKB,uklayoutKB,pII,pIII,atx,i820,scsicontroller,gcard,gcardinmb.

249
Configuration of a PC
smodels version 2.27. Reading...done
Answer: 1
Stable Model: gcard i820 pIII germanlayoutKB idedisk computer
Answer: 2
Stable Model: gcard scsicontroller scsidisk i820 pIII germanlayoutKB idedisk computer
Answer: 3
Stable Model: gcard scsicontroller scsidisk i820 pIII germanlayoutKB floppydrive idedisk computer
Answer: 4
Stable Model: gcard i820 pIII germanlayoutKB floppydrive idedisk computer
Answer: 5
Stable Model: gcard i820 pIII germanlayoutKB floppydrive computer
Answer: 6
Stable Model: gcard scsicontroller scsidisk i820 pIII germanlayoutKB floppydrive computer
Answer: 7
Stable Model: gcard scsicontroller scsidisk i820 pIII germanlayoutKB computer
Answer: 8
Stable Model: gcardinmb atx scsicontroller scsidisk pII germanlayoutKB computer
Answer: 9
Stable Model: gcardinmb atx pII germanlayoutKB idedisk computer
Answer: 10
Stable Model: gcardinmb atx scsicontroller scsidisk pII germanlayoutKB idedisk computer
Answer: 11
Stable Model: gcardinmb atx scsicontroller scsidisk pII germanlayoutKB floppydrive idedisk computer
Answer: 12
Stable Model: gcardinmb atx scsicontroller scsidisk pII germanlayoutKB floppydrive computer
Answer: 13
Stable Model: gcardinmb atx pII germanlayoutKB floppydrive computer
Answer: 14
Stable Model: gcardinmb atx pII germanlayoutKB floppydrive idedisk computer

250
References

1. T. Syrjänen: A rule-based formal model for software configuration,


1999,

2. T. Soininen: An approach to knowledge representation and


reasoning for product configuration tasks, 2000,

3. T. Syrjänen: Including diagnostic information in configuration


models, 2000,

4. T. Soininen, I. Niemelä: Developing a declarative rule language for


applications in product configuration, 1999.

251
Action languages

• Transition Systems

• Action language A

• Action language C

252
Action signatures

An action signature consists of three nonempty sets:

• a set V of value names,

• a set F of fluent names, and

• a set A of action names.

Intuitively, any ”fluent” has a specific ”value” in any ”state of the


world”. An ”action”, if executed in some state, leads to a ”resulting”
state.

253
Transition systems

A transition system hS, V, Ri of an action signature hV, F, Ai consists of

1. a set S ,

2. a function V from F × S into V, and

3. a subset R of S × A × S .

The elements of S are called states.


V (P, s) is the value from P in s.

254
Transitions

A transition is any triple hs, A, s′ i ∈ R, where s′ is a result of the


execution of A in s.
A is executable in s if there is at least one such s′ .
A is deterministic in s if there is at most one such s′ .
An action signature hV, F, Ai is propositional if its value names are the
truth values of classical logic: V = {f, t}.
A transition system is propositional if its signature is propositional.

255
Transition graph

A transition system can be thought of as a labeled directed graph.

• States are the vertices,

• transitions hs, A, s′ i ∈ R are represented as edges from s to s′ labeled


with A.

256
Example
Doors

F luents : {closed}
Actions : {opendoor} 
s1
s1 = {closed} 
States :
s2 = {¬closed}
a
?

s2 
T ransitions : hs1 , a, s2 i  a

hs2 , a, s2 i

257
Example

F luents : {p, q, r}
Actions : {a, b}
States : s1 = {¬p, ¬q, ¬r}  
s2 a - s3
s2 = {p, q, ¬r}  
6 
s3 = {p, ¬q, r}
b b

s1 
T ransitions : hs1 , a, s1 i  a

hs1 , b, s2 i
hs1 , b, s3 i
hs2 , a, s3 i

258
Example

F luents : {p, q}
Actions : {a}
States : s1 = {p, q}
 
s2 = {¬p, q} ? a
 ? a

s1  s3 
s3 = {p, ¬q}  
s4 = {¬p, ¬q} 6 6

a a
 
s2 s4
T ransitions : hs1 , a, s1 i  
hs2 , a, s1 i
hs3 , a, s3 i
hs4 , a, s3 i

259
Action language A

Let h{f, t}, F, Ai be a propositional action signature.


A proposition is an expression of the form

A causes L if F

where A is an action name, L is a literal and F is a conjunction of


literals.
If F is true then if F can be dropped.
An action description is a set of propositions.

260
Action language A

Let h{f, t}, F, Ai be a propositional action signature. Let D be an action


description in A.
The transition system hS, V, Ri described by D is defined as follows:

• S is the set of all interpretations of F,

• V (P, s) = s(P ),

• R is set of transitions hs, A, s′ i such that

E(A, s) ⊆ s′ ⊆ E(A, s) ∪ s,

where E(A, s) = {L | A causes L if F in D, s satisfies F } are the


effects of A executed in s.

261
Example
F luents : {p, q} Actions : {a}
P ropositions : a causes p
States : s1 = {p, q}
 
s2 = {¬p, q} ? a
 ? a

s1  s3 
s3 = {p, ¬q}  
s4 = {¬p, ¬q} 6 6

a a
 
s2 s4
T ransitions : hs1 , a, s1 i  
hs2 , a, s1 i
hs3 , a, s3 i
hs4 , a, s3 i
Effects of a executed in si are {p} for all i ∈ {0, . . . , 4}. E(A, s) ⊆ s′ ⊆ E(A, s) ∪ s holds for all transitions hs, a, s′ i.

262
Example
F luents : {p, q} Actions : {a}
P ropositions : a causes p if q
States : s1 = {p, q}
 
s2 = {¬p, q} ? a
 ? a

s1  s3 
s3 = {p, ¬q}  
s4 = {¬p, ¬q} 6

a

 ? a

s2 s4 
T ransitions : hs1 , a, s1 i  
hs2 , a, s1 i
hs3 , a, s3 i
hs4 , a, s4 i
E(a, s1 ) = E(a, s2 ) = {p}, E(a, s3 ) = E(a, s4 ) = ∅. E(A, s) ⊆ s′ ⊆ E(A, s) ∪ s holds for all transitions hs, a, s′ i.

263
Action language C

• A state formula is a propositional combination of fluent names.


• A formula is a propositional combination of fluent names and
elementary action names.

• A static law is an expression of the form

caused F if G

where F, G are state formulas.

• A dynamic law is an expression of the form

caused F if G after U

where F, G are state formulas and U is a formula.

• An action description is a set of static and dynamic laws.

264
Action language C

A formula F is caused in a transition hs, a, s′ i if it is

(i) the head of a static law

caused F if G

such that s′ satisfies G, or

(ii) the head of a dynamic law

caused F if G after U

such that s′ satisfies G and s ∪ a satisfies U .

A transition hs, a, s′ i is causally explained by D if there is only one s′ that


satisfies all formulas caused in this transition.

265
Action language C

Let D be an action description in C .


The transition system hS, V, Ri described by D is as follows:

(i) S is the set of all interpretations s of F such that for every

caused F if G

in D , s satisfies F if s satisfies G,

(ii) V (P, s) = s(P ),

(iii) R is the set of transitions hs, A, s′ i which are causally explained in D .

266
Example
Doors

Action: {OpenDoor} open a springloaded door


Fluents: {Closed}
Action description:

caused Closed if Closed,


caused ¬Closed if T rue after OpenDoor

States: {¬Closed, Closed}


Transitions (all causally explained):

h¬Closed, ¬OpenDoor, Closedi,


hClosed, ¬OpenDoor, Closedi,
h¬Closed, OpenDoor, ¬Closedi,
hClosed, OpenDoor, ¬Closedi.

267
Shortcuts

A causes F if G stands for caused F if T rue after G ∧ A,


inertial F stands for caused F if F after F,
inertial F1 , . . . Fn stands for inertial Fi (1 ≤ i ≤ n),
always F stands for caused F alse if ¬F,
nonexecutable A if F stands for caused F alse after F ∧ A,
default F if G stands for caused F if F ∧ G
exogenous F stands for caused F if F.

268
Translation to extended logic programs

Consider timesteps t = 0, . . . , T

(i) caused F if L1 ∧ . . . ∧ Lm is translated to


F (t) ← not ¬L1 (t), . . . , not ¬Lm (t),

(ii) caused F if L1 ∧ . . . ∧ Lm after Lm+1 , . . . , Ln is translated to


F (t + 1) ← not ¬L1 (t + 1), . . . , not ¬Lm (t + 1), Lm+1 (t), . . . , Ln (t),

(iii) for all fluents B at time step 0 or for action names:

¬B ← not B
B ← not ¬B.

269
Example
Doors

default Closed,
OpenDoor causes ¬Closed
stands for

caused Closed if Closed,


caused ¬Closed if T rue after OpenDoor

(i) Closed(t) ← not ¬Closed(t)


(ii) ¬Closed(t + 1) ← OpenDoor(t)
(iii) Closed(0) ← not ¬Closed(0)
¬Closed(0) ← not Closed(0)
(iii) OpenDoor(t) ← not ¬OpenDoor(t)
¬OpenDoor(t) ← not OpenDoor(t)

270
Example
Doors

time(0..1).

closed(T) :- not -closed(T),time(T).


-closed(T1) :- openDoor(T),time(T),T1 = T+1,time(T1).
closed(0) :- not -closed(0).
-closed(0) :- not closed(0).
openDoor(T):- not -openDoor(T),time(T).
-openDoor(T):- not openDoor(T),time(T).

271
Example
Doors

Answer: 1
Stable Model: closed(0) openDoor(0) -closed(1)
Answer: 2
Stable Model: -closed(0) openDoor(0) -closed(1)
Answer: 3
Stable Model: -closed(0) -openDoor(0) closed(1)
Answer: 4
Stable Model: closed(0) -openDoor(0) closed(1)

272
Example
Monkey& Bananas

A monkey wants a bunch of bananas, hanging from the ceiling. To get


the bananas the monkey must push a box to the empty place under the
bananas and then climb on top of the box.

Fluents: for x ∈ {M onkey, Bananas, Box}

Loc(x),
HasBananas, OnBox

Actions: for l ∈ {L1 , L2 , L3 }

W alk(l), P ushBox(l), ClimbOn, ClimbOf f, GraspBananas

273
Example
Monkey& Bananas

caused Loc(Bananas) = l if HasBananas ∧ Loc(M onkey) = l


caused Loc(M onkey) = l if OnBox ∧ Loc(Box) = l

W alk(l) causes Loc(M onkey) = l


nonexecutable W alk(l) if Loc(M onkey) = l
nonexecutable W alk(l) if OnBox

P ushBox(l) causes Loc(Box) = l


P ushBox(l) causes Loc(M onkey) = l
nonexecutable P ushBox(l) if Loc(M onkey) = l
nonexecutable P ushBox(l) if OnBox
nonexecutable P ushBox(l) if Loc(M onkey) 6= Loc(Box)
274
Example
Monkey& Bananas

ClimbOn causes OnBox


nonexecutable ClimbOn if OnBox
nonexecutable ClimbOn if Loc(M onkey) 6= Loc(Box)

ClimbOf f causes ¬OnBox


nonexecutable ClimbOf f if ¬OnBox

GraspBananas causes HasBananas


nonexecutable GraspBananas if HasBananas
nonexecutable GraspBananas if ¬OnBox
nonexecutable GraspBananas if Loc(M onkey) 6= Loc(Bananas)

275
Example
Monkey& Bananas

nonexecutable W alk(l) ∧ P ushBox(l)


nonexecutable W alk(l) ∧ ClimbOn
nonexecutable P ushBox(l) ∧ ClimbOn
nonexecutable ClimbOf f ∧ GraspBananas

exogenous c % for every action constant c

inertial c % for every simple fluent constant c

276
Example
Monkey& Bananas

Initial situation:
• loc(bananas,l1,0), loc(monkey,l2,0), loc(box,l3,0)
Solution:
• walk(l3,0)
– walk(l3,0) causes loc(monkey,l3,1)

• pushBox(l1,1)
– pushBox(l1,1) causes loc(box,l1,2)
– pushBox(l1,1) causes loc(monkey,l1,2)

• climbOn(2)
– climbOn(2) causes onBox(3)

• graspBananas(3)
– graspBananas(3) causes hasBananas(4)

277
Monkey& Bananas with DLVK

DLVK is a planning system, which provides an implementation of action


language K as a front-end of the DLV system.
More information and download of the Monkey & Bananas example on:

http://www.dbai.tuwien.ac.at/proj/dlv/K/

278
monkey.dl

%% Background Knowledge

object(box).
object(monkey).
object(bananas).

279
monkey.plan

fluents: loc(O,L) requires object(O), #int(L).


onBox.
hasBananas.

actions: walk(L) requires #int(L).


pushBox(L) requires #int(L).
climbBox.
graspBananas.

280
monkey.plan
always: caused loc(monkey,L) after walk(L).
caused -loc(monkey,L) after walk(L1), loc(monkey,L), L<>L1.
executable walk(L) if not onBox.
caused loc(monkey,L) after pushBox(L).
caused loc(box,L) after pushBox(L).
caused -loc(monkey,L) after pushBox(L1), loc(monkey,L), L<>L1.
caused -loc(box,L) after pushBox(L1), loc(box,L), L<>L1.
executable pushBox(L) if loc(monkey,L1), loc(box,L1), not onBox.
caused onBox after climbBox.
executable climbBox if not onBox, loc(monkey,L), loc(box,L).
caused hasBananas after graspBananas.
executable graspBananas if onBox, loc(monkey,L), loc(bananas,L).
inertial loc(O,L).
inertial onBox.
inertial hasBananas.

281
monkey.plan

initially: loc(monkey,2).
loc(box,3).
loc(bananas,1).

noConcurrency.

goal: hasBananas ? (4)

282
Solutions
bash-2.05b$ dlv -FP -N=4 monkeyK.plan monkeyK.dl
DLV [build BEN/May 23 2004 gcc 2.95.4 20011002 (Debian prerelease)]

STATE 0: loc(box,3), loc(monkey,2), loc(bananas,1)


ACTIONS: walk(3)
STATE 1: loc(monkey,3), loc(box,3), -loc(monkey,2), loc(bananas,1)
ACTIONS: pushBox(1)
STATE 2: loc(monkey,1), -loc(monkey,3), -loc(box,3), loc(bananas,1), loc(box,1)
ACTIONS: climbBox
STATE 3: onBox, loc(monkey,1), loc(bananas,1), loc(box,1)
ACTIONS: graspBananas
STATE 4: loc(monkey,1), loc(bananas,1), loc(box,1), onBox, hasBananas
PLAN: walk(3); pushBox(1); climbBox; graspBananas

Check whether that plan is secure (y/n)? y


The plan is secure.

Search for other plans (y/n)? y


bash-2.05b$

283
Meta-interpreting Logic Programs

A logic program can be encoded for and interpreted by a generic


meta-interpreter.
A representation F (Π) of a logic program Π is a set of facts.
These facts are combined with a generic logic program ΠIα such that

AS(Π) = {π(A) | A ∈ AS(F (Π) ∪ ΠIα )},

where π is a ”simple projection function”.

284
Representation
of a logic program

We translate Π into F (Π) as follows:

1. For every rule

L0 ← L1 , . . . Lm , not Lm+1 , . . . not Ln .

of Π, F (Π) contains the facts:

rule(r). head(L0 , r). pbl(L1 , r). . . . pbl(Lm , r).


nbl(Lm+1 , r). . . . nbl(Ln , r).

where r is a unique rule identifier.

2. For each pair of complementary literals L, ¬L in Π we add the fact


compl(L, ¬L).

285
Example
bird & penguin

(1) peng.
(2) bird.
(3) ¬f lies ← not f lies, peng.
(4) f lies ← not ¬f lies, bird.
F (Π) : rule(r1 ). head(peng, r1 ).
rule(r2 ). head(bird, r2 ).
rule(r3 ). head(negf lies, r3 ).
pbl(peng, r3 ). nbl(f lies, r3 ).
rule(r4 ). head(f lies, r4 )
pbl(bird, r4 ). nbl(negf lies, r4 ).
and compl(f lies, negf lies).

286
Basic Meta-interpreter program

in AS(X) is true if literal X is in an answer set of Π.

in AS(X) ← head(X, R), pos body true(R),


not neg body f alse(R).

287
Basic Meta-interpreter program

The positive part of the body is true, if all its literals are in the answer
set.
If there are no positive literals, the positive body is trivially true.

pos body exists(R) ← pbl(X, R).


pos body true(R) ← rule(R), not pos body exists(R).

288
Basic Meta-interpreter program

If positive literals exists, we proceed iteratively. We use DLV’s built-in


total order on constants for defining successor relation on positive body
literals of each rule, and to identify the first and the last literal of a
positive rule body in this total order.
Auxiliary relations:

pbl inbetween(X, Y, R) ← pbl(X, R), pbl(Y, R), pbl(Z, R), X < Z, Z < Y.
pbl notlast(X, R) ← pbl(X, R), pbl(Y, R), X < Y.
pbl notf irst(X, R) ← pbl(X, R), pbl(Y, R), Y < X.

289
Basic Meta-interpreter program

The positive body is true up to some positive body literal (wrt the
built-in order):

pos body true upto(R, X) ← pbl(X, R), not pbl notf irst(X, R), in AS(X).
pos body true upto(R, X) ← pos body true upto(R, Y ), pbl(X, R),
in AS(X), Y < X, not pbl inbetween(Y, X, R).
pos body true(R) ← pos body true upto(R, X),
not pbl notlast(X, R).

290
Basic Meta-interpreter program

The negative part of a body is false, if one of its literals is in the answer
set.

neg body f alse(R) ← nbl(X, R), in AS(X).

Each answer set is consistent:

← compl(X, Y ), in AS(X), in AS(Y ).

Each answer set A of ΠIα ∪ F (Π) represents an answer set A′ of Π, where


π(A) = A′ and

π(A) = {l | in AS(l) ∈ A}.

291
Meta-interpreter

in_AS(X) :- head(X,R), pos_body_true(R), not neg_body_false(R).


pos_body_exists(R) :- pbl(X,R).
pos_body_true(R) :- rule(R), not pos_body_exists(R).
pbl_inbetween(X,Y,R) :- pbl(X,R), pbl(Y,R), pbl(Z,R), X < Z, Z < Y.
pbl_notlast(X,R) :- pbl(X,R), pbl(Y,R), X < Y.
pbl_notfirst(X,R) :- pbl(X,R), pbl(Y,R), Y < X.
pos_body_true_upto(R,X) :- pbl(X,R), not pbl_notfirst(X,R), in_AS(X).
pos_body_true_upto(R,X) :- pos_body_true_upto(R,Y), pbl(X,R),
in_AS(X), Y < X, not pbl_inbetween(Y,X,R).
pos_body_true(R) :- pos_body_true_upto(R,X), not pbl_notlast(X,R).
neg_body_false(R) :- nbl(X,R), in_AS(X).
:- compl(X,Y), in_AS(X), in_AS(Y).

292
Example
bird & penguin

rule(r1). head(peng,r1).
rule(r2). head(bird,r2).
rule(r3). head(negflies,r3).
pbl(peng,r3). nbl(flies,r3).
rule(r4). head(flies,r4).
pbl(bird,r4). nbl(negflies,r4).
compl(flies,negflies).

bash-2.05b$ dlv -filter=in_AS metainterpreterAS.pl


DLV [build BEN/Apr 12 2002 gcc 2.95.3 20010315 (SuSE)]
{in_AS(peng), in_AS(bird), in_AS(flies)}
{in_AS(peng), in_AS(bird), in_AS(negflies)}

293
Crossing a river

canCross ← boat, not leaking


canCross ← boat, leaking, hasBucket

We observe somebody crossing the river with a boat. How can we


explain that?

294
Abduction

An abduction problem is a triple hΠ, H, Oi, where

• Π is a logic program,

• H is a set of facts, referred to as hypotheses, and

• O is a set of atoms, referred to as observations.

A set ∆ ⊆ H is an explanation of O wrt Π if all answer sets of Π ∪ ∆


contain O.

An explanation ∆1 is minimal if for every other explanation ∆2 of O


∆2 6⊂ ∆1 holds.
We call ∆ a single explanation if |∆| = 1.

295
Crossing a river
Explanations

 
 canCross ← boat, not leaking 
• Π=
 canCross ← boat, leaking, hasBucket 

• Hypotheses: H = {boat, leaking, hasBucket}.

• Observation: canCross

• Explanations:
1. {boat}
2. {boat, hasBucket}
3. {boat, leaking, hasBucket}

• Only boat is a minimal (and single) explanation.

296
Running DLV

• canCross.dl
canCross :- boat, not leaking.
canCross :- boat, leaking, hasBucket.

• canCross.hyp
boat.
leaking.
hasBucket.

• canCross.obs
canCross.

297
Running DLV
Computing all explanations:

bash-2.05b$ dlv -FD canCross.dl canCross.hyp canCross.obs


DLV [build BEN/May 23 2004 gcc 2.95.4 20011002 (Debian prerelease)]

Diagnosis: boat leaking hasBucket


Diagnosis: boat
Diagnosis: boat hasBucket

Computing single explanations:

bash-2.05b$ dlv -FDsingle canCross.dl canCross.hyp canCross.obs


DLV [build BEN/May 23 2004 gcc 2.95.4 20011002 (Debian prerelease)]

Diagnosis: boat

298
Further Semantics

• Completion

• Supported Models

• Fitting semantics

• Well-founded semantics

299
Completion
Let Π be a basic normal logic program.
Then, Π∗ is a set of rules obtained from Π as follows:

• Replace each rule A ← with A ← true.


• If an atom A is not the head of a rule in Π, then add the rule
A ← f alse.

Π∗∗ is obtained from Π∗ as follows:


• Replace each rule A0 ← A1 , . . . An with A0 ← (A1 ∧ . . . ∧ An ).
• Next, replace all rules A ← B1 , . . . , A ← Bm with the same head by
A ← (B1 ∨ . . . ∨ Bm ).

We obtain the program completion of Π by replacing each occurrence of


← by ≡.

300
Example
Completion

a ← true
a ←
b ← a
b ← a

c ← a
Π: c ← a Π :
c ← b
c ← b
d ← c, e
d ← c, e
e ← f alse

a ← true a ≡ true
b ← a b ≡ a
Π∗∗ : c ← (a ∨ b) Completion of Π : c ≡ (a ∨ b)
d ← (c ∧ e) d ≡ (c ∧ e)
e ← f alse e ≡ f alse
301
2-valued models

• truth-values: {true, f alse},

• representation: hT, F i, where T is the set of all true atoms and F is


the set of all f alse atoms,

• T ∩ F = ∅,

• T ∪ F is the set of all atoms.

302
Supported models

A supported model for a (basic) normal logic program Π is a (2-valued)


Herbrand model in which all equivalences of the completion of Π are
true.

303
Example
Supported model

Completion of Π:

a ≡ true
b ≡ a
c ≡ (a ∨ b)
d ≡ (c ∧ e)
e ≡ f alse

The supported model of Π is


h{a, b, c}, {d, e}i.

304
Including negation as failure

Π:

q ← not p
p ← not x, not q

Completion of Π:

q ≡ ¬p
p ≡ (¬x ∧ ¬q)
x ≡ f alse

305
3-valued models

• truth-values: {true, f alse, ⊥},

• representation: hT, F i, where T is the set of all true atoms and F is


the set of all f alse atoms,

• T ∩ F = ∅, T ∩ ⊥ = ∅, F ∩ ⊥ = ∅,

• T ∪ F ∪ ⊥ is the set of all atoms.

For hT1 , F1 i and hT2 , F2 i we define


hT1 , F1 i ≤ hT2 , F2 i if T1 ⊆ T2 and F1 ⊆ F2 .

306
Fitting Operator

Let Π be a normal logic program. The mapping ΦΠ is defined as follows:

ΦΠ hT, F i = hT ′ , F ′ i

where for all atoms A we have:

(i) A ∈ T ′ if there is a rule A ← A1 , . . . , Am , not Am+1 , . . . not An such that


{A1 , . . . , Am } ⊆ T and {Am+1 , . . . An } ⊆ F ,

(ii) A ∈ F ′ if for all rules A ← A1 , . . . , Am , not Am+1 , . . . not An either


{A1 , . . . , Am } ∩ F 6= ∅ or {Am+1 , . . . , An } ∩ T 6= ∅,

(iii) A ∈ ⊥ otherwise.

307
Example

Π:

a ←
b ← a
c ← not a
d ← b, c

Given 3-valued model h{a}, ∅i, then


ΦΠ h{a}, ∅i = h{a, b}, {c}i.

308
Properties of ΦΠ

Let Π be a normal logic program.

• Operator ΦΠ is monotonic, that is


hT1 , F1 i ≤ hT2 , F2 i implies ΦΠ hT1 , F1 i ≤ ΦΠ hT2 , F2 i.

• ΦΠ has a least fixpoint.

309
Fitting semantics

Φ0Π = h∅, ∅i
Φi+1
Π = ΦΠ (ΦiΠ )
Φω
Π = ∪i<ω {ΦiΠ }

The least fixpoint of ΦΠ , denoted by Φω


Π , supplies the Fitting semantics.

310
Example
Fitting

 


 r ← s ← 


 
 t ← r, s u ← not t 
 
Π=


 p ← not p, not q a ← b 



 

 b ← a 

Φ0Π = h∅, ∅i
Φ1Π = h{r, s}, {q}i
Φ2Π = h{r, s, t}, {q}i
Φ3Π = h{r, s, t}, {q, u}i
Φ4Π = Φ3Π

311
Example
Fitting

 
 a ← b 
Π=
 b ← a 

Φ0Π = h∅, ∅i
Φ1Π = h∅, ∅i

But, a and b never become true!


⇒: ”Extension” of Fitting semantics: well-founded semantics

312
Unfounded sets

Let Π be a normal logic program.


A set of atoms A is an unfounded set (of Π wrt hT, F i) if each atom
A ∈ A and for each rule A ← A1 , . . . Am , not Am+1 , . . . not An one of the
following conditions is satisfied:

1. either {A1 , . . . , Am } ∩ F 6= ∅ or {Am+1 , . . . , An } ∩ T 6= ∅, or

2. there is an 0 ≤ i ≤ m such that Ai ∈ A.

The greatest unfounded set (of Π wrt hT, F i) is the union of all
unfounded sets (of Π wrt hT, F i).

313
Example
Unfounded sets

 
 a ← b 
Π=
 b ← a 

Given h∅, ∅i,


the greatest unfounded set is {a, b}.

314
Unfounded sets

The mapping UΠ is defined as follows:

UΠ hT, F i = hT ′ , F ′ i

where for all atoms A we have:

(i) A ∈ T ′ if A ∈ T ,

(ii) A ∈ F ′ if A is in the greatest unfounded set (wrt Π and hT, F i),

(iii) A ∈ ⊥ otherwise.

315
Well-founded semantics

0
WΠ = h∅, ∅i
i+1 i i
WΠ = ΦΠ (WΠ ) ∪ UΠ (WΠ )
ω i
WΠ = ∪i<ω WΠ

ω
WΠ is the well-founded model of Π.
There always exists a well-founded model of Π.
If the well-founded model is total, then it is the unique stable model.
The well-founded model is a subset of every stable model.

316
Example
 
 r ← s ← t ← r, s u ← not t 
Π=
 p ← not p, not q a ← b b ← a 

Φ0Π = h∅, ∅i ∪ UΠ0 = h∅, ∅i


0
WΠ = h∅, ∅i
Φ1Π = h{r, s}, {q}i ∪ UΠ1 = h∅, {a, b}i
1
WΠ = h{r, s}, {q, a, b}i
Φ2Π = h{r, s, t}, {q, a, b}i ∪ UΠ2 = h{r, s}, {q, a, b}i
2
WΠ = h{r, s, t}, {q, a, b}i
Φ3Π = h{r, s, t}, {q, a, b, u}i ∪ UΠ3 = h{r, s, t}, {q, a, b, u}i
3
WΠ = h{r, s, t}, {q, a, b, u}i
4 3
WΠ = WΠ
ω
WΠ = h{r, s, t}, {q, u, a, b}i

317
Relation to other systems

noMoRe:
Let Γ be the RDG of normal logic program Π.
PΓ∗ ((∅, ∅)) corresponds to Φω
Π (h∅, ∅i), and

UΓ (C) gives us the greatest unfounded set wrt Π and the 3-valued model
obtained from C .
(PU)∗Γ ((∅, ∅)) gives us the well-founded model of Π.

smodels:
expand(∅, A) gives well-founded model of Π, where A is the set of all
atoms in Π

318
Alternating fixpoint characterization

Let Π be a logic program and X be a set of atoms.

• Define CΠ (X) = Cn(ΠX ).

• The fixpoints of CΠ (X) are the answer sets of Π.


2
• CΠ (X) is anti-monotonic. Hence, CΠ (CΠ (X)) = CΠ (X) is monotonic.
2
• Define AΠ (X) = CΠ (X).

• hlf pAΠ (X), Atm \ CΠ (lf pAΠ (X))i is the well-founded model of Π.

319
Example
Alternating fixpoint characterization

 
 r ← s ← t ← r, s u ← not t 
Π=
 p ← not p, not q a ← b b ← a 

X = {r, s, t}

Cn(Π{r,s,t} ) = {r, s, t, p} Cn(Π{r,s,t,p} ) = {r, s, t} AΠ (X) = {r, s, t} = X


lf pAΠ (X) = {r, s, t}

CΠ (lf pAΠ (X)) = {r, s, t, p} Atm \ CΠ (lf pAΠ (X)) = {u, a, b, q}

Well-founded model: h{r, s, t}, {q, u, a, b}i

320
The Cmodels approach

For syntactically restricted (tight) programs answer sets and models of


completion coincide.

Cmodels idea: use program completion to compute answer sets of tight


programs.

• Completion

• Basic Davis-Putnam-Logemann-Loveland procedure for SAT

• Operation of Cmodels

321
Completion (Recapitulation)

Let Π be a normal logic program.


Then, Π∗ is a set of rules obtained from Π as follows:

• Replace each rule A ← with A ← true.

• If an atom A is not the head of a rule in Π, then add A ← f alse.

Π∗∗ is obtained from Π∗ as follows:

• Replace each occurence of not with ¬.

• Replace each rule A0 ← A1 , . . . An with A0 ← (A1 ∧ . . . ∧ An ).

• Replace all rules A ← B1 , . . . , A ← Bm with same head A by


A ← (B1 ∨ . . . ∨ Bm ).

Finally, we obtain the program completion of Π by replacing each


occurence of ← by ≡.
322
Example

p ← not q
q ← not p
Π: Π∗ = Π
r ← p
r ← q

p ← ¬q p ≡ ¬q
Π∗∗ : q ← ¬p Completion of Π : q ≡ ¬p
r ← (p ∨ q) r ≡ (p ∨ q)

323
Satisfiability

Satisfiability problem (SAT)


Find an interpretation satisfying a given set of propositional
formulas (or determine that this set is unsatisfiable).

We consider the (superficially) simpler problem of finding an


interpretation satisfying a given set of clauses
(that is, a propositional formula in CNF).

324
Propositional Satisfiability

• A literal is an atom or its negation.

• For any atom A the literals A and ¬A are complementary to each


other.

• For any literal L the literal complementary to L is denoted by L.

• A clause is a (possibly empty) disjunction of literals.


The empty clause is denoted by ⊥.

☞ Any formula can be transformed into an equivalent set of clauses.

325
Clausification

Let F be a formula.

Clausify(F )
eliminate all connectives from F except ¬, ∧ and ∨;
distribute ¬ over ∧ and ∨ until it applies to atoms only;
distribute ∨ over ∧ until it applies to literals only;
return the set of conjunctive terms of the resulting formula;

326
Clausification

We have

Clausify(p ∨ ¬(q → r)) = (p ∨ q) ∧ (p ∨ ¬r).

Problem: Clausify(F ) can be much longer than F ; for instance if F is

(p1 ∧ q1 ) ∨ . . . ∨ (pn ∧ qn ) then Clausify(F ) consists of 2n clauses.

☞ Use alternative clausification.

327
Clausification with new atoms

Let F be a formula and let Γ be set of clauses (initially Γ = ∅).

Clausify⋆ (F, Γ)
if F is a conjunction of clauses C1 ∧ . . . ∧ Ck
then exit with {C1 , . . . , Ck } ∪ Γ;
G ← a minimal (wrt subformulas) non-literal subformula of F ;
u ← a new atom;
F ← result of replacing G in F by u;
Clausify⋆ (F, Γ ∪ Clausify(u ≡ G));

☞ Clausify⋆ (F, ∅) contains atoms not contained in F .

328
Example for Clausify⋆ (F, Γ)

F Γ G u Clausify(u ≡ G)
p ∨ ¬(q → r) ∅ q→r u0 (¬u0 ∨ ¬q ∨ r) ∧ (q ∨ u0 ) ∧ (¬r ∨ u0 )
p ∨ ¬u0 ∅

☞ Clausify⋆ (F, Γ) = (p ∨ ¬u0 ) ∧ (¬u0 ∨ ¬q ∨ r) ∧ (q ∨ u0 ) ∧ (¬r ∨ u0 )

329
Properties of Clausify⋆
• F and Clausify⋆ (F, ∅) are not equivalent:

To see this consider


F = p ∨ ¬(q → r)
Clausify⋆ (F, Γ) = (p ∨ ¬u0 ) ∧ (¬u0 ∨ ¬q ∨ r) ∧ (q ∨ u0 ) ∧ (¬r ∨ u0 )

Let I be an interpretation s.t. I(q) = I(u0 ) = 1 and I(p) = I(r) = 0.


Then I(F ) = 1 but I(Clausify⋆ (F, Γ)) = 0.

• Each model of F can be extended to “new” atoms such that


Clausify⋆ (F, ∅) will be satisfied (take I(u0 ) = 0).

• Each model of Clausify⋆ (F, ∅) is a model of F when restricted to


“old” atoms.

330
Example for Clausify⋆ (F, Γ)

F Γ G u Clausify(u ≡ G)
(p1 ∧ q1 ) ∨ (p2 ∧ q2 ) ∅ p1 ∧ q1 u0 (¬u0 ∨p1 )∧(¬u0 ∨q1 )∧
(¬p1 ∨ ¬q1 ∨ u0 )
u0 ∨ (p2 ∧ q2 ) Clausify(u0 ≡ p1 ∧ q1 ) ∪ Γ p2 ∧ q2 u1 (¬u1 ∨p2 )∧(¬u1 ∨q2 )∧
(¬p2 ∨ ¬q2 ∨ u1 )
u0 ∨ u1 Clausify(u1 ≡ p2 ∧ q2 ) ∪ Γ

Clausify⋆ (F, Γ) = (u0 ∨ u1 )∧


(¬u0 ∨ p1 ) ∧ (¬u0 ∨ q1 ) ∧ (¬p1 ∨ ¬q1 ∨ u0 )∧
(¬u1 ∨ p2 ) ∧ (¬u1 ∨ q2 ) ∧ (¬p2 ∨ ¬q2 ∨ u1 )

For F = (p1 ∧ q1 ) ∨ . . . ∨ (pn ∧ qn ) we have that Clausify⋆ (F, Γ) has (3n + 1)


clauses.

☞ This is small compared to 2n clauses of Clausify(F ) (take n = 5).


331
Unit Clause Propagation

A unit clause is a clause that consists of a single literal.

If a set of clauses contains a unit clause, then it can be simplified


using the fact that

• the set of clauses {F, F ∨ G} is equivalent to {F } and

• the set of clauses {F, ¬F ∨ G} is equivalent to {F, G}.

A simplification step like this may create a new unit clause and that can
make further simplifications possible.

☞ This process is called unit propagation.

332
Unit Clause Propagation Procedure

UnitPropagation(Γ, U )
while there is a unit clause {L} in Γ
U ← U ∪ {L}
for every clause C ∈ Γ do
if L ∈ C then Γ ← Γ \ {C}
elsif L ∈ C then Γ ← (Γ \ {C}) ∪ {C \ {L}}
end
end

• Γ is a set of clauses;

• U is a consistent set of literals such that, for every L ∈ U ,


neither L nor L occurs in any clause in Γ.

333
Some remarks

• During execution, Γ is simplified and U grows bigger.

• Upon termination, there are no unit clauses in Γ.

• To apply unit clause propagation to a set of clauses Γ0 , the


procedure is invoked with Γ = Γ0 and U = ∅.

• After every execution of the while-loop, Γ ∪ U remains equivalent to


the original set of clauses Γ0 .

334
Example

For Γ = {p, ¬p ∨ ¬q, ¬q ∨ r} apply Unit-Propagation.

Γ U L
{p, ¬p ∨ ¬q, ¬q ∨ r} ∅ p
{¬q, ¬q ∨ r} {p} ¬q
∅ {p, ¬q} no

☞ This computation shows that Γ = {p, ¬p ∨ ¬q, ¬q ∨ r} is equivalent to


{p, ¬q}.

☞ Each interpretation I with I(p) = 1 and I(q) = 0 is a model of Γ.

335
Another Example
For Γ = {p, p ∨ q, ¬p ∨ ¬q, q ∨ r, ¬q ∨ ¬r} apply Unit-Propagation.

Γ U L
{p, p ∨ q, ¬p ∨ ¬q, q ∨ r, ¬q ∨ ¬r} ∅ p
{¬q, q ∨ r, ¬q ∨ ¬r} {p} ¬q
{r} {p, ¬q} r
∅ {p, ¬q, r} no

☞ Interpretation I with I(p) = I(r) = 1 and I(q) = 0 is a model of Γ.

336
Properties of Unit-Propagation

There are two cases when unit clause propagation alone is sufficient for
solving SAT for a set of clauses Γ0 .
For this, consider the values of Γ and U upon termination of
Unit-Propagation(Γ0 , ∅).

1. if Γ includes the empty clause, then Γ is unsatisfiable, and so is Γ0 ;

2. if Γ = ∅, then Γ0 is equivalent to U , which is a consistent set of


literals.
A model of Γ0 can easily obtained from U .

337
Davis-Putnam-Logemann-Loveland Procedure

The DPLL procedure is an extension to unit clause propagation that


allows for solving SAT in full generality.

Observation
For any set of formulas Γ and any formula F ,
the set of models of Γ is the union of the sets of models
of Γ ∪ {F } and Γ ∪ {¬F }.

The DPLL procedure uses this fact to apply unit clause propagation
(even) when Γ does not contain unit clauses.

338
The DPLL algorithm
DPLL(Γ, U )
UnitPropagation(Γ, U )
if ∅ ∈ Γ then return
if Γ = ∅ then exit with a model of U
A ← select(atoms(Γ))
DPLL(Γ ∪ {A}, U )
DPLL(Γ ∪ {A}, U )

• Γ is a set of clauses; U is a consistent set of literals such that, for


every L ∈ U , neither L nor L occurs in any clause in Γ (see above).

• atoms(Γ) returns the set of all atoms occuring in Γ,


• Initially, DPLL is invoked with Γ = Γ0 and U = ∅.

339
Some remarks

• The return of the first if-statement indicates that Γ ∪ U is


unsatisfiable.

• The exit in the second statement produces a model of Γ ∪ U .

340
Example
Let Γ = {¬p ∨ q, ¬p ∨ r, q ∨ r, ¬q ∨ ¬r} be a set of clauses and apply DPLL.

2
DPLL(Γ ∪ {p}, U )
6
6
6 UP gives ∅ ∈ Γ hence no model
6 2
6
6 DPLL(Γ ∪ {q}, U )
6 6
Γ = {¬p ∨ q, ¬p ∨ r, q ∨ r, ¬q ∨ ¬r} 6 6 UP gives
DPLL(Γ ∪ {¬p}, U ) 6
6 6
U =∅ 6 Γ=∅
6
6
6 UP gives 6
DPLL(Γ, U ) 6 U = {¬p, q, ¬r} is model
6 6
6
6 Γ = {q ∨ r, ¬q ∨ ¬r} 6
UP leaves Γ and U unchanged 6 6 6 DPLL(Γ ∪ {¬q}, U )
6
6 U = {¬p} 6
6 UP gives
6 6
select q
6
6 6
6 6 Γ=∅
4 4
U = {¬p, ¬q, r} is model

341
Operation of Cmodels

In the process of its operations, Cmodels

1. simplifies the given normal program,

2. verifies that the resulting program is tight,

3. forms the program completion and call a SAT solver to find its
models.

342
Simplification

Let AS(Π) denote the set of all answer sets of program Π.

• Two programs Π and Π′ are equivalent if AS(Π) = AS(Π′ ).

☞ Many other different equivalence concepts were proposed


in the literature!

343
Some Definitions

Define

• Atom(Π) all atoms occurring in Π


+
T
• Atom (Π) = X∈AS(Π)X intersection of all answer sets

S
• Atom (Π) = Atom(Π) \ X∈AS(Π) X atoms not in any answer set of Π

344
Simplification

Any program Π of the form

Head ← Body, F.
Π′

s.t. F ∈ Atom− (Π) is equivalent to program

← F.
(2)

Π

345
Simplification

Let Π be a program of the form

Head ← Body, not F.


Π′

• If F ∈ Atom+ (Π) then Π is equivalent to program

← not F.
(3)

Π

• If F ∈ Atom− (Π) then Π is equivalent to program

← F.
Head ← Body. (4)
Π′

346
Example

a ← b, not c.
Π = d ← not a.
c ← not d.

☞ AS(Π) = {{d}} implies Atom+ (Π) = {d} and Atom− (Π) = {a, b, c}.
According to (2) Π is equivalent to

← b.
Π′ = d ← not a.
c ← not d.

☞ Atom+ (Π′ ) = Atom+ (Π) = {d} and Atom− (Π′ ) = Atom− (Π) = {a, b, c}.
347
Example ctd

According to (3) Π′ is equivalent to

← b.
Π′′ = d ← not a.
← not d.

According to (4) Π′′ is equivalent to

← b.

′′′ ← a.
Π =
d←.
← not d.

348
Remark on Simplification

How to determine sets Atom+ (Π) and Atom− (Π)?

• for example, all facts of Π are in Atom+ (Π)

• for example, atoms {a | (← a) ∈ Π} are in Atom− (Π)

• cmodels uses smodels procedures atmost and atleast to determine


subsets of Atom+ (Π) and Atom− (Π), respectively.

• In general, the WFM is part of any answer set.

349
Tight Programs

The positive dependency graph G of a normal logic program Π is a


directed graph s.t.

1. the vertexes of G are the atoms occurring in Π

2. G has an edge from A to B if Π has a rule with head B that


contains A in the positive part of the body.

A program is tight if its positive dependency graph has no cycles.

350
Example

p ← not p.
Π = p ← q.
q ← p.

The positive dependency graph of Π:

 
p  - q
 

☞ The graph has a cycle and thus Π is not tight.


351
Tightness

Before verifying tightness cmodels applies some further simplifications

• rules of the form A ← . . . , A, . . . are deleted since this does not


change answer sets and

• “inessential” vertexes are eliminated, for example atoms that do not


occur in the head of a rule.

Then cmodels verifies tightness by

1. building the positive dependency graph and

2. uses a standard depth first search algorithm to detect cycles.

352
Example

Let Π be the following program:

a ← not b, not d.
b ← not a, not c.
c ← d.
d ← c.
f ← c, not f.
c ← not d, not a, not b.
d ← not c, not a, not b.

☞ Which answer sets?

353
Example

Π Sim(Π) Completion
a ← not b, not d. a ← not b. a ≡ ¬b
b ← not a, not c. b ← not a. b ≡ ¬a
c ← d. ← d. ⊥ ≡ d.
d ← c. ← c. ⊥ ≡ c.
f ← c, not f. ← c.
c ← not d, not a, not b. c ← not a, not b. c ≡ ¬b ∧ ¬a.
d ← not c, not a, not b. d ← not a, not b. d ≡ ¬b ∧ ¬a.

☞ Π is not tight, but Sim(Π) is tight.

☞ AS(Π) = {{a}, {b}} .


354
Detailed Operation of Cmodels

In the process of its operations, Cmodels

1. simplifies a given program generated from lparse

2. turns it into a basic nested program

3. verifies that the resulting program is tight,

4. forms the program completion and call a SAT solver to find its
models.

355
lparse Programs

An output program of lparse contains

• normal rules of the form

A0 ← A1 , . . . , Am , not Am+1 , . . . , not An ,

• choice rules of the form

{A1 , . . . , Am } ← Am+1 , . . . , An , not An+1 , . . . , not Ak ,

• Weight constraint rules of the form

A0 ← l {A1 = w1 , . . . , Am = wm },

where each Ai is an atom, and l (lower bound) and wj (weights) are


integers.

356
Basic Nested Programs

A basic nested program contains

• basic nested rules of the form

A0 ← A1 , . . . , Am , not Am+1 , . . . , not An , not not An+1 , . . . , not not Ak ,

where each Ai is an atom.

☞ This is a special case of the concept of programs with nested


expressions.

☞ Observe that the definiton of tightness works for basic nested


without changes.

357
Example: choice rules

The following lparse program

{p, q}
r ← p
r ← q

is translated by cmodels into the following program with nested


expressions:

p ← not not p
q ← not not q
r ← p
r ← q

358
Simplification

Any lparse program of the form

Head ← L{F = w, T ail}


Π′

s.t. F ∈ Atom− (Π) is equivalent to program

← F
Head ← L{T ail} (5)
Π′

359
Simplification
Let Π be a lparse program of the form

Head ← L{not F = w, T ail}


Π′

• If F ∈ Atom+ (Π) then Π is equivalent to program

← not F.
Head ← L{T ail} (6)
Π′

• If F ∈ Atom− (Π) then Π is equivalent to program

← F.
Head ← L − w{T ail} (7)
Π′

360
Example

Let Π be the following program:

{a}
c ← 4{a = 1, b = 1, not d = 2}

☞ AS(Π) = {{a}, ∅} implies Atom+ (Π) = ∅ and Atom− (Π) = {b, c, d}.
According to (5) Π is equivalent to

{a}
←b
c ← 4{a = 1, not d = 2}

361
Example ctd

Since Atom− (Π) = {b, c, d}, according to (7) program

{a}
←b
c ← 4{a = 1, not d = 2}

is equivalent to

{a}
←b
←d
c ← 2{a = 1}.

362
Example: Translation to Basic Nested Programs

The rule

p ← 3{q = 3, r = 2, s = 2}

is translated to four simpler rules:

p ← aux1
aux1 ← 3{r = 2, s = 2}
p ← q, aux2
aux2 ← 0{r = 2, s = 2}

☞ aux1 is an abbreviation for 3{r = 2, s = 2} and


☞ aux2 is an abbreviation for 0{r = 2, s = 2}.
☞ since 0{r = 2, s = 2} is always true aux2 can be dropped.

363
Example ctd
We obtain
p ← aux1
aux1 ← 3{r = 2, s = 2}
p←q
A similar step gives:

p ← aux1
aux1 ← aux3
aux3 ← 3{s = 2}
aux1 ← r, aux4
aux4 ← 1{s = 2}
p←q
☞ aux3 is an abbreviation for 3{s = 2} and
☞ aux4 is an abbreviation for 1{s = 2}.
364
Example ctd

Since 3{s = 2} is always false we obtain program

p ← aux1
aux1 ← r, aux4
aux4 ← 1{s = 2}
p←q

Finally, we get the following program since 1{s = 2} can be replaced by s:

p ← aux1
aux1 ← r, aux4
aux4 ← s
p←q

365
SAT for Horn Clauses and
Computation of the least Herbrand Modell

Clauses vs Rules:
The efficient DPLL algorithm for SAT can be further optimized if we
restrict ourself to clauses with “direction”.
☞ We deal with definite programs, Horn clauses or rules.

• efficient procedure for SAT on Horn clauses

• efficient computation of the least Herbrand model


• naive algorithm

• optimized algorithm according to Dowling und Gallier (1984)

• application to ASP solvers

366
Horn-Klauseln (Erinnerung)

Eine aussagenlogische Horn-Klausel ist

• eine definite Programmklausel oder

• ein definites Ziel

☞ eine Horn-Klausel hat folgende Form:

• A (Fakt)

• [A, ¬B1 , . . . , ¬Bm ] ( A ← B1 ∧ . . . ∧ Bm ) (definite Klausel kein Fakt)

• [¬B1 , . . . , ¬Bm ] ( ← B1 ∧ . . . ∧ Bm ) (definites Ziel)

☞ Horn-Klauseln und definite Programme unterscheiden sich nur durch


definite Ziele

367
Beispiel

Betrachte folgende Menge von Horn-Klauseln:

A
¬A ∨ B
¬A ∨ ¬B

☞ Horn-Klauseln können inkonsistent sein, aber


☞ definite Programme (als Klauselmenge) sind immer konsistent.

368
Das Kleinste Herbrand-Modell (Erinnerung)

Sei P ein definites aussagenlogisches Programm und I ein


Interpretation.

TP (I) = {A | (A ← B1 ∧ . . . ∧ Bm ) ∈ P und {B1 , . . . , Bn } ⊆ I}


TP ↑ 0 = ∅
TP ↑ (n + 1) = TP (TP ↑ n) (für n ∈ IN )

TP ↑ 1 = {A | (A ← B1 ∧ . . . ∧ Bm ) ∈ P und {B1 , . . . , Bn } ⊆ ∅}
TP ↑ (n + 1) = {A | (A ← B1 ∧ . . . ∧ Bm ) ∈ P und {B1 , . . . , Bn } ⊆ TP ↑ (n)}

369
Algorithmus 1 für definite Programme
Sei P = {r1 , . . . , rn } ein definites Programm, Atm(P) = {A1 , . . . , Am } die
aussagenlogischen Variablen von P , V ~ ein boolscher Vektor der Länge m und ch
eine boolsche Variable.
program a l g o r i t h m 1 ;
begin ch := t ;
f o r each X ∈ Atm(P) do V (X) := f end f o r
f o r each X ∈ Atm(P) s.t. X ∈ P do V (X) := t end f o r
w h i l e ch do
ch := f ;
f o r each (A ← B1 ∧ . . . ∧ Bk ) ∈ P do
if V (B1 ) = t, . . . , V (Bk ) = t and V (A) = f th en
V (A) := t; ch := t;
P := P \ {A ← B1 ∧ . . . ∧ Bk }
end if
end f o r
end w h i l e
end

☞ MP = {A | V (a) = t} mit Komplexität O(n2 ) .


370
Beispiel

Betrachte folgendes definite Programm (Ordnung nicht relevant):

A B←A
C D ←B∧C
E ←D∧F F ←E

➥ V (A) = V (B) = V (C) = V (D) = V (E) = V (F ) = V (G) = f ;

➥ V (A) = V (C) = t

➥ 1. While-Loop: V (B) = t ; P := P \ {B ← A}

➥ 2. While-Loop: V (D) = t ; P := P \ {D ← B ∧ C}

➥ 3. While-Loop: keine weitern Änderungen

371
Algorithmus 1 für Horn-Klauseln
Sei H = {r1 , . . . , rn } ein definites Programm, Atm(H) = {A1 , . . . , Am } die
aussagenlogischen Variablen, V ~ ein boolscher Vektor der Länge m und ch und cons
boolsche Variablen.

program a l g o r i t h m 1 ;
begin ch := t; cons := t;
f o r each X ∈ Atm(H) do V (X) := f end f o r
f o r each X ∈ Atm(H) s.t. X ∈ H do V (X) := t end f o r
w h i l e ch and cons do ch := f ;
f o r each C ∈ H and ch do
i f C = ¬B1 ∨ . . . ∨ ¬Bk and V (B1 ) = t, . . . , V (Bk ) = t th en cons := f
else
i f C = (A ∨ ¬B1 ∨ . . . ∨ ¬Bk ) and V (B1 ) = t, . . . , V (Bk ) = t and V (A) = f th en
V (A) := t; ch := t;
H := H \ C
end if
end if
end f o r
end w h i l e end 372
Beispiel

Betrachte folgende Menge von Horn-Klauseln (Ordnung nicht relevant):

A
¬A ∨ B
¬A ∨ ¬B

➥ V (A) = V (B) = f ;

➥ V (A) = t

➥ 1. While-Loop: V (B) = t ; H := H \ {¬A ∨ B}

➥ 2. While-Loop: cons = f ;

☞ Inkonsistenz entdeckt!!
☞ Komplexität O(n2 )

373
Optimierung von Algorithmus 1
☞ Initial werden alle aussagenlogischen Variablen gleich f (false)
gesetzt (wie bisher), aber es wird andere Datenstruktur verwendet.

• für jede Horn-Klausel C ∈ H wird ein Zähler eingeführt, dessen


Wert die Anzahl der negativen Literale mit Wahrheitswert f (false)
angibt (falls es keine negativen Literale in c gibt ist der Wert 0 )

• eine Klausel C wird bearbeitet, wenn der Wert ihres Zählers 0 ist,
d.h. für alle negativen Literale ¬B ∈ C ist B = t (true)
➥ das positive Literal A ∈ C wird auf t (true) gesetzt sobald der
Zähler von C null ist

• mit jeder aussagenlogischen Variabel B ist die Liste der Klauseln


assoziiert, in denen B negative vorkommt

• ist ein positives Literal A = t (true), werden die Zähler aller


Klauseln in denen A negativ vorkommt um eins decrementiert

374
Algorithmus 2 für Horn-Klauseln
Sei H = {r1 , . . . , rn } ein definites Programm und
Atm(H) = {A1 , . . . , Am } die aussagenlogischen Variablen, die in H vorkommen.

program algorithm2;
type clause = r e c o r d N : 1 . . n ; next : ˆ clause end ;
type lit = record val : b o o l e a n ; clauselist : ˆ clause end ;
type Hornclause = a r r a y [ 1 . . m ] of lit ;
type count = a r r a y [ 1 . . n ] of 0 .. m ;
var H : Hornclause ; queue : q-type ;
num, poslit : count ; cons : b o o l e a n ;
begin
input(H);
init(H, num, poslit, queue, new);
cons := t;
sat(H, num, poslit, queue, cons, new);
i f cons th en
print(assignment);
else
print(unsat);
end 375
Algorithmus 2 Initialisierung
Gegeben: H
Initialisierung von num , poslit und cons ( queue ):

1. für alle Variablen A ∈ Atm(H) setzte


• A.val := f und
• A.clauselist := Liste aller C ∈ H mit ¬A ∈ C
2. für alle Klauseln C ∈ H setzte
• num[C] := Anzahl der negativen Literale in C und

 A falls A positive in C
• poslit[C] :=
 0 sonst (steht für false)

3. setzte queue := Liste aller Fakten,


d.h. aller Klauseln ohne negative Literale

4. setzte cons := t

376
Algorithmus 2 sat
program sat(H, num, poslit, queue, cons, new);
var c1, c2, old, new, next : 1 . . n; \ ∗ H = {r1 , . . . , rn } ∗ \
k : 1 . . m; \ ∗ Atm(H) = {A1 , . . . , Am } ∗ \
begin old := new;
w h i l e queue <> nil and cons do new := 0;
f o r i := 1 t o old and cons do
c1 := pop(queue); next := poslit(c1);
f o r c2 ∈ H[next].clauselist do num[c2] := num[c2] − 1;
i f num[c2] = 0 th en k := poslit[c2];
i f H[k].val 6= 1 th en
i f k <> 0 th en
H[k].val := t; queue := push(c2, queue); new := new + 1;
else cons := f ;
end if end if end if
end f o r end f o r
old := new;
end w h i l e end

377
Beispiel: Initialisierung

Betrachte folgende Horn-Klauseln:

c1 : A c2 : B ∨ ¬A ≡ (B ← A)
c3 : C ∨ ¬A ∨ ¬B ≡ (C ← A ∧ B) c4 : ¬B ∨ ¬C ≡ (← B ∧ C)

clauselist(A) = {c2, c3} poslit(c1) = A poslit(c3) = C


clauselist(B) = {c3, c4} poslit(c2) = B poslit(c4) = 0
clauselist(C) = {c4}
Es gilt:
partielles Modell = {A} num(c1) = 0
queue = {A} num(c2) = 1
cons = t num(c3) = 2
num(c4) = 2

378
Beispiel: nach 1. While-Loop

c1 : A c2 : B ∨ ¬A ≡ (B ← A)
c3 : C ∨ ¬A ∨ ¬B ≡ (C ← A ∧ B) c4 : ¬B ∨ ¬C ≡ (← B ∧ C)

clauselist(A) = {c2, c3} poslit(c1) = A poslit(c3) = C


clauselist(B) = {c3, c4} poslit(c2) = B poslit(c4) = 0
clauselist(C) = {c4}
Es gilt:
partielles Modell = {A, B} num(c1) = 0
queue = {B} num(c2) = 0
cons = t num(c3) = 1
num(c4) = 2

379
Beispiel: nach 2. While-Loop

c1 : A c2 : B ∨ ¬A ≡ (B ← A)
c3 : C ∨ ¬A ∨ ¬B ≡ (C ← A ∧ B) c4 : ¬B ∨ ¬C ≡ (← B ∧ C)

clauselist(A) = {c2, c3} poslit(c1) = A poslit(c3) = C


clauselist(B) = {c3, c4} poslit(c2) = B poslit(c4) = 0
clauselist(C) = {c4}
Es gilt:
partielles Modell = {A, B, C} num(c1) = 0
queue = {C} num(c2) = 0
cons = t num(c3) = 0
num(c4) = 1

380
Beispiel: nach 3. While-Loop

c1 : A c2 : B ∨ ¬A ≡ (B ← A)
c3 : C ∨ ¬A ∨ ¬B ≡ (C ← A ∧ B) c4 : ¬B ∨ ¬C ≡ (← B ∧ C)

clauselist(A) = {c2, c3} poslit(c1) = A poslit(c3) = C


clauselist(B) = {c3, c4} poslit(c2) = B poslit(c4) = 0
clauselist(C) = {c4}
Es gilt:
partielles Modell = {A, B, C} num(c1) = 0
queue = {0} (false!!) num(c2) = 0
cons = f (!!) num(c3) = 0
num(c4) = 0
☞ Inkonsistenz entdeckt
381
Komplexität von Algorithmus 2

• Jede Horn Klausel C ∈ H kommt höchsten einmal in die queue ; C


kommt genau dann in die queue wenn alle ihre negativen Literale t
(true) sind.

• Sobald eine Klausel c2 bearbeitet wird, wird ihr positives Literal zu


t (true), dass verhindert doppelte Behandlung von Klauseln.

• Wenn eine Klausel c1 im While-Loop gelöscht wird, werden sofort


alle Klauseln behandelt, die das positive Literal von c1 negativ
enthalten. Jedes negative Vorkommen einer Variable wird nur genau
einmal betrachtet. Es gibt nur linear (in n der Anzahlder Klauseln)
viele negative Vorkommen von aussagenlogischen Variablen.

☞ Algorithmus 2 braucht O(n) Schritte.


☞ Für definite Programme berechnet Algorithmus 2 das kleinste
Herbrand Modell MP
382
How to Apply the Idea to ASP?

Horn Clauses normal rules


a ← b1 , . . . , bn a ← b1 , . . . , bn , not c1 , . . . , not ck
← b1 , . . . , bn ← b1 , . . . , bn , not c1 , . . . , not ck

Remeber application condition for rule r wrt a set of atoms X

• r has to be supported, that is, body + (r) ⊆ X , and

• r has to be unblocked, that is, body − (r) ∩ X = ∅ .

☞ Use tow counter for each rule, one for support and one for blockage.

383
Notions of Equivalence
Two programs Π1 and Π2 are

• (weakly) equivalent ( Π1 ≡ Π2 ) if AS(Π1 ) = AS(Π2 ) .


• strongly equivalent ( Π1 ≡s Π2 )if AS(Π1 ∪ Π′ ) = AS(Π2 ∪ Π′ )
for any program Π′ .

• uniformly equivalent ( Π1 ≡u Π2 ) if AS(Π1 ∪ F ) = AS(Π2 ∪ F )


for any set of facts F .

Example: Π1 = {a ∨ b ← } and Π2 = {a ← not b , b ← not a }

• Π1 ≡ Π2 since AS(Π1 ) = {{a}, {b}} = AS(Π2 )


• Π1 ≡u Π2
• Π1 6≡s Π2 , e.g. Π′ = {a ← b , b ← a }

384
How to Show Strong Equivalence

• close relation to non-classical logic of here-and-there (Lifschitz,


Pearce, Valverde)

• model-theoretic characterization (Turner)


– Let Π be a logic program and X, Y interpretations such that
X⊆Y
– (X, Y ) is an SE-model of Π if Y |= Π and X |= ΠY
– Ms (Π) denotes the set of all SE-models of Π
– Π1 ≡s Π2 iff Ms (Π1 ) = Ms (Π2 )

385
How to Show Strong Equivalence (ctd.)

Example: Π1 = {a ∨ b ← } and Π2 = {a ← not b , b ← not a }

Ms (Π1 ) = {({a}, {a}), ({b}, {b}), ({a}, {a, b}), ({b}, {a, b}),
({a, b}, {a, b})}

Ms (Π2 ) = Ms (Π1 ) ∪ {(∅, {a, b})}

Ms (Π1 ) 6= Ms (Π2 ) therefore Π1 6≡s Π2

386
How to Show Uniform Equivalence

• model-theoretic characterization (Eiter, Fink)


– Let Π be a logic program and X, Y interpretations such that
X⊆Y
– (X, Y ) ∈ Ms (Π) is an UE-model of Π if
for every (X ′ , Y ) ∈ Ms (Π) it holds that X ⊂ X ′ implies X ′ = Y
– Mu (Π) denotes the set of all UE-models of Π
– Π1 ≡u Π2 iff Mu (Π1 ) = Mu (Π2 )

387
How to Show Uniform Equivalence (ctd.)

Example: Π1 = {a ∨ b ← } and Π2 = {a ← not b , b ← not a }

Ms (Π1 ) = {({a}, {a}), ({b}, {b}), ({a}, {a, b}), ({b}, {a, b}),
({a, b}, {a, b})}

Ms (Π2 ) = Ms (Π1 ) ∪ {(∅, {a, b})}

☞ (X, Y ) = (∅, {a, b}) is not an UE-models of Π2 since


X ⊂ X ′ implies X ′ = Y does not hold e.g. for (X ′ , Y ) = ({a}, {a})
☞ All other SE-models of Π1 and Π2 are also UE-models:
Mu (Π1 ) = Mu (Π2 ) therefore Π1 ≡u Π2

388

You might also like