CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic...
Transcript of CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic...
CS 4700:Foundations of
Artificial Intelligence
Fall 2017Instructor: Prof. Haym Hirsh
Lecture 16
Cornell Cinema
Thursday, April 13 7:00pm
Friday, April 14 7:00pm
Sunday, April 16 4:30pm
Cornell Cinema
Thursday, April 13 7:00pmCo-Sponsored by CIS
Friday, April 14 7:00pm
Sunday, April 16 4:30pm
Today
• First Order Logic (R&N Ch 8-9)
Tuesday, March 28
• First Order Logic (R&N Ch 8-9)
• Machine Learning (R&N Ch 18)
First-Order Logic: Examples• Mother(Alice,Charlie)
• Father(Bob,Charlie)
First-Order Logic: Examples• Mother(Alice,Charlie)
• Father(Bob,Charlie)
• ∀ x,y Mother(x,y) Parent(x,y)
• ∀ x,y Father(x,y) Parent(x,y)
First-Order Logic: Examples• Mother(Alice,Charlie)
• Father(Bob,Charlie)
• ∀ x,y Mother(x,y) Parent(x,y)
• ∀ x,y Father(x,y) Parent(x,y)
• ∀ x,y Parent(x,y) Ancestor(x,y)
• ∀ x,y,z Ancestor(x,y) Ancestor(y,z) Ancestor(x,z)
First-Order Logic: Examples• Mother(Alice,Charlie)
• Father(Bob,Charlie)
• ∀ x,y Mother(x,y) Parent(x,y)
• ∀ x,y Father(x,y) Parent(x,y)
• ∀ x,y Parent(x,y) Ancestor(x,y)
• ∀ x,y,z Ancestor(x,y) Ancestor(y,z) Ancestor(x,z)
• ∀ x ∃ y Mother(y,x)
• ∀ x ∃ y Father(y,x)
First-Order Logic: Examples• Mother(Alice,Charlie)
• Father(Bob,Charlie)
• ∀ x,y Mother(x,y) Parent(x,y)
• ∀ x,y Father(x,y) Parent(x,y)
• ∀ x,y Parent(x,y) Ancestor(x,y)
• ∀ x,y,z Ancestor(x,y) Ancestor(y,z) Ancestor(x,z)
• ∀ x ∃ y Mother(y,x)
• ∀ x ∃ y Father(y,x)
• ∃ x ∃ y Mother(x,y)
First Order Logic
• Sentence → AtomicSentence | ComplexSentence
• AtomicSentence → Predicate | Predicate(Arguments) | Term = Term
• Arguments → Term | Term,Arguments
• Term → Function(Arguments) | Constant | Variable
• ComplexSentence → (Sentence) | [Sentence] | Sentence
| Sentence Sentence | Sentence Sentence
| Sentence Sentence | Quantifiers Sentence
• Quantifiers → Quantifier Variables | Quantifier Variables Quantifiers
• Quantifier → ∀ | ∃
• Constant/Predicate/Function → <strings starting with upper case letters>
• Variables → Variable | Variable,Variables
• Variable → <strings comprised of lower case letters>
First Order Logic
• Sentence → AtomicSentence | ComplexSentence
• AtomicSentence → Predicate | Predicate(Arguments) | Term = Term
• Arguments → Term | Term,Arguments
• Term → Function(Arguments) | Constant | Variable
• ComplexSentence → (Sentence) | [Sentence] | Sentence
| Sentence Sentence | Sentence Sentence
| Sentence Sentence | Quantifiers Sentence
• Quantifiers → Quantifier Variables | Quantifier Variables Quantifiers
• Quantifier → ∀ | ∃
• Constant/Predicate/Function → <strings starting with upper case letters>
• Variables → Variable | Variable,Variables
• Variable → <strings comprised of lower case letters>
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Mortal(Socrates)
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Mortal(Socrates) 1,2 [x/Socrates]
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Mortal(Socrates) 1,2 [x/Socrates]
1. ∀ x,y Mother(x,y) Parent(x,y)
2. Mother(Alice,Charlie)
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Mortal(Socrates) 1,2 [x/Socrates]
1. ∀ x,y Mother(x,y) Parent(x,y)
2. Mother(Alice,Charlie)
Parent(Alice,Charlie)
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Mortal(Socrates) 1,2 [x/Socrates]
1. ∀ x,y Mother(x,y) Parent(x,y)
2. Mother(Alice,Charlie)
Parent(Alice,Charlie) 1,2 [x/Alice, y/Charlie]
Inference in First-Order Logic: Modus Ponens
1. ∀ x Man(x) Mortal(x)
2. Man(Socrates)
Mortal(Socrates) 1,2 [x/Socrates]
1. ∀ x,y Mother(x,y) Parent(x,y) “Substitutions”
2. Mother(Alice,Charlie)
Parent(Alice,Charlie) 1,2 [x/Alice, y/Charlie]
Inference in First-Order Logic: Modus Ponens
1. ∀ x P(x,B) Q(x)
2. ∀ y P(A,y)
Inference in First-Order Logic: Modus Ponens
1. ∀ x P(x,B) Q(x)
2. ∀ y P(A,y)
Q(A) 1,2 [x/A, y/B]
Inference in First-Order Logic: Modus Ponens
1. ∀ x,y,z Ancestor(x,y) Ancestor(y,z) Ancestor(x,z)
2. Ancestor(David,Ed)
3. Ancestor(Ed,Fran)
Inference in First-Order Logic: Modus Ponens
1. ∀ x,y,z Ancestor(x,y) Ancestor(y,z) Ancestor(x,z)
2. Ancestor(David,Ed)
3. Ancestor(Ed,Fran)
Ancestor(David,Fran) 1,2,3 [x/David, y/Ed, z/Fran]
Inference in First-Order Logic: Modus Ponens
1. ∀ x,y Ancestor(x,y) Ancestor(x,Child(y))
2. Ancestor(Alice,Bob)
Inference in First-Order Logic: Modus Ponens
1. ∀ x,y Ancestor(x,y) Ancestor(x,Child(y))
2. Ancestor(Alice,Bob)
3. Ancestor(Alice,Child(Bob)) 1,2 [x/A, y/Bob]
Inference in First-Order Logic: Modus Ponens
1. ∀ x,y Ancestor(x,y) Ancestor(x,Child(y))
2. Ancestor(Alice,Bob)
3. Ancestor(Alice,Child(Bob)) 1,2 [x/A, y/Bob]
4. Ancestor(Alice,Child(Child(Bob))) 1,3 [x/A, y/Child(Bob)]
Inference in First-Order Logic: Modus Ponens
1. ∀ x Relative(x,Bob) Happy(x)
2. ∀ y Relative(Child(y),y)
Inference in First-Order Logic: Modus Ponens
1. ∀ x Relative(x,Bob) Happy(x)
2. ∀ y Relative(Child(y),y)
Happy(Child(Bob)) 1,2 [x/Child(y), y/Bob]
Inference in First-Order Logic: Modus Ponens
1. ∀ x Relative(x,Friend(x)) Happy(x)
2. ∀ y Relative(Child(y),y)
Inference in First-Order Logic: Modus Ponens
1. ∀ x Relative(x,Friend(x)) Happy(x)
2. ∀ y Relative(Child(y),y)
???? 1,2 [x/Child(y), y/Friend(x)]
CYCLE!
Unification
• Unify(Man(x),Man(Socrates)) = [x/Socrates]
• Unify(Mother(x,y),Mother(Alice,Charlie)) = [x/Alice, y/Charlie]
• Unify(P(x,B),P(A,y)) = [x/A, y/B]
• Unify(Ancestor(x,y),Ancestor(Alice,Child(Bob))) =
[x/Alice, y/Child(Bob)]
• Unify(Relative(x,Bob),Relative(Child(y),y)) = [x/Child(y), y/Bob]
• Unify(Relative(x,Friend(x)),Relative(Child(y),y)) = ERROR
“Occurs Check”
Unification
Unify(x,y,answer): {wrong!}
If answer=“fail” then Return(“fail”)
Else if x=y then Return(answer)
Else if Variable(x) then Return(answer+x/y)
Else if Variable(y) then Return(answer+y/x)
Else if Head(x)=Head(y) then
For i=1 to #args(Head(x))
answer ← answer+Unify(Arg(x,i),Arg(y,i))
Return(answer)
Else Return(Fail)
Unification
Unify(x,y,answer):
If answer=“fail” then Return(“fail”)
Else if x=y then Return(answer)
Else if Variable(x) then Return(UnifyVar(x,y,answer))
Else if Variable(y) then Return(UnifyVar(y,x,answer))
Else if Head(x)=Head(y) then
For i=1 to #args(Head(x))
answer ← answer+Unify(Arg(x,i),Arg(y,i))
Return(answer)
Else Return(Fail)
Unification
UnifyVar(x,y,answer)
If x/val answer then Return(Unify(val,y,answer))
If y/val answer then Return(Unify(x,val,answer))
Else if OccursCheck(x,y) then Return(“fail”)
Else Return(answer+x/y)
Inference in First Order Logic
• First-order Horn clauses are an analogous subset of first-order logic• They have analogs of forward chaining and backward chaining
• Uses unification to match rules and facts
• Prolog is a programming language based on backward chaining on first-order Horn clauses
• There is a conjunctive normal form for First-Order Logic
• There is a resolution inference rule for First-Order Logic
CNF
Replace α β with α β everywhere [no more “”]
Replace (α β) with α β [push “” inward until
Replace (α β) with α β you can’t any more]
Replace α with α [“” only before prop symbols]
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Standardize variables: If the same variable name is used in multiple places withmultiple quantifiers, rename them so there is no duplication
∀ x P(x) ∀ x Q(x) becomes ∀ x P(x) ∀ z Q(z) [where z is new]
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Standardize variables: If the same variable name is used in multiple places withmultiple quantifiers, rename them so there is no duplication
∀ x P(x) ∀ x Q(x) becomes ∀ x P(x) ∀ z Q(z) [where z is new]
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Standardize variables: If the same variable name is used in multiple places withmultiple quantifiers, rename them so there is no duplication
∀ x P(x) ∀ x Q(x) becomes ∀ x P(x) ∀ z Q(z) [where z is new]
Skolemization
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Standardize variables: If the same variable name is used in multiple places withmultiple quantifiers, rename them so there is no duplication
∀ x P(x) ∀ x Q(x) becomes ∀ x P(x) ∀ z Q(z) [where z is new]
Skolemization
Distribute over : Rewrite α (β γ) as (α β) (α γ)
CNF
Replace α β with α β everywhere
Replace (α β) with α β
Replace (α β) with α β
Replace α with α
Replace ∀ x with ∃ x
Replace ∃ x with ∀ x
Standardize variables: If the same variable name is used in multiple places withmultiple quantifiers, rename them so there is no duplication
∀ x P(x) ∀ x Q(x) becomes ∀ x P(x) ∀ z Q(z) [where z is new]
Skolemization
Drop universal quantifiers
Distribute over : Rewrite α (β γ) as (α β) (α γ)
Skolemization
• ∃ x P(x) becomes P(A) where A is a constant that is new
Skolemization
• ∃ x P(x) becomes P(A) where A is a new constant
• ∀ x,y ∃ z P(z) becomes P(F(x,y)) where F is a new function
Skolemization
• ∃ x P(x) becomes P(A) where A is a new constant
• ∀ x,y ∃ z P(z) becomes P(F(x,y)) where F is a new function
• Replace existentially quantified variables with Skolem functions – new functions whose arguments are all universally quantified variables of higher scope
Resolution in First Order Logic
Recall:
(l α1 … αk) where each αi and βj are propositional
( l β 1 … βn) symbols or their negations and l is a
(α1 … αk β 1 … βn) propositional symbol
Resolution in First Order Logic
Here:
(l α1 … αk) [l and l‘ can be made identical by
(l‘ β 1 … βn) substituting variables with terms]
Subst(ѳ, α1 … αk β 1 … βn) [the necessary substitution]
where ѳ = Unify(l, l‘)