Artificial Intelligence Reduce to propositional logic FOL inference

Reduce to propositional logic
Artificial Intelligence
• Reduce the first order logic sentences to
propositional (boolean) logic.
• Use the inference systems in propositional
logic.
Inference in first-order logic
Chapter 9, AIMA
We need a system for transfering sentences
with quantifiers to sentences without
quantifiers ⇒
FOL inference rules
FOL inference rules
All the propositional rules (Modus Ponens, And
Elimination, And introduction, etc.) plus:
Universal Instantiation (UI)
Existential Instantiation (EI)
All the propositional rules (Modus Ponens, And
Elimination, And introduction, etc.) plus:
Universal Instantiation (UI)
Existential Generalization (EG)
∀x w( x)
w(a )
∃x w( x)
w(a )
∀x w( x)
w(a )
w(a)
∃x w( x)
Where the variable x is replaced by
the ground term a everywhere in
Where the variable x is replaced by a
ground term a (that makes the
Where the variable x is replaced by
the ground term a everywhere in
Where the ground term a is replaced
by the variable x everywhere in the
w.
sentence true) in the sentence w.
Example:
∃x Q(x,g(x),B) ⇒ Q(A,g(A),B)
the sentence
Example:
∀x P(x,f(x),B) ⇒ P(A,f(A),B)
A must be a new symbol.
the sentence
w.
Example:
∀x P(x,f(x),B) ⇒ P(A,f(A),B)
sentence w.
Example:
∀y Q(A,g(A),y) ⇒
∃x ∀y Q(x,g(x),y)
Ground term = a term without variables
Ground term = a term without variables
Example: Kings...
Example: Kings...
UI: (Universal Instantiation)
UI: (Universal Instantiation)
∀x (King(x) ∧ Greedy(x)) ⇒ Evil(x)
∀x (King(x) ∧ Greedy(x)) ⇒ Evil(x)
King(John) ∧ Greedy(John) ⇒ Evil(John)
King(John) ∧ Greedy(John) ⇒ Evil(John)
King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard)
King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard)
∶
∶
EI: (Existential Instantiation)
EI: (Existential Instantiation)
∃x (Crown(x) ∧ OnHead(x,John))
∃x (Crown(x) ∧ OnHead(x,John))
Crown(C) ∧ OnHead(C,John)
Crown(C) ∧ OnHead(C,John)
C is called a Skolem constant
C is called a Skolem constant
Making up names is called skolemization
Making up names is called skolemization
1
Propositionalization
Notation: Substitution
Apply Universal Instantiation (UI) and Existential Instantiation
(EI) so that every FOL KB is made into a propositional KB.
Subst(θ,α) = Apply the substitution θ to the sentence α.
⇒ We can use the tools from propositional logic to prove
theorems.
Example:
θ = {x/John} (replace x with John)
Problem with function constants: Father(A),
Father(Father(A)), Father(Father(Father(A))), etc. ad
infinitum...infinite number of sentences...how can we prove
this in finite time?
α = (King(x) ∧ Greedy(x)) ⇒ Evil(x)
Theorem: We can find every entailed sentence [Gödel,
Herbrand], but the search is not guaranteed to stop for
nonentailed sentences.
(”Solution”: negation-as-failure, stop after a certain time
and assume the sentence is false)
(King(John) ∧ Greedy(John)) ⇒ Evil(John)
General form: θ = {v/g} where v is a variable and g is a
ground term.
Inefficient...generalized (lifted) inference rules better
Generalized (lifted) Modus Ponens
Generalized (lifted) Modus Ponens
For atomic sentences pi, qi, and r where
there exists a substitution θ such that
Subst(θ,pi) = Subst(θ,qi) for all i
For atomic sentences pi, qi, and r where
there exists a substitution θ such that
Subst(θ,pi) = Subst(θ,qi) for all i
p1 , p2 , K, pn , (q1 ∧ q2 ∧ L ∧ qn ⇒ r )
Subst(θ , r )
KB
p1 , p2 , K, pn , (q1 ∧ q2 ∧ L ∧ qn ⇒ r )
Subst(θ , r )
KB
p1 = King(John)
q1 = King(x)
p2 = Greedy(John)
θ = {x/John}
∀x (King(x) ∧ Greedy(x) ⇒ Evil(x))
p1 = King(John)
q1 = King(x)
q2 = Greedy(x)
p2 = Greedy(John)
q2 = Greedy(x)
r = Evil(x)
θ = {x/John}
r = Evil(x)
Generalized (lifted) Modus Ponens
For atomic sentences pi, qi, and r where
there exists a substitution θ such that
Subst(θ,pi) = Subst(θ,qi) for all i
p1 , p2 , K, pn , (q1 ∧ q2 ∧ L ∧ qn ⇒ r )
Subst(θ , r )
KB
p1 = King(John)
q1 = King(x)
p2 = Greedy(John)
q2 = Greedy(x)
θ = {x/John}
r = Evil(x)
Subst(θ,r) = Evil(John)
∀x (King(x) ∧ Greedy(x) ⇒ Evil(x))
∀x (King(x) ∧ Greedy(x) ⇒ Evil(x))
Example: Arms dealer
KB in Horn Form
(1) ∀x (American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z) ⇒ Criminal(x))
(2) Owns(NoNo,M)
(3) Missile(M)
(4) ∃x (Missile(x) ∧ Owns(NoNo,x) ⇒ Sells(West,x,NoNo))
(5) ∀x (Missile(x) ⇒ Weapon(x))
(6) ∀x (Enemy(x,America) ⇒ Hostile(x))
King(John), Greedy(John)
⇒Evil(John)
(7) American(West)
(8) Enemy(NoNo,America)
Lifted inference rules make only the necessary substitutions
2
Example: Arms dealer
KB in Horn Form
Forward chaining: Arms dealer
Forward chaining generates all inferences (also irrelevant ones)
(1) ∀x (American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z) ⇒ Criminal(x))
We have proved that
West is a criminal
Criminal(West)
(2) Owns(NoNo,M)
American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z) ⇒ Criminal(x)
θ = {x/West, y/M, z/NoNo}
(3) Missile(M)
(4) ∃x (Missile(x) ∧ Owns(NoNo,x) ⇒ Sells(West,x,NoNo))
(5) ∀x (Missile(x) ⇒ Weapon(x))
(6) ∀x (Enemy(x,America) ⇒ Hostile(x))
(7) American(West)
Facts
(8) Enemy(NoNo,America)
Example: Financial advisor
Weapon(M)
Sells(West,M,NoNo)
Missile(x) ⇒ Weapon(x)
θ = {x/M}
Missile(x) ∧ Owns(NoNo,x) ⇒
Sells(West,x,NoNo)
θ = {x/M}
American(West)
Missile(M)
Hostile(NoNo)
Enemy(x,America) ⇒ Hostile(x)
θ = {x/NoNo}
Owns(NoNo,M)
Enemy(NoNo,America)
FC financial advisor
KB in Horn Form
Investments(Mixed)
1)
2)
3)
4)
5)
6)
7)
8)
SavingsAccount(Inadequate) ⇒ Investments(Bank)
SavingsAccount(Adequate) ∧ Income(Adequate) ⇒ Investments(Stocks)
SavingsAccount(Adequate) ∧ Income(Inadequate) ⇒ Investments(Mixed)
∀x (AmountSaved(x) ∧ ∃y (Dependents(y) ∧ Greater(x,MinSavings(y))) ⇒
SavingsAccount(Adequate))
∀x (AmountSaved(x) ∧ ∃y (Dependents(y) ∧ ¬Greater(x,MinSavings(y))) ⇒
SavingsAccount(Inadequate))
∀x (Earnings(x,Steady) ∧ ∃y (Dependents(y) ∧ Greater(x,MinIncome(y))) ⇒
Income(Adequate))
∀x (Earnings(x,Steady) ∧ ∃y (Dependents(y) ∧ ¬Greater(x,MinIncome(y)))
⇒ Income(Inadequate))
∀x (Earnings(x,UnSteady) ⇒ Income(Inadequate))
9)
AmountSaved($22000)
10) Earnings($25000,Steady)
11) Dependents(3)
MinSavings(x) ≡ $5000•x
MinIncome(x) ≡ $15000 + ($4000•x)
SavingsAccount(Adequate)
Income(Inadequate)
¬Greater($25000,MinIncome)
MinIncome = $27000
Greater($22000,MinSavings)
MinSavings = $15000
AmountSaved($22000)
Dependents(3)
Earnings($25000,Steady)
Example from G.F. Luger, ”Artificial Intelligence” 2002
FOL CNF
(Conjunctive Normal Form)
CNF example
”Everyone who loves all animals is loved by someone”
Literal = (possibly negated) atomic sentence, e.g., ¬Rich(Me)
Clause = disjunction of literals, e.g. ¬Rich(Me) ∨ Unhappy(Me)
The KB is a conjunction of clauses
Any
1.
2.
3.
4.
5.
6.
7.
FOL KB can be converted to CNF as follows:
Replace (P ⇒ Q) by (¬P ∨ Q)
(implication elimination)
Move ¬ inwards, e.g., ¬∀x P(x) becomes ∃x ¬P(x)
Standardize variables apart, e.g., (∀x P(x) ∨ ∃x Q(x)) becomes (∀x P(x) ∨
∃y Q(y))
Move quantifiers left, e.g., (∀x P(x) ∨ ∃y Q(y)) becomes ∀x ∃y (P(x) ∨ Q(y))
Eliminate ∃ by Skolemization
Drop universal quantifiers
Distribute ∧ over ∨, e.g., (P ∧ Q) ∨ R becomes (P ∨ R) ∧ (Q ∨ R)
∀x [∀y Animal(y) ⇒ Loves(x,y)] ⇒ ∃y Loves(y,x)
Implication elimination
∀x ¬[∀y ¬Animal(y) ∨ Loves(x,y)] ∨ ∃y Loves(y,x)
Move ¬ inwards (¬∀y P becomes ∃y ¬P)
∀x [∃y ¬(¬Animal(y) ∨ Loves(x,y))] ∨ ∃y Loves(y,x)
∀x [∃y (Animal(y) ∧ ¬Loves(x,y))] ∨ ∃y Loves(y,x)
∀x [∃y Animal(y) ∧ ¬Loves(x,y)] ∨ ∃y Loves(y,x)
Standardize variables individually
∀x [∃y Animal(y) ∧ ¬Loves(x,y)] ∨ ∃z Loves(z,x)
Skolemize (Replace ∃ with constants)
∀x [Animal(F(x)) ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
Why not ∀x [Animal(A) ∧ ¬Loves(x,A)] ∨ Loves(B,x) ??
Drop ∀
[Animal(F(x)) ∧ ¬Loves(x,F(x))] ∨ Loves(G(x),x)
Distribute ∨ over ∧
[Animal(F(x)) ∨ Loves(G(x),x)] ∧ [¬Loves(x,F(x)) ∨ Loves(G(x),x)]
Slide from S. Russel
3
Notation: Unification
FOL resolution inference rule
First-order literals are complementary if one unifies
with the negation of the other
Unify(p,q) = θ
(l1 ∨ l2 ∨ L ∨ lk ), (m1 ∨ m2 ∨ L ∨ mn )
Subst (θ , l1 ∨ L ∨ li −1 ∨ li +1 ∨ L ∨ lk ∨ m1 ∨ L ∨ m j −1 ∨ m j +1 ∨ L ∨ mn )
means that
Subst(θ,p) = Subst(θ,q)
Where Unify(li,¬mj) = θ.
Note that li and mj are removed
[Animal(F(x)) ∨ Loves(G(x),x)], [¬Loves(u,v) ∨ ¬Kills(u,v)]
Subst({u/G(x),v/x}, [Animal(F(x)) ∨ ¬Kills(u,v)])
Which produces resolvent [Animal(F(x)) ∨ ¬Kills(G(x),x)]
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
∀x (American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z) ⇒ Criminal(x))
Translate to CNF:
∀x (¬(American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z)) ∨ Criminal(x))
∀x ((¬American(x) ∨ ¬Weapon(y) ∨ ¬Hostile(z) ∨ ¬Sells(x,y,z)) ∨ Criminal(x))
∀x (¬American(x) ∨ ¬Weapon(y) ∨ ¬Hostile(z) ∨ ¬Sells(x,y,z) ∨ Criminal(x))
¬American(x) ∨ ¬Weapon(y) ∨ ¬Hostile(z) ∨ ¬Sells(x,y,z) ∨ Criminal(x)
Start from
the top
¬
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
∀x (American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z) ⇒ Criminal(x))
Translate to CNF:
∀x (¬(American(x) ∧ Weapon(y) ∧ Hostile(z) ∧ Sells(x,y,z)) ∨ Criminal(x))
∀x ((¬American(x) ∨ ¬Weapon(y) ∨ ¬Hostile(z) ∨ ¬Sells(x,y,z)) ∨ Criminal(x))
∀x (¬American(x) ∨ ¬Weapon(y) ∨ ¬Hostile(z) ∨ ¬Sells(x,y,z) ∨ Criminal(x))
¬American(x) ∨ ¬Weapon(y) ∨ ¬Hostile(z) ∨ ¬Sells(x,y,z) ∨ Criminal(x)
Any FOL KB can be converted to CNF as follows:
1.
Replace (P ⇒ Q) by (¬P ∨ Q) (implication elimination)
2.
Move ¬ inwards, e.g., ¬∀x P(x) becomes ∃x ¬P(x)
3.
Standardize variables apart, e.g., (∀x P(x) ∨ ∃x Q(x)) becomes (∀x P(x) ∨ ∃y
Q(y))
4.
Move quantifiers left, ¬
e.g., (∀x P(x) ∨ ∃y Q(y)) becomes ∀x ∃y (P(x) ∨ Q(y))
5.
Eliminate ∃ by Skolemization
6.
Drop universal quantifiers
dealer example
7.
Distribute ∧ over ∨, e.g., (P ∧ Q) ∨ R becomes (P ∨ R) ∧Arms
(Q ∨ R)
Any FOL KB can be converted to CNF as follows:
1.
Replace (P ⇒ Q) by (¬P ∨ Q) (implication elimination)
2.
Move ¬ inwards, e.g., ¬∀x P(x) becomes ∃x ¬P(x)
3.
Standardize variables apart, e.g., (∀x P(x) ∨ ∃x Q(x)) becomes (∀x P(x) ∨ ∃y
Q(y))
4.
Move quantifiers left, ¬
e.g., (∀x P(x) ∨ ∃y Q(y)) becomes ∀x ∃y (P(x) ∨ Q(y))
5.
Eliminate ∃ by Skolemization
6.
Drop universal quantifiers
dealer example
7.
Distribute ∧ over ∨, e.g., (P ∧ Q) ∨ R becomes (P ∨ R) ∧Arms
(Q ∨ R)
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
(l1 ∨ l2 ∨ L ∨ lk ), (m1 ∨ m2 ∨ L ∨ mn )
Subst (θ , l1 ∨ L ∨ li −1 ∨ li +1 ∨ L ∨ lk ∨ m1 ∨ L ∨ m j −1 ∨ m j +1 ∨ L ∨ mn )
Where Unify(li,¬mj) = θ.
¬
Arms dealer example
4
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
(l1 ∨ l2 ∨ L ∨ lk ), (m1 ∨ m2 ∨ L ∨ mn )
Subst (θ , l1 ∨ L ∨ li −1 ∨ li +1 ∨ L ∨ lk ∨ m1 ∨ L ∨ m j −1 ∨ m j +1 ∨ L ∨ mn )
Where Unify(li,¬mj) = θ.
l1 = ¬American(x)
l2 = ¬Weapon(y)
l3 = ¬Sells(x,y,z)
l4 = ¬Hostile(z)
l5 = Criminal(x)
m1 = Criminal(West)
Unify(l5,¬m1) = θ = {x/West}
Subst(θ, l1 ∨ l2 ∨ l3 ∨ l4) =...
¬
¬
Arms dealer example
Resolution proves KB ⊨
l1 = ¬American(x)
l2 = ¬Weapon(y)
l3 = ¬Sells(x,y,z)
l4 = ¬Hostile(z)
l5 = Criminal(x)
m2 = American(West)
α by proving (KB ∧ ¬α) is unsatisfiable
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
Unify(l1,¬m2) = θ = {x/West}
Subst(θ, l2 ∨ l3 ∨ l4) =...
¬
¬
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
?
¬
¬
Arms dealer example
Arms dealer example
5
Resolution proves KB ⊨
l2 = ¬Weapon(y)
l3 = ¬Sells(x,y,z)
l4 = ¬Hostile(z)
m3 = Weapon(x)
m4 = Missile(x)
α by proving (KB ∧ ¬α) is unsatisfiable
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
Unify(l2,¬m3) = θ = {y/x}
?
Subst(θ, l2 ∨ l3 ∨ l4 ∨ m4) =...
¬
¬
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
Arms dealer example
Resolution proves KB ⊨
¬
α by proving (KB ∧ ¬α) is unsatisfiable
¬
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
¬
Arms dealer example
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
¬
Arms dealer example
Arms dealer example
6
Resolution proves KB ⊨
α by proving (KB ∧ ¬α) is unsatisfiable
¬
∅
Arms dealer example
7