0% found this document useful (0 votes)
85 views52 pages

Inference in Fol 2

This document discusses inference in first-order logic. It covers definite and Horn clauses, generalized modus ponens, forward chaining, and backward chaining. Forward chaining starts with facts and applies rules to derive new facts, while backward chaining starts with a goal and recursively applies rules to reduce it to facts. Resolution is also discussed as a way to resolve two clauses that contain complement literals. Examples are provided to illustrate these inference techniques.

Uploaded by

Ahmed Khaled
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
85 views52 pages

Inference in Fol 2

This document discusses inference in first-order logic. It covers definite and Horn clauses, generalized modus ponens, forward chaining, and backward chaining. Forward chaining starts with facts and applies rules to derive new facts, while backward chaining starts with a goal and recursively applies rules to reduce it to facts. Resolution is also discussed as a way to resolve two clauses that contain complement literals. Examples are provided to illustrate these inference techniques.

Uploaded by

Ahmed Khaled
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

Artificial Intelligence

Lecture 8
Inference in First Order Logic
8-12-2022
Outline
 Definite clause and Horn clauses.
 Generalized Modus Ponens.
 Forward chaining.
 Backward chaining.
 Resolution in first order logic
 Conversion to CNF
 Skolemization
Definite clause and Horn clause
 Definite clause: disjunction of literals with exactly
one positive literal
 P ∨¬ Q (Q  P)
 𝑃1  𝑃2  …  𝑃𝑛  Q
 Q

 Horn clause: disjunction of literals with at most


one positive literal
𝑃1  𝑃2  …  𝑃𝑛  Q
Q

¬ Q
Example
 The following are not Horn clauses:
 P∨R (two positive literals)
 C ⟹ (A ∨ B) (two positive literals)

 The statement: P ∨ Q ⇒ R is not definite clause,


but it can be transformed to 2 definite clauses:
( ¬ P ∧¬ Q) ∨ R (by ⇒ elimination)
(¬ P ∨ R) ∧ (¬ Q ∨ R) (by distribution of ∧ over ∨)
P ⇒ R and Q ⇒ R (by and elimination)
Modus Ponens (MP) inference rule

𝛼 ⟹ 𝛽, 𝛼
𝛽
Example,
α Adam study hard
α⇒β if Adam study hard, Adam will pass
----------
β Adam will pass
Generalized Modus Ponens (GMP)
𝑃′1 , 𝑃′2 , … , 𝑃′ 𝑛 , 𝑃1  𝑃2  …  𝑃𝑛 ⇒ 𝑄
𝑄θ
θ is a substitution
where Pi'θ = Pi θ for all i : 1, …, n

𝑃 𝑥 , 𝑄 𝐴 , 𝑄 𝑦 𝑃 𝐵 ⇒ 𝑅(𝑥,𝑦)
Example 1:
𝑅(𝐵, 𝐴)
θ = { x / B, y/ A}
Generalized Modus Ponens (GMP)
𝑃′1 , 𝑃′2 , … , 𝑃′ 𝑛 , 𝑃1  𝑃2  …  𝑃𝑛 ⇒ 𝑄
𝑄θ where Pi'θ = Pi θ for all i : 1, …, n

Example 2:
𝑃1 𝑖𝑠 𝐾𝑖𝑛𝑔 𝑥 𝑃2 is Greedy(x)
𝑃′1 𝑃′2
𝑲𝒊𝒏𝒈 𝑱𝒐𝒉𝒏 , 𝑮𝒓𝒆𝒆𝒅𝒚 𝒚 , (𝑲𝒊𝒏𝒈 𝒙 ∧ 𝑮𝒓𝒆𝒆𝒅𝒚(𝒙) ⟹ 𝑬𝒗𝒊𝒍 (𝒙)
Q is Evil(x)
𝑬𝒗𝒊𝒍 𝑱𝒐𝒉𝒏
Qθ is Evil (John)

θ is {x/John,y/John}, Q is Evil(x) , Qθ is Evil (John)


 GMP used with KB of definite clauses (exactly one positive literal)

 All variables are assumed universally quantified


Renaming
 One sentence is a renaming of another if they are
identical except for the names of the variables.
 For example, Likes(x, IceCream) and
Likes(y, IceCream)
are renaming of each other; they differ only in the
choice of x or y.
Their meanings are identical: everyone likes ice
cream.
Example 1: knowledge base
 The law says that it is a crime for an American to sell weapons
to hostile nations. The country Nono, an enemy of America,
has some missiles, and all of its missiles were sold to it by
Colonel West, who is American.

 Prove that West is a criminal


Example 1: knowledge base (cont.)
First: Represent the problem in first order definite clauses
... it is a crime for an American to sell weapons to hostile nations:
American(x) Weapon(y)  Sells(x, y, z)  Hostile(z)  Criminal(x) rule 1

Nono … has some missiles:


x Owns(Nono, x)  Missile(x):
Owns(Nono, M1) and Missile(M1) rule 2
(M1 is a new constant - Skolem constant)

Owns(Nono,M1) and Missile(M1) are 2 facts


Example 1 knowledge base (cont.)
First: Represent the problem in first order definite clauses
… all of its missiles were sold to it by Colonel West
Missile(x)  Owns(Nono, x)  Sells(West, x, Nono) rule 3

Missiles are weapons:


Missile(x)  Weapon(x) rule 4
Example1 knowledge base (cont.)
First: Represent the problem in first order definite clauses
An enemy of America counts as "hostile“:
Enemy(x, America)  Hostile(x) rule 5

West, who is American …


American(West) (fact) 6

The country Nono, an enemy of America …


Enemy(Nono, America) (fact) 7
Example 1 (cont.)
 After representing the problem in FOL definite
clauses, one of the following techniques can be
applied to show that west is criminal:
 Forwardchaining
 Backward chaining
Forward chaining proof tree for
Example1

Start with the facts of the problem


Forward chaining proof tree
Missile(x)  Owns(Nono, x)  Sells(West, x, Nono) 3
Missile(x)  Weapon(x) 4
Enemy(x, America)  Hostile(x) 5

rule4
rule 3 rule 5
Forward chaining proof tree for
Example 1
American(x) Weapon(y)  Sells(x, y, z)  Hostile(z)  Criminal(x) 1

θ ={x/West, y/ M1, z/Nono}

rule 1
Properties of forward chaining
 Sound and complete for first-order definite clauses

 Datalog = first-order definite clauses + no functions


 Forward chaining terminates for Datalog in finite number of
iterations

 May not terminate in general if α is not entailed


 This is unavoidable: entailment with definite clauses is
semidecidable
Note
 For general definite clauses with function symbols, forward
chaining can generate infinitely new facts:
 NatNum(0) S(n) is the successor function, it
returns the successor number of n
 ∀ n NatNum(n) ⟹ NatNum(S(n))
 The forward chaining adds NatNum(S(0)), NatNum(S(S(0))),
NatNum(S(S(S(0)))), …
Note
 A major disadvantage of the forward chaining algorithm
is that the algorithm might generate many facts that are
irrelevant to the goal.
Backward chaining for Example 1

Begin from the goal


Backward chaining for Example 1
• To prove Criminal(West), the four conjuncts below
it must be proved.
• Some of these are in the knowledge base, and
others require further backward chaining

American(x) Weapon(y)  Sells(x, y, z)  Hostile(z)  Criminal(x) Rule 1


Backward chaining For Example 1

American(West) Fact 6
Backward chaining for Example 1

Missile(y)  Weapon(y) Rule 4


Backward chaining for Example 1

Missile(M1) Fact 2
Backward chaining for Example 1

Missile(z)  Owns(Nono, z)  Sells(West, z, Nono) Rule 3


Backward chaining for Example 1

Enemy(x, America)  Hostile(x) Rule 5


Enemy(Nono, America) Fact 7
Missile (M1) Fact 2
Owns (Nono, M1) Fact 2
Backward chaining for Example 1
Properties of backward chaining
 Depth-first recursive proof search: space is linear in
size of proof
 Widely used for logic programming
Example 2
 Show that Murad is a grandparent of Adam by both forward-
chaining and backward-chaining if you know that:
Murad is the father of Basem, Samia is Basem’s mother, and Basem is
Adam’s father.
 First the problem is translated to the following facts:

Father(Murad, Basem)
Father(Basem, Adam)
Mother(Samia, Basem)
 The following family rules can be used:

Father(x, y) ⟹ Parent(x, y) rule 1


Mother (x1, y1) ⟹ Parent(x1, y1) rule 2
Parent(x2, y2)  Parent (y2, z) ⟹ Grandparent(x2, z) rule 3
Example 2 (cont.)
 In the forward chaining, we start with facts:

Father(Murad, Basem) Father(Basem, Adam)


Example 2 (cont.)
 In the forward chaining, we start with the facts:

GrandParent(Murad, Adam)
Using rule 3 with substitution
{x2/Murad, y2/ Basem, z/Adam}

Parent(Murad, Basem) Parent (Basem, Adam)


Using rule 1 with substitution Using rule 1 with substitution
{x/Murad, y/Basem} {x/Basem, y/Adam}

Father(Murad, Basem) Father(Basem, Adam)

Father(x, y) ⟹ Parent(x, y) rule 1


Example 2 (cont.)
 In the forward chaining, we start with the facts:

GrandParent(Murad, Adam)
Using rule 3 with substitution
{x2/Murad, y2/ Basem, z/Adam}

Parent(Murad, Basem) Parent (Basem, Adam)


Using rule 1 with substitution Using rule 1 with substitution
{x/Murad, y/Basem} {x/Basem, y/Adam}

Father(Murad, Basem) Father(Basem, Adam)

Father(x, y) ⟹ Parent(x, y) rule 1


Parent(x2, y2)  Parent (y2, z) ⟹ Grandparent(x2, z) rule 3
Example 2 (cont.)
 In the backward chaining, we start with the goal:

GrandParent(Murad, Adam)
And then use rule 3 to get 2 subgoals:
Parent(Murad, y2) Parent (y2, Adam)
Using rule 1:
Father(Murad, y2) Father(y2, Adam)
The 2 facts are true using the substitution {y2/Bassem}:
Father(Murad, Basem) Father(Basem, Adam)
Father(x, y) ⟹ Parent(x, y) rule 1
Parent(x2, y2)  Parent (y2, z) ⟹ Grandparent(x2, z) rule 3
Example 2 (cont.)
 In the backward chaining, we start with the goal:

Write the
substitution used GrandParent(Murad, Adam)
in each step

Parent(Murad, y2) Parent (y2, Adam)

Father(Murad, Basem) Father(Basem, Adam)

Father(x, y) ⟹ Parent(x, y) rule 1


Parent(x2, y2)  Parent (y2, z) ⟹ Grandparent(x2, z) rule 3
Resolution in FOL
 Two clauses can be resolved if they contain
complement literals, where one literal unifies with the
negation of the other
 Example:
Animal(y) ∨ Loves (Adam, x) and ¬Loves (u, v) ∨ ¬Kills(u, v)
Resolves to
Animal(y) ∨ ¬Kills(Adam, x)
Since Loves (Adam, x) unifies with ¬Loves (u, v) using
the substitution Ɵ = {u/Adam , v/x}
Resolution in FOL (cont.)
 Full first-order version:
l1  ···  lk, m1  ···  mn

(l1  ···  li-1  li+1  ···  lk  m1  ···  mj-1  mj+1  ···  mn)θ
where Unify(li, mj) = θ, i.e., θ li = θ mj

 The two clauses are assumed to be standardized apart so that


they share no variables

 Example,
Rich(x)  Unhappy(x)
Rich(Adam)
, θ = {x/Adem}
Unhappy(Adem)
Resolution in FOL (cont.)
 Full first-order version:
l1  ···  lk, m1  ···  mn

(l1  ···  li-1  li+1  ···  lk  m1  ···  mj-1  mj+1  ···  mn)θ
where Unify(li, mj) = θ.

 Resolution proves that KB ⊨ α by proving KB  α is


unsatisfiable, i.e., by deriving the empty clause.
 Apply resolution steps to CNF (KB  α); complete
for FOL
Conversion to CNF

1. Eliminate biconditionals and implications See the example in


Lecture 6
2. Move  inwards, take care of the rules
x P ≡ x P,  x Q ≡ x Q
3. Standardize variables: each quantifier should use a different
variable name.
4. Skolemize: a more general form of existential instantiation.
Each existential variable is replaced by a Skolem function of the
enclosing universally quantified variables:

5. Drop universal quantifiers


6. Distribute  over  .
Solving Example 1 using resolution

1. American(x) Weapon(y)  Sells(x, y, z)  Hostile(z) 


Criminal(x)
2. Owns(Nono,M1), Missile(M1)
3. Missile(x)  Owns(Nono, x)  Sells(West, x, Nono)
4. Missile(x)  Weapon(x)
5. Enemy(x, America)  Hostile(x)
6. American(West)
7. Enemy(Nono, America) Goal: Criminal (West)
Solving Example 1 using resolution
All statements should be in CNF:
1. American(x) Weapon(y)  Sells(x, y, z)  Hostile(z) 
Criminal(x)
¬American(x)∨ ¬ Weapon(y) ∨ ¬ Sells(x, y, z) ∨ ¬
Hostile(z) ∨ Criminal(x)
2. Owns(Nono,M1), Missile(M1)
3. Missile(x)  Owns(Nono, x)  Sells(West, x, Nono)
¬ Missile(x) ∨ ¬ Owns(Nono, x) ∨ Sells(West, x, Nono)
4. Missile(x)  Weapon(x)
¬ Missile(x) ∨ Weapon(x)
Solving Example 1 using resolution
5. Enemy(x, America)  Hostile(x)
¬ Enemy(x, America) ∨ Hostile(x)
6. American(West)
7. Enemy(Nono, America)

8. The negation of the goal is ¬ Criminal(West)


Resolution proof of Criminal(West)
goal

We reached to empty clause, then


Criminal(West) is entailed from this KB
Skolemization
 Conversion of sentences FOL to CNF requires
skolemization.
 Skolemization: remove existential quantifiers by
introducing new function symbols.
 How: For each existentially quantified variable
introduce a n-place function where n is the number
of previously appearing universal quantifiers.
 Special case: introducing constants (trivial
functions: no previous universal quantifier).
Skolemization examples
 Someone loves everybody
∃x ∀y Loves (x, y)
Skolemize: A loves everybody (A is a Skolem constant)
∀y Loves (A, y)
 Everyone has a mother

∀x∃y Mother (x, y)


Skolemize: M(x) is the son of x (M(x) is a Skolem function)
∀x Mother (x, M(x))
Skolemization examples
 Every philosopher writes at least one book.
∀x[Philo(x) ⟹∃y[Book(y)∧Write(x, y)]]
Eliminate Implication:
∀x[¬Philo(x)∨∃y[Book(y)∧Write(x, y)]]
Skolemize: substitute y by G(x)
∀x[¬Philo(x)∨[Book(G(x))∧Write(x, G(x))]]
Skolemization examples
 All students of a philosopher read one of their teacher’s
books.
∀x∀y[Philo(x)∧StudentOf (y, x) ⟹ ∃z[Book(z)∧Write(x,z)∧Read(y,z)]]
Eliminate Implication:
∀x∀y[¬Philo(x)∨¬StudentOf (y, x) ∨ ∃z[Book(z)∧ Write(x,z)∧Read(y,z)]]

Skolemize: substitute z by H(x, y) since ∃z is under the scope of ∀x∀y


∀x∀y[¬Philo(x)∨¬StudentOf (y,x)∨[Book(H(x,y))∧ Write(x,
H(x,y))∧Read(y, H(x,y))]]
Skolemization examples
 There exists a philosopher with students.
∃x∃y[Philo(x)∧StudentOf (y, x)]
Skolemize: substitute x by constant A and y by constant B
Philo(A)∧ StudentOf (B, A)
Example 3
Consider the following knowledge base

1. Jack owns a dog.


2. Every dog owner is an animal lover.
3. No animal lover kills an animal.
4. Either Jack or Curiosity killed the cat, who is
named Tuna.
5. Did Curiosity kill the cat?
Example 3 (cont.)
1. Jack owns a dog.
∃x Dog(x) ∧ Owns(Jack, x)
2. Every dog owner is an animal lover.
∀x (∃y Dog(y) ∧Owns(x, y))⟹ AnimalLover(x)
3. No animal lover kills an animal.
∀x AnimalLover(x) ⟹ (∀y Animal(y) ⟹ ¬Kills(x, y))
4. Either Jack or Curiosity killed the cat, who is named Tuna.
Kills(Jack, Tuna) ∨Kills(Curiosity, Tuna)
Cat(Tuna)
∀x Cat(x) ⟹ Animal(x)
5. Did Curiosity kill the cat? Kill (Curiosity, Tuna)?
Example 3 (cont.)
Convert statements to CNF
Dog(D)
Owns(Jack, D)
W is a new
¬ Dog(y) ∨¬ Owns(x, y) ∨ AnimalLover(x) variable used
for
¬AnimalLover(w) ∨ ¬ Animal(y) ∨ ¬Kills(w, y) standardization
Kills(Jack, Tuna) ∨ Kills(Curiosity, Tuna)
Cat(Tuna)
¬ Cat(z) ∨ Animal(z)
goal : ¬Kills(Curiosity, Tuna)
Example 3 (cont.)
resolution
Goal:

We get contradiction, therefore kill(Curiosity,


Tune) is entailed from this KB
H. W.
 Consider the following problem
Anyone passing Automata exam and winning the
football is happy. But anyone who studies or is lucky
can pass all his exams. Adel didn’t study but he is
lucky. Anyone who is lucky wins the football.
Use Forward chaining to show that Adel is happy.
(Hint: Use the 2-ary predicates: Pass and Win and the
unary predicates Study, Lucky, and Happy)

You might also like