PKR 2 Stable.1nup

Download as pdf or txt
Download as pdf or txt
You are on page 1of 114

626.015 VU 2.

0 Selected Topics in Informatics:


Principles of Knowledge Representation

Stable Models and Answer Set Semantics

Thomas Eiter

Institute of Logic and Computation


Knowledge-Based Systems Group
Vienna University of Technology

Alpen Adria Universität, SS 2024


Unit Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 1/78


1. Introduction

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 2/78


1. Introduction 1.1 Logic for Knowledge Representation

Logic for Knowledge Representation

The dream of early AI:


Declare knowledge about a “world” of interest by logical sentences
Use predicate logic for knowledge representation
Derive new (implicit) knowledge by an automated procedure

Example 1

KB = {human(socrates), ∀x(human(x) ⇒ mortal(x))}

Conclusion: mortal(socrates)

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 3/78


1. Introduction 1.1 Logic for Knowledge Representation

Ways to derive new (implicit) knowledge

Purely syntactic: manipulate formulas according to inference rules


φ, φ⇒ψ ∀x(φ(x)), individual c
E.g.: Modus Ponens ψ , Specialisation: φ(c)
⇒ Logical Calculi
Semantical: Reason about the models of a knowledge base.

Big Problem

Predicate logic is undecidable in general (Turing, Church, 1930s)

Insight

Knowledge processing needs a control


(which inference rule(s) should be applied?)
very often, knowledge comprises rules and facts

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 4/78


1. Introduction 1.2 Prolog

Logic Programming – Prolog revisited

1960s/70s: Logic as a Programming Language (?)

Breakthrough in Computational Logic:


Robinson’s discovery of the Resolution Principle (1965)
Milestone: Prolog (1972)

Kowalski (1979):
ALGORITHM = LOGIC + CONTROL

Knowledge for problem solving (LOGIC)

“Processing” of the knowledge (CONTROL)

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 5/78


1. Introduction 1.2 Prolog

Prolog
Prolog = “Programming in Logic”

Basic data structures: terms


Programs: rules and facts
Computing: Queries (goals)
• Proofs provide answers
• SLD-resolution
• unification - basic mechanism to manipulate data structures

Example 2

man(dilbert).
person(X) ← man(X).

Query ?− person(X)
Answer X = dilbert
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 6/78
1. Introduction 1.2 Prolog

Example 3 (Recursion)

append([],X,X).
append([X|Y],Z,[X|T]) :- append(Y,Z,T).
reverse([],[]).
reverse([X|Y],Z) :- append(U,[X],Z), reverse(Y,U).

Both relations are defined recursively.


Terms represent complex objects: lists, sets, ...

Problem:
Reverse the list [a,b,c]

Ask query: ?- reverse([a,b,c],X).


A proof of the query yields a substitution: X=[c,b,a]
The substitution constitutes an answer

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 7/78


1. Introduction 1.2 Prolog

The key: techniques to search for proofs

Understanding of the resolution mechanism is important


It may make a difference which logically equivalent form is used (e.g.,
termination).

Example 4

reverse([X|Y], Z) ← append(U, [X], Z), reverse(Y, U). (1)


vs
reverse([X|Y], Z) ← reverse(Y, U), append(U, [X], Z). (2)

Query: ?− reverse([a|X], [b, c, d, b])


(1) yields answer “no”, (2) does not terminate

Is this truly declarative programming?

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 8/78


1. Introduction 1.3 LP Desiderata

LP Desiderata

Relieve the programmer from several concerns.

It is desirable that
• the order of subgoals in a rule does not matter;
• the order of program rules does not matter;
• in particular, termination is not subject to such order.

“Pure” declarative programming

Prolog does not satisfy these desiderata

Satisfied e.g. by the answer set semantics of logic programs

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 9/78


2. Horn Logic Programming

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 10/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Positive Logic Programs


Definition 5 (positive logic program)
A positive logic program P is a finite set of clauses (rules) of the form
a ← b1 , . . . , bm , (1)
where a, b1 , . . . , bm are atoms of a first-order language L.
a is the head of the rule
b1 , . . . , bm is the body of the rule.
If m = 0, the rule is a fact (written shortly a)

Roughly, (1) can be seen as material implication b1 ∧ · · · ∧ bm ⊃ a.

Example 6

connected(cagliari) ← hub(rome), link(rome, cagliari)


connected(X) ← hub(Y), link(Y, X)

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 11/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Semantics

Definition 7 (Herbrand universe / base / interpretation)

Given a logic program P, the Herbrand universe of P, HU(P) , is the set of


all terms which can be formed from constants and functions symbols in P
(resp., the vocabulary, if explicitly known).
The Herbrand base of P, HB(P), is the set of all ground atoms which can be
formed from predicates and terms t ∈ HU(P).
A (Herbrand) interpretation is a first-order interpretation I = (D, ·I ) of the
vocabulary with domain D = HU(P) where each term t ∈ HU(P) is
interpreted by itself, i.e., tI = t.
I is identified with the set { p(t1 , . . . , tn ) ∈ HB(P) | ht1I , . . . , tnI i ∈ pI }.

Informally, a (Herbrand) interpretation can be seen as a set denoting which


ground atoms are true in a given scenario.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 12/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Example 8 (Program P1 )

h(0, 0).
t(a, b, r).
p(0, 0, b).
p(f (X), Y, Z) ← p(X, Y, Z 0 ), h(X, Y), t(Z, Z 0 , r).
h(f (X), f (Y)) ← p(X, Y, Z 0 ), h(X, Y), t(Z, Z 0 , r).

Constant symbols: 0, a, b, r; Function symbols: f .

HU(P1 ): { 0, a, b, r, f (0), f (f (0)), ... f i (0)), .... f (a), f (f (a)), ... }

 h(f i (0), f j (0)), h(f i (0), f j (a)), ...h(f i (r), f j (r)),


 

HB(P1 ): p(f i (0), f j (0), f k (0)), p(f i (0), f j (0), f k (a)), ...p(f i (r), f j (r), f k (r)),
t(f i (0), f j (0), f k (0)), t(f i (0), f j (0), f k (a)), ...t(f i (r), f j (r), f k (r))
 

Some Herbrand interpretations:


I1 = ∅; I2 = HB(P1 ); I3 = {h(0, 0), t(a, b, r), p(0, 0, b)}; ...

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 13/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Grounding

The semantics of positive logic programs is defined in terms of grounding.

Definition 9 (ground instance, grounding)


A ground instance of a clause C of the form (1) is any clause C0 obtained from C
by applying a substitution
θ : Var(C) → HU(P)

to the variables in C, denoted as Var(C).


grnd(C) denotes the set of all possible ground instances of C
for any program P, the grounding of P is grnd(P) = C∈P grnd(C).
S

Roughly speaking, C is a shortcut denoting grnd(C), and each variable


appearing in C ranges over the Herbrand universe.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 14/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Example 10 (Program P2 )
p(f (X), Y, Z) ← p(X, Y, Z 0 ), h(X, Y), t(Z, Z 0 , r).
h(0, 0).

The ground instances of the first rule are

p(f (0), 0, 0) ← p(0, 0, 0), h(0, 0), t(0, 0, r). X = Y = Z = Z0 = 0


...
p(f (0), r, 0) ← p(0, r, 0), h(0, r), t(0, 0, r). X = Z = Z 0 = 0, Y = r
...
p(f (r), r, r) ← p(r, r, r), h(r, r), t(r, r, r). X = Y = Z = Z0 = r
...
p(f (f (0)), 0, 0) ← p(f (0), 0, 0), h(f (0), 0), t(0, 0, r). X = f (0), Y = Z = Z 0 = 0
...
The single ground instance of the second rule is

h(0, 0).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 15/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Herbrand Models

Definition 11 (model, satisfaction)


An interpretation I is a (Herbrand) model of a
a ground (variable-free) clause C = a ← b1 , . . . , bm , if either
{b1 , . . . , bm } * I or a ∈ I ; (I |= C)

a clause C, if I |= C0 for every C0 ∈ grnd(C); (I |= C)

a program P, if I |= C for every clause C in P. (I |= P)

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 16/78


2. Horn Logic Programming 2.1 Positive Logic Programs

Example 12 (Program P2 cont’d)

p(f (X), Y, Z) ← p(X, Y, Z 0 ), h(X, Y), t(Z 0 , Z, r).


h(0, 0).

Which of the following interpretations are models of P2 ?


I1 = ∅ no
I2 = HB(P2 ) yes
I3 = {h(0, 0), t(r, 0, r), p(0, 0, r)} no

Which of the above interpretations are models of P1 ?

Note:
Proposition 1
For every positive logic program P, HB(P) is a model of P.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 17/78


2. Horn Logic Programming 2.2 Minimal Model Semantics

Minimal Model Semantics

A logic program has multiple models in general.


Select one of these models as the canonical model.
Commonly accepted: truth of an atom in model I should be “founded” by
clauses.
Example 13
Given
P3 = {a ← b. b ← c. c},

truth of a in the model I = {a, b, c} is “founded.”


Given
P4 = { a ← b. b ← a. c },

truth of a in the model I = {a, b, c} is not founded.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 18/78


2. Horn Logic Programming 2.2 Minimal Model Semantics

Minimal Model Semantics (cont’d)

Semantics: Prefer models with true-part as small as possible.

Definition 14 (minimal model)


A model I of P is minimal, if there exists no model J of P such that J ⊂ I .

Theorem 15
Every logic program P has a single minimal model (called the least model),
denoted LM(P).

This is entailed by the following property:

Proposition 2 (intersection closure)


If I and J are models of P, then also I ∩ J is a model of P.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 19/78


2. Horn Logic Programming 2.2 Minimal Model Semantics

Example 16

For P3 = { a ← b. b ← c. c }, we have LM(P3 ) = {a, b, c}.

For P4 = { a ← b. b ← a. c }, we have LM(P4 ) = {c}.

For P2 = { p(f (X), Y, Z) ← p(X, Y, Z 0 ), h(X, Y), t(Z, Z 0 , r). h(0, 0)}, we
have LM(P2 ) = {h(0, 0) }.

For P1 above, we have

LM(P1 ) = {h(0, 0), t(a, b, r), p(0, 0, b), p(f (0), 0, a), h(f (0), f (0))}.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 20/78


2. Horn Logic Programming 2.2 Minimal Model Semantics

Computation
The minimal model can be computed via fixpoint iteration.

Definition 17 (TP operator)


Let TP : 2HB(P) → 2HB(P) be defined as

there exists some a ← b1 , . . . , bm


 
TP (I) = a .
in grnd(P) such that {b1 , . . . , bm } ⊆ I

We let denote TP0 = ∅, TPi+1 = TP (TPi ), i ≥ 0.

Fundamental result:
Theorem 18
TP has a least fixpoint, lfp(TP ), and lfp(TP ) = LM(P). Furthermore, the
sequence hTPi i, i ≥ 0, converges to lfp(TP ).

Proof: Use the fixpoint theorems of Knaster-Tarski and Kleene.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 21/78


2. Horn Logic Programming 2.2 Minimal Model Semantics

Example 19

For P3 = { a ← b. b ← c. c }, we have

TP03 = {}, TP13 = {c}, TP23 = {c, b}, TP33 = {c, b, a}, TP43 = TP33

Hence lfp(TP3 ) = {c, b, a}

For P4 = { a ← b. b ← a. c }, we have

TP04 = {}, TP14 = {c}, TP24 = TP14

Hence lfp(TP4 ) = {c}

For program P2 above, we have

TP02 = ∅, TP12 = {h(0, 0)}, TP22 = TP12 .

Hence lfp(TP2 ) = {h(0, 0)}.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 22/78


2. Horn Logic Programming 2.2 Minimal Model Semantics

Example 20 (cont’d)

For program P1 above, we have

TP01 = ∅,
TP11 = {h(0, 0), t(a, b, r), p(0, 0, b)},
TP21 = {h(0, 0), t(a, b, r), p(0, 0, b), p(f (0), 0, b), h(f (0), f (0))},
TP21 = TP31 .

Hence lfp(TP1 ) = {h(0, 0), t(a, b, r), p(0, 0, b), p(f (0), 0, b), h(f (0), f (0))}.

For program P = {p(0). p(f (X)) ← p(X)}, we have

TP0 = ∅, TP1 = {p(0)}, . . . , TPi = {p(0), . . . p(f i−1 (0))}, i ≥ 0;

hence lfp(TP ) = {p(f i (0)) | i ≥ 0} is infinite.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 23/78


3. Negation in Logic Programs

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 24/78


3. Negation in Logic Programs

Negation in Logic Programs


Why negation?

Natural linguistic concept

Facilitates convenient, declarative descriptions (definitions)


E.g., "Men who are not husbands are singles.”

Definition 21 (normal logic program)


A normal logic program is a set of rules of the form
a ← b1 , . . . , bm , not c1 , . . . , not cn (n, m ≥ 0) (2)

where a and all bi , cj are atoms in a first-order language L.


not is called “negation as failure”, “default negation”, or “weak negation”

Things get more complex!

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 25/78


3. Negation in Logic Programs

Programs with Negation

Prolog: “not hXi” means “Negation as Failure (to prove to hXi)”


Different from negation in classical logic!

Example 22 (Program P5 )

man(dilbert).
single(X) ← man(X), not husband(X).
husband(X) ← fail. % fail = "false" in Prolog

Query:
? − single(X).
Answer:
X = dilbert .

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 26/78


3. Negation in Logic Programs

Example 23 (cont’d)
Modifying the last rule of P5 , we get P6 :

man(dilbert).
single(X) ← man(X), not husband(X).
husband(X) ← man(X), not single(X).

Result in Prolog ????


Problem: not a single intuitive model!
Two intuitive Herbrand models:

M1 = {man(dilbert), single(dilbert)}, and


M2 = {man(dilbert), husband(dilbert)} .

Which one to choose?

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 27/78


3. Negation in Logic Programs

Semantics of Logic Programs with Negation


“War of Semantics” in Logic Programming (1980/90ies):
Meaning of programs like the Dilbert example above
Great Schism: Single model vs. multiple model semantics
To date:
• Well-Founded Semantics [van Gelder et al., 1991]

Partial model: man(dilbert) is true,


single(dilbert), husband(dilbert) are unknown
• Answer Set (alias Stable Model) Semantics by Gelfond and Lifschitz
[1988,1991].
Alternative models: M1 = {man(dilbert), single(dilbert)},
M2 = {man(dilbert), husband(dilbert)}.
Fundamental for the Answer Set Programming (ASP) paradigm

Agreement for so-called “stratified programs”


Different selection principles for non-stratified programs
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 28/78
3. Negation in Logic Programs

Multiple Preferred Models


How to interpret multiple-models semantics?
Query Answering:
• Cautious (Skeptical) Reasoning:
A query (formula) is true if it is true in every preferred model
• Brave (Credulous) Reasoning:
A query (formula) is true if it is true in some preferred model.
Model Generation, Problem Solving:
• Each preferred model represents a solution (possible world) for the
problem represented.

Example 24 (Dilbert cont’d)

man(dilbert) is both a cautious and brave consequence


Neither single(dilbert) nor ¬man(dilbert) is a cautious consequence
Both single(dilbert) and ¬single(dilbert) are brave consequences.
The preferred models M1 and M2 above represent “possible worlds”.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 29/78


3. Negation in Logic Programs

ASP Paradigm

General idea: stable models (=answer sets) are solutions!


Reduce solving a problem instance I to computing answer sets of an LP

Problem Encoding: Model(s)


ASP Solver
Instance I Program P Solution(s)

Method:
1 encode I as a (non-monotonic) logic program P, such that solutions of
I are represented by models of P
2 compute some model M of P, using an ASP solver
3 extract a solution for I from M .
variant: compute multiple/all models (for multiple/all solutions)
Often: decompose I into problem specification and data
Approach: guess and check (alias generate and test) plus auxiliary
definitions

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 30/78


4. Stratified Negation

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 31/78


4. Stratified Negation

Stratified Negation

Intuition: To evaluate a rule r: a ← · · · , not p(~t), · · · , the value of p(~t)


should be known.

1 Evaluate first p(~t).


then not p(~t) is true,

false,
2 if p(~t) is
true, then not p(~t) is false and r is not applicable.

Example 25

P = { boring(chess) ← not interesting(chess) }


interesting(chess) is false ⇒ not interesting(chess) is true.
hence, r is applied and boring(chess) is true.
This leads to the Herbrand model H = {boring(chess)} of P.

Note: this introduces procedurality (violates declarativity)!

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 32/78


4. Stratified Negation

Dependency Graph

Restriction:
The method works if there is no cyclic negation.

Need a syntactic criterion to ensure this property.

Definition 26 (dependency graph)


The dependency graph of a set P of rules, is a directed graph dep(P) = (N, E)
where
N = { predicate p | p occurs in P, p is not a built-in } (=: pred(S))
E contains p → q, iff P contains some rule a ← · · · , `, · · · with a = p(· · · )
and ` = q(· · · ) or ` = not q(· · · )
Label p → q with “*”, if ` = not q(· · · )

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 33/78


4. Stratified Negation

Example 27 (Program P7 )

man(dilbert).
husband(X) ← man(X), married(X).
single(X) ← man(X), not husband(X).

dep(P7 ):

husband
OO L
// married
LLL

LLL
LLL
L&&
single // man

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 34/78


4. Stratified Negation

Stratification

Definition 28 (stratification)
A stratification of a set P of rules is a partitioning
Σ = {S1 . . . , Sn }
of pred(P) into n nonempty, pairwise disjoint sets such that
(a) if p ∈ Si , q ∈ Sj , and p → q is in dep(P), then i ≥ j; and
(b) if p ∈ Si , q ∈ Sj , and p →? q is in dep(P) then i > j.

The sets S1 , . . . , Sn are the strata of P w.r.t. Σ.


P is stratified, if it has some stratification Σ.

Informally, Σ specifies an order of evaluation for the predicates in P


The sequential evaluation of S1 , S2 ,. . . ,Sn can be done by computing a
series of iterative least models.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 35/78


4. Stratified Negation

Semantics

Definition 29 (iterative least model)


Suppose P is a logic program with stratification Σ = {S1 , . . . , Sk }, k ≥ 1.
Then
PSi = {a ← b1 , . . . , bn ∈ P | a = p(· · · ), p ∈ Si }, and
HB? (PSi ) = j≤i {p(t) ∈ HB(P) | p ∈ Sj }.
S

The iterative least models Mi ⊆ HB(P), 1 ≤ i ≤ k, are such that


(i) M1 is the least model of PS1 ;
(ii) if i > 1, then Mi is the least subset M of HB(P) such that
• M is a model of PSi , and
• M ∩ HB? (PSi−1 ) = Mi−1 ∩ HB? (PSi−1 ).
The iterative least model of P is MP,Σ = Mk .

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 36/78


4. Stratified Negation

Example 30 (P7 cont’d)

man(dilbert).
husband(X) ← man(X), married(X).
single(X) ← man(X), not husband(X).

Stratification: Σ = {S1 = {man, married}, S2 = {husband}, S3 = {single}}

PS1 = {man(dilbert)} and M1 = LM(PS1 ) = {man(dilbert)}.


PS2 = {husband(X) ← man(X), married(X)}.
HB? (PS1 ) = {man(dilbert), married(dilbert)}.
Then, M2 = {man(dilbert)} is a model of PS2 and
M2 ∩ HB? (PS1 ) = M1 ∩ HB? (PS1 ) (no smaller such model exists)
PS3 = {single(X) ← man(X), not husband(X)}.
Thus M3 = {single(dilbert)} ∪ M2 is the least model of PS3 such that
M3 ∩ HB? (PS2 ) = M2 ∩ HB? (PS2 ).
HB? (PS2 ) = {man(dilbert), married(dilbert), husband(dilbert)}.
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 37/78
4. Stratified Negation

Stratification Theorem
Note: stratifications are not unique.
Example 31 (P7 cont’d)
Other stratification: Σ0 = {S10 = {man, married, husband}, S20 = {single}}.
Evaluation with Σ0 yields same result!

This is not accidental:

Theorem 32 (Apt et al. [1988])


Let P be a stratified program. Then for every stratifications Σ and Σ0 of P, it
holds that MP,Σ = MP,Σ0 .

Hence, we can simplify MP,Σ to MP = MP,Σ (for arbitrary Σ of choice)

Corollary 33
Stratified programs have a canonical model, also called perfect model.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 38/78


5. Stable Models

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 39/78


5. Stable Models 5.1 Ground Programs

Stable Model Semantics


First, for variable-free (ground) programs P
Treat “not ” specially
Intuitively, literals not a are a source of “incoherence” or “unstability”.

Example 34 (P6 cont’d)

man(dilbert). (f1 )
single(dilbert) ← man(dilbert), not husband(dilbert). (r1 )
husband(dilbert) ← man(dilbert), not single(dilbert). (r2 )

Consider M 0 = {man(dilbert)}.
If as in M 0 , man(dilbert) were true and husband(dilbert) false, by r1 also
single(dilbert) should be true. This is not coherent.
Consider M 00 = {man(dilbert), single(dilbert), husband(dilbert)}.
The bodies of r1 and r2 are not true wrt M 00 , hence there is no evidence for
single(dilbert) and husband(dilbert) being true.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 40/78


5. Stable Models 5.1 Ground Programs

Stable Models

Definition 35 (Gelfond-Lifschitz reduct PM 1988)


The GL-reduct (simply reduct) of a ground program P w.r.t. an interpretation M ,
denoted PM , is the program obtained from P by
1 removing rules with not a in the body for each a ∈ M ; and
2 removing literals not a from all other rules.

Intuition:
M makes an assumption about what is true and what is false.
The reduct PM incorporates this assumptions.
As a “not ”-free program, PM derives positive facts, given by LM(PM ).
If this coincides with M , then the assumption of M is “stable”.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 41/78


5. Stable Models 5.1 Ground Programs

Stable Models (cont’d)

Definition 36 (stable model)


An interpretation M of P is a stable model (or answer set) of P, if M = LM(PM ).

Observe:
PM = P for any “not ”-free program P.
Thus, for any positive program LM(P) (=LM(PM )) is its single stable model.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 42/78


5. Stable Models 5.1 Ground Programs

Example 37 (P6 cont’d)

man(dilbert). (f1 )
single(dilbert) ← man(dilbert), not husband(dilbert). (r1 )
husband(dilbert) ← man(dilbert), not single(dilbert). (r2 )

Candidate interpretations:
M1 = {man(dilbert), single(dilbert)},
M2 = {man(dilbert), husband(dilbert)},
M3 = {man(dilbert), single(dilbert), husband(dilbert)}
M4 = {man(dilbert)},

M1 and M2 are stable models.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 43/78


5. Stable Models 5.1 Ground Programs

Example 38 (P6 cont’d)

man(dilbert). (f1 )
single(dilbert) ← man(dilbert), not husband(dilbert). (r1 )
husband(dilbert) ← man(dilbert), not single(dilbert). (r2 )

M1 = {man(dilbert), single(dilbert)}:
M
reduct P6 1 :
man(dilbert).
single(dilbert) ← man(dilbert).
M
The least model of P6 1 is {man(dilbert), single(dilbert)} = M1 .

M2 = {man(dilbert), husband(dilbert)}: by symmetry of husband and single, also


M2 is stable.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 44/78


5. Stable Models 5.1 Ground Programs

Example 39 (P6 cont’d)

man(dilbert). (f1 )
single(dilbert) ← man(dilbert), not husband(dilbert). (r1 )
husband(dilbert) ← man(dilbert), not single(dilbert). (r2 )

M3 = {man(dilbert), single(dilbert), husband(dilbert)}: PM3


6 is

man(dilbert).

LM(P6M3 ) = {man(dilbert)} 6= M3 .

M4 = {man(dilbert)}: PM4
6 is

man(dilbert).
single(dilbert) ← man(dilbert).
husband(dilbert) ← man(dilbert).

LM(P6M4 ) = {man(dilbert), single(dilbert), husband(dilbert)} =


6 M4 .

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 45/78


5. Stable Models 5.1 Ground Programs

Inconsistent Programs

Each normal logic program has some Herbrand model.


However, it may have no stable model.

Example 40 (P⊥ )
p ← not p
Candidate M1 = {}: PM
⊥ = {p}, and LM(P⊥ ) = {p} =
1
6 M1 .
Candidate M2 = {p}: PM
⊥ = {}, and LM(P⊥ ) = {} =
2
6 M2 .

Is lack of a stable model bad??

Example 41 (Russell’s Barber Paradox)

shaves(X, Y) ← barber(X), man(Y), not shaves(Y, Y).


man(bertrand). man(dilbert).
barber(bertrand).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 46/78


5. Stable Models 5.2 Non-ground Programs

Programs with Variables

Consider, like in Prolog, only Herbrand interpretations.


As for positive programs, view a program clause as a shorthand for all its
ground instances.
Recall: grnd(P) is the grounding of program P.

Definition 42 (stable model, general case)


An interpretation M of P is a stable model of P, if M is a stable model of grnd(P).

Alternative way: Perform grounding in the GL-reduct, i.e., require


M = LM(PM ) where PM =def grnd(P)M for non-ground P.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 47/78


5. Stable Models 5.2 Non-ground Programs

Example 43 (Variant P06 of P6 )

man(dilbert). (r1 )
woman(alice). (r2 )
single(X) ← man(X), not husband(X). (r3 )
husband(X) ← man(X), not single(X). (r4 )

We have that, for instance,

grnd(r3 ) = { single(dilbert) ← man(dilbert), not husband(dilbert).


single(alice) ← man(alice), not husband(alice). };
grnd(P06 ) = { man(dilbert).
woman(alice).
single(dilbert) ← man(dilbert), not husband(dilbert).
single(alice) ← man(alice), not husband(alice).
husband(dilbert) ← man(dilbert), not single(dilbert).
husband(alice) ← man(alice), not single(alice). }.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 48/78


5. Stable Models 5.2 Non-ground Programs

Example 44 (P06 cont’d)

The program grnd(P06 ), and thus P06 , has the following stable models:
M1 = {man(dilbert), woman(alice), single(dilbert)}
M2 = {man(dilbert), woman(alice), husband(dilbert)}
Indeed,
the rule instances of r3 and r4 for dilbert generate two possible scenarios;
the rule instances of r3 and r4 for alice are inapplicable.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 49/78


5. Stable Models 5.3 Semantic Properties

Semantic Properties of Stable Models

Stable model semantics has a strong theoretical basis, many properties are
known.

We consider here some elementary ones.

See e.g.
• [Lifschitz, 2008]
• [Ferraris and Lifschitz, 2005]
• [Gelfond, 2008]
for other insights, alternative definitions and properties of stable models.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 50/78


5. Stable Models 5.3 Semantic Properties

Relationship to Classical Models

How do stable models of P relate to classical models of P?

Definition 45 (classical model of normal logic program)


An interpretation I is a model of
a ground clause C : a ← b1 , . . . , bm , not c1 , . . . , not cn , if either
{b1 , . . . , bm } * I or {a, c1 , . . . , cn } ∩ I 6= ∅ (I |= C);
a clause C, if I |= C0 for every C0 ∈ grnd(C) (I |= C);
a set P of rules, if I |= C for every clause C in P (I |= P).

This complies with Herbrand models satisfying the clause

a ∨ not b1 ∨ . . . ∨ not bm ∨ c1 ∨ . . . ∨ cn ,

where not is interpreted as classical negation (“¬”).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 51/78


5. Stable Models 5.3 Semantic Properties

Relationship to Classical Models (cont’d)

The following holds:

Theorem 46
1 Every stable model M of P is a model of P.
2 A stable model M does not contain any model M 0 of P properly (M 0 6⊂ M ),
i.e., is a minimal model of P (w.r.t. ⊆).

Corollary 47
Stable models are incomparable w.r.t. ⊆, i.e., if M1 and M2 are different stable
models of P, then M1 6⊆ M2 and M2 6⊆ M1 .

Thus, stable models adhere to minimality of positive information.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 52/78


5. Stable Models 5.3 Semantic Properties

Supportedness

Note: each atom a in a stable model M must be derived from some rule of
P.
Extend the immediate consequence operator TP to not .

Definition 48 (TP for normal P)


Given a normal program P and an interpretation I , let

there is some r = a ← b1 , . . . , bm , not c1 , . . . , not cn ∈ grnd(P)


 
TP (I) = a .
such that {b1 , . . . , bm } ⊆ I, {c1 , . . . cn } ∩ I = ∅

An interpretation I of P is a supported model of P, if TP (I) = I .

Theorem 49
Every stable model M of P is a supported model of P.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 53/78


5. Stable Models 5.3 Semantic Properties

Supportedness (cont’d)
In fact, by minimality of stable models, every stable model is a minimal
(w.r.t. ⊆) supported model of P.
The converse is not true.

Example 50 (Program Ps )

a ← not b.
b ← c.
c ← b.

Note that M1 = {a} and M2 = {b, c} are both minimal such that
TPs (M1 ) = M1 and TPs (M2 ) = M2 .
The single stable model of Ps is M1 .
Problem with M2 : Self-supportedness of b (via c)
Similar: Ps0 = {a ← not a; a ← a}

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 54/78


5. Stable Models 5.3 Semantic Properties

Unfounded sets
Stable models amount to supported models with no (cyclic) self-support

Definition 51 (unfounded set, cf. [van Gelder et al., 1991],[Leone et al., 1997])
A set U ⊆ HBP is an unfounded set of P relative to interpretation I , if for every
a ∈ U and r : a ← b1 , . . . , bm , not c1 , . . . , not cn in ∈ grnd(P), either
1 for some i ∈ {1, . . . , m}, either bi 6∈ I or bi ∈ U , or
2 for some j ∈ {1, . . . , n}, cj ∈ I .

Every P has a greatest unfounded set relative to I , denoted UP (I).


Intuitively, if I is compatible with P, all atoms in UP (I) can be safely
switched to false while maintaining compatibilty.

Definition 52 (unfounded-freeness)
I is called unfounded-free, if I ∩ U = ∅ for each unfounded set U of P rel. to I .

Note: I is unfounded-free iff I ∩ UP (I) = {}.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 55/78


5. Stable Models 5.3 Semantic Properties

Unfounded sets (cont’d)


Theorem 53 (implicit in [Leone et al., 1997])
Given a program P, a model M of P is stable iff M is unfounded-free.

Example 54 (Ps cont’d)

a ← not b.
b ← c.
c ← b.

M2 = {b, c}: UPs (M2 ) = {a, b, bc}, thus M2 ∩ UPs (M2 ) 6= ∅.


M1 = {a}: UPs (M1 ) = {b, c}, thus M1 ∩ UPs (M1 ) = ∅.

Unfounded-freeness is exploited for computing stable models (DLV)


It corresponds to loop formulas [Lin and Zhao, 2002], [Lee, 2005].
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 56/78
5. Stable Models 5.3 Semantic Properties

Stratified Programs
Stable model semantics gracefully generalizes stratified semantics:

Theorem 55
If a program P is stratified, then P has a single stable model, which coincides
with the perfect (i.e., the iterative least) model of P.

Notes:
A stratified P may have several minimal models; only one is stable
E.g., P = {boring(chess) ← not interesting(chess)}
has two minimal models:
M1 = {boring(chess)} and M2 = {interesting(chess)}.
The perfect model is MP = M1 .

Stratified programs can only express deterministic scenarios, no


“alternatives” are possible!

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 57/78


5. Stable Models 5.3 Semantic Properties

Non-Cumulativity
In classical logic, adding consequences of a theory T to T preserves its
semantics.
This property is known as cumulativity (or lemma support).
For stable model semantics, this property does not hold.
Proposition 3
Suppose P and atom a fulfill M |= a, for each stable model M of P. Then P and
P ∪ { a } need not have the same stable models (even if P is consistent).

Example 56

b ← not c. c ← not b.
a ← b. a ← not a.

P has the stable model M = {a, b}; P ∪ {a} has in addition M 0 = {a, c}.

Note: the property holds for stratified programs.


[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 58/78
5. Stable Models 5.4 Computational Aspects

Computation
How difficult is it to compute some stable model?

Decision problem CONS:


Given a program P, does P have some stable model?

Theorem 57
For normal logic programs P, problem CONS is
NP-complete in the propositional and ground case;
NE XP T IME-complete in the datalog (function-free) case;
Σ11 -complete in the general first-order case.

Recall: NP (NE XP T IME) = class of problems solvable in polynomial (exponential)


time on a non-deterministic Turing machine.
Σ11 is a class in the Analytic Hierarchy

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 59/78


5. Stable Models 5.4 Computational Aspects

Computation (cont’d)

Lower complexity holds for fragments:


For positive and stratified propositional programs, CONS is polynomial (in
fact, trivial).
• Still solvable in linear time if constraints and strong negation are
allowed (P-complete).
• For datalog programs, complexity increases to E XP T IME.
For programs with function symbols, several decidable program classes are
known (up to 3-E XP T IME, see [Šimkus, 2010]).

More on basic complexity: [Dantsin et al., 2001].

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 60/78


5. Stable Models 5.4 Computational Aspects

Stable Models (ASP) Engines


ASPERIX www.info.univ-angers.fr/pub/claire/asperix/
ASSAT https://cse.hkust.edu.hk/assat/
1
CLASP https://potassco.org/clasp/
CMODELS www.cs.utexas.edu/users/tag/cmodels/
2
DLV www.dbai.tuwien.ac.at/proj/dlv/
ASPTOOLS https://research.ics.aalto.fi/software/asp/
ME - ASP www.mat.unical.it/ricca/me-asp/
OMIGA www.kr.tuwien.ac.at/research/systems/omiga
ALPHA www.kr.tuwien.ac.at/research/systems/alpha/
SMODELS www.tcs.hut.fi/Software/smodels/
WASP www.mat.unical.it/ricca/wasp/
XASP http://www.swmath.org/software/13876, with XSB
S ( CASP ) https://gitlab.software.imdea.org/ciao-lang/sCASP
....
1
+ CLASP D, CLINGO, CLINGCON etc. (http://potassco.sourceforge.net/)
2
+ DLVHEX, DLVDB , DLT, DLV- COMPLEX, ONTO - DLV, DLV2, etc.

Many ASP solvers are available (mostly function-free programs)


Efforts to realize tractable fragments (downscaling)
clasp was first ASP solver competitive to top SAT solvers
ASP Solver competition (at LPNMR, since 2007)
Benchmark platform http://asparagus.cs.uni-potsdam.de/
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 61/78
5. Stable Models 5.4 Computational Aspects

Evaluation Approaches
Different methods and evaluation approaches:
• resolution-based: [Bonatti et al., 2008]
• forward chaining: [Lefèvre et al., 2015]
• lazy grounding: [Palù et al., 2009], [Dao-Tran et al., 2012], [de Cat et
al., 2012]
• translation-based: e.g. to SAT: assat [Lin and Zhao, 2004], cmodels
[Lierler, 2005], or SMT [Niemelä, 2009]
• meta-interpretation: [E_ et al., 2003]
• portfolio solving: e.g. claspfolio [Gebser et al., 2011], me-asp [Maratea
et al., 2014]

Predominant architecture

Intelligent Grounding + Model Search (Solving)


• modern SAT techniques (conflict driven clause learning)
• Export of techniques for optimal answer sets to SAT
More information: [Kaufmann et al., 2016]
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 62/78
6. Extensions

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 63/78


6. Extensions

Extensions
Many extensions exist, partly motivated by applications
Some are syntactic sugar, other strictly add expressiveness
Incomplete list:
• constraints
• strong negation
• disjunction
• aggregates (Smodels, DLV, clasp, wasp)
• cardinality constraints (Smodels)
• optimization: weight constraints, minimize (Smodels);
weak constraints (DLV)
• nested expressions
• templates (for macros), external functions (DLVHEX)
• Frame Logic syntax (for Semantic Web)
• preferences: e.g., PLP
• temporal logic: telingo, ticker
• probabilities: plingo
• KR frontends (diagnosis, inheritance, planning,...) in DLV
Surveys: [Niemelä (ed.), 2005], [Gebser and Schaub, 2016]
[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 64/78
6. Extensions

Application Areas
configuration non-classical reasoning
information integration (abduction, induction)
inconsistency management recommender systems
planning, reasoning about actions systems biology / biomedicine
routing, scheduling knowledge management
diagnosis, repair robotics
security, verification natural language processing
Semantic Web computational linguistics
games, puzzles agents
algorithm design musicology
argumentation context-aware reasoning
classification ...

early report: http://www.kr.tuwien.ac.at/projects/WASP/report.html


articles in AI Magazine [Erdem et al., 2016], KI-Zeitschrift [Falkner et al., 2018]
survey table:
https://www.dropbox.com/s/pe261e4qi6bcyyh/aspAppTable.pdf?dl=0

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 65/78


6. Extensions 6.1 Constraints

Constraints

Adding
p ← q1 , . . . , qm , not r1 , . . . , not rn , not p.

to P “kills” all stable models of P that


• contain q1 , . . . , qm , and
• do not contain r1 , . . . , rn

This is convenient to eliminate scenarios which do not satisfy integrity


constraints.

Short:

Constraint

← q1 , . . . , qm , not r1 , . . . , not rn .

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 66/78


6. Extensions 6.1 Constraints

Example 58 (Dilbert P6 cont’d)

man(dilbert). (f1 )
single(dilbert) ← man(dilbert), not husband(dilbert). (r1 )
husband(dilbert) ← man(dilbert), not single(dilbert). (r2 )
← husband(X), not has_wedding_ring(X). (c1 )

The constraint c1 eliminates models in which there is no evidence for a


husband having a wedding ring.
Single stable model: M1 = {man(dilbert), single(dilbert)}

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 67/78


6. Extensions 6.2 Strong Negation

Strong Negation

Weak negation “not a” means “a can not be proved (derived) using rules,”
and that a is false by default (believed to be false).
This is different from knowing (provably) that a is false; this is expressed by
−a (sometimes ¬a).
This is called strong negation and may make an important difference.

Example 59 (due to John McCarthy)


Consider an agent A with the following task:
“At a railroad crossing, cross the rails if no train approaches.”
We may encode this scenario using one of the following two rules:

walk ← at(A, L), crossing(L), not train_approaches(L). (r1 )


walk ← at(A, L), crossing(L), −train_approaches(L). (r2 )

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 68/78


6. Extensions 6.2 Strong Negation

Extended Logic Programs

Definition 60
An extended logic program (ELP) is a finite set of rules
a ← b1 , . . . , bm , not c1 , . . . , not cn (n, m ≥ 0) (3)

where a, bi , cj are atoms or strongly negated atoms in a f.o. language L.

The semantics of ELPs can be defined by program transformation:


X)” as atoms with fresh predicate symbols “−p”;
view literals “−p(~
add constraints ← p(~
X), −p(~
X) to P (p(~
X) and −p(~
X) are not simultaneously
true); and
select the stable models of the resulting program (called answer sets of P).

Answer sets M : three-valued view


Atom a may be true (a ∈ M ), false (−a ∈ M ), or unknown (a, −a ∈
/ M ).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 69/78


6. Extensions 6.2 Strong Negation

Strong negation (combined with weak negation) is e.g. helpful to express default
rules.

Example 61 (French speaking)

french(luc). (f1 )
speaks(X, french) ← french(X), not − speaks(X, french). (r1 )
−speaks(X, french) ← thumb(X). (r2 )

r1 expresses that by default, French can speak French.


Single answer set M = {french(luc), speaks(luc, french)}.

Note:
ELPs are closely related to Default Logic [Reiter, 1980]
The answer sets of P correspond 1-1 to the extensions of the default theory
T = (∅, {d(C) | C ∈ P}) (d(C) casts C into a default rule).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 70/78


6. Extensions 6.3 Disjunction

Disjunction

The use of disjunction is natural to express indefinite knowledge.

Example 62

female(X) ∨ male(X) ← person(X).

broken(left_hand, tom) ∨ broken(right_hand, tom).

Disjunction is natural for expressing a “guess” and to create non-determinism

Example 63

ok(C) ∨ −ok(C) ← component(C).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 71/78


6. Extensions 6.3 Disjunction

Minimality

Semantics: disjunction is minimal (different from classical logic):


a ∨ b ∨ c.
Minimal models: {a}, {b}, and {c}.

actually subset minimal:


a ∨ b. a ∨ c.
Minimal models: {a} and {b, c}.
a ∨ b. a←b
Models {a} and {a, b}, but only {a} is minimal.

but minimality is not necessarily exclusive:


a ∨ b. b ∨ c. a ∨ c.
Minimal models: {a, b}, {a, c}, and {b, c}.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 72/78


6. Extensions 6.3 Disjunction

Disjunction vs. Unstratified Negation

Reconsider the Dilbert Program P6 :

man(dilbert).
single(X) ← man(X), not husband(X).
husband(X) ← man(X), not single(X).

is under stable semantics equivalent to the program Pdd :

man(dilbert).
single(X) ∨ husband(X) ← man(X).

The use of disjunction is more intuitive!

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 73/78


6. Extensions 6.3 Disjunction

Extended Logic Programs with Disjunctions

Definition 64 (extended disjunctive logic program)


An extended disjunctive logic program (EDLP) is a finite set of rules
a1 ∨ · · · ∨ ak ← b1 , . . . , bm , not c1 , . . . , not cn (k, m, n ≥ 0) (4)

where all ai , bj , cl are atoms or strongly negated atoms in f.o. language L.

Semantics:
Answer sets of P are defined similarly as for an ELP
Differences:
• I is a model of ground (4), if either {b1 , . . . , bm } * I or
{a1 , . . . , ak , c1 , . . . , cn } ∩ I 6= ∅
• “M is the least model of PM ” ; “M is a minimal model of PM ”
(PM may have multiple minimal models).

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 74/78


6. Extensions 6.3 Disjunction

Example 65 (Disjunctive Dilbert Pdd , cont’d)

man(dilbert).
single(X) ∨ husband(X) ← man(X).

As Pdd is “not ”-free, grnd(Pdd )M = grnd(Pdd ) for every M .

Answer sets:
M1 = {man(dilbert), single(dilbert)}, and

M2 = {man(dilbert), husband(dilbert)}.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 75/78


6. Extensions 6.3 Disjunction

Some Properties of EDLPs

Every answer set of an EDLP P is a minimal model of P (models analogous


as for ELPs)
Different answer sets of an EDLP P are incomparable
An EDLP may have no, a single or multiple answer sets
For EDLPs without strong negation, answer sets are models that are
unfounded-free [Leone et al., 1997]
Deciding whether a propositional EDLP P has some answer set is
Σp2 -complete. p
(Σ2 = NP NP )

Disjunction adds higher problem solving capacity, it is not just syntactic


sugar!

But: EDLPs can not be regarded as a fragment of Reiter’s Default Logic.

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 76/78


7. Conclusion

Outline

1. Introduction

2. Horn Logic Programming

3. Negation in Logic Programs

4. Stratified Negation

5. Stable Models

6. Extensions

7. Conclusion

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 77/78


7. Conclusion

Conclusion
Answer Set (Stable model) Semantics is a predominant semantics for
nonmonotonic logic programs to date (“pure” declarative programming)
Paradigm shift from computing proofs (Prolog) to computing models
This is massively exploited for Answer Set Programming (ASP)
• encode the solution of a problem in answers sets of a logic program
• run an ASP solver
• extract solution(s) from answer set(s)
ASP is a highly active research field, with growing application range
• brief introduction: e.g., [Brewka et al., 2011]
• a primer: [E_ et al., 2009]
• textbooks: e.g. [Baral, 2003], [Gebser et al., 2012], [Gelfond and Kahl, 2014],
[Lifschitz, 2019]
Special issues on ASP:

Fall 2016 July 2018 May 2019

[email protected] 626.015 VU 2.0 Principles of KR AAU, SS 2024 78/78


References I

K.R. Apt, H.A. Blair, and A. Walker.


Towards a Theory of Declarative Knowledge.
In J. Minker, editor, Foundations of Deductive Databases and Logic Programming, pages 89–148. Morgan
Kaufman, Washington DC, 1988.
C. Baral and M. Gelfond.
Logic Programming and Knowledge Representation.
Journal of Logic Programming, 19/20:73–148, 1994.
Chitta Baral.
Knowledge Representation, Reasoning and Declarative Problem Solving.
Cambridge University Press, Cambridge, 2003.
Bart Bogaerts, Esra Erdem, and Amelia Harrison.
Guest editorial: special issue on answer set programming and other computing paradigms.
Ann. Math. Artif. Intell., 86(1-3):1–2, 2019.
Piero A. Bonatti, Enrico Pontelli, and Tran Cao Son.
Credulous resolution for answer set programming.
In Dieter Fox and Carla P. Gomes, editors, Proceedings of the Twenty-Third AAAI Conference on Artificial
Intelligence, AAAI 2008, Chicago, Illinois, USA, July 13-17, 2008, pages 418–423. AAAI Press, 2008.
Gerd Brewka, Thomas Eiter, and Miroslaw Truszczyński.
Answer set programming at a glance.
Communications of the ACM, 54(12):92–103, 2011.
doi>10.1145/2043174.2043195.
References II

Gerd Brewka, Thomas Eiter, and Miroslaw Truszczyński, editors.


AI Magazine: special issue on Answer Set Programming. AAAI Press, 2016.
Volume 37, number 3. Editorial pp. 5-6.
Evgeny Dantsin, Thomas Eiter, Georg Gottlob, and Andrei Voronkov.
Complexity and Expressive Power of Logic Programming.
ACM Computing Surveys, 33(3):374–425, 2001.
Minh Dao-Tran, Thomas Eiter, Michael Fink, Gerald Weidinger, and Antonius Weinzierl.
OMiGA: An open minded grounding on-the-fly answer-set solver.
In Luis Fariñas del Cerro, Andreas Herzig, and Jérôme Mengin, editors, Proceedings 13th European
Conference on Logics in Artificial Intelligence (JELIA 2012), number 7519 in LNCS, pages 480–483.
Springer, 2012.
Broes de Cat, Marc Denecker, and Peter J. Stuckey.
Lazy model expansion by incremental grounding.
In Agostino Dovier and Vítor Santos Costa, editors, Technical Communications of the 28th International
Conference on Logic Programming, ICLP 2012, September 4-8, 2012, Budapest, Hungary, volume 17 of
LIPIcs, pages 201–211. Schloss Dagstuhl - Leibniz-Zentrum fuer Informatik, 2012.
DLV homepage, since 1996.
http://www.dbai.tuwien.ac.at/proj/dlv/.
T. Eiter, W. Faber, N. Leone, and G. Pfeifer.
Declarative Problem-Solving Using the DLV System.
In J. Minker, editor, Logic-Based Artificial Intelligence, pages 79–103. Kluwer Academic Publishers, 2000.
References III

Thomas Eiter, Wolfgang Faber, Nicola Leone, and Gerald Pfeifer.


Computing preferred answer sets by meta-interpretation in answer set programming.
Theory and Practice of Logic Programming, 3(4-5):463–498, 2003.
Thomas Eiter, Giovambattista Ianni, and Thomas Krennwallner.
Answer set programming: A primer.
In Sergio Tessaris and Enrico Franconi et al., editors, Reasoning Web, Fifth International Summer School
2008, Bressanone Italy, August 30–September 4, 2009, Tutorial Lectures, number 5689 in LNCS, pages
40–110. Springer, 2009.
Esra Erdem, Michael Gelfond, and Nicola Leone.
Applications of answer set programming.
AI Magazine, 37(3):53–68, 2016.
Andreas A. Falkner, Gerhard Friedrich, Konstantin Schekotihin, Richard Taupe, and Erich Christian Teppan.
Industrial applications of answer set programming.
Künstliche Intell., 32(2-3):165–176, 2018.
Paolo Ferraris and Vladimir Lifschitz.
Mathematical foundations of answer set programming.
In We Will Show Them! Essays in Honour of Dov Gabbay, Volume One, pages 615–664. College
Publications, 2005.
Martin Gebser and Torsten Schaub.
Modeling and language extensions.
In Brewka et al. [2016], pages 33–44.
References IV

Martin Gebser, Roland Kaminski, Benjamin Kaufmann, Torsten Schaub, Marius Thomas Schneider, and
Stefan Ziller.
A portfolio solver for answer set programming: Preliminary report.
In James P. Delgrande and Wolfgang Faber, editors, Logic Programming and Nonmonotonic Reasoning -
11th International Conference, LPNMR 2011, Vancouver, Canada, May 16-19, 2011. Proceedings, volume
6645 of Lecture Notes in Computer Science, pages 352–357. Springer, 2011.
Martin Gebser, Roland Kaminski, Benjamin Kaufmann, and Torsten Schaub.
Answer Set Solving in Practice.
Synthesis Lectures on Artificial Intelligence and Machine Learning. Morgan & Claypool Publishers, 2012.
Michael Gelfond and Yulia Kahl.
Knowledge Representation, Reasoning, and the Design of Intelligent Agents: The Answer-Set Programming
Approach.
Cambridge University Press, New York, NY, USA, 2014.
M. Gelfond and V. Lifschitz.
The Stable Model Semantics for Logic Programming.
In Logic Programming: Proceedings Fifth Intl Conference and Symposium, pages 1070–1080, Cambridge,
Mass., 1988. MIT Press.
M. Gelfond and V. Lifschitz.
Classical Negation in Logic Programs and Disjunctive Databases.
New Generation Computing, 9:365–385, 1991.
M. Gelfond.
Answer sets.
In B. Porter F. van Harmelen, V. Lifschitz, editor, Handbook of Knowledge Representation, chapter 7, pages
285–316. Elsevier, 2008.
References V

Benjamin Kaufmann, Nicola Leone, Simona Perri, and Torsten Schaub.


Grounding and solving in answer set programming.
In Brewka et al. [2016], pages 25–32.
Joohyung Lee.
A model-theoretic counterpart of loop formulas.
In Leslie Pack Kaelbling and Alessandro Saffiotti, editors, IJCAI, pages 503–508. Professional Book Center,
2005.
Claire Lefèvre, Christopher Béatrix, Igor Stéphan, and Laurent Garcia.
Asperix, a first order forward chaining approach for answer set computing.
CoRR, abs/1503.07717, 2015.
Nicola Leone, Pasquale Rullo, and Francesco Scarcello.
Disjunctive Stable Models: Unfounded Sets, Fixpoint Semantics and Computation.
Information and Computation, 135(2):69–112, June 1997.
Nicola Leone, Gerald Pfeifer, Wolfgang Faber, Thomas Eiter, Georg Gottlob, Simona Perri, and Francesco
Scarcello.
The DLV System for Knowledge Representation and Reasoning.
ACM Transactions on Computational Logic, 7(3):499–562, 2006.
Available via http://www.arxiv.org/ps/cs.AI/0211004.
Yuliya Lierler.
cmodels - sat-based disjunctive answer set solver.
In Chitta Baral, Gianluigi Greco, Nicola Leone, and Giorgio Terracina, editors, Logic Programming and
Nonmonotonic Reasoning, 8th International Conference, LPNMR 2005, Diamante, Italy, September 5-8,
2005, Proceedings, volume 3662 of Lecture Notes in Computer Science, pages 447–451. Springer, 2005.
References VI

Vladimir Lifschitz.
Answer Set Programming and Plan Generation.
Artificial Intelligence, 138:39–54, 2002.
Vladimir Lifschitz.
Twelve definitions of a stable model.
In ICLP, pages 37–51, 2008.
Vladimir Lifschitz.
Answer Set Programming.
Springer, 2019.
Fangzhen Lin and Yuting Zhao.
ASSAT: Computing Answer Sets of a Logic Program by SAT Solvers.
In Proceedings of the Eighteenth National Conference on Artificial Intelligence (AAAI-2002), Edmonton,
Alberta, Canada, 2002. AAAI Press / MIT Press.
Fangzhen Lin and Yuting Zhao.
ASSAT: computing answer sets of a logic program by SAT solvers.
Artificial Intelligence, 157(1-2):115–137, 2004.
Marco Maratea, Luca Pulina, and Francesco Ricca.
A multi-engine approach to answer-set programming.
TPLP, 14(6):841–868, 2014.
References VII

Ilkka Niemelä (ed.).


Language Extensions and Software Engineering for ASP.
Technical Report WP3, Working Group on Answer Set Programming (WASP), IST-FET-2001-37004,
September 2005.
Available at http://www.tcs.hut.fi/Research/Logic/wasp/wp3/wasp-wp3-web/.
Ilkka Niemelä.
Integrating answer set programming and satisfiability modulo theories.
In Esra Erdem, Fangzhen Lin, and Torsten Schaub, editors, Logic Programming and Nonmonotonic
Reasoning, 10th International Conference, LPNMR 2009, Potsdam, Germany, September 14-18, 2009.
Proceedings, volume 5753 of Lecture Notes in Computer Science, page 3. Springer, 2009.
Alessandro Dal Palù, Agostino Dovier, Enrico Pontelli, and Gianfranco Rossi.
Gasp: Answer set programming with lazy grounding.
Fundamenta Informaticae, 96(3):297–322, 2009.
R. Reiter.
A Logic for Default Reasoning.
Artificial Intelligence, 13:81–132, 1980.
Torsten Schaub and Stefan Woltran.
Answer set programming unleashed!
KI, 32(2-3):105–108, 2018.
Mantas Šimkus.
Nonmonotonic Logic Programs with Function Symbols.
PhD thesis, Institut für Informationssysteme, Technische Universität Wien, 2010.
References VIII

A. van Gelder, K.A. Ross, and J.S. Schlipf.


The Well-Founded Semantics for General Logic Programs.
Journal of the ACM, 38(3):620–650, 1991.
9. Appendix 9.1 Fixpoint Theorems of Knaster-Tarski/Kleene

Appendix: Fixpoint Theorems of Knaster-Tarski and


Kleene
Definition 66 (complete lattice)
A complete lattice is a partially ordered set (V, ≤) such that each subset W ⊆ V
has a least upper bound sup(W) and a greatest lower bound inf (W).

Example 67

V is the set of all Herbrand interpretations of program P


≤ is set inclusion (⊆)

Definition 68 (operator)
An operator on a complete lattice (V, ≤) is a mapping T : V −→ V .

Example 69
TP operator for program P on Herbrand interpretations
9. Appendix 9.1 Fixpoint Theorems of Knaster-Tarski/Kleene

Monotone Operators
Definition 70 (monotone operator)
An Operator T : V −→ V on (V, ≤) is monotone, if

x ≤ y ⇒ T(x) ≤ T(y) ∀x, y ∈ V.

Monotone operators have nice fixpoint properties

Theorem 71 (Knaster-Tarski)
Any monotone operator T on a complete lattice (V, ≤) has a least fixpoint
lfp(T), and
lfp(T) = inf ({x ∈ V | T(x) ≤ x}).

Example 72
TP operator for program P is monotone
9. Appendix 9.1 Fixpoint Theorems of Knaster-Tarski/Kleene

Continuous Operators
A stronger theorem holds for continuous operators.

Definition 73 (directed set)


A set W ⊆ V is directed, if for each x, y ∈ W there exists some z ∈ W such that x ≤ z and
y ≤ z, where (V, ≤) is a partial order.

Definition 74 (continuous operator)


Operator T : V −→ V on a complete lattice (V, ≤) is continuous, if

T(sup(W)) = sup({T(x) | x ∈ W})

for every directed set W ⊆ V .

Intuitively, directedness models convergence (build chain x0 < x1 < ...)


Continuous operators are monotone

Example 75
TP operator is also continuous.
9. Appendix 9.1 Fixpoint Theorems of Knaster-Tarski/Kleene

Theorem 76 (Kleene)
Any continuous operator T on a complete lattice (V, ≤) has a least fixpoint, and

lfp(T) = sup({T i | i ≥ 0}),

where T 0 = inf (V) and T i+1 = T(T i ), for all i ≥ 0.

Notation: T ∞ = sup({T i | i ≥ 0}).


Finite convergence: T k = T k−1 for some k ⇒ T ∞ = T k
Remark. A weaker form of Kleene’s theorem holds for all monotone operators
(transfinite sequence T i ).
9. Appendix 9.2 Railroad Network

Appendix: Stratification Example: Railroad Network

Determine whether safe connections between locations in a railroad


network

bis
semel
quincy
clote ter

mamuk olfe
dalte icsi
quater

Cutpoint for a and b: if it fails, there is no connection between a and b


Safe connection between a and b:p no cutpoints between a and b
E.g., ter is a cutpoint for olfe and semel, while quincy is not.
9. Appendix 9.2 Railroad Network

Predicates:

link(X, Y): direct connection from station X to Y (facts)

linked(A, B): symmetric closure of link.

connected(A, B): there is path between A and B (one or more links)

cutpoint(X, A, B): each path from A to B goes through station X

circumvent(X, A, B): there is a path between A and B not passing X

has_icut_point(A, B): there is at least one cutpoint between A and B.

safely_connected(A, B): A and B are connected with no cutpoint.

station(X): X is a railway station.


9. Appendix 9.2 Railroad Network

Railroad program P:

R1 : linked(A, B) : −link(A, B).


R2 : linked(A, B) : −link(B, A).
R3 : connected(A, B) : −linked(A, B).
R4 : connected(A, B) : −connected(A, C), linked(C, B).
R5 : cutpoint(X, A, B) : − connected(A, B), station(X),
not (circumvent(X, A, B)).
R6 : circumvent(X, A, B) : −linked(A, B), X 6= A, station(X), X 6= B.
R7 : circumvent(X, A, B) : −circumvent(X, A, C), circumvent(X, C, B).
R8 : has_icut_point(A, B) : −cutpoint(X, A, B), X 6= A, X 6= B.
R9 : safely_connected(A, B) : − connected(A, B),
not (has_icut_point(A, B)).
R10 : station(X) : −linked(X, Y).
9. Appendix 9.2 Railroad Network

dep(P):

station linked
circumvent link
*
has_icut_point connected
cutpoint
*

safely_connected

Stratification Σ = {S1 , S2 , S3 }:

S1 = {link, linked, station, circumvent, connected}


S2 = {cutpoint, has_icut_point}
S3 = {safely_connected}
9. Appendix 9.2 Railroad Network

Evaluation:
1 PS1 :
M1 = {linked(semel, bis), linked(bis, ter), linked(ter, olfe),
. . . , connected(semel, olfe), . . . ,
circumvent(quincy, semel, bis), . . .}
2 PS2 :
M2 = M1 ∪ {cutpoint(ter, semel, olfe),
has_icut_point(semel, olfe), . . .}
3 PS3 :
MP = M3 = M2 ∪ {safely_connected(semel, bis),
safely_connected(semel, ter)}
/ MP
Note: safely_connected(semel, olfe) ∈
9. Appendix 9.3 The DLV System

Appendix: The DLV System

http://www.dbai.tuwien.ac.at/proj/dlv/,
http://www.dlvsystem.com

DLV was a longtime state-of-the-art disjunctive answer set solver

Developed at TU Wien / University of Calabria (since 1996)

Possesses richer syntax than normal logic programs, resulting in higher


expressiveness!

Offers front-ends for specific KR-tasks (diagnosis, planning, etc.).

Later version:
• DLV 2.0, combines i-DLV and wasp
https://www.mat.unical.it/DLV2/
9. Appendix 9.3 The DLV System

Features of DLV

Language: disjunctive extended logic programs, formerly no function


symbols.

Additionally:
• bounded integer arithmetic, and comparison built-ins
• integrity constraints
• weak constraints
• aggregates
• since Release 2010-10-14: functions symbols available! (also in
DLV-Complex)

Support for
• answer set generation
• With release 2010-10-14: well-founded model generation
• brave and cautious reasoning
• many extensions: e.g. DLVHEX, DLVDB , ASPIDE, JDLV ...
9. Appendix 9.3 The DLV System

DLV Syntax

Rules

a1 v · · · v an :- b1 , . . . , bk , not bk+1 , . . . , not bm .

where n ≥ 1, m ≥ 0 and all ai , bj are atoms or strongly negated atoms


(e.g. −a); no function symbols.

Integrity Constraints

:- b1 , . . . , bk , not bk+1 , . . . , not bm .

can be regarded as rules with an empty (false) head.

Queries
b1 , . . . , bk , not bk+1 , . . . , not bm ?
9. Appendix 9.3 The DLV System

Built-in Predicates

Comparison Predicates:

<, >, <=, >=, ==, ! =

Arithmetic Predicates:

#int, #succ, +, ∗; Release 2010-10-14: #mod, #prec, − /

#int(X): X is known integer (1 ≤ X ≤ N).


#succ(X, Y): Y is successor of X, i.e., Y = X + 1.
+(X, Y, Z): Z = X + Y.
∗(X, Y, Z): Z = X ∗ Y.
N.B. An upper bound for integers has to be specified when dlv is invoked.
9. Appendix 9.3 The DLV System

Safety

Each variable occurring in a rule (resp. constraint) r in either


the head,
a default literal not b, or
a built-in comparsion predicate,
must occur in at least 1 non-comparison not-free literal in the body of r.

Safe rules
a(X) :- not b(X), c(X).
a(X) :- X > Y, node(X), node(Y).

Unsafe rules
a(X) v − a(X).
a(X) :- not b(X).
:- X <= Y, node(X).
9. Appendix 9.3 The DLV System

Using DLV

DLV is command-line oriented . . .


. . . but there is also a simple GUI.

Input is read from files whose names are passed on the command-line.
If the command-line option “--” has been specified, input is also read from
standard input (stdin).
Output is printed to standard output (stdout), one line per model / answer
set.

Detailed documentation is at
http://www.dbai.tuwien.ac.at/proj/dlv/,
http://www.dlvsystem.com
9. Appendix 9.4 Declarative Problem Solving in DLV

Declarative Problem Solving in DLV

DLV supports, like similar system, declarative problem solving in the


Answer Set Programming paradigm [Brewka et al., 2011].

Certain techniques/methodologies are available for developing encodings.

Review here briefly some; for more discussion, see [E_ et al., 2009].

DLV also has front-ends for some problems.


9. Appendix 9.4 Declarative Problem Solving in DLV

Front-ends

Besides the answer set semantics core, DLV offers front-ends for problem
solving.

The problem, expressed in a designated language, is translated into ASP.

Built-in front ends for KR tasks:


• diagnosis
• inheritance reasoning
• knowledge-based planning (K language)

built-in front end to SQL3

Many external front ends to DLV exist (e.g., updates, preferences, plan
diagnosis, execution monitoring, etc.)
9. Appendix 9.4 Declarative Problem Solving in DLV

Use of Double Negation

Maximum
Input: Employees and their salaries, represented by empl(_ , _).
Problem: Determine maximum salary of employees.

Solve Problem using projection and double negation!

−max(S) :- empl(N, S), empl(N1, S1), S < S1.


max(S) :- empl(N, S), not −max(S).
9. Appendix 9.5 The “Guess and Check” Methodology

The “Guess and Check” Methodology

Important element of ASP: Guess and Check methodology (also called


Generate-and-Test [Lifschitz, 2002]).

1 Guess: use unstratified negation or disjunctive heads to create candidate


solutions to a problem (program part G ), and

2 Check: use further rules and/or constraints to test candidate solution if it is


a proper solution for our problem (program part C ).

From another perspective:


G : defines the search space
C : prunes illegal branches.

Further discussion in [E_ et al., 2000], [Leone et al., 2006], [E_ et al., 2009] (+
additional component for computing optimal solutions).
9. Appendix 9.5 The “Guess and Check” Methodology

Example: 3-Coloring

Problem specification PS: 3-Colorability condition

Problem specification PPS

g(X) ∨ r(X) ∨ b(X):-node(X) Guess

:-b(X), b(Y), edge(X, Y) 


:-r(X), r(Y), edge(X, Y) Check


:-g(X), g(Y), edge(X, Y)

Data PD : Graph G = (V, E)


PD = {node(v) | v ∈ V} ∪ {edge(v, w) | (v, w) ∈ E}.

Correspondence 3-colorings models:


v ∈ V is colored with c ∈ {r, g, b} iff c(v) is in the model of PPS ∪ PD .
9. Appendix 9.5 The “Guess and Check” Methodology

Example: 3-Coloring (ctd.)


c c
• •

c
• a • • b a • • b

a • • b c c
• •

PD = {node(a), node(b),
a • • b a • • b
node(c), edge(a, b),
edge(b, c), edge(a, c)}
c c
• •

a • • b a • • b
9. Appendix 9.5 The “Guess and Check” Methodology

Example: Hamiltonian Path/Cycle

Input: A directed graph represented by node(_) and edge(_, _)


and a starting node start(_).
Problem: Find a path/cycle beginning at the starting node
which contains all nodes of the graph.

inPath(X, Y) ∨ outPath(X, Y) :- edge(X, Y). Guess


:-inPath(X, Y), inPath(X, Y1 ), Y 6= Y1 . 

:-inPath(X, Y), inPath(X1 , Y), X 6= X1 .




Check
:-node(X), not reached(X). 
:-not start_reached.

reached(X):-start(X).


reached(X):-reached(Y), inPath(Y, X). Auxiliary Predicate
start_reached:-start(Y), inPath(X, Y).

9. Appendix 9.5 The “Guess and Check” Methodology

Example: Hamiltonian Path/Cycle (ctd.)

d • • c • c • c
d • d •

a • • b a • • b a • • b

PD = {node(a), node(b),
node(c), node(d),
edge(a, b), edge(a, c) d • • c d • • c
edge(c, b), edge(b, c)
edge(b, d), edge(d, c)
edge(d, a), edge(a, d)
a • • b a • • b
start(a)}
9. Appendix 9.5 The “Guess and Check” Methodology

Example: Same Generation

Given a parent-child relationship parent(P, X) (an acyclic directed graph), find all
pairs of persons belonging to the same generation.
Two persons are of the same generation, if either (i) they are siblings, or (ii) they
are children of two persons of the same generation.

samegeneration(X, Y):-parent(P, X), parent(P, Y).


samegeneration(X, Y):-parent(P1, X), parent(P2, Y),
samegeneration(P1, P2).
9. Appendix 9.5 The “Guess and Check” Methodology

Example: Traveling Salesperson

Give: Weighted directed graph G = (V, E, C) and a node a ∈ V of this graph.


Task: Find a minimum-cost cycle (closed path) in G starting at a and going through
each node in V exactly once.

G stored by facts over predicates node (unary) and arc (binary).


Starting node a is specified by the predicate start (unary).

inPath(X, Y, C) v outPath(X, Y, C):-start(X), arc(X, Y, C).




inPath(X, Y, C) v outPath(X, Y, C):-reached(X), arc(X, Y, C). Guess
reached(X):-inPath(Y, X, C). (aux.)

:-inPath(X, Y, _), inPath(X, Y1, _), Y <> Y1.




:-inPath(X, Y, _), inPath(X1, Y, _), X <> X1. Check
:-node(X), not reached(X).

o
:∼ inPath(X, Y, C). [C : 1] Optimize
9. Appendix 9.5 The “Guess and Check” Methodology

Example: Ramsey Numbers

The Ramsey number R(k, m) is the least integer n such that, no matter how
we color the arcs of the complete undirected graph (clique) with n nodes
using two colors, say red and blue, there is a red clique with k nodes (a red
k-clique) or a blue clique with m nodes (a blue m-clique).
R(k, m) exists for all pairs of positive integers k and m.
Consider the following program:
o
blue(X, Y) v red(X, Y):-arc(X, Y). Guess

:-red(X, Y), red(X, Z), red(Y, Z).




:-blue(X, Y), blue(X, Z), blue(Y, Z), Check
blue(X, W), blue(Y, W), blue(Z, W).

+ facts F on predicates node and arc encoding a complete graph on n


nodes without loops: F = {node(i), arc(i, j) | 1 ≤ i 6= j ≤ n}
The smallest n such that the program is has an answer set is R(3, 4).
More elegant encoding using aggregates!
9. Appendix 9.5 The “Guess and Check” Methodology

Example: Course Assignment


Information about members and courses of a computer science dept. cs:
member(sam, cs). course(java, cs). course(ai, cs).
member(bob, cs). course(c, cs). course(logic, cs).
member(tom, cs).
likes(sam, java). likes(sam, c). likes(tom, ai).
likes(bob, java). likes(bob, ai). likes(tom, logic).

teach(X, Y):-member(X, cs), course(Y, cs), likes(X, Y), not − teach(X, Y).
−teach(X, Y):-member(X, cs), course(Y, cs), teach(X1 , Y), X1 6= X.
has_course(X):-member(X, cs), teach(X, Y).
:-member(X, cs), not has_course(X).
:-teach(X, Y1 ), teach(X, Y2 ), teach(X, Y3 ),
Y1 6= Y2 , Y1 6= Y3 , Y2 6= Y3 .

More elegant encoding using aggregates!

You might also like