0% found this document useful (0 votes)
6 views

Asp Lecture

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Asp Lecture

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Artificial Intelligence II

2014/2015 Prof: Daniele Nardi

Answer Set Programming


Francesco Riccio
email: [email protected]

March 11th 2015


Recap: Non-Monotonic Reasoning

When a Logic Formalism is monotonic?

Whenever a sentence A is a logical consequence of a set


of sentences φ, then A is also a consequence of an
arbitrary superset of φ.

If (φ ⊆ Ψ and φ ⊨ A) then (Ψ ⊨ A)

Answer Set Programming 2


Recap: Non-Monotonic Reasoning

… or in other words:
Adding information cannot invalidate the conclusion

For example:
Let us assume that we want to meet Prof.X

Answer Set Programming 3


Recap: Non-Monotonic Reasoning
• Prof.X has lunch at 1.00 pm.
• After lunch, Prof.X drinks a coffee at
the cafeteria at the university.
φ
• Current time is 1.30 pm.

We can infer that Prof. X is at the


cafeteria.
A

Answer Set Programming 4


Recap: Non-Monotonic Reasoning
• Prof.X has lunch at 1.00 pm.
• After lunch, Prof.X drinks a coffee at
the cafeteria at the university. Ψ
• Current time is 1.30 pm.
• Cafeteria on Fire.

Can we still infer that Prof. X is at the


cafeteria?
A

Answer Set Programming 5


Recap: Closed World Assumption (CWA)
Idea: If something is not in the KB, it can reasonably be assumed
to be false.

It is based on the assumption that a set W of sentences


designed to represent an application domain determines all
ground atomic facts that hold in it.

The CWA Rule infers the negation of every ground atom not
implied by W. Formally,
𝐶𝑊𝐴 𝑊 =
𝑾 ∪ ¬𝒂 𝒂 𝑖𝑠 𝑔𝑟𝑜𝑢𝑛𝑑 𝑎𝑡𝑜𝑚 𝑎𝑛𝑑 𝑾 ⊭ 𝒂}

Answer Set Programming 6


Recap: Closed World Assumption (CWA)
Example

KB =
{
distracted(fabio),
attends(fabio),
attends(antonio),
∀𝑥 ¬ 𝑑𝑖𝑠𝑡𝑟𝑎𝑐𝑡𝑒𝑑(𝑥) ∧ 𝑎𝑡𝑡𝑒𝑛𝑑𝑠(𝑥) → 𝑙𝑒𝑎𝑟𝑛𝑠(𝑥)
}

Does CWA entail learns(antonio)?

Answer Set Programming 7


Recap: Negation as Failure (NAF)

Idea: not A will be taken to be true if A cannot be proven from a


given knowledge base KB.

NAF is:
• a non-monotonic inference rule;
• used in logic programming, such as prolog;
• based on CWA.

Answer Set Programming 8


Recap: Stable Models Semantics
Ground & Reduct

Given a logic program ∏ , that is, a set of clauses:


𝐴 ←𝐿 , … , 𝐿 with 𝑚 ≥ 0
1 𝑚
each clause is replaced with its ground instances.

Given a set M of atoms of ∏ , the reduct ∏ 𝑀 is obtained by


eliminating:

• all the clauses that in the body have a negated atom of M;


• all the negative literals not in M.

Answer Set Programming 9


Recap: Stable Models Semantics
Stable Models
A stable model is a set of atoms.

Given a reduct program ∏ 𝑀 which has only Horn clauses and a


unique minimal model M’.
If M’ == M then
It is called stable set.

Th: Every stable set of a program ∏ is a minimal Herbrand


model of ∏.

The semantics of stable models states that:


if a program has only one stable model this is the
canonical/preferred model of the program.

Answer Set Programming 10


Recap: Stable Models Semantics
Minimal Herbrand Model

• The Herbrand universe U is the finite set of all ground terms


that can be formed from the constants used in a set of logic
rules.

• The Herbrand base A is the set of all ground atomic rules that
can be formed using the constants ∈ U.

• A Herbrand model is any subset of rules of the Herbrand


base A.

• A Minimal Herbrand model is the smallest Herbrand model,


i.e. any subset is not a model.

Answer Set Programming 11


Recap: Stable Models Semantics
Minimal Herbrand Model (Example)

Given the set of rules

p(a, b)
q(x) ← p(x, y), ¬ q(y)

Ex1. Let the model M1 = {q(b)}.

Ex2. Let the model M2 = {p(a,b), q(a)}.

Answer Set Programming 12


Recap: Stable Models Semantics
Minimal Herbrand Model (Example)

p(a,b), q(a) ← p(a, a), ¬ q(a),


Ground: q(a) ← p(a, b), ¬ q(b), q(b) ← p(b, b), ¬ q(b)
q(b) ← p(b, a), ¬ q(a),

Ex1. M1 ={q(b)}. Ex2. M2 ={p(a,b),q(a)}.


Reduct: Different, Reduct:
p(a,b), p(a,b), Equal,
Hence it is Hence it is
q(b) ← p(b, a), not a stable q(a) ← p(a, b),
a stable
q(b) ← p(b, b) model. q(a) ← p(a, a)
model.
=> Minimal Model = {p(a,b)} => Minimal Model = {p(a,b),q(a)}

Answer Set Programming 13


SATisfiability

Satisfiability Problem (aka SATISFIABILITY or SAT) is the problem


of evaluating a given Boolean formula by determining if there
exists an interpretation which satisfies such a formula.

An interpretation is an instantiation of the variables within a


formula such that the formula evaluates TRUE.
In a single word: A Model of the formula.

Ex1. (𝑎 ∧ ¬𝑏) Ex4. (𝑎 ∧ 𝑏) → (𝑎 ∨ 𝑏)


Ex2. (𝑎 ∧ ¬𝑎) Ex5. 𝑎 ∨ 𝑏 → 𝑎
Ex3. (𝑎 ∨ (𝑏 → 𝑐)) Ex6. (𝑎 ∧ ¬(¬𝑎 → 𝑏))

Answer Set Programming 14


Answer Set Programming

Answer Set Programming 15


Answer Set Programming
Traditional programming

Programming
Problem Program

Executing

Interpreting
Solution Output

Answer Set Programming 16


Answer Set Programming
Declarative Problem solving

Modeling
Problem Representation

Solving

Interpreting
Solution Output

Answer Set Programming 17


Answer Set Programming

In ASP the programmer can focus on describing the problem


rather than having to design the search algorithm.

ASP is:
• a language for knowledge representation and
reasoning based on the answer set/stable model
semantics of logic programs.

• a form of declarative programming.

• oriented towards search problems.

Answer Set Programming 18


Answer Set Programming

ASP relies upon:

• knowledge representation and non-monotonic


reasoning;

• databases;

• constraint solving (SATisfiability testing);

• logic programming (with negation).

Answer Set Programming 19


Declarative Problem solving

Given a representation of the problem

o Theorem Proving based approach (eg. Prolog)


A solution is given by a derivation of a query.

o Model Generation based approach (eg. SAT testing)


A solution is given by a model of the representation.

Answer Set Programming 20


Answer Sets
Logic Programming

• A rule r is an ordered pair of the form


A0 𝑜𝑟 Ak ← A1, … , Am, 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An
where 0 ≤ m ≤ n, and each Ai (0 ≤ i ≤ n) is a literal.

• A logic program is a finite set of rules


head(r) = A0
body(r) = A1, … , Am, 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An
body(r) + = A1, … , Am
body(r) − = 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An

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

Answer Set Programming 21


Answer Sets
Syntax

• Given a rule r
A0 𝑜𝑟 Ak ← A1, … , Am, 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An

If ℎ𝑒𝑎𝑑 𝑟 = ∅ then r is called a constraint.


If 𝑏𝑜𝑑𝑦 𝑟 = ∅ then r is called a fact.

Given a logic program ∏ (a set of rules)


• U is the set of terms, aka Herbrand universe
• A is the set of atoms wrt U, aka Herbrand base

Answer Set Programming 22


Answer set
Grounding

Ground instances of each rule r in the program ∏

A ground instance is the set of variable-free rules given


by replacing all the variables in r using elements of U

𝑔𝑟𝑜𝑢𝑛𝑑 𝑟 = 𝜑(𝑟) ∀𝑣 ∈ 𝑟, 𝜑: 𝑣 → 𝑈 ∧
𝑡ℎ𝑒 𝑔𝑟𝑜𝑢𝑛𝑑𝑒𝑑 𝑟𝑢𝑙𝑒 𝜑 𝑟 ℎ𝑎𝑠 𝑛𝑜 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 }

accordingly, a ground instantiation of a program ∏ is


𝑔𝑟𝑜𝑢𝑛𝑑 ∏ =∪ 𝑟∈∏ 𝑔𝑟𝑜𝑢𝑛𝑑(𝑟)

Answer Set Programming 23


Answer set
(Example)
∏ = { foo(a,b), foo(b,c), bar(X,Y) ← foo(X,Y) }
U=
A=

Answer Set Programming 24


Answer set
(Example)
∏ = { foo(a,b), foo(b,c), bar(X,Y) ← foo(X,Y) }
U = {a,b,c}
A={ foo(a,a), foo(b,b), foo(c,c), foo(a,b), foo(a,c),
foo(b,a), foo(b,c), foo(c,a), foo(a,b),
bar(a,a), bar(b,b), bar(c,c), bar(a,b), bar(a,c),
bar(b,a), bar(b,c), bar(c,a), bar(a,b)
}

Answer Set Programming 25


Answer set
(Example)
∏ = { foo(a,b), foo(b,c), bar(X,Y) ← foo(X,Y) }
U = {a,b,c}
A={ foo(a,a), foo(b,b), foo(c,c), foo(a,b), foo(a,c),
foo(b,a), foo(b,c), foo(c,a), foo(a,b),
bar(a,a), bar(b,b), bar(c,c), bar(a,b), bar(a,c),
bar(b,a), bar(b,c), bar(c,a), bar(a,b)
}

ground( ∏ ) = { foo(a,b), foo(b,c),


bar(a,a) ← foo(a,a), bar(b,b) ← foo(b,b),
bar(c,c) ← foo(c,c) , bar(a,b) ← foo(a,b),
bar(a,c) ← foo(a,c), bar(b,a) ← foo(b,a),
bar(b,c) ← foo(b,c), bar(c,a) ← foo(c,a),
bar(c,b) ← foo(c,b)
}

Answer Set Programming 26


Answer set semantics
A model M of a program ∏ is an answer set for ∏ if M is minimal
among the models satisfying the rules of ∏.

𝜃 ∶ 𝑞 ∧ (𝑞 ∧ ¬𝑟 → 𝑝) formula

Classical models: {p,q}, {q,r} and {p,q,r}

∏ 𝜃: q. asp-like program
p ← q, 𝑛𝑜𝑡 r.

Program ∏ 𝜃
has a single stable model, ie. answer set: {p, q}

A set M of atoms is a stable model of a program ∏ if:


• M is a classical model;
• M is a minimal model;
• All atoms in M are justified by some rule of ∏.

Answer Set Programming 27


Answer set
Programs without Negation

Ex1. ∏ = { Answer set =


q(a). {
p(a). q(a),p(a),r(a)
r(a) ← p(a),q(a). }
r(b) ← q(b).
}

Ex2. ∏ = { Answer set =


q(a). {
p(a). q(a),p(a),q(b),r(a),r(b)
q(b). }
r(a) ← p(a),q(a).
r(b) ← q(b).
}

Answer Set Programming 28


Answer set
Programs with Negation
Negation-as-failure is an important component used
extensively in logic programming. In ASP is generally written
as not.

∏={
happy ← not sad.
sad ← not happy.
}

This program has two answer set {happy} or {sad}

Answer Set Programming 29


Answer set
Programs with Negation
Negation-as-failure is an important component used
extensively in logic programming. In ASP is generally written
as not.

∏={
happy ← not sad.
sad ← not happy.
}

This program has two answer set {happy} or {sad}


Strong negation, denoted with the standard negation symbol
¬, allows us to distinguish between having no justification for
an atom a, expressed by not a, and having one for the
negation of a, expressed by ¬a.

Answer Set Programming 30


Answer set
Programs with Negation

The negation used in a program varies its semantic and


necessarely its answer set.

Example. Whether we want to write a strong negation or a


negation-as-failure, given the program p :- neg q we can
rewrite the formula as q or p .
strong negation negation-as-failure

{q,p} Models {p}

The negation-as-failure has a more restriction power, hence


the generated model has only p.

Answer Set Programming 31


Answer set
Programs with Negation

Ex1. ∏ = { Ex3. ∏ = {
cross ← not train. ¬ train.
} cross ← ¬ train.
}

Ex2. ∏ = { Ex4. ∏ = {
cross ← ¬ train. ¬ train ← not train .
} cross ← ¬ train.
}

Answer Set Programming 32


ASP vs LP vs SAT
ASP Prolog SAT
Model generation Query orientation Model generation
Modeling language Programming language --

• Minimal model • The order of • All model


generation program rules is generation
• Interpreting logic crucially
programs via important.
answer set • The order of
semantics subgoals in a rule
is crucially
important.
• Proof by
resolution
• Depth-first search

Answer Set Programming 33


ASP vs SAT

Modeling Programming
Logic Formula
Problem Problem
Programming (CNF)

Grounder

Solver Solver

(Classical)
Solution Stable Models Solution
Models

Interpreting Interpreting

Answer Set Programming 34


ASP solving

KR
Modeling
Logic
Problem LP
Programming

Grounder DB

Solving
Solver SAT

Stable
Solution KR+LP
Models

Interpreting

Answer Set Programming 35


ASP vs Default Logic
Recall default logic statements of the form
𝛼 ∶ ¬𝛽
𝛾
States that, if 𝛼 holds and we can assume ¬𝛽 then we can
infer 𝛾.

In ASP:
𝛾 ← 𝛼, 𝒏𝒐𝒕 𝛽

Accordingly, M is a model of the above formula if M does


not contains 𝛽 and includes 𝛼 and 𝛾.

M is an answer set iff the deductive


closure of M is a consistent extension of
the equivalent default theory.

Answer Set Programming 36


Example – Playing with blocks
LP style

on(a,b).
on(b,c).

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


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

1) ?- above(a,c). 2) ?- above(a,c).
true. no.

Answer Set Programming 37


Example – Playing with blocks
SAT style

on(a, b)
∧ on(b,c)
∧ (on(X,Y) → above(X, Y))
∧ (on(X, Z) ∧ above(Z,Y) → above(X,Y))

Herbrand model:
{ on(b, b), on(a, b), on(b, c), on(a, c),
above(b, b), above(c, b), above(a, b),
above(b, c), above(c, c), above(a, c) }

Answer Set Programming 38


Example – Playing with blocks
ASP style

on(a,b).
on(b,c).

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


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

Minimal Herbrand model:


{ on(a, b), on(b, c), above(a, b),
above(b, c), above(a, c) }

Answer Set Programming 39


Answer Set Programming
Methodology (on Models)

Generate and Test

Answer Set Programming 40


Answer Set Programming
Methodology (on Models)

Generate and Test


M2
a set of potential stable M1
model canditates
M4
M3

Mn

Answer Set Programming 41


Answer Set Programming
Methodology (on Models)

Generate and Test


M2
evaluate and eliminate M1
invalid models
M4
M3

Mn

Answer Set Programming 42


Answer Set Programming
Syntax & Language constructs

Choice:
{A0 , … , Am} ← Am+1, … , An, not An+1, … , not Ak

If the body is satisfied by the stable model at hand,


then any subset of {A0 , … , Am} can be included in the
stable model.

Answer Set Programming 43


Answer Set Programming
Syntax & Language constructs

Choice:
{p(X,Y), q(Y)} : − 𝑟 𝑋 .
For all X such that r(X) holds, the answer set will contain literals of the
form p(X, Y), given that q(Y) holds.

Ex1. X specifies the domain of all the students, Y specifies


the domain of the available courses. Generate all the
possible solution which state that a student is enrolled in
a set of courses.

Answer Set Programming 44


Answer Set Programming
Syntax & Language constructs

Ex1. X specifies the domain of all the students, Y specifies


the domain of the available courses. Generate all the
possible solution which state that a student is enrolled in
a set of courses.

Sol.
{ enrolled(X, Y) , course(Y) } :−student(X).

Generated sets { enrolled(x1,y1), … , enrolled(x1,yn) }


{ … }

Answer Set Programming 45


Answer Set Programming
Syntax & Language constructs

Integrity constraits:
: − A1, … , Am, 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An
The effect of adding a constraint to a program is to
eliminate some of its stable models.

Ex2. For each X,Y such that X ={Matteo, Fabio} and Y =


{Rome,London}. Write a choice rule that generates all the
possible solution of a predicate lives(X,Y).

Answer Set Programming 46


Answer Set Programming
Syntax & Language constructs

Choice:
{ p(X,Y) , q(Y) } : − 𝑟 𝑋

Ex2. For each X,Y such that X ={Matteo, Fabio} and Y =


{Rome,London}. Write a choice rule that generates all the
possible solution of a predicate lives(X,Y).

Sol.
{ lives(X, Y) , place(Y) } :−person(X).

Generated sets { p(Matteo,Rome), p{Matteo,London} }


{ p(Fabio,Rome), p{Fabio,London} }

Answer Set Programming 47


Answer Set Programming
Syntax & Language constructs

Integrity constraint:
We use the integrity constraint to model the fact that a
person cannot live in two places simultaneously.

Sol.
{ lives(X, Y) , place(Y) } :−person(X).
:- lives(X,Y), lives(X,Z), person(X).

In this case we will obtain 4 different aswer sets.

Answer Set Programming 48


Answer Set Programming
In practice
Therefore, ASP systems solve a given problem in two
steps:

Grounding, the grounder instantiate all the variables in


the rules of the program (Time consuming and high space
complexity).

Solving, the solver acquires the grounded program and


generates answer sets, aka stable models, aka solutions.

Well known ASP system is Potassco (the POTsdam Answer


Set Solving COllection) which relyies upon a grounder
(gringo) and a solver (clasp).
$ sudo apt-get install gringo clasp

Answer Set Programming 49


Answer Set Programming
Potassco syntax

This answer set solver slightly modifies the syntax of the


choice rule.

Such rule is written as

<rangeMin> { p(X,Y) : q(Y) } <rangeMax> : − 𝑟 𝑋

For all X such that r(X) holds, each answer set must
contain from rangeMin to rangeMax literals of the form
p(X, Y), given that q(Y) holds.

Answer Set Programming 50


Answer Set Programming
Potassco syntax

The new syntax helps us to reformulate the two previous


examples.

Ex. Students enrolled in n courses.

Ex. A person lives in a city.

Answer Set Programming 51


ASP in practice
Ex.1 Graph Coloring

1 4
Problem description:
Given a grah with N nodes and E
edges connecting them, we want 3
to assign a color to each node n 2
6
such that:
5
• each node has one color;
• if exists an edge connecting
two nodes then such nodes
must have different colors.

Answer Set Programming 52


ASP in practice
Ex.1 Graph Coloring

node(1..6).

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


edge(2,4). edge(2,5). edge(2,6).
edge(3,1). edge(3,4). edge(3,5). Problem instance
edge(4,1). edge(4,2).
edge(5,3). edge(5,4). edge(5,6).
edge(6,2). edge(6,3). edge(6,5).
col(r). col(g). col(b).

1 { color(X,C) : col(C) } 1 :- node(X).


Problem encoding
:- edge(X,Y), color(X,C), color(Y,C).

Answer Set Programming 53


ASP in practice
Ex.2 Default Reasoning in ASP
Write a default theory representing the sentences below. Add
sentences:
• Italians usually eat spaghetti.
• Europeans usually don’t eat spaghetti.
• Italians are Europeans

In Answer Set Programming translate the previous rules and add the
following ones:

If Daniele is Italian,
• which extensions does the default theory have?
• Is there a preferred extension? Explain the answer.
• Which are the extensions if the second sentence is replaced by:
Europeans usually don't eat pasta?

Answer Set Programming 54


ASP in practice
Ex.2 Default Reasoning in ASP

𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 ∧ 𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑆 : 𝑒𝑎𝑡(𝑋, 𝑆)


,
𝑒𝑎𝑡(𝑋, 𝑆)
𝐷=
𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 ∧ 𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑆 : ¬𝑒𝑎𝑡(𝑋, 𝑆)
¬𝑒𝑎𝑡(𝑋, 𝑆)

𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑠𝑝 ,
∀𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑋 → 𝑝𝑎𝑠𝑡𝑎 𝑋 ,
𝑊=
∀𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 → 𝑒𝑢𝑟𝑜𝑝𝑒𝑎𝑛 𝑋 ,
𝑖𝑡𝑎𝑙𝑖𝑎𝑛(𝑑𝑎𝑛𝑖𝑒𝑙𝑒)

Answer Set Programming 55


ASP in practice
Ex.2 Default Reasoning in ASP
The formalized defualt theory has two extensions:

𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑑𝑎𝑛𝑖𝑒𝑙𝑒 , 𝑒𝑢𝑟𝑜𝑝𝑒𝑎𝑛 𝑑𝑎𝑛𝑖𝑒𝑙𝑒 ,


𝜀 = 𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑠𝑝 , 𝑝𝑎𝑠𝑡𝑎 𝑠𝑝 ,
1
𝑒𝑎𝑡(𝑑𝑎𝑛𝑖𝑒𝑙𝑒, 𝑠𝑝)

𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑑𝑎𝑛𝑖𝑒𝑙𝑒 , 𝑒𝑢𝑟𝑜𝑝𝑒𝑎𝑛 𝑑𝑎𝑛𝑖𝑒𝑙𝑒 ,


𝜀 = 𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑠𝑝 , 𝑝𝑎𝑠𝑡𝑎 𝑠𝑝 ,
2
¬𝑒𝑎𝑡(𝑑𝑎𝑛𝑖𝑒𝑙𝑒, 𝑠𝑝)

 The application order of the default rules makes the difference!


However, 𝜀 1 is the preferred extension since it has a most specific
restriction.

Answer Set Programming 56


ASP in practice
Ex.2 Default Reasoning in ASP

If we consider
𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 ∧ 𝒑𝒂𝒔𝒕𝒂 𝑆 : ¬𝑒𝑎𝑡(𝑋, 𝑆)
¬𝑒𝑎𝑡(𝑋, 𝑆)

instead of
𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 ∧ 𝒔𝒑𝒂𝒈𝒉𝒆𝒕𝒕𝒊 𝑆 : ¬𝑒𝑎𝑡(𝑋, 𝑆)
¬𝑒𝑎𝑡(𝑋, 𝑆)

then, the two extensions do not change!


𝜀 1 remains preferred one.

Answer Set Programming 57


ASP in practice
Ex.2 Default Reasoning in ASP
In ASP:

%-------------------- W
italian(daniele).
spaghetti(sp).
pasta(X) :- spaghetti(X).
european(X) :- italian(X).

%-------------------- D
eat(X,S) :- Italian(X), spaghetti(S), not not eat(X,S).
-eat(X,S) :- european(X), pasta(S), not eat(X,S).

%-eat(X,S) :- european(X), spaghetti(S), not eat(X,S). %Decomment this line


for modeling the default rule: ‘Usually, europeans do not eat spaghetti.

Answer Set Programming 58


ASP in practice
Ex.2 Default Reasoning in ASP

As in the defualt theory, the answer set solver generates two


different answer sets.
Answer 1 says that daniele does not eat spaghetti, while Answer
2 says that he does.

Answer Set Programming 59

You might also like