SlideShare a Scribd company logo
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
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
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
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.
5
Using Predicate Logic
1. Marcus was a man.
Man(Marcus)
6
Using Predicate Logic
2. Marcus was a Pompeian.
Pompeian(Marcus)
7
Using Predicate Logic
3. All Pompeians were Romans.
x: Pompeian(x)  Roman(x)
8
Using Predicate Logic
4. Caesar was a ruler.
ruler(Caesar)
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)
10
Using Predicate Logic
6. Every one is loyal to someone.
x: y: loyalto(x, y) y: x: loyalto(x, y)
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)
12
Using Predicate Logic
8. Marcus tried to assassinate Caesar.
tryassassinate(Marcus, Caesar)
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
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
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
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
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)
18
1. man (Marcus)
2. Pompeian (Marcus)
3. Born (Marcus, 40)
4. x : man (x)  mortal (x)
5. x : [ Pompeian (x)  died (x, 79)]
6. erupted (volcano , 79)
7. x : t1 :  t2 : mortal (x)  born (x, t1)  gt (t2 - t1 , 150) 
dead (x , t2)
8. now = 1991
9. x : t : [ alive(x , t)   dead (x , t) ]  [ dead (x , t) 
alive(x , t) ]
10. x : t1 :  t2 : died (x, t1)  gt (t2 , t1 )  dead (x , t2)
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.)
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
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
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
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
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
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)
26
Conversion to Clause Form
Another Eg: (winter  wearingboots )  (summer  wearingsandals)
(P  Q)  R = (P  R)  (Q  R)
Solution: First Step : [ winter  (summer  wearingsandals) ] 
[wearingboots  (summer  wearingsandals) ]
Solution: Second Step : (winter  summer) 
(winter  wearingsandals) 
(wearingboots  summer )
(wearingboots  wearingsandals)
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
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.
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
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.
31
Example
1. 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).
9. x: man (x)  person (x)
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)
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)
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)
:
:
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)
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
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)
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)
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
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.
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.

More Related Content

PPT
Ch8-LogicalRepresentationAndReasoning.ppt
FELICIALILIANJ
 
PPT
predicate logic in artificial intelligence for knowledge representation ppt
BhavishaSuthar2
 
PPTX
AIML 7th semester VTU
AyushiLodha3
 
PPT
firstorder_predicate_logic_resolution.ppt
ssuserc108ce1
 
PPT
Predlogic
saru40
 
PPT
L03 ai - knowledge representation using logic
Manjula V
 
PDF
16_FirstOrderLogic.p_4_moduleModuleNotespdf
ShylaBg1
 
Ch8-LogicalRepresentationAndReasoning.ppt
FELICIALILIANJ
 
predicate logic in artificial intelligence for knowledge representation ppt
BhavishaSuthar2
 
AIML 7th semester VTU
AyushiLodha3
 
firstorder_predicate_logic_resolution.ppt
ssuserc108ce1
 
Predlogic
saru40
 
L03 ai - knowledge representation using logic
Manjula V
 
16_FirstOrderLogic.p_4_moduleModuleNotespdf
ShylaBg1
 

Similar to MCA 3rd sem Unit_III_Predicate_Logics .ppt (20)

PPTX
Predicate logic
Harini Balamurugan
 
PPT
Unit III Knowledge Representation in AI K.Sundar,AP/CSE,VEC
sundarKanagaraj1
 
PPTX
First order logic
Faiz Zeya
 
PPTX
Knowledge representation and Predicate logic
Amey Kerkar
 
PPT
chapter9.ppt
Praveen Kumar
 
DOC
Chapter 4 (final)
Nateshwar Kamlesh
 
PDF
16 1 predicate resolution
Tianlu Wang
 
PPT
Predicate calculus
Rajendran
 
PDF
16 2 predicate resolution
Tianlu Wang
 
PDF
Knowledge representation using predicate logic
HarshitaSharma285596
 
PPTX
knowledge representation.pptx
SwatiHans10
 
PPT
3 fol examples v2
Digvijay Singh
 
PPT
9.class-notesr9.ppt
Pabitha Chidambaram
 
PPT
PredicateLogic or FOL for Computer Science
parvath vigna
 
PPT
Lec8-PredicateLogic knowledge representation.ppt
ratnababum
 
PPTX
Converse, contrapositive, inverse
Abdur Rehman
 
PPTX
Knowledge Representation and Reasoning.pptx
MohanKumarP34
 
PDF
BCS515B Module 5 vtu notes : Artificial Intelligence Module 5.pdf
Swetha A
 
PPT
Inference in first-order logic Reducing first-order
erasmuskratos
 
PPT
PropositionalLogic.ppt
MArunyNandinikkutty
 
Predicate logic
Harini Balamurugan
 
Unit III Knowledge Representation in AI K.Sundar,AP/CSE,VEC
sundarKanagaraj1
 
First order logic
Faiz Zeya
 
Knowledge representation and Predicate logic
Amey Kerkar
 
chapter9.ppt
Praveen Kumar
 
Chapter 4 (final)
Nateshwar Kamlesh
 
16 1 predicate resolution
Tianlu Wang
 
Predicate calculus
Rajendran
 
16 2 predicate resolution
Tianlu Wang
 
Knowledge representation using predicate logic
HarshitaSharma285596
 
knowledge representation.pptx
SwatiHans10
 
3 fol examples v2
Digvijay Singh
 
9.class-notesr9.ppt
Pabitha Chidambaram
 
PredicateLogic or FOL for Computer Science
parvath vigna
 
Lec8-PredicateLogic knowledge representation.ppt
ratnababum
 
Converse, contrapositive, inverse
Abdur Rehman
 
Knowledge Representation and Reasoning.pptx
MohanKumarP34
 
BCS515B Module 5 vtu notes : Artificial Intelligence Module 5.pdf
Swetha A
 
Inference in first-order logic Reducing first-order
erasmuskratos
 
PropositionalLogic.ppt
MArunyNandinikkutty
 
Ad

Recently uploaded (20)

PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPTX
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
DOCX
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
PDF
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
PDF
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
DOCX
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Artificial Intelligence in Gastroentrology: Advancements and Future Presprec...
AyanHossain
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
pgdei-UNIT -V Neurological Disorders & developmental disabilities
JELLA VISHNU DURGA PRASAD
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
INTESTINALPARASITES OR WORM INFESTATIONS.pptx
PRADEEP ABOTHU
 
Biological Classification Class 11th NCERT CBSE NEET.pdf
NehaRohtagi1
 
Health-The-Ultimate-Treasure (1).pdf/8th class science curiosity /samyans edu...
Sandeep Swamy
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
A Smarter Way to Think About Choosing a College
Cyndy McDonald
 
Unit 5: Speech-language and swallowing disorders
JELLA VISHNU DURGA PRASAD
 
Ad

MCA 3rd sem Unit_III_Predicate_Logics .ppt

  • 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.
  • 5. 5 Using Predicate Logic 1. Marcus was a man. Man(Marcus)
  • 6. 6 Using Predicate Logic 2. Marcus was a Pompeian. Pompeian(Marcus)
  • 7. 7 Using Predicate Logic 3. All Pompeians were Romans. x: Pompeian(x)  Roman(x)
  • 8. 8 Using Predicate Logic 4. Caesar was a ruler. ruler(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)
  • 10. 10 Using Predicate Logic 6. Every one is loyal to someone. x: y: loyalto(x, y) y: x: loyalto(x, y)
  • 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)
  • 12. 12 Using Predicate Logic 8. Marcus tried to assassinate Caesar. tryassassinate(Marcus, Caesar)
  • 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)
  • 18. 18 1. man (Marcus) 2. Pompeian (Marcus) 3. Born (Marcus, 40) 4. x : man (x)  mortal (x) 5. x : [ Pompeian (x)  died (x, 79)] 6. erupted (volcano , 79) 7. x : t1 :  t2 : mortal (x)  born (x, t1)  gt (t2 - t1 , 150)  dead (x , t2) 8. now = 1991 9. x : t : [ alive(x , t)   dead (x , t) ]  [ dead (x , t)  alive(x , t) ] 10. 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)
  • 26. 26 Conversion to Clause Form Another Eg: (winter  wearingboots )  (summer  wearingsandals) (P  Q)  R = (P  R)  (Q  R) Solution: First Step : [ winter  (summer  wearingsandals) ]  [wearingboots  (summer  wearingsandals) ] Solution: Second Step : (winter  summer)  (winter  wearingsandals)  (wearingboots  summer ) (wearingboots  wearingsandals)
  • 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.
  • 31. 31 Example 1. 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). 9. x: man (x)  person (x)
  • 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.