Predicate Logic

48
Using Predicate and Propositional Logic Unit 2

Transcript of Predicate Logic

Page 1: Predicate Logic

Using Predicate and Propositional Logic

Unit 2

Page 2: Predicate Logic

2

Using Propositional LogicRepresenting simple facts

It is rainingRAININGIt is sunnySUNNYIt is windyWINDYIf it is raining, then it is not sunnyRAINING SUNNY

Page 3: Predicate Logic

3

Using Propositional Logic•Theorem proving is decidable

•Cannot represent objects and quantification

Page 4: Predicate Logic

Compound Proposition or Complex sentences are formed from atomic formulas using the logical connectives. There are five connectives in common are:⋀ (&) : for AND or conjunction

˅ : for OR or disjunction (~) : for NOT or negation ( ) : for if_then or implication ( ) : for if and only if or

biconditional or equivalence

4

Page 5: Predicate Logic

Every propositional symbol is a Well formed formulas(WFF) • If P and Q are WFF then (P ⋀ Q)

(P ˅ Q)(P Q) and (P Q) are also WFFs.

• Negation of a WFF is a WFF

5

Page 6: Predicate Logic

Truth Table for WFF

P Q P P˄Q P˅Q P Q P Q T T F T T T T T F F F T F F F T T F T T F

F F T F F T T

6

Page 7: Predicate Logic

Example : Prove that implication is transitive in the propositional calculus using truth table i.e. (((P Q)˄(Q R)) (P R))

• Solution :_______________________________________________

P Q R A:P Q B:Q R C:A˄B D:P R C D T T T T T T T T T T F T F F F T T F T F T F T T T F F F T F F T F T T T T T T T F T F T F F T T F F T T T T T T F F F T T T T T

7

Page 8: Predicate Logic

8

Using Predicate Logic•Can represent objects and quantification

•Theorem proving is semi-decidable

Page 9: Predicate Logic

9

Using Predicate Logic1. Marcus was a man.2. Marcus was a Pompeian.3. All Pompeians were Romans.4. Caesar was a ruler.5. All Pompeians were either loyal to Caesar or hated him.6. Every one is loyal to someone.7. People only try to assassinate rulers they are not loyal to.8. Marcus tried to assassinate Caesar.

Page 10: Predicate Logic

10

Using Predicate Logic1. Marcus was a man.

man(Marcus)

Page 11: Predicate Logic

11

Using Predicate Logic2. Marcus was a Pompeian.

Pompeian(Marcus)

Page 12: Predicate Logic

12

Using Predicate Logic3. All Pompeians were Romans.

x: Pompeian(x) Roman(x)

Page 13: Predicate Logic

13

Using Predicate Logic4. Caesar was a ruler.

ruler(Caesar)

Page 14: Predicate Logic

14

Using Predicate Logic5. All Pompeians were either loyal to Caesar or hated

him.inclusive-orx: Roman(x) loyalto(x, Caesar) hate(x, Caesar)

exclusive-orx: Roman(x) (loyalto(x, Caesar) hate(x, Caesar))

(loyalto(x, Caesar) hate(x, Caesar))

Page 15: Predicate Logic

15

Using Predicate Logic6. Every one is loyal to someone.

x: y: loyalto(x, y) y: x: loyalto(x, y)

Page 16: Predicate Logic

16

Using Predicate Logic7. People only try to assassinate rulers they are not loyal

to.

x: y: person(x) ruler(y) tryassassinate(x, y) loyalto(x, y)

Page 17: Predicate Logic

17

Using Predicate Logic8. Marcus tried to assassinate Caesar.

tryassassinate(Marcus, Caesar)

Page 18: Predicate Logic

18

Using Predicate LogicWas Marcus loyal to Caesar?

man(Marcus) ruler(Caesar) tryassassinate(Marcus, Caesar)

x: man(x) person(x)loyalto(Marcus, Caesar)

Page 19: Predicate Logic

19

Using Predicate Logic• Many English sentences are ambiguous.

• There is often a choice of how to represent knowledge.

• Obvious information may be necessary for reasoning

• We may not know in advance which statements to deduce (P or P).

Page 20: Predicate Logic

Properties of Well Formed Formulas(WFFs)

• Valid or Tautologies : True for every interpretation• Satisfiable or Consistent : Some Interpretation True• Contradiction or Inconsistent or Unsatisfiable : No

Interpretation True• Equivalence : Two sentences are equivalent if they

have the same truth value under every interpretation

• Logical Consequences or Logically Follow : A sentence is a logical consequence of another if it is satisfied by all interpretations which satisfy the first.

20

Page 21: Predicate Logic

21

Reasoning1. Marcus was a Pompeian.2. All Pompeians died when the volcano erupted in 79

A.D.3. It is now 2008 A.D.

Is Marcus alive?

Page 22: Predicate Logic

22

Reasoning1. Marcus was a Pompeian.

Pompeian(Marcus)

2. All Pompeians died when the volcano erupted in 79 A.D.erupted(volcano, 79) x: Pompeian(x) died(x, 79)

3. It is now 2008 A.D.now = 2008

Page 23: Predicate Logic

23

Reasoning1. Marcus was a Pompeian.

Pompeian(Marcus)

2. All Pompeians died when the volcano erupted in 79 A.D.erupted(volcano, 79) x: Pompeian(x) died(x, 79)

3. It is now 2008 A.D.now = 2008

x: t1: t2: died(x, t1) greater-than(t2, t1) dead(x, t2)

Page 24: Predicate Logic

24

ResolutionRobinson, J.A. 1965. A machine-oriented logic based on the resolution principle.

Page 25: Predicate Logic

25

ResolutionThe basic ideas

KB | KB |false

Page 26: Predicate Logic

26

ResolutionThe basic ideas

KB | KB |false

( ) ( ) ( )

Page 27: Predicate Logic

27

ResolutionThe basic ideas

KB | KB |false

( ) ( ) ( )

sound and complete

Page 28: Predicate Logic

28

Resolution in Propositional Logic1. Convert all the propositions of KB to clause form (S).2. Negate and convert it to clause form. Add it to S.3. Repeat until either a contradiction is found or no

progress can be made.a. Select two clauses ( P) and ( P).b. Add the resolvent ( ) to S.

Page 29: Predicate Logic

29

Resolution in Propositional LogicExample:

KB = {P, (P Q) R, (S T) Q, T}

= R

Page 30: Predicate Logic

30

Resolution in Predicate LogicExample:

KB = {P(a), x: (P(x) Q(x)) R(x), y: (S(y) T(y)) Q(y), T(a)}

= R(a)

Page 31: Predicate Logic

31

Resolution in Predicate LogicUnification:

UNIFY(p, q) = unifier where SUBST(, p) = SUBST(, q)

Page 32: Predicate Logic

32

Resolution in Predicate LogicUnification:x: knows(John, x) hates(John, x)knows(John, Jane)y: knows(y, Leonid)y: knows(y, mother(y))x: knows(x, Elizabeth)

UNIFY(knows(John, x), knows(John, Jane)) = {Jane/x}UNIFY(knows(John, x), knows(y, Leonid)) = {Leonid/x, John/y}UNIFY(knows(John, x), knows(y, mother(y))) = {John/y, mother(John)/x}UNIFY(knows(John, x), knows(x, Elizabeth)) = FAIL

Page 33: Predicate Logic

33

Resolution in Predicate LogicUnification: Standardization

UNIFY(knows(John, x), knows(y, Elizabeth)) = {John/y, Elizabeth/x}

Page 34: Predicate Logic

34

Resolution in Predicate LogicUnification: Most general unifier

UNIFY(knows(John, x), knows(y, z)) = {John/y, John/x, John/z}

= {John/y, Jane/x, Jane/z}

= {John/y, v/x, v/z}= {John/y, z/x, Jane/v}= {John/y, z/x}

Page 35: Predicate Logic

35

Resolution in Predicate LogicUnification: Occur check

UNIFY(knows(x, x), knows(y, mother(y))) = FAIL

Page 36: Predicate Logic

36

Conversion to Clause Form1. Eliminate .

P Q P Q2. Reduce the scope of each to a single term.

(P Q) P Q(P Q) P Qx: P x: Px: p x: P P P

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

(x: P(x)) (x: Q(x)) (x: P(x)) (y: Q(y))

Page 37: Predicate Logic

37

Conversion to Clause Form4. Move all quantifiers to the left without changing their

relative order.(x: P(x)) (y: Q(y)) x: y: (P(x) (Q(y))

5. Eliminate (Skolemization).x: P(x) P(c) Skolem constantx: y P(x, y) x: P(x, f(x)) Skolem function

6. Drop . x: P(x) P(x)

7. Convert the formula into a conjunction of disjuncts. (P Q) R (P R) (Q R)

8. Create a separate clause corresponding to each conjunct.9. Standardize apart the variables in the set of obtained

clauses.

Page 38: Predicate Logic

38

Conversion to Clause Form1. Eliminate .2. Reduce the scope of each to a single term.3. Standardize variables so that each quantifier binds a unique

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

order.5. Eliminate (Skolemization).6. Drop .7. Convert the formula into a conjunction of disjuncts.8. Create a separate clause corresponding to each conjunct.9. Standardize apart the variables in the set of obtained clauses.

Page 39: Predicate Logic

39

Example1. Marcus was a man.2. Marcus was a Pompeian.3. All Pompeians were Romans.4. Caesar was a ruler.5. All Pompeians were either loyal to Caesar or hated him.6. Every one is loyal to someone.7. People only try to assassinate rulers they are not loyal to.8. Marcus tried to assassinate Caesar.

Page 40: Predicate Logic

40

Example1. Man(Marcus).2. Pompeian(Marcus).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(Marcus, Caesar).

Page 41: Predicate Logic

41

ExampleProve:

hate(Marcus, Caesar)

Page 42: Predicate Logic

42

Question Answering1. When did Marcus die?2. Whom did Marcus hate?3. Who tried to assassinate a ruler?4. What happen in 79 A.D.?. 5. Did Marcus hate everyone?

Page 43: Predicate Logic

43

Question AnsweringPROLOG:• Only Horn sentences are acceptable

Page 44: Predicate Logic

44

Question AnsweringPROLOG:• Only Horn sentences are acceptable• The occur-check is omitted from the unification: unsound

test P(x, x) P(x, f(x))

Page 45: Predicate Logic

45

Question AnsweringPROLOG:• Only Horn sentences are acceptable• The occur-check is omitted from the unification: unsound

test P(x, x) P(x, f(x))

• Backward chaining with depth-first search: incompleteP(x, y) Q(x, y) P(x, x)Q(x, y) Q(y, x)

Page 46: Predicate Logic

46

Question AnsweringPROLOG:• Unsafe cut: incomplete

A B, C AB D, !, ED B, C

D, !, E, C

!, E, C

Page 47: Predicate Logic

47

Question AnsweringPROLOG:• Unsafe cut: incomplete

A B, C AB D, !, ED B, C

D, !, E, C

!, E, C

• Negation as failure: P if fails to prove P

Page 48: Predicate Logic

48

HomeworkExercises 1-13, Chapter 5, Rich&Knight AI Text Book