Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
14 views76 pages

Unit 3 - Part 2

The document covers Unit 3 of an Artificial Intelligence course, focusing on First Order Logic (FOL) and its inference mechanisms. It discusses concepts such as unification, forward and backward chaining, and propositionalization, along with examples and algorithms for inference. The document also addresses the challenges of converting FOL to propositional logic and the inefficiencies of propositionalization.

Uploaded by

kesavaraj018
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)
14 views76 pages

Unit 3 - Part 2

The document covers Unit 3 of an Artificial Intelligence course, focusing on First Order Logic (FOL) and its inference mechanisms. It discusses concepts such as unification, forward and backward chaining, and propositionalization, along with examples and algorithms for inference. The document also addresses the challenges of converting FOL to propositional logic and the inefficiencies of propositionalization.

Uploaded by

kesavaraj018
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/ 76

Artificial Intelligence

INT310
Dr. A. Suganya
Asst. Professor / CSE / School of Computing

Progress Through
Progress Through Quality
Quality Education
Education
Unit 3

• First Order Logic:


• Inference in FOL
• Propositional Vs. FOL
• Unification and Lifting
• Forward chaining
• First Order definite clauses
• A simple forward chaining algorithm
• Backward chaining
• Backward chaining algorithm
• Resolution CNF for FOL
• The resolution inference rule
• Example Proofs

Progress Through Quality Education


Inference in FOL

 Reducing first-order inference to propositional inference


 Potentially great expense

 Lifting inference (direct inference in FOL)


 Unification
 Generalized Modus Ponens
 KB of Horn clauses
 Forward chaining
 Backward chaining
 General KB
 Resolution

3 Progress Through Quality Education


FOL to PL
 FOL to PL conversion
 First order inference by converting the knowledge base to PL
and using propositional inference.

 How to remove universal and existential quantifiers?


 Universel Instantiation
 Existential Instantiation

4
Progress Through Quality Education
Universal instantiation (UI)

 Every instantiation of a universally quantified sentence is entailed by


it:

∀𝑣 𝛼
𝑆𝑢𝑏𝑠𝑡( 𝑣, 𝑔 , 𝛼)

 Example

5
Progress Through Quality Education
Existential instantiation (EI)

6
Progress Through Quality Education
Reduction to propositional inference:
Example
 KB of FOL sentences:
 𝑥 𝐾𝑖𝑛𝑔 𝑥  𝐺𝑟𝑒𝑒d𝑦 𝑥  𝐸𝑣𝑖𝑙 𝑥
 𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
 𝐺𝑟𝑒𝑒𝑑𝑦 𝐽𝑜ℎ𝑛
 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛
 𝑥 𝐶𝑟𝑜𝑤𝑛(𝑥) ∧ 𝑂𝑛𝐻𝑒𝑎𝑑(𝑥, 𝐽𝑜ℎ𝑛)

 A universally quantified sentence is replaced by all possible instantiations & an


existentially quantified sentence by one instantiation:
 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)  𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛) ⇒ 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
 𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)  𝐺𝑟𝑒𝑒𝑑𝑦(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐸𝑣𝑖𝑙(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
 𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛)
 𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
 𝐶𝑟𝑜𝑤𝑛 𝐶1  𝑂𝑛𝐻𝑒𝑎𝑑 𝐶1, 𝐽𝑜ℎ𝑛
7
Progress Through Quality Education
Propositionalization

 Every FOL KB and query can be propositionalized


 Algorithms for deciding PL entailment can be used

 Problem: infinitely large set of sentences


 Infinite set of possible ground-term substitution due to function symbols
 e.g., 𝐹𝑎𝑡ℎ𝑒𝑟(…𝐹𝑎𝑡ℎ𝑒𝑟(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛)))

 Solution:
 Theorem (Herbrand, 1930): If a sentence 𝛼 is entailed by an FOL KB,
it can be entailed by a finite subset of its propositionalized KB

for 𝑛 = 0 to ∞ do
Generate all instantiations with depth 𝑛 nested symbols
if 𝛼 is entailed by this 𝐾𝐵 then return 𝑡𝑟𝑢𝑒

8 Progress Through Quality Education


Propositionalization

 Problem: When procedure go on and on, we will not know


whether it is stuck in a loop or the proof is just about to pop
out

 Theorem (Turing-1936, Church-1936): Deciding entailment for


FOL is semidecidable
 Algorithms exist that say yes to every entailed sentence, but no
algorithm exists that also says no to every non-entailed sentence.

9
Progress Through Quality Education
Propositionalization is inefficient

 Generates lots of irrelevant sentences

 Example:
 𝐾𝑖𝑛𝑔 𝑅𝑖𝑐ℎ𝑎𝑟𝑑  𝐺𝑟𝑒𝑒𝑑𝑦 𝑅𝑖𝑐ℎ𝑎𝑟𝑑  𝐸𝑣𝑖𝑙 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 is irrelevant.
KB
Query
𝑥 𝐾𝑖𝑛𝑔 𝑥  𝐺𝑟𝑒𝑒𝑑𝑦 𝑥  𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛 𝐸𝑣𝑖𝑙(𝑥)
𝐺𝑟𝑒𝑒𝑑𝑦 𝐽𝑜ℎ𝑛
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛

 𝑝 𝑘-ary predicates and 𝑛 constants


 𝑝 × 𝑛𝑘 instantiations

10 Progress Through Quality Education


Lifting & Unification

 Lifting: raising inference rules or algorithms from ground


(variable-free) PL to FOL.
 E.g., generalized Modus Ponens

 Unification: Lifted inference rules require finding substitutions


that make different expressions looks identical.
 Instantiating variables only as far as necessary for the proof.

 All variables are assumed universally quantified.

11
Progress Through Quality Education
Unification: Simple example

 Example: Infer immediately when finding a substitution θ such


that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦)

KB
Query
𝑥 𝐾𝑖𝑛𝑔 𝑥  𝐺𝑟𝑒𝑒𝑑𝑦 𝑥  𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛 𝐸𝑣𝑖𝑙(𝑥)
∀𝑦 𝐺𝑟𝑒𝑒𝑑𝑦 𝑦
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛

12
Progress Through Quality Education
Unification: examples

 𝑈𝑁𝐼𝐹𝑌 𝑝, 𝑞 = 𝜃 where 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 = 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)

𝑝 𝑞 𝜃

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝐵𝑖𝑙𝑙) {𝑥 𝐵𝑖𝑙𝑙, 𝑦/𝐽𝑜ℎ𝑛}

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦)) {𝑥 𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛), 𝑦/𝐽𝑜ℎ𝑛}

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ) 𝑓𝑎𝑖𝑙

13
Progress Through Quality Education
Unification: examples

 𝑈𝑁𝐼𝐹𝑌 𝑝, 𝑞 = 𝜃 where 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 = 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)

𝑝 𝑞 𝜃

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝐵𝑖𝑙𝑙) {𝑥 𝐵𝑖𝑙𝑙, 𝑦/𝐽𝑜ℎ𝑛}

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦)) {𝑥 𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛), 𝑦/𝐽𝑜ℎ𝑛}

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ) 𝑓𝑎𝑖𝑙

14
Progress Through Quality Education
Unification: complications

 Complications
 Two sentences using the same variable name
 Standardizing apart: renaming the variables causing name clashes in
one of sentences
 More than one unifier
 Most General Unifier (MGU)

𝑝 𝑞 𝜃

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ) 𝑓𝑎𝑖𝑙

𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥2, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ) {𝑥 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ, 𝑥2/𝐽𝑜ℎ𝑛}

15
Progress Through Quality Education
Unification (MGU)

 𝑈𝑁𝐼𝐹𝑌( 𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝑥 , 𝐾𝑛𝑜𝑤𝑠 𝑦, 𝑧 )


 𝜃1 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑧 }
 𝜃2 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝐽𝑜ℎ𝑛, 𝑧/𝐽𝑜ℎ𝑛}
 𝜃1 is more general

 There is a single most general unifier (MGU) that is unique up


to renaming of variables.

16
Progress Through Quality Education
Generalized Modus Ponens (GMP)

• Apply modus ponens reasoning to generalized rules


• Combines And-Introduction, Universal-Elimination, and Modus Ponens
– From P(c) and Q(c) and (x)(P(x)  Q(x))  R(x) derive R(c)
• General case: Given
– atomic sentences P1, P2, ..., PN
– implication sentence (Q1  Q2  ...  QN)  R
 Q1, ..., QN and R are atomic sentences
– substitution subst(θ, Pi) = subst(θ, Qi) for i=1,...,N
– Derive new sentence: subst(θ, R)
• Substitutions
– subst(θ, α) denotes the result of applying a set of substitutions defined by θ to
the sentence α
– A substitution list θ = {v1/t1, v2/t2, ..., vn/tn} means to replace all occurrences of
variable symbol vi by term ti
– Substitutions are made in left-to-right order in the list
– subst({x/IceCream, y/Ziggy}, eats(y,x)) = eats(Ziggy, IceCream)

17 Progress Through Quality Education


Generalized Modus Ponens (GMP)

 For atomic sentences 𝑝𝑖 , 𝑝𝑖′ , 𝑞 & 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝𝑖′ = 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 for


all 𝑖 𝑖

𝑝 ′ , 𝑝 ′ , … , 𝑝 ′ , (𝑝 ∧ 𝑝 ∧ … ∧ 𝑝 ⇒ 𝑞)
1 2 𝑛 1 2 𝑛
𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)
KB
𝑝1′ : 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) 𝑝1 : 𝐾𝑖𝑛𝑔(𝑥) 𝐾𝑖𝑛𝑔 𝑥  𝐺𝑟𝑒𝑒𝑑𝑦 𝑥  𝐸𝑣𝑖𝑙 𝑥
𝑝2′ :𝐺𝑟𝑒𝑒𝑑𝑦(𝑦) 𝑝2 : 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) 𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
𝑞:𝐸𝑣𝑖𝑙(𝑥) 𝐺𝑟𝑒𝑒𝑑𝑦 𝑦

𝜃 = {𝑥/𝐽𝑜ℎ𝑛,𝑦/𝐽𝑜ℎ𝑛}
Query
𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞) is 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛) 𝐸𝑣𝑖𝑙(𝑥)

18
Progress Through Quality Education

𝑝1′ , 𝑝 ′2 , … , 𝑝𝑛 , (𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝 𝑛 ⇒ 𝑞)
GMP is sound 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)

 Universal instantiation: 𝑝 ⊨ 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑝)

𝑝1′ ∧ … ∧ 𝑝 𝑛′
1)
𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 ′1 ∧ …∧ 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑝 ′ )

𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝 𝑛 ⇒ 𝑞
2)
𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 1 ∧ … ∧ 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 𝑛 ⇒ 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)

3) 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞) follows by Modus Ponens since we have


𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 ′ = 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 .
𝑖 𝑖

19
KB of definite clauses

 Definite clause: disjunctions of literals of which exactly


one is positive.
 Atomic:𝑃1, 𝑃2, …
 Implication: 𝑃1 ∧ 𝑃2 ∧ … ∧𝑃𝑘 ⇒ 𝑃𝑘+1

 First order definite clause examples:


 𝐾𝑖𝑛𝑔 𝑥 ∧ 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 ⇒ 𝐸𝑣𝑖𝑙 𝑥
 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
 𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑)

20
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

 Question: Prove that ColonelWest is a criminal

21
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∧ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)

22
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

23
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

𝑥 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥)  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥)

𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1) ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)

24
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ∧ 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥)  𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)

25
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)

26
Progress Through Quality Education
KB of first order definite clauses:
Example

 “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 ColonelWest,who isAmerican.”

 We need to know missiles are weapons:


𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)

 We need to know an enemy of America counts as“hostile”:


𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
27
Progress Through Quality Education
KB of first order definite clauses:
Example

𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∧ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)

𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1) ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ∧ 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥)  𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)

𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥)  𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)

𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)

28
Progress Through Quality Education
Forward chaining

• Proofs start with the given axioms/premises in KB,


deriving new sentences using GMP until the
goal/query sentence is derived
• This defines a forward-chaining inference procedure
because it moves “forward” from the KB to the goal
[eventually]
• Inference using GMP is complete for KBs containing
only Horn clauses

29 Progress Through Quality Education


FC algorithm

function FOL_FC_ASK(𝐾𝐵, 𝛼) returns a substitution or 𝑓𝑎𝑙𝑠𝑒


inputs: 𝐾𝐵, a set of first-order definite clauses
𝛼,the query, an atomic sentence

repeat until 𝑛𝑒𝑤 = {}


𝑛𝑒𝑤 = {}
for each 𝑟𝑢𝑙𝑒 in 𝐾𝐵 do
(𝑝1 ∧ ⋯ ∧ 𝑝𝑛 ⇒ 𝑞) ← STANDARDIZE_VARS(𝑟𝑢𝑙𝑒)
for each 𝜃 such that SUBST 𝜃, 𝑝1 ∧ ⋯ ∧ 𝑝𝑛 = SUBST(𝜃, 𝑝′1 ∧ ⋯ ∧𝑝′𝑛)
for some 𝑝′1, … , 𝑝′𝑛 in 𝐾𝐵
𝑞′ ← SUBST(𝜃, 𝑞)
if 𝑞′ does not unify with some sentence already in 𝐾𝐵 or 𝑛𝑒𝑤 then
add 𝑞′ to 𝑛𝑒𝑤
𝜑 ← UNIFY(𝑞′, 𝛼)
if 𝜑 is not 𝑓𝑎𝑖𝑙 then return 𝜑
add 𝑛𝑒𝑤 to𝐾𝐵
return 𝑓𝑎𝑙𝑠𝑒
30
Progress Through Quality Education
FC: example

Known facts
1) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
31
Progress Through Quality Education
FC: example

1) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜 {𝑥/𝑀1}

2) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥

3) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥 {𝑥/𝑀1}

4) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) {𝑥/𝑁𝑜𝑛𝑜}


32
Progress Through Quality Education
FC: example

1) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜 {𝑥/𝑀1}

2) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥 {𝑥/𝑊𝑒𝑠𝑡, 𝑦/𝑀1,𝑧/𝑁𝑜𝑛𝑜}

3) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥 {𝑥/𝑀1}

4) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) {𝑥/𝑁𝑜𝑛𝑜}


33
Progress Through Quality Education
Properties of FC

 Sound

 Complete (for KBs of first-order definite clauses)

 For Datalog KBs, proof is fairly easy.

 Datalog KBs contain first-order definite clauses with no function symbols

 FC reaches a fix point for Datalog KBs after finite number of iterations

 It may not terminate in general if 𝛼 is not entailed (query has no answer)


 entailment with definite clauses is also semi-decidable

34
Progress Through Quality Education
More efficient FC

 Heuristics for matching rules against known facts


 E.g., conjunct ordering

 Incremental forward chaining to avoid redundant rule matching


Every new fact inferred on iteration 𝑡 must be derived from at least

one new fact inferred on iteration 𝑡 − 1.
 Check a rule only if its premise includes a newly inferred fact (at iteration 𝑡− 1)

 Avoid drawing irrelevant facts (to the goal)

35
Progress Through Quality Education
First-order definite clauses

• Consider the following problem:


– The law says that it is a crime for a Spanish to sell weapons
to other nations. The country Israel has some missiles and
all of its missiles were sold to it by Rodríguez Zapatero, who
is Spanish.
• To prove that Rodríguez Zapatero is a criminal, first,
we have to represent the facts as first-order definite
clauses.
• Then we can solve the problem with forward-
chaining.

36
36 Progress Through Quality Education
First-order definite clauses

• “... it is a crime for a Spanish to sell weapons to other


nations”:
Spanish(x) ∧ Weapon(y) ∧ Sells(x, y, z) ∧ NotInSpain(z) ⇒
Criminal(x).
• “...Israel has some missiles” is transformed into two
definite clauses by Existential Elimination, introducing
a new constant AGM12:
Owns(Israel, AGM12)
Missile(AGM12)

37
37 Progress Through Quality Education
First-order definite clauses

• “All of its missiles were sold to it by Rodríguez


Zapatero”:
Missile(x) ∧ Owns(Israel, x) ⇒ Sells(ZP, x, Israel).
• We need to know that missiles are weapons:
Missile(x) ⇒ Weapon(x)
• We also need to know that Israel is not in Spain:
NotInSpain(Israel)
• “Rodríguez Zapatero, who is Spanish...”:
Spanish(ZP)

38
38 Progress Through Quality Education
• Jack owns a dog. Every dog owner is an animal lover.
No animal lover kills an animal. Either Jack or
Curiosity killed the cat, who is named Tuna. Did
Curiosity kill the cat?

Progress Through Quality Education


Progress Through Quality Education
Backward Chaining (BC)

 Works backward from the goal, chaining through rules to


find known facts supporting the proof

 AND-OR search
 OR: any rule 𝑙ℎ𝑠 ⇒ 𝑔𝑜𝑎𝑙 in KB can be used to prove the goal
 AND: all conjuncts in 𝑙ℎ𝑠 must be proved.

 It is used in logic programming (Prolog)

41
Progress Through Quality Education
Backward chaining

• Backward-chaining deduction using GMP is also complete


for KBs containing only Horn clauses
• Proofs start with the goal query, find rules with that
conclusion, and then prove each of the antecedents in the
implication
• Keep going until you reach premises
• Avoid loops: check if new subgoal is already on the goal
stack
• Avoid repeated work: check if new subgoal
– Has already been proved true
– Has already failed

42 Progress Through Quality Education


BC algorithm
(depth-first recursive proof search)
function FOL_BC_ASK(𝐾𝐵, 𝑞𝑢𝑒𝑟𝑦) returns a generator of substitutions
return FOL_BC_OR(𝐾𝐵, 𝑞𝑢𝑒𝑟𝑦,{})

generator FOL_BC_OR(𝐾𝐵, 𝑔𝑜𝑎𝑙, 𝜃) yields a substitution


for each rule (𝑙ℎ𝑠 ⇒ 𝑟ℎ𝑠) in FETCH_RULES_FOR_GOAL(𝐾𝐵, 𝑔𝑜𝑎𝑙) do
(𝑙ℎ𝑠, 𝑟ℎ𝑠) ← STANDARDIZE_VARS(𝑙ℎ𝑠, 𝑟ℎ𝑠)
for each 𝜃′ in FOL_BC_AND(𝐾𝐵, 𝑙ℎ𝑠, UNIFY(𝑟ℎ𝑠, 𝑔𝑜𝑎𝑙, 𝜃) do
yield 𝜃′

generator FOL_BC_AND(𝐾𝐵, 𝑔𝑜𝑎𝑙𝑠, 𝜃) yields a substitution


if 𝜃 = 𝑓𝑎𝑖𝑙𝑢𝑟𝑒 then return
else if LENGTH 𝑔𝑜𝑎𝑙𝑠 = 0 then yield 𝜃
else do
𝑓𝑖𝑟𝑠𝑡 ← FIRST 𝑔𝑜𝑎𝑙𝑠
𝑟𝑒𝑠𝑡 ← REST 𝑔𝑜𝑎𝑙𝑠
for each 𝜃′ in FOL_BC_OR(𝐾𝐵, SUBST 𝜃, 𝑓𝑖𝑟𝑠𝑡 , 𝜃) do
for each 𝜃′′ in FOL_BC_AND(𝐾𝐵, 𝑟𝑒𝑠𝑡, 𝜃′) do
yield 𝜃′′
43
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
44
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)

Progress Through Quality Education


Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)

56
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
57
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
58
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
59
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
60
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
61
Progress Through Quality Education
Backward chaining example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
52
Progress Through Quality Education
Properties of BC

 Space is linear in the size of the proof

 Suffers from repeated states and incompleteness


 Repeated subgoals (both success and failure)
 Solution: caching of previous results

 Incompleteness due to infinite loops


 Solution: checking current goal against every goal on stack

53
Progress Through Quality Education
FC vs BC

Difference between backward chaining and


forward chaining

Progress Through Quality Education


FC vs BC

Progress Through Quality Education


Resolution algorithm

 General theorem proving

 Apply resolution rule to 𝐶𝑁𝐹(𝐾𝐵 ∧ ¬𝛼)


 Refutation-complete for FOL

56
Progress Through Quality Education
Steps for Resolution

• Conversion of facts into first-order logic.


• Convert FOL statements into CNF
• Negate the statement which needs to prove (proof by
contradiction)
• Draw resolution graph (unification).

Progress Through Quality Education


Converting FOL sentence to CNF

 Example:“everyone who loves all animals is loved by someone”


𝑥 [∀𝑦 𝐴𝑛𝑖𝑚𝑎𝑙(𝑦) ⇒ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)]  [𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦,𝑥)]

1) Eliminate implications (𝑃 ⇒ 𝑄 ≡ ¬𝑃 ∨𝑄)


𝑥 [¬∀𝑦 ¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)]  [𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦,𝑥)]

2) Move  inwards: x p to x p,  x p to x p


𝑥 [∃𝑦 ¬(¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦))]  [𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦,𝑥)]
𝑥 [∃𝑦 ¬¬𝐴𝑛𝑖𝑚𝑎𝑙(𝑦) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)]  [𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)]
𝑥 [∃𝑦 𝐴𝑛𝑖𝑚𝑎𝑙(𝑦) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)]  [𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)]

3) Standardize variables (avoiding same names for variables)


𝑥 [∃𝑦 𝐴𝑛𝑖𝑚𝑎𝑙(𝑦) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)]  [𝑧 𝐿𝑜𝑣𝑒𝑠(𝑧, 𝑥)]

58
Progress Through Quality Education
Converting FOL sentence to CNF

4) Skolemize: a more general form of existential instantiation.


Each existentially quantified variable is replaced by a Skolem function of the
enclosing universally quantified variables.

𝑥 [𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥))] ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥),𝑥)

5) Drop universal quantifiers:


[𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥))] ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)

6) Distribute  over  :
[𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)] ∧ [¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)]

59
Progress Through Quality Education
Example

• John likes all kind of food.


• Apple and vegetable are food
• Anything anyone eats and not killed is food.
• Anil eats peanuts and still alive
• Harry eats everything that Anil eats.
Prove by resolution that:
• John likes peanuts.

Progress Through Quality Education


Example
• John likes all kind of food.

• Apple and vegetable are food

• Anything anyone eats and not killed is food.

• Anil eats peanuts and still alive

• Harry eats everything that Anil eats.

Prove by resolution that:

• John likes peanuts.

Progress Through Quality Education


Example

• Step-2: Conversion of FOL into CNF


– In First order logic resolution, it is required to convert the
FOL into CNF as CNF form makes easier for resolution
proofs.
• Eliminate all implication (→) and rewrite.
– ∀x ¬ food(x) V likes(John, x)
– food(Apple) Λ food(vegetables)
– ∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V food(y)
– eats (Anil, Peanuts) Λ alive(Anil)
– ∀x ¬ eats(Anil, x) V eats(Harry, x)
– ∀x¬ [¬ killed(x) ] V alive(x)
– ∀x ¬ alive(x) V ¬ killed(x)
– likes(John, Peanuts).
Progress Through Quality Education
Example

• Move negation (¬)inwards and rewrite


1.∀x ¬ food(x) V likes(John, x) ∀x ¬ food(x) V likes(John, x)
food(Apple) Λ food(vegetables)
2.food(Apple) Λ ∀x ∀y ¬ [eats(x, y) Λ ¬ killed(x)] V
food(vegetables) food(y)
3.∀x ∀y ¬ eats(x, y) V killed(x) eats (Anil, Peanuts) Λ alive(Anil)
∀x ¬ eats(Anil, x) V eats(Harry, x)
V food(y) ∀x¬ [¬ killed(x) ] V alive(x)
4.eats (Anil, Peanuts) Λ ∀x ¬ alive(x) V ¬ killed(x)
alive(Anil) likes(John, Peanuts).

5.∀x ¬ eats(Anil, x) V
eats(Harry, x)
6.∀x ¬killed(x) ] V alive(x)
7.∀x ¬ alive(x) V ¬ killed(x)
8.likes(John, Peanuts).

Progress Through Quality Education


Example

• Rename variables or standardize variables


– ∀x ¬ food(x) V likes(John, x)
– food(Apple) Λ food(vegetables)
– ∀y ∀z ¬ eats(y, z) V killed(y) V food(z)
– eats (Anil, Peanuts) Λ alive(Anil)
– ∀w¬ eats(Anil, w) V eats(Harry, w)
– ∀g ¬killed(g) ] V alive(g)
– ∀k ¬ alive(k) V ¬ killed(k)
– likes(John, Peanuts).

Progress Through Quality Education


Example

• Rename variables or standardize variables


– In this step, we will eliminate existential quantifier ∃, and this
process is known as Skolemization.
– But in this example problem since there is no existential
quantifier so all the statements will remain same in this step.

Progress Through Quality Education


Example

• Drop Universal quantifiers.


In this step we will drop all universal quantifier since all the statements
are not implicitly quantified so we don't need it.
– ¬ food(x) V likes(John, x)
– food(Apple)
– food(vegetables)
– ¬ eats(y, z) V killed(y) V food(z)
– eats (Anil, Peanuts)
– alive(Anil)
– ¬ eats(Anil, w) V eats(Harry, w)
– killed(g) V alive(g)
– ¬ alive(k) V ¬ killed(k)
– likes(John, Peanuts).
Progress Through Quality Education
Example

• Distribute conjunction ∧ over disjunction ¬.


This step will not make any change in this problem.

Progress Through Quality Education


Example

• Step-3: Negate the statement to be proved


– In this statement, we will apply negation to the conclusion
statements, which will be written as ¬likes(John, Peanuts)

Progress Through Quality Education


• Step-4: Draw
Resolution graph:
– Now in this step, we will
solve the problem by
resolution tree using
substitution.
– For the above problem,
it will be given as
follows:

Progress Through Quality Education


Example

• In the first step of resolution graph, ¬likes(John, Peanuts) , and likes(John, x) get
resolved(canceled) by substitution of {Peanuts/x}, and we are left with ¬
food(Peanuts)
• In the second step of the resolution graph, ¬ food(Peanuts) , and food(z) get resolved
(canceled) by substitution of { Peanuts/z}, and we are left with ¬ eats(y, Peanuts) V
killed(y) .
• In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil,
Peanuts) get resolved by substitution {Anil/y}, and we are left with Killed(Anil) .
• In the fourth step of the resolution graph, Killed(Anil) and ¬ killed(k) get resolve by
substitution {Anil/k}, and we are left with ¬ alive(Anil) .
• In the last step of the resolution graph ¬ alive(Anil) and alive(Anil) get resolved.

Progress Through Quality Education


Properties of resolution
 Resolution
 Complete when used in combination with factoring

 Extend factoring to FOL


 Factoring in PL: reduces two literals to one if they are identical
 Factoring in FOL: reduces two literals to one if they are
unifiable.The unifier must be applied to the entire clause

71
Progress Through Quality Education
Resolution: definite clauses example

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Convert to CNF

1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) ¬ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∨ ¬𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ∨ 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) ¬𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∨ ¬𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∨ ¬𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 ∨ ¬𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ∨ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) ¬𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∨ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) ¬𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ∨ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)

72
Progress Through Quality Education
Resolution: definite clauses example

𝐾𝐵 ¬𝛼

73
Progress Through Quality Education
Resolution: general example

 Every one who loves all animals is loved by someone.


 𝑥 [∀𝑦 𝐴𝑛𝑖𝑚𝑎𝑙(𝑦) ⇒ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)]  [𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦,𝑥)]
 Anyone who kills an animal is loved by no one.
 𝑥 [∃𝑧 𝐴𝑛𝑖𝑚𝑎𝑙(𝑧) ∧ 𝐾𝑖𝑙𝑙𝑠(𝑥, 𝑧)]  [∀𝑦 ¬𝐿𝑜𝑣𝑒𝑠(𝑦,𝑥)]
 Jack loves all animals.
 𝑥 𝐴𝑛𝑖𝑚𝑎𝑙(𝑥)  𝐿𝑜𝑣𝑒𝑠(𝐽𝑎𝑐𝑘, 𝑥)
 Either Jack or Curiosity killed the cat,who is namedTuna.
 𝐾𝑖𝑙𝑙𝑠 𝐽𝑎𝑐𝑘, 𝑇𝑢𝑛𝑎 ∨ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
 𝐶𝑎𝑡(𝑇𝑢𝑛𝑎)
 Query: Did Curiosity kill the cat?
 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)

74
Progress Through Quality Education
Resolution: general example

 CNF (𝐾𝐵 ∧ ¬𝛼):


 𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
 ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
 ¬𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥) ∨ ¬𝐴𝑛𝑖𝑚𝑎𝑙(𝑧) ∨ ¬𝐾𝑖𝑙𝑙𝑠(𝑥,𝑧)
 ¬𝐴𝑛𝑖𝑚𝑎𝑙(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐽𝑎𝑐𝑘, 𝑥)
 𝐾𝑖𝑙𝑙𝑠 𝐽𝑎𝑐𝑘, 𝑇𝑢𝑛𝑎 ∨ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
 𝐶𝑎𝑡(𝑇𝑢𝑛𝑎)
 ¬ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)

 Query:“Who killed the cat”?


 𝛼: ∃𝑤 𝐾𝑖𝑙𝑙𝑠(𝑤, 𝑇𝑢𝑛𝑎)
 The binding {𝑤/𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦} in one of steps

75
Progress Through Quality Education
Resolution: general example

 Query:“Who killed the cat”?


 𝛼: ∃𝑤 𝐾𝑖𝑙𝑙𝑠(𝑤, 𝑇𝑢𝑛𝑎)
 The binding {𝑤/𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦} in one of steps

76
Progress Through Quality Education

You might also like