1. Shri Vaishnav Institute of Management & Science
Department of Computer Science
MCA III Semester
2024-2025
MCA – 302
Artificial Intelligence
Topic: Unit III
FOPL (First Order Predicate Logic)
by
Dr. Ekta Agrawal
2. 2
Using Propositional Logic
Representing simple facts
It is raining
Raining
It is sunny
Sunny
It is windy
Windy
If it is raining, then it is not sunny
Raining Sunny
3. 3
Using Propositional Logic
Representing simple facts
Socrates is a man.
SocratesMan
Plato is a man.
PlatoMan
This type of facts would be represent much better as :
Man (x) where x is replaced by Socrates or Plato.
Or we can say that
Man (Socrates)
Man (Plato)
4. 4
Using Predicate Logic
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Romans 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.
9. 9
Using Predicate Logic
5. All Romans were either loyal to Caesar or hated him.
inclusive-or
x: Roman(x) loyalto(x, Caesar) hate(x, Caesar)
exclusive-or
x: Roman(x) (loyalto(x, Caesar) hate(x, Caesar))
(loyalto(x, Caesar) hate(x, Caesar))
• Roman is loyal to caesar.
Loyal (Roman, caesar)
• Roman is hated to caesar.
Hate (Roman, caesar)
11. 11
Using Predicate Logic
7. People only try to assassinate rulers they are not loyal to.
x: y: person(x) ruler(y) tryassassinate(x, y)
loyalto(x, y)
13. 13
Using Predicate Logic
Was Marcus loyal to Caesar? (Using Backward Chaining)
Goal State : loyalto(Marcus, Caesar)
Proof: loyalto(Marcus, Caesar)
(7 , Substitution)
person (Marcus) ruler(Caesar) tryassassinate(Marcus, Caesar)
(4 , Substitution)
person (Marcus) tryassassinate(Marcus, Caesar)
(8 , Substitution)
person (Marcus)
Note: Marcus was a man , we do not have any way to conclude from that
Marcus was a person. So we include another fact as
9. All men are person.
x: man(x) person(x)
14. 14
Using Predicate Logic
So including fact number 9, we have
person (Marcus)
(9 , Substitution)
man (Marcus)
(1 , Substitution)
NIL
Now we can satisfy the goal state and thus it shows that Marcus was not
loyal to Caesar.
15. 15
Computational Functions
If the number of facts is not very large or if the facts
themselves unstructured that there is little alternative.
But suppose we want to express simple facts , such as
following greater than or less than relationships gt
(1,0) lt(0,1)
gt (2,1) lt(1,2)
gt (3,2) lt(2,3)
... ....
16. 16
Example
1. Marcus was a man.
– man (Marcus)
2. Marcus was a Pompeian.
– Pompeian (Marcus)
3. Marcus was born in 40 A. D.
– Born (Marcus, 40)
4. All men are mortal.
x : man (x) mortal (x)
5. All Pompeians died when the volcano erupted in 79 A.D.
- erupted (volcano , 79) Λ x : [ Pompeian (x) died (x, 79)]
17. 17
6. No Mortal lives longer than 150 years.
- x : t1 : t2 : mortal (x) born (x, t1) gt (t2 - t1 , 150) dead (x , t2)
7. It is now 1991.
now = 1991
8. Alive means not dead.
x : t : [ alive(x , t) dead (x , t) ]
x : t : [ dead (x , t) alive(x , t) ]
9. If someone dies, then he is dead at all later times.
x : t1 : t2 : died (x, t1) gt (t2 , t1 ) dead (x , t2)
19. 19
Prove that Marcus is dead using backward chaining.
Goal State : alive(Marcus, now)
Proof: alive(Marcus, now)
(9 , Substitution)
dead(Marcus, now)
(10 , Substitution)
died (Marcus, t1) gt (now , t1 )
(5 , Substitution)
Pompeian (Marcus ) gt (now , 79 )
(2 , Substitution)
gt (Now , 79 )
(8 , Substitution)
gt (1991 , 79 )
(compute gt)
NIL ( Note: Try to solve it by one more way.)
20. Resolution
The resolution proof by the refutation. In other words to prove a statement
resolution attempts to show that the negation of the statement produces a
contradiction with the know statement(that is unsatisfiable).
The resolution procedure is a iterative process, at each step two clauses
called the parent clauses are compared, resulting a new clause has been
inferred from them.
Winter Summer
Winter cold
The resolution is operates on two clauses that each contain the same
literal, the literal must occur in positive form in one clause and in negative
form in the other.The resolvent is obtained by combining all of the literals
of the two parents clauses.
21. 21
Example: All Romans who know Marcus either hate caesar or
think that anyone who hates someone is crazy.
Sentence is break into smaller sentence like:
All Romans : x : Roman (x)
who know Marcus : know (x. Marcus)
hate to caesar : hate (x , caesar)
Then Complete sentence is
x : [Roman (x) know (x, Marcus)] [hate (x, caesar) ( y :
z : hate (y , z) thinkcrazy (x, y))]
22. 22
Example: All Romans who know Marcus either hate caesar or think that anyone
who hates anyone is crazy.
x : [Roman (x) know (x, Marcus)] [hate (x, caesar) ( y : z : hate (y , z)
thinkcrazy (x, y))]
1. Conversion to Clause Form
Eliminate .
P Q P Q
Example 1: x : Pompeian (x) Roman (x)
Solution : x : Pompeian (x) Roman (x)
Another Example:
x : [Roman (x) know (x, Marcus)] [hate (x, caesar) ( y :
(z : hate (y , z) ) thinkcrazy (x, y))]
Conversion to Clause Form
23. 23
Example: All Romans who know Marcus either hate caesar or think that anyone
who hates anyone is crazy.
x : [Roman (x) know (x, Marcus)] [hate (x, caesar) ( y : z : hate (y , z)
thinkcrazy (x, y))]
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
Example: x : [Roman (x) know (x, Marcus)] [hate (x, caesar) ( y :
(z : hate (y , z) ) thinkcrazy (x, y))]
Solution: x : [ Roman (x) know (x, Marcus)] [hate (x, caesar) ( y :
z : hate (y , z) thinkcrazy (x, y))]
3. Standardize variables so that each quantifier binds a unique variable.
(x: P(x)) (x: Q(x)) (x: P(x)) (y: Q(y))
24. 24
Conversion to Clause Form
4. Move all quantifiers to the left without changing their relative order.
(x: P(x)) (y: Q(y)) x: y: (P(x) (Q(y))
x : y : z : [ Roman (x) know (x, Marcus)] [hate (x, caesar) ( hate
(y , z) thinkcrazy (x, y))]
At this point , the formula is in what is known as prenex normal form. It consists of
a prefix of quantifiers followed by a matrix, which is quantifier – free.
5. Eliminate existential quantifiers.(Skolemization).
x: P(x) P(c) Skolem constant
x: y P(x, y) x: P(x, f(x)) Skolem function
Example: y : President (y)
President (S1) Where S1 is a function with no arguments.
25. 25
Conversion to Clause Form
6. Drop the prefix .
x: P(x) P(x)
Example: x : y : z : [ Roman (x) know (x, Marcus)] [hate
(x, caesar) ( hate (y , z) thinkcrazy (x, y))]
Solution : [ Roman (x) know (x, Marcus)] [hate (x, caesar) (
hate (y , z) thinkcrazy (x, y))]
7. Convert the formula into a conjunction of disjuncts.
(P Q) R (P R) (Q R)
Example : [ Roman (x) know (x, Marcus)] [hate (x, caesar) (
hate (y , z) thinkcrazy (x, y))]
Solution : Roman (x) know (x, Marcus) hate (x, caesar)
hate (y , z) thinkcrazy (x, y)
27. 27
Conversion to Clause Form
8. Create a separate clause corresponding to each conjunct.
(winter summer) (winter wearingsandals)
(wearingboots summer ) (wearingboots wearingsandals)
i. (winter summer)
ii. (winter wearingsandals)
iii. (wearingboots summer )
iv. (wearingboots wearingsandals)
9. Standardize apart the variables in the set of obtained clauses.
28. 28
Conversion to Clause Form
1. 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.
29. Resolution algorithm
• Convert all the statements of F to clause form.
• Negate P and convert the result to clause form. Add it to the set of
clauses obtained in the previous step.
Repeat the following procedure until the null clause has been derived:
◦ Select two clauses (called parent clauses).
◦ Resolve them together. The resolvent is a disjunction of all the literals
of both parent clauses with appropriate substitutions preformed and
with the following exception: If there is one pair of literals T1 and ~T2
such that one of the parent clauses contains T1 and the other contains
T2 and if T1 and T2 are unifiable, then neither T1 nor T2 should
appear in the resolvent. We call T1 and T2 complementary literals.
Use the substitution produced by the unification algorithm to create the
resolvent. If there is more than one pair of complementary literals, only
one pair should be omitted from the resolvent.
◦ If the resolvent is the empty clause then a contradiction (proof) has
been found, else add the resolvent to the set of clauses and continue.
30. 30
Example
1. Marcus was a man.
2. Marcus was a Pompeian.
3. All Pompeians were Romans.
4. Caesar was a ruler.
5. All Romans 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.
9. All men are persons.
32. A Resolution Proof
• Axioms in clause form:
1. man(Marcus)
2. Pompeian(Marcus)
3. Pompeian(x1) v Roman(x1)
4. Ruler(Caesar)
5. Roman(x2) v loyalto(x2, Caesar) v hate(x2,
Caesar)
6. loyalto(x3, f1(x3))
7. person(x4) v ruler(y1) v tryassassinate(x4,
y1) v loyalto (x4, y1)
8. tryassassinate(Marcus, Caesar)
9. man(x5) v person (x5)
33. Resolution Proof cont.
Prove: hate(Marcus, Caesar) hate(Marcus, Caesar)
Roman(Marcus) V loyalto(Marcus,Caesar)
Marcus/x2
5
3
2
7
9
4 8
Marcus/x1
Pompeian(Marcus) V loyalto(Marcus,Caesar)
loyalto(Marcus,Caesar)
Marcus/x4, Caesar/y1
person(Marcus) V ruler(Caesar) V tryassassinate(Marcus, Caesar)
man(Marcus) V ruler(Caesar) V tryassassinate(Marcus, Caesar)
ruler(Caesar) V tryassassinate(Marcus, Caesar)
1
tryassassinate(Marcus, Caesar)
34. An Unsuccessful Attempt at Resolution
Prove: loyalto(Marcus,
Caesar)
loyalto(Marcus, Caesar)
Roman(Marcus) V hate(Marcus,Caesar)
Marcus/x2
5
3
2
Marcus/x1
Pompeian(Marcus) V hate(Marcus,Caesar)
hate(Marcus,Caesar)
Marcus/x6, Caesar/y3
(a)
hate(Marcus,Cae
sar)
10
persecute(Caesar, Marcus)
hate(Marcus,Caesar)
9
Marcus/x5, Caesar/y2
(b)
:
:
35. Using Resolution with Equality and
Reduce
• Axioms in clause form:
1. man(Marcus)
2. Pompeian(Marcus)
3. Born(Marcus, 40)
4. man(x1) V mortal(x1)
5. Pompeian(x2) V died(x2,79)
6. erupted(volcano, 79)
7. mortal(x3) V born(x3, t1) V gt(t2—t1, 150) V dead(x3, t2)
8. Now=2002
9. alive(x4, t3) V dead (x4, t3)
10. dead(x5, t4) V alive (x5, t4)
11. died (x6, t5) V gt(x6, t5) V dead(x6, t6)
Prove: alive(Marcus, now)
36. Backward Chaining / Resolution Example
Anyone passing his history exams and winning the lottery is
happy. But anyone who studies or is lucky can pass all his
exams. John did not study but John is lucky. Anyone who is
lucky wins the lottery.
Is John happy?
36
37. Backward Chaining / Resolution Example
Anyone passing his history exams and winning the lottery is
happy. But anyone who studies or is lucky can pass all his
exams. John did not study but John is lucky. Anyone who is
lucky wins the lottery.
Is John happy?
37
1st step: Convert to predicate logic
1. Anyone passing his history exams and winning the lottery is
happy.
x : Pass(x, History) Win(x, Lottery) Happy(x)
2. But anyone who studies or is lucky can pass all his exams.
x : Study(x) Lucky(x) y : Pass(x,y)
3. John did not study, but John is lucky.
Study(John) Lucky(John)
4. Anyone who is lucky wins the lottery.
x : Lucky(x) Win(x, Lottery)
38. Using Backward Chaining . Prove that Is John happy?
38
1. x : Pass(x, History) Win(x, Lottery) Happy(x)
2. x : y :Study(x) Lucky(x) Pass(x,y)
3. Study(John) Lucky(John)
4. x : Lucky(x) Win(x, Lottery)
Is John Happy? Happy (John)
(1- Substitution) (John / x)
Pass (John , History) Win(John, Lottery)
(2- Substitution) (John / x) & ( History / y)
Study(John) Lucky(John) Win(John, Lottery)
(4- Substitution) (John / x) & ( history / y)
39. Resolution Example
39
2nd step: Convert to CNF
• Eliminate implications:
1. x : (Pass(x, History) Win(x, Lottery)) Happy(x)
2. x : y : (Study(x) Lucky(x)) Pass(x,y)
3. Study(John) Lucky(John)
4. x : Lucky(x) Win(x, Lottery)
• Move inward:
1. x : Pass(x, History) Win(x, Lottery) Happy(x)
2. x : y : ( Study(x) Lucky(x)) Pass(x,y)
3. Study(John) Lucky(John)
4. x : Lucky(x) Win(x, Lottery)
• Standardize variables: no action needed
• Move quantifiers left: no action needed except drop quantifiers
• Skolemize: no action needed
40. Unification Algorithm
Algorithm: Unify(L1, L2)
1.If L1 or L2 are both variables or constants, then
a. If L1 and L2 are identical, then return NIL.
b. Else if L1 is a variable, then L1 occurs in L2 then return {FAIL}, else
return (L2/L1).
c. Else if L2 is a variable, then L2 occurs in L2 then return {FAIL}, else
return (L1/L2).
d. Else return {FAIL}.
2.If the initial predicate symbols in L1 and L2 are not identical, then return
{FAIL}.
3.If L1 and L2 have a different number of arguments, then return {FAIL}.
4.Set SUBST to NIL. (AT the end of this procedure, SUBST will contain all
the substitutions used to unify L1 and L2.)
5.For I <- 1 to number of arguments in L1:
a. Call Unify with the ith
argument of L1 and the ith
argument of L2,
putting result in S.
b. If S contains FAIL then return {FAIL}.
c. If S is not equal to NIL then:
i. Apply S to the remainder of both L1 and L2.
ii. SUBST:= APPEND(S, SUBST)
6.Return SUBST.
41. Unification Algorithm
Example:
1.Male (Tom) = Male (Tom) is true
2.Male (Bob) = Male (Tom) is False
3.Male (x) = Male (Tom) is True as x is replaced by Tom
4. parent(A, B, C)
parent (kevin, henry, 30)
It will succeed with A, B, and C variables bound to kevin, henry, and 30, res
pectively.
5. Parent (kevin, B, 25)
parent (A, henry, 30)
The 25 cannot be unified with 30, so it will fail.