Asp Lecture
Asp Lecture
If (φ ⊆ Ψ and φ ⊨ A) then (Ψ ⊨ A)
… or in other words:
Adding information cannot invalidate the conclusion
For example:
Let us assume that we want to meet Prof.X
The CWA Rule infers the negation of every ground atom not
implied by W. Formally,
𝐶𝑊𝐴 𝑊 =
𝑾 ∪ ¬𝒂 𝒂 𝑖𝑠 𝑔𝑟𝑜𝑢𝑛𝑑 𝑎𝑡𝑜𝑚 𝑎𝑛𝑑 𝑾 ⊭ 𝒂}
KB =
{
distracted(fabio),
attends(fabio),
attends(antonio),
∀𝑥 ¬ 𝑑𝑖𝑠𝑡𝑟𝑎𝑐𝑡𝑒𝑑(𝑥) ∧ 𝑎𝑡𝑡𝑒𝑛𝑑𝑠(𝑥) → 𝑙𝑒𝑎𝑟𝑛𝑠(𝑥)
}
NAF is:
• a non-monotonic inference rule;
• used in logic programming, such as prolog;
• based on CWA.
• The Herbrand base A is the set of all ground atomic rules that
can be formed using the constants ∈ U.
p(a, b)
q(x) ← p(x, y), ¬ q(y)
Programming
Problem Program
Executing
Interpreting
Solution Output
Modeling
Problem Representation
Solving
Interpreting
Solution Output
ASP is:
• a language for knowledge representation and
reasoning based on the answer set/stable model
semantics of logic programs.
• databases;
• Given a rule r
A0 𝑜𝑟 Ak ← A1, … , Am, 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An
𝑔𝑟𝑜𝑢𝑛𝑑 𝑟 = 𝜑(𝑟) ∀𝑣 ∈ 𝑟, 𝜑: 𝑣 → 𝑈 ∧
𝑡ℎ𝑒 𝑔𝑟𝑜𝑢𝑛𝑑𝑒𝑑 𝑟𝑢𝑙𝑒 𝜑 𝑟 ℎ𝑎𝑠 𝑛𝑜 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 }
𝜃 ∶ 𝑞 ∧ (𝑞 ∧ ¬𝑟 → 𝑝) formula
∏ 𝜃: q. asp-like program
p ← q, 𝑛𝑜𝑡 r.
Program ∏ 𝜃
has a single stable model, ie. answer set: {p, q}
∏={
happy ← not sad.
sad ← not happy.
}
∏={
happy ← not sad.
sad ← not happy.
}
Ex1. ∏ = { Ex3. ∏ = {
cross ← not train. ¬ train.
} cross ← ¬ train.
}
Ex2. ∏ = { Ex4. ∏ = {
cross ← ¬ train. ¬ train ← not train .
} cross ← ¬ train.
}
Modeling Programming
Logic Formula
Problem Problem
Programming (CNF)
Grounder
Solver Solver
(Classical)
Solution Stable Models Solution
Models
Interpreting Interpreting
KR
Modeling
Logic
Problem LP
Programming
Grounder DB
Solving
Solver SAT
Stable
Solution KR+LP
Models
Interpreting
In ASP:
𝛾 ← 𝛼, 𝒏𝒐𝒕 𝛽
on(a,b).
on(b,c).
1) ?- above(a,c). 2) ?- above(a,c).
true. no.
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) }
on(a,b).
on(b,c).
Mn
Mn
Choice:
{A0 , … , Am} ← Am+1, … , An, not An+1, … , not Ak
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.
Sol.
{ enrolled(X, Y) , course(Y) } :−student(X).
Integrity constraits:
: − A1, … , Am, 𝑛𝑜𝑡 Am+1, … , 𝑛𝑜𝑡 An
The effect of adding a constraint to a program is to
eliminate some of its stable models.
Choice:
{ p(X,Y) , q(Y) } : − 𝑟 𝑋
Sol.
{ lives(X, Y) , place(Y) } :−person(X).
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).
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.
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.
node(1..6).
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?
𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑠𝑝 ,
∀𝑠𝑝𝑎𝑔ℎ𝑒𝑡𝑡𝑖 𝑋 → 𝑝𝑎𝑠𝑡𝑎 𝑋 ,
𝑊=
∀𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 → 𝑒𝑢𝑟𝑜𝑝𝑒𝑎𝑛 𝑋 ,
𝑖𝑡𝑎𝑙𝑖𝑎𝑛(𝑑𝑎𝑛𝑖𝑒𝑙𝑒)
If we consider
𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 ∧ 𝒑𝒂𝒔𝒕𝒂 𝑆 : ¬𝑒𝑎𝑡(𝑋, 𝑆)
¬𝑒𝑎𝑡(𝑋, 𝑆)
instead of
𝑖𝑡𝑎𝑙𝑖𝑎𝑛 𝑋 ∧ 𝒔𝒑𝒂𝒈𝒉𝒆𝒕𝒕𝒊 𝑆 : ¬𝑒𝑎𝑡(𝑋, 𝑆)
¬𝑒𝑎𝑡(𝑋, 𝑆)
%-------------------- 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).