Inference in First-Order Logic Chapter 9

54
1 Inference in First- Order Logic Chapter 9

description

Inference in First-Order Logic Chapter 9. Some Basic Definitions. A free variable is a variable that isn't bound by a quantifier. $ y Likes(x,y) x is free, y is bound A sentence is a well-formed formula where all variables are quantified. Rules of Inference. Universal instantiation. - PowerPoint PPT Presentation

Transcript of Inference in First-Order Logic Chapter 9

Page 1: Inference in First-Order Logic Chapter 9

1

Inference in First-Order LogicChapter 9

Page 2: Inference in First-Order Logic Chapter 9

2

Some Basic Definitions

  A free variable is a variable thatisn't bound by a quantifier.– y Likes(x,y)

x is free, y is bound

  A sentence is a well-formed formula whereall variables are quantified.

Page 3: Inference in First-Order Logic Chapter 9

3

Rules of Inference

x P(x)__________ P(c) if cU

Universal Universal instantiationinstantiation

P(c) for an arbitrary cP(c) for an arbitrary cUU______________________________________

x P(x)x P(x)

Universal Universal generalizationgeneralization

x P(x)x P(x)____________________________________________

P(c) for some element cP(c) for some element cUU

Existential Existential instantiationinstantiation

P(c) for some element cP(c) for some element cUU________________________________________

x P(x) x P(x)

Existential Existential generalizationgeneralization

Page 4: Inference in First-Order Logic Chapter 9

4

An example of U.G.

1. x(Ontable(x, T1) Upturned(x, T2))

2. xy(Upturned(x, y) Empty(x, y))

T1 T2

b1 b2 b3b1 b2 b3

Page 5: Inference in First-Order Logic Chapter 9

5

An example of U.G.

3. Ontable(b2, T1) Assumption4. Ontable(b2, T1) Upturned(b2, T2) - , 15. Upturned (b2, T2) - , 3, 46. Upturned(b2, T2) Empty(b2, T2) - , 2 7. Empty(b2, T2) - , 5, 68. Ontable(b2, T1) Empty(b2, T2) + , 7 9. x(Ontable(x, T1) Empty(x, T2)) + , 8

Page 6: Inference in First-Order Logic Chapter 9

6

An example of E.I.

1. x(Bottle(x,T1) Upturned(x, T2))

2. xy(Upturned(x, y) Empty(x, y))

3. x(Full(x, T1) & Empty(x, T2) Wet(Floor))

4. x (Bottle(x, T1) & Full(x, T1))

T1 T2

b1 b2 b3b1 b2 b3

Page 7: Inference in First-Order Logic Chapter 9

7

An example of E.I.

5. Bottle(b1, T1) & Full(b1, T1)) - EI assumption

6. Bottle(b1, T1) - & , 5

7. Full(b1, T1) - & , 5

8. Upturned (b1, T2) - , 1 , - , 6

9. Empty(b1, T2) - , 2 , - , 7

10. Full(b1, T1) & Empty (b1, T2) + & , 7, 9

11. Wet(Floor) - , 3, - , 10   Wet(Floor) - EI conclusion

Page 8: Inference in First-Order Logic Chapter 9

8

1. x(P(x) Q) Assumption2. xP(x)

Assumption3. P(x) - Ass.4. P(x) Q + , 1 5. Q - 3, 46. Q - Conc. 7. xP(x) Q + 2, 68. (x(P(x) Q)) (xP(x) Q) + 1, 7

Prove (x(P(x) Q)) (xP(x) Q)

Page 9: Inference in First-Order Logic Chapter 9

9

1. (xP(x) Q) Assumption2. P(x)

Assumption3. xP(x) + 4. Q - 1, 35. P(x) Q - 2, 4 6. x(P(x) Q) + 57. (xP(x) Q) (x(P(x) Q)) + 1, 6

Prove (xP(x) Q) (x(P(x) Q))

Page 10: Inference in First-Order Logic Chapter 9

10

Unification

  Can we find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)

= {x/John,y/John} is such a substitution

  Unify( ,) = if = p q Knows(John,x) Knows(John,Jane) Knows(John,x) Knows(y,OJ) Knows(John,x) Knows(y,Mother(y))Knows(John,x) Knows(x,OJ)

  Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)

Page 11: Inference in First-Order Logic Chapter 9

11

Unification

  Can we find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)

= {x/John,y/John} is such a substitution

  Unify( ,) = if = p q Knows(John,x) Knows(John,Jane) {x/Jane}Knows(John,x) Knows(y,OJ) Knows(John,x) Knows(y,Mother(y))Knows(John,x) Knows(x,OJ)

  Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)

Page 12: Inference in First-Order Logic Chapter 9

12

Unification

  Can we find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)

= {x/John,y/John} is such a substitution

  Unify( ,) = if = p q Knows(John,x) Knows(John,Jane) {x/Jane}Knows(John,x) Knows(y,OJ) {x/OJ,y/John}Knows(John,x) Knows(y,Mother(y))Knows(John,x) Knows(x,OJ)

  Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)

Page 13: Inference in First-Order Logic Chapter 9

13

Unification

  Can we find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)

= {x/John,y/John} is such a substitution

  Unify( ,) = if = p q Knows(John,x) Knows(John,Jane) {x/Jane}Knows(John,x) Knows(y,OJ) {x/OJ,y/John}Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}Knows(John,x) Knows(x,OJ)

  Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)

Page 14: Inference in First-Order Logic Chapter 9

14

Unification

  Can we find a substitution such that King(x) and Greedy(x) match King(John) and Greedy(y)

= {x/John,y/John} is such a substitution

  Unify( ,) = if = p q Knows(John,x) Knows(John,Jane) {x/Jane}Knows(John,x) Knows(y,OJ) {x/OJ,y/John}Knows(John,x) Knows(y,Mother(y)) {y/John,x/Mother(John)}Knows(John,x) Knows(x,OJ) {fail}

  Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)

Page 15: Inference in First-Order Logic Chapter 9

15

Unification

  To unify Knows(John,x) and Knows(y,z),θ = {y/John, x/z } or θ = {y/John, x/John, z/John}

  The first unifier is more general than the second.  There is a single most general unifier (MGU) that is

unique up to renaming of variables.MGU = { y/John, x/z }

–  

  

Page 16: Inference in First-Order Logic Chapter 9

16

The unification algorithm

Page 17: Inference in First-Order Logic Chapter 9

17

The unification algorithm

Page 18: Inference in First-Order Logic Chapter 9

18

Example Knowledge Base

Mark was a man. Mark was a Pompeian. All Pompeians were Romans. Caesar was a ruler. All Romans were either loyal to Caesar or hated him. Everyone is loyal to someone. People only try to assassinate rulers they are not loyal to. Mark tried to assassinate Caesar.

Page 19: Inference in First-Order Logic Chapter 9

19

Example Knowledge Base

(1) Mark was a man.man(Mark) Was Mark loyal to Caesar?

(2) Mark was a Pompeian.Pompeian(Mark)

(3) All Pompeians were Romans.x (Pompeian(x) Roman(x))

(4) Caesar was a ruler.ruler(Caesar)

(5) All Romans were either loyal to Caesar or hated him. x (Roman(x) loyalto(x, Caesar) hate(x, Caesar))

(6) Everyone is loyal to someone. x y loyalto(x, y)

(7) People only try to assassinate rulers they are not loyal to. x y (person(x) ruler(y) tryassassinate(x, y) loyalto(x, y))

(8) Mark tried to assassinate Caesar.tryassassinate(Mark, Caesar)

Page 20: Inference in First-Order Logic Chapter 9

20

Reasoning Backward

(1) man(Mark)(2) Pompeian(Mark)(3) x (Pompeian(x) Roman(x))(4) ruler(Caesar)(5) x (Roman(x) loyalto(x, Caesar) hate(x, Caesar))(6) x y loyalto(x, y)(7) x y (person(x) ruler(y) tryassassinate(x, y) loyalto(x, y))(8) tryassassinate(Mark, Caesar)

loyalto(Mark, Caesar)

(x/Mark) (y/Caesar)

person(Mark) ruler(Caesar) tryassassinate(Mark, Caesar)

Page 21: Inference in First-Order Logic Chapter 9

21

Reasoning Backward

(1) man(Mark)(2) Pompeian(Mark)(3) x (Pompeian(x) Roman(x))(4) ruler(Caesar)(5) x (Roman(x) loyalto(x, Caesar) hate(x, Caesar))(6) x y loyalto(x, y)(7) x y (person(x) ruler(y) tryassassinate(x, y) loyalto(x, y))(8) tryassassinate(Mark, Caesar)(9) x (man(x) person(x))

loyalto(Mark, Caesar)

(x/Mark) (y/Caesar)

person(Mark) ruler(Caesar) tryassassinate(Mark, Caesar)

(x/Mark)

Man(Mark)

Page 22: Inference in First-Order Logic Chapter 9

22

Functions and Predicates

(1) Mark was a man.man(Mark)

(2) Mark was a Pompeian.Pompeian(Mark)

(3) Mark was born in 40 A.D.born(Mark, 40)

(4) All men are mortal.x (man(x) mortal(x))

(5) A volcano erupted in 79 A.D. erupted(volcano, 79)

(6) AllPompeians died in 79 A.D. x (Pompeian(x) died(x,79))

(7) No mortal lives longer than 150 years. x t1 t2 (mortal(x) born(x, t1) gt(t2-t1, 150) dead(x, t2))

(8) It is now 2010.now = 2010

Is Mark alive?

Page 23: Inference in First-Order Logic Chapter 9

23

Functions and Predicates

(1) man(Mark)(2) Pompeian(Mark)(3) born(Mark, 40)(4) x (man(x) mortal(x))(5) erupted(volcano, 79) (6) x (Pompeian(x) died(x,79)) (7) x t1 t2 (mortal(x) born(x, t1) gt(t2-t1, 150) dead(x, t2))(8) now = 2010

alive(Mark, now)

Page 24: Inference in First-Order Logic Chapter 9

24

Functions and Predicates - Filling in the Blanks

(1) man(Mark)(2) Pompeian(Mark)(3) born(Mark, 40)(4) x (man(x) mortal(x))(5) erupted(volcano, 79) (6) x (Pompeian(x) died(x,79)) (7) x t1 t2 (mortal(x) born(x, t1) gt(t2-t1, 150) dead(x, t2))(8) now = 2010(9a) x t (dead(x,t) alive(x, t))(9b) x t (alive(x, t) dead(x, t))(10) x t1 t2 (died(x, t1) gt(t2, t1) dead(x, t2))

alive(Mark, now)

Page 25: Inference in First-Order Logic Chapter 9

25

Showing that Mark is Not Alive

alive(Mark, now) (9a) (x/Mark) (t/now)

dead(Mark, now)

(10)(x/Mark)(t2/now) (7) (Mark/x)(now/t2) died(Mark, t1) gt(now, t1) mortal(Mark) born(Mark, t1) gt(now-t1,150)

(6)(x/Mark) (t1/79) (4) (x/Mark) (3) (t1/40)

Pompeian(Mark) gt(now, 79) man(Mark) born(Mark, 40) gt(now-40,150) (2) subst (1) subst

T gt(2010, 79) T T gt(2010-40,150) eval eval

T T

Page 26: Inference in First-Order Logic Chapter 9

26

A Harder One

Given:x [Roman(x) know(x, Mark)]

[hate(x, Caesar) (y (z hate(y, z)) thinkcrazy(x, y))]

Roman(Isaac)hate(Isaac, Caesar)hate(Paulus, Mark)thinkcrazy(Isaac, Paulus)

Prove:know(Isaac, Mark)

Page 27: Inference in First-Order Logic Chapter 9

27

Clause Form Simplifies the Process

Standard:x [Roman(x) know(x, Mark)]

[hate(x, Caesar) (y (z hate(y, z)) thinkcrazy(x, y))]

Clausal:Roman(x) know(x, Mark) hate(x, Caesar) hate(y, z) thinkcrazy(x, z)

Page 28: Inference in First-Order Logic Chapter 9

28

Conversion to Clause Form - Step 1

1. Eliminate , using the fact that a b is equivalent to a b

x [Roman(x) know(x, Mark)] [hate(x, Caesar) (y (z hate(y, z)) thinkcrazy(x, y))]

x [Roman(x) know(x, Mark)] [hate(x, Caesar) (y (z hate(y, z)) thinkcrazy(x, y))]

Page 29: Inference in First-Order Logic Chapter 9

29

Conversion to Clause Form - Step 2

2. Reduce the scope of each to a single term, using:(p) = p•deMorgan’s lawsx P(x) x P(x)x P(x) x P(x)

x [Roman(x) know(x, Mark)] [hate(x, Caesar) (y (z hate(y, z)) thinkcrazy(x, y))]

x [ Roman(x) know(x, Mark)] [hate(x, Caesar) (y z hate(y, z) thinkcrazy(x, y))]

Page 30: Inference in First-Order Logic Chapter 9

30

Conversion to Clause Form - Step 3

3. Standardize variables so that each quantifier binds a unique variable.

x P(x) x Q(x)

x P(x) y Q(y)

Page 31: Inference in First-Order Logic Chapter 9

31

Conversion to Clause Form - Step 4

4. Move all quantifiers to the left without changing their relative order.

x [ Roman(x) know(x, Mark)] [hate(x, Caesar) (y z hate(y, z) thinkcrazy(x, y))]

x y z [ Roman(x) know(x, Mark)] [hate(x, Caesar) ( hate(y, z) thinkcrazy(x, y))]

At this point, we have prenex normal form.

Page 32: Inference in First-Order Logic Chapter 9

32

Conversion to Clause Form - Step 5

5. Eliminate existential quantifiers through the use of Skolem functions and constants.

x Roman(x) Roman(S1)

x z father-of(x, z) x father-of(x, S2(x))

Page 33: Inference in First-Order Logic Chapter 9

33

Conversion to Clause Form - Step 6

6. Drop the prefix since all remaining quantifiers are universal.

x y z [ Roman(x) know(x, Mark)] [hate(x, Caesar) ( hate(y, z) thinkcrazy(x, y))]

[ Roman(x) know(x, Mark)] [hate(x, Caesar) ( hate(y, z) thinkcrazy(x, y))]

Page 34: Inference in First-Order Logic Chapter 9

34

Conversion to Clause Form - Step 7

7. Convert the matrix into a conjunction of disjuncts by using:•Associative properties of and .

[ Roman(x) know(x, Mark)] [hate(x, Caesar) ( hate(y, z) thinkcrazy(x, y))]

Roman(x) know(x, Mark) hate(x, Caesar) ( hate(y, z) thinkcrazy(x, y))

•Distribution of over .

(P(x) Q(x)) T(x)

(P(x) T(x)) (Q(x)) T(x))

Page 35: Inference in First-Order Logic Chapter 9

35

Conversion to Clause Form - Step 8

8. Create a separate clause for each conjunct.

(P(x) T(x)) (Q(x) T(x))

(P(x) T(x)) (Q(x) T(x))

Page 36: Inference in First-Order Logic Chapter 9

36

Conversion to Clause Form - Step 9

9. Standardize apart the variables.

(P(x) T(x)) (Q(x) T(x))

(P(x) T(x)) (Q(y) T(y))

Page 37: Inference in First-Order Logic Chapter 9

37

Resolution in Predicate Logic

p’ v q ~p v r (q v r)

p(x) v q(x) ~p(a) v r(b) (q(x) v r(b)) [x/a] => q(a) v r(b)

  All variables assumed universally quantified.

where p' = p

where = [x/a]

Page 38: Inference in First-Order Logic Chapter 9

38

Importance of Standardizing Variables Apart

Consider:1. father(x, y) woman(x)

{father(x, y) woman(x)}2. mother(x, y) woman(x)

{mother(x, y) woman(x)}3. mother(Chris, Mary)4. father(Chris, Bill)

1 2

* father(x, y) mother(x, y) 3

x/Chris, y/Mary

father(Chris, Mary)

Page 39: Inference in First-Order Logic Chapter 9

39

Back to Mark

(1) man(Mark)(2) Pompeian(Mark)(3) Pompeian(x1) Roman(x1)(4) ruler(Caesar)(5) Roman(x2) loyalto(x2, Caesar) hate(x2, Caesar)(6) loyalto(x3, S1(x3))(7) man(x4) ruler(y1) tryassassinate(x4, y1) loyalto(x4, y1)(8) tryassassinate(Mark, Caesar)

Page 40: Inference in First-Order Logic Chapter 9

40

Proving Mark Not Loyal to Caesar

loyalto(M, C) man(x4) ruler(y1) tryassassinate(x4, y1) loyalto(x4, y1)

(x4/M)(y1/C)

man(M) ruler(C) tryassassinate(M,C) man(M)

ruler(C) tryassassinate(M,C) ruler(C)

tryassassinate(M,C) tryassassinate(M,C)

nil

Page 41: Inference in First-Order Logic Chapter 9

41

Does Isaac Know Mark?

Given:1. x [Roman(x) know(x, Mark)]

[hate(x, Caesar) (y (z hate(y, z)) thinkcrazy(x, y))]

Roman(x) know(x, Mark) hate(x, Caesar) hate(y, z) thinkcrazy(x, y)

2. Roman(Isaac)3. hate(Isaac, Caesar)4. hate(Paulus, Mark)5. thinkcrazy(Isaac, Paulus)

Prove:know(Isaac, Mark) * know(Isaac, Mark)

Page 42: Inference in First-Order Logic Chapter 9

42

Proving Issac Doesn’t know Mark

know(Isaac, Mark) 1

(x/I)

Roman(I) hate(I, C) hate(y, z) thinkcrazy(I, y) 2: Roman(I)

hate(I, C) hate(y, z) thinkcrazy(I, y) 3: hate(I, C)

hate(y, z) thinkcrazy(I, y) 4: hate(P, M)

(y/P)(z/M)

thinkcrazy(I, P) 5: thinkcrazy(I, P)

nil

Page 43: Inference in First-Order Logic Chapter 9

43

Question Answering

When did Mark die?

died(Mark, ??)

Mark must have died sometime, so we could try to prove:

x died(Mark, x) by adding to the KB:

x died(Mark, x). Converting to clause form:

x died(Mark, x)

Page 44: Inference in First-Order Logic Chapter 9

44

When Did Mark Die?

died(Mark, x) Pompeian(x1) died(x1,79)

(x1/Mark)(x/79)

Pompeian(Mark) Pompeian(Mark)

nil

But how do we retrieve the answer 79?

Page 45: Inference in First-Order Logic Chapter 9

45

When Did Mark Die?

died(Mark, x) died(Mark, x) Pompeian(x1) died(x1,79)

(x1/Mark)(x/79)

Pompeian(Mark) died(Mark, 79) Pompeian(Mark)

died(Mark, 79)

The underlined literal will get carried along and collect all the substitutions. We stop when we generate a clause that contains only it.

Page 46: Inference in First-Order Logic Chapter 9

46

Resolution Strategies

  Unit Preference:– prefer to do resolutions where 1 sentence

is a single literal, a unit clause

– goal is to produce the empty clause, focus searchby producing resolvents that are shorter

complete but too slow for medium sized problems

  Unit Resolution:– requires at least 1 to be a unit clause complete for Horn Clauses

Page 47: Inference in First-Order Logic Chapter 9

1. p q KB2. ~p r KB3. ~q r KB4. ~r S5. ~p 2, 4

6. ~q 3, 47. q 1, 5

8. p 1, 6

9. r 3, 7

10. nil 6, 7

11. r 2, 8

12. nil 5, 8

Unit Resolution Example (1)

Page 48: Inference in First-Order Logic Chapter 9

1. p q

2. ~p q

3. p ~q

4. ~p ~q

Cannot perform a single unit resolution since all clauses are

of size 2!

Unit Resolution Example(2)

Page 49: Inference in First-Order Logic Chapter 9

49

Resolution Strategies (Cont.)

  Set-of-Support (SoS):– identify some subset of sentences, called SoS

– P and Q can be resolved if one is from SoS

– resolvent is added to the SoS

– common approach: query is the initial SoS, resolvents are added assumes KB is satisfiable

complete if KB-SoS is satisfiable

Page 50: Inference in First-Order Logic Chapter 9

1. p q KB2. ~p r KB3. ~q r KB4. ~r S5. ~p 2, 4 add to S6. ~q 3, 4 add to S7. q 1, 5 add to S8. p 1, 6 add to S9. r 3, 710. nil 6, 711. r 2, 812. nil 5, 8

Set of Support resolution example

Page 51: Inference in First-Order Logic Chapter 9

51

Resolution Strategies (Cont.)

  Input Resolution:– P and Q can be resolved if at least one is from

the set of original clauses, i.e., KB and query complete for Horn Clauses

  Linear Resolution:– a slight generalization of input resolution– P and Q can be resolved if:

– P is from the set of the original clauses, or – P is an ancestor of Q, in the proof tree

complete

Page 52: Inference in First-Order Logic Chapter 9

Ex: 1. p q KB

2. ~p q KB

3. p ~q KB

4. ~p ~q KBCannot performinput resolution!

Input Resolution

Page 53: Inference in First-Order Logic Chapter 9

p q ~p q p ~q ~p ~q

q

p

~q q

nil

Linear Resolution

Page 54: Inference in First-Order Logic Chapter 9

54

Natural Deduction vs. Resolution

• CNF is simpler to work with• But, we loose readability and some useful control

information

x(judge(x) & ~crooked(x) educated(x))

~judge(x) v crooked(x) v educated(x)