cs 4700: foundations of artificial intelligence · 2017-03-26 · inference in first order logic...

49
CS 4700: Foundations of Artificial Intelligence Fall 2017 Instructor: Prof. Haym Hirsh Lecture 16

Upload: others

Post on 06-Mar-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

CS 4700:Foundations of

Artificial Intelligence

Fall 2017Instructor: Prof. Haym Hirsh

Lecture 16

Page 2: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Cornell Cinema

Thursday, April 13 7:00pm

Friday, April 14 7:00pm

Sunday, April 16 4:30pm

Page 3: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Cornell Cinema

Thursday, April 13 7:00pmCo-Sponsored by CIS

Friday, April 14 7:00pm

Sunday, April 16 4:30pm

Page 4: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 5: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

First-Order Logic: Examples• Mother(Alice,Charlie)

• Father(Bob,Charlie)

Page 6: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 7: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 8: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 9: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 10: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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>

Page 11: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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>

Page 12: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x Man(x) Mortal(x)

2. Man(Socrates)

Page 13: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x Man(x) Mortal(x)

2. Man(Socrates)

Mortal(Socrates)

Page 14: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x Man(x) Mortal(x)

2. Man(Socrates)

Mortal(Socrates) 1,2 [x/Socrates]

Page 15: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 16: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 17: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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]

Page 18: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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]

Page 19: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x P(x,B) Q(x)

2. ∀ y P(A,y)

Page 20: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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]

Page 21: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 22: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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]

Page 23: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x,y Ancestor(x,y) Ancestor(x,Child(y))

2. Ancestor(Alice,Bob)

Page 24: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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]

Page 25: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)]

Page 26: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x Relative(x,Bob) Happy(x)

2. ∀ y Relative(Child(y),y)

Page 27: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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]

Page 28: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Inference in First-Order Logic: Modus Ponens

1. ∀ x Relative(x,Friend(x)) Happy(x)

2. ∀ y Relative(Child(y),y)

Page 29: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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!

Page 30: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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”

Page 31: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 32: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 33: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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)

Page 34: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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

Page 35: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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 (α β) (α γ)

Page 36: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

CNF

Replace α β with α β everywhere

Replace (α β) with α β

Replace (α β) with α β

Replace α with α

Distribute over : Rewrite α (β γ) as (α β) (α γ)

Page 37: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

CNF

Replace α β with α β everywhere

Replace (α β) with α β

Replace (α β) with α β

Replace α with α

Distribute over : Rewrite α (β γ) as (α β) (α γ)

Page 38: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

CNF

Replace α β with α β everywhere

Replace (α β) with α β

Replace (α β) with α β

Replace α with α

Replace ∀ x with ∃ x

Replace ∃ x with ∀ x

Distribute over : Rewrite α (β γ) as (α β) (α γ)

Page 39: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

CNF

Replace α β with α β everywhere

Replace (α β) with α β

Replace (α β) with α β

Replace α with α

Replace ∀ x with ∃ x

Replace ∃ x with ∀ x

Distribute over : Rewrite α (β γ) as (α β) (α γ)

Page 40: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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 (α β) (α γ)

Page 41: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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 (α β) (α γ)

Page 42: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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 (α β) (α γ)

Page 43: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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 (α β) (α γ)

Page 44: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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 (α β) (α γ)

Page 45: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

Skolemization

• ∃ x P(x) becomes P(A) where A is a constant that is new

Page 46: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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

Page 47: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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

Page 48: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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

Page 49: CS 4700: Foundations of Artificial Intelligence · 2017-03-26 · Inference in First Order Logic •First-order Horn clauses are an analogous subset of first-order logic •They have

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‘)