You are on page 1of 45

Artificial Intelligence

(2180703)

Unit-4 Using Predicate Logic

Rutal Mahajan
S.N.P.I.T.R.C., Umrakh
rutal.mahajan@gmail.com

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 1
by Rutal Mahajan
Predicate Logic

• Can represent objects and quantification


• Theorem proving is semi-decidable

What is First order Logic??


Or Write Short note on Predicate Logic

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 2
by Rutal Mahajan
Predicate Logic

Quantifiers:
2 types:-

Universal quantifier ()

x: means “for all” x


It is used to represent phrase “ for all”.
It says that something is true for all possible values of a variable.

Ex. “ John loves everyone”


x: loves(John , x)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 3
by Rutal Mahajan
Predicate Logic

Existential quantifier (  ):

Used to represent the fact “ there exists some”


Ex:
“some people like reading and hence they gain good knowledge”

 x: { [person(x)  like (x , reading)] gain(x, knowledge) }

•“lord Haggins has a crown on his head”


• x: crown(x)  onhead (x , Haggins)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 4
by Rutal Mahajan
Predicate Logic- Nested Quantifier
We can use both  and  seperately

Ex: “ everybody loves somebody ”

x: y: loves ( x , y)

Connection between  and 


“ everyone dislikes garlic”
x:  like ( x , garlic )
This can be also said as:
“there does not exists someone who likes garlic”
 x: like (x, garlic)
Using Predicate Logic (AI B.E.8th semester)
3/12/2019 5
by Rutal Mahajan
Predicate Logic

Pompeian
Pompeian were Romans

All Pompeian were either loyal to Caesar or


hated him

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 6
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans

All Pompeian were either loyal to Caesar or


hated him

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 7
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans x Pompeian (X)-> roman(X)

All Pompeian were either loyal to Caesar or


hated him

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 8
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans x Pompeian (X)-> roman(X)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 9
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans x Pompeian (X)-> roman(X)

x2: roman(x2)  [ loyalto(x2,


caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 10
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans x Pompeian (X)-> roman(X)

x2: roman(x2)  [ loyal(x2 ,


caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 11
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans x Pompeian (X)-> roman(X)

x2: roman(x2)  [ loyal(x2 ,


caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 12
by Rutal Mahajan
Predicate Logic

Pompeian Pompeian (Marcus)


Pompeian were Romans x Pompeian (X)-> roman(X)

x2: roman(x2)  [ loyal(x2 ,


caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 13
by Rutal Mahajan
Resolution Algorithm in Predicate Logic
Resolution produces proof by refutation. i.e. in other words, to prove a statement,
resolution attempts to show that the negation of statement produces contradiction.

INPUT: Predicate sentences in clausal Normal form (CNF)


Assume set of given statements are in knowledge base,  is statement to be proved.

Algorithm steps :-
1. Convert all the propositions (statements) of Knowledge Base to clausal Normal
form (S).
2. Negate  and convert it to clause form. Add it to set of clauses 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
c. If resolvent is empty clause, then contradiction has been found.

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 14
by Rutal Mahajan
Resolution Algorithm in Predicate Logic

1. Eliminate .
P  Q  P  Q
2. Reduce the scope of each  to a single term.
(P  Q)  P  Q
(P  Q)  P  Q

x: P  x: P
x: 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))

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 15
by Rutal Mahajan
Resolution Algorithm in Predicate Logic
4. 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 constant

x: y P(x, y)  x: P(x, f(x)) Skolem function

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

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 16
by Rutal Mahajan
Resolution Algorithm in Predicate Logic

• Example to demostrate step 5: skolemization ( i.e. elimination of  quantifier )

y: President (y)


Can be transformed into
President (S1)
where S1 is a function that somehow produces a value that satisfies President (S1)
– S1 called as Skolem constant

• Ex. 2:
y: x: leads ( y , x )
Here value of y that satisfies ‘leads’ depends on particular value of x hence above
stmt can be written as:
x: leads ( f(x) , x )
Where f(x) is skolem function.

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 17
by Rutal Mahajan
Resolution Algorithm in Predicate Logic

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.

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 18
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X)

x2: roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 19
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X)
¬ Pompeian (X), roman(X) Remove -> so: ¬ Pompeian(X) V roman (X)

x2: roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 20
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X)
¬ ¬Pompeian
man(X) V(X)person(X)
V roman(X)

x2: Roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 21
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X) x2: Pompeian(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]
¬¬ Pompeian
man(X1) (X) V roman(X)
V person(X1) x2:  Pompeian(x2)  loyal(x2 , caesar)  hate(x2 , caesar)
 Pompeian(x2)  loyal(x2 , caesar)  hate(x2 , caesar)

x2: roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]


 roman ( x2)  loyal (x2 , caesar)  hate (x2 , caesar)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 22
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X)
¬¬Pompeian
man(X1)(X), roman(X)
V person(X1)

x2: roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]


 roman ( x2)  loyal (x2 , caesar)  hate (x2 , caesar)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 23
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus) x3: y1: loyal(x3, y1).


x Pompeian (X)-> roman(X) Let f(x3) be a skolem function then,
x3: loyal(x3, f(x3)).
¬¬Pompeian
man(X1)(X), roman(X)
V person(X1) loyal(x3, f(x3))

x2: roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]


 roman ( x2)  loyal (x2 , caesar)  hate (x2 , caesar)

loyal(X3) V f(X3) Let f(x3) be a skolem function here

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 24
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X)
¬¬Pompeian
man(X1)(X),
V person(X1)
roman(X)

x2: roman(x2)  [ loyal(x2 , caesar)  hate(x2 , caesar) ]


 roman ( x2)  loyal (x2 , caesar)  hate (x2 , caesar)

loyal(X3) V f(X3)

 person( x4)   ruler(f(x4))   tryassassinate(x4, f(x4))  loyal(x4, f(x4))

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 25
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

x4: y2: [person(x4)  ruler(y2)  tryassassinate(x4, y2) ] loyal(x4, y2)


x4: y2:  [person(x4)  ruler(y2)  tryassassinate(x4, y2) ]  loyal(x4, y2)

x4: y2:  person(x4)   ruler(y2)   tryassassinate(x4, y2)  loyal(x4, y2)

let f(x4) be skolem function then,

x4:  person(x4)   ruler(f(x4))   tryassassinate(x4, f(x4))  loyal(x4, f(x4))

Remove quantifiers
 person(x4)   ruler(f(x4))   tryassassinate(x4, f(x4))  loyal(x4, f(x4))

Final statement

 person( x4)   ruler(f(x4))   tryassassinate(x4, f(x4))  loyal(x4, f(x4))

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 26
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
x Pompeian (X)-> roman(X)
¬¬Pompeian
man(X1)(X)  roman(X)
V person(X1)

x2: roman(X2)  [ loyal(X2 , caesar)  hate(X2 , caesar) ]


 roman ( X2)  loyal (X2 , caesar)  hate (X2 , caesar)

loyal(X3) V f(X3)

 person( X4)   ruler(f(X4))   tryassassinate(X4, f(X4))  loyal(X4, f(X4))

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 27
by Rutal Mahajan
Resolution in Predicate Logic – 1. Convert to Clausal Normal Form

Pompeian (Marcus)
 Pompeian
¬ man(X1) (X1), roman(X1)
V person(X1)

 roman ( X2)  loyal (X2 , caesar)  hate (X2 , caesar)


loyal(X3) V f(X3)
 person( X4)   ruler(f(X4))   tryassassinate(X4, f(X4))  loyal(X4, f(X4))

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 28
by Rutal Mahajan
Resolution in Predicate Logic – 2. Unification

• It’s a matching procedure that compares two literals and discovers


whether there exists a set of substitutions that can make them
identical.

• E.g.
Hate( marcus , X) Hate (marcus , caesar)

caesar/ X

e.g. 2.

Hate(X,Y) Hate( john, Z) could be unified as:

John/X and Y/Z

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 29
by Rutal Mahajan
Predicate Logic –Proof
To prove : marcus hate caesar i.e. hate(marcus, caesar)
Assume  hate(marcus, caesar)
(5)
hate (marcus , caesar)  roman ( x2)  loyal (x2 , caesar) 
hate (x2 , caesar)

x2 / marcus

 roman ( marcus)  loyal (marcus, caesar)

 pompeian (x1)  roman(x1)


(3)
x1 / marcus
(2)
pompeian (marcus)
 pompeian (marcus)  loyal (marcus, caesar)

loyal (marcus, caesar)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 30
by Rutal Mahajan
loyal (marcus, caesar)
(7)
 person (x4)   ruler(f(x4)   tryassassinate(x4,f(x4))
  loyal(x4,f(x4))
f(x4)/ Caesar
x4/ marcus

 person( marcus)   ruler( caesar ) 


 tryassassinate( marcus , caesar )
(8)
tryassassinate( marcus , caesar )

 person( marcus)   ruler( caesar )


(1) person(marcus)

(4)
 ruler( caesar ) ruler( caesar )

E (empty clause/ contradiction)


Using Predicate Logic (AI B.E.8th semester) 31
3/12/2019 31
by Rutal Mahajan
Predicate Logic –Proof

Since we get an empty clause i.e. contradiction our


assumption that  hate(marcus, caesar) is false

Hence, hate(marcus, caesar) must be true.

Using Predicate Logic (AI B.E.8th semester) 32


3/12/2019 32
by Rutal Mahajan
Predicate Logic- Answer extraction using resolution
Query: Who Hated Caesar?

Step1: To answer this question, first it must be considered true that someone hated
Caesar. i.e.
x: Hate (x,Caesar).

Step2: So to answer it by resolution negate it first:


 x: Hate (x, Caesar) = x:  Hate (x, Caesar)

Step3: conversion to Clausal Form (if someone hate Caesar then x is someone)
 (Hate (x, Caesar) V ans(x))

Step4: Resolution process for answer extraction

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 33
by Rutal Mahajan
Predicate Logic- Answer extraction using resolution

 (Hate (x2, Caesar),ans(x2))


 roman ( x2)  loyal (x2 , caesar  hate (x2 , Caesar ) (5)

 roman ( x2)  loyal (x2 , caesar) V ans(x2) roman(Marcus) (2)

X2/Marcus
Loyal(Marcus,Caesar) V ans(Marcus)

(7)  person( marcus)   ruler(Caesar) 


 tryassassinate(Marcus, Caesar))  loyal(Marcus, Caesar)
V ans(Marcus)

 man (marcus)   ruler(Caesar)   tryassassinate(Marcus, Caesar) man(Marcus) (1)


(3)  ans (Marcus))

 ruler(Caesar)   tryassassinate(Marcus, Caesar)  ans(Marcus)

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 34
by Rutal Mahajan
Predicate Logic- Answer extraction using resolution

 ruler(Caesar)   tryassassinate(Marcus, Caesar)  ans(Marcus)


ruler (Caesar) (4)

 tryassassinate(Marcus, Caesar)  ans(Marcus) tryassassinate(Marcus, Caesar) (8)

ans(Marcus)

Hence, the answer of query : Who hate Caesar is


Marcus

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 35
by Rutal Mahajan
Predicate Logic Examples-Home Work
Represent following sentences in First order logic/ Predicate Logic

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 36
by Rutal Mahajan
Predicate Logic Examples-Home Work

Answers:

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 37
by Rutal Mahajan
Predicate Logic Examples-Home Work

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 38
by Rutal Mahajan
Predicate Logic Examples
Answers:

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 39
by Rutal Mahajan
Predicate Logic –Proof by resolution Examples Home Work
1) Consider following facts and Use resolution to prove “marcus is not alive now”
a. Marcus was a man.
b. Marcus was a Pompeian.
c. Marcus was born in 40 A.D.
d. All men are mortal.
e. All Pompeians died when the volcano erupted in 79 A.D.
f. No mortal lives longer than 150 years.
g. It is now 1991 A.D.

Use Resolution to find the Answer of following Question


a. When did Marcus die?
b. Whom did Marcus hate?
c. Who tried to assassinate a ruler?
d. What happen in 79 A.D.?.
e. Did Marcus hate everyone?
Hint: answer given on page 106-120 Kevin Knight
Using Predicate Logic (AI B.E.8th semester)
3/12/2019 40
by Rutal Mahajan
Predicate Logic –Proof by resolution Examples Home Work
2) Consider following facts and Use resolution to prove that “john like peanuts”
a. John likes all kinds of food.
b. Apples are food.
c. Banana is food.
d. Anything anyone eats and isn’t killed by is food.
e. Bill eats peanuts and is still alive.
f. Sue eats everything Bill eats.
Use Resolution to find the Answer of Question: What food does Sue eat?

3) Consider following facts and


Use resolution to answer the question “what courses would Steve like?”
a. Steve only likes easy courses.
b. Science courses are hard.
c. All the courses in the basket weaving department are easy.
d. BK301 is a basket weaving course.

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 41
by Rutal Mahajan
Predicate Logic –Proof by resolution Examples Home Work
4) Consider following facts and using predicate logic find the course of Anish’s liking:
a. Anish only likes easy courses.
b. Computer courses are hard.
c. All the electronic courses are easy.
d. DSP is an electronic course.

5) Consider following facts and using resolution in predicate logic


Prove that: someone is smiling
a. All people who are graduating are happy
b. All happy people smile
c. Someone is graduating

6) Consider following facts and using resolution in predicate logic


Prove that: Raja is angry
a. Rimi is hungry
b. If Rimi is hungry she barks
c. If Rimi is barking then Raja is angry

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 42
by Rutal Mahajan
Predicate Logic –Proof by resolution Examples Home Work
7) Consider following facts and using resolution in predicate logic
Prove that conclusion (fact 4 ) is valid.
1. If maid stole the jewelry then butler was not guilty
2. Either maid stole the jewelry or she milked the cow
3. If maid milked the cow then butler got the crème
4. Therefore if butler was guilty then he got the cream.

8) Consider following facts and using resolution in predicate logic


Prove that: “Ram did not jump” is false
1. Ram went to temple
2. The way to temple is, walk till post box and take left or right road.
3. The left road has ditch
4. Way to cross the ditch is to jump
5. A log is across the right road
6. One needs to jump across the log to go ahead.

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 43
by Rutal Mahajan
Other questions from GTU

1. Differentiate propositional logic and predicate logic


2. Explain unification algorithm. Explain unification step with example.
3. Explain Algorithm for Resolution in predicate logic.
4. Explain steps to convert logical statements to clausal form.

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 44
by Rutal Mahajan
References

1. Artificial Intelligence, 3rd Edition, Elaine Rich, Kevin Knight,


Shivshankar B Nair
2. NPTEL Notes and video lectures

Using Predicate Logic (AI B.E.8th semester)


3/12/2019 45
by Rutal Mahajan

You might also like