Inference in First-Order Logic Chapter 9

Preview:

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

Citation preview

1

Inference in First-Order LogicChapter 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.

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

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

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

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

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

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)

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

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)

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)

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)

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)

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)

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 }

–  

  

16

The unification algorithm

17

The unification algorithm

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.

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)

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)

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)

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?

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)

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)

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

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)

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)

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

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

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)

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.

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

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

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

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

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

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]

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)

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)

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

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)

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

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)

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?

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.

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

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)

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)

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

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

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

Ex: 1. p q KB

2. ~p q KB

3. p ~q KB

4. ~p ~q KBCannot performinput resolution!

Input Resolution

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

q

p

~q q

nil

Linear Resolution

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)

Recommended