0% found this document useful (0 votes)
3 views72 pages

L6-FirstOrderLogic 2023

The document discusses First-Order Logic (FOL), including its syntax and semantics, and compares it to propositional logic. It outlines the structure of a knowledge-based agent and provides examples of FOL applications, such as the wumpus world. Key concepts include the definition of objects, relations, functions, and the interpretation of models in FOL.

Uploaded by

fast forward
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)
3 views72 pages

L6-FirstOrderLogic 2023

The document discusses First-Order Logic (FOL), including its syntax and semantics, and compares it to propositional logic. It outlines the structure of a knowledge-based agent and provides examples of FOL applications, such as the wumpus world. Key concepts include the definition of objects, relations, functions, and the interpretation of models in FOL.

Uploaded by

fast forward
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/ 72

First-Order Logic (FOL)

Tjitze Rienstra
Chapters 8 and 9
Outline
1. First-order logic
• Syntax
• Semantics
2. Example: wumpus world in FOL
3. Inference in FOL:
• Reduction to propositional logic
• Resolution
• Forward chaining
• Backward chaining

Chapters 8, 9 2
A simple knowledge-based agent
function KB-AGENT(percept) returns an action
static: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
action ← ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t←t+1
return action
Knowledge base = set of sentences in a formal language
+
Inference = derive new sentences from old ones

Chapters 8, 9 3
A simple knowledge-based agent
function KB-AGENT(percept) returns an action
static: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
action ← ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t←t+1
return action
Knowledge base = set of sentences in a formal language
+
Inference = derive new sentences from old ones
Formal language examples:
• Propositional Logic (last lecture)
• First Order Logic (today)
Chapters 8, 9 4
1. First-order logic:
Syntax and Semantics

Chapters 8, 9 5
First-order logic
Whereas propositional logic assumes world contains facts, first-order logic (like natural
language) assumes the world contains

• Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball games,
wars, centuries, …

• Relations:
• unary (a.k.a. properties): red, round, bogus, prime, multistoried, …
• n-ary: brother of, bigger than, inside, part of, has color, occurred after, owns, comes
between, …

• Functions: father of, best friend, third inning of, one more than, end of, …

Chapters 8, 9 6
Syntax of FOL: Basic elements

Constants 𝐽𝑜ℎ𝑛, 2, 𝑈𝐶𝐵, …


Predicates 𝐵𝑟𝑜𝑡ℎ𝑒𝑟, >, …
Functions 𝑆𝑞𝑟𝑡, 𝐿𝑒𝑓𝑡𝐿𝑒𝑔𝑂𝑓, …
Variables 𝑥, 𝑦, 𝑎, 𝑏, …
Connectives     
Equality =
Quantifiers ∀ ∃

Chapters 8, 9 7
Syntax of FOL: Terms and atomic sentences
Term = 𝑐𝑜𝑛𝑠𝑡𝑎𝑛𝑡
or 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒
or 𝑓𝑢𝑛𝑐𝑡𝑖𝑜𝑛(𝑡𝑒𝑟𝑚1 , … , 𝑡𝑒𝑟𝑚𝑛 )
E.g., 𝐽𝑜ℎ𝑛, 𝐽𝑜ℎ𝑛𝑠𝐿𝑒𝑓𝑡𝐿𝑒𝑔, 𝐿𝑒𝑓𝑡𝐿𝑒𝑔𝑂𝑓 𝐽𝑜ℎ𝑛

Atomic sentence = 𝑝𝑟𝑒𝑑𝑖𝑐𝑎𝑡𝑒(𝑡𝑒𝑟𝑚1 , … , 𝑡𝑒𝑟𝑚𝑛 )


or 𝑡𝑒𝑟𝑚1 = 𝑡𝑒𝑟𝑚2

E.g., 𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑)


> (𝐿𝑒𝑛𝑔𝑡ℎ(𝐿𝑒𝑓𝑡𝐿𝑒𝑔𝑂𝑓(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)), 𝐿𝑒𝑛𝑔𝑡ℎ(𝐿𝑒𝑓𝑡𝐿𝑒𝑔𝑂𝑓(𝐽𝑜ℎ𝑛)))

Chapters 8, 9 8
Syntax of FOL: Complex sentences
Complex sentences are made from atomic sentences
using logical connectives and quantifiers
¬𝑆, 𝑆1  𝑆2 , 𝑆1  𝑆2 , 𝑆1  𝑆2 , 𝑆1  𝑆2 ,
 𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 S,  𝑣𝑎𝑟𝑖𝑎𝑏𝑙𝑒𝑠 S,
E.g.
𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝐽𝑜ℎ𝑛, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑)  𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
> 1, 2  ≤ 1, 2
< 1, 2   > (1, 2)
𝑥 𝐴𝑡 𝑥, 𝐵𝑒𝑟𝑘𝑒𝑙𝑒𝑦 ⇒ 𝑆𝑚𝑎𝑟𝑡 𝑥
REMEMBER! Operator precedence: , =, , , , 
Chapters 8, 9 9
Semantics of FOL: models
REMEBER? To define semantics of propositional logic we need to
define the models (i.e. possible worlds).

Models for propositional logic: all possible combinations of


true/false values for the proposition symbols.
Models for first-order logic?

Chapters 8, 9 10
Semantics of FOL: models
REMEBER? To define semantics of propositional logic we need to
define the models (i.e. possible worlds).

Models for propositional logic: all possible combinations of


true/false values for the proposition symbols.
Models for first-order logic?

objects (1) + relations + functional relations

Chapters 8, 9 11
Models for FOL: Example
object
binary relation crown
function
unary relation
on head
person brother
person
brother king

R $
J
left leg left leg

Is this enough to
specify semantics?
Chapters 8, 9 12
Semantics of FOL
We also need an interpretation of the model.

Interpretation specifies referents for


constant symbols → objects
predicate symbols → relations
function symbols → functional relations
Sentences are true with respect to a model and an
interpretation

An atomic sentence 𝑝𝑟𝑒𝑑𝑖𝑐𝑎𝑡𝑒(𝑡𝑒𝑟𝑚1 , … , 𝑡𝑒𝑟𝑚𝑛 ) is true


iff the objects referred to by 𝑡𝑒𝑟𝑚1 , … , 𝑡𝑒𝑟𝑚𝑛
are in the relation referred to by 𝑝𝑟𝑒𝑑𝑖𝑐𝑎𝑡𝑒

Chapters 8, 9 13
Example: Intended Interpretation
object
binary relation crown
function
unary relation
on head
person brother
person
brother king

R $
J
left leg left leg

Chapters 8, 9 14
Example: Intended Interpretation
object
binary relation crown  Crown
function
Brother
unary relation
 on head  OnHead
Person → person brother
person
brother king  King

 John
Richard →
R $
J LeftLeg

left leg left leg

𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
is true
Chapters 8, 9 15
Example: Another Interpretation
object
binary relation crown  King
function  Richard
Brother
unary relation
 on head  OnHead
Crown → person brother
person
brother king  Person

R $
J LeftLeg

left leg left leg

𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛) John →


is false
Chapters 8, 9 16
Note: Semantics of Equality
𝑡𝑒𝑟𝑚1 = 𝑡𝑒𝑟𝑚2 is true under a given interpretation
if and only if 𝑡𝑒𝑟𝑚1 and 𝑡𝑒𝑟𝑚2 refer to the same object

E.g., 1 = 2 and 𝑥  𝑆𝑞𝑟𝑡 𝑥 , 𝑆𝑞𝑟𝑡 𝑥 = 𝑥 are satisfiable


2 = 2 is valid

Chapters 8, 9 17
Note: semantics of quantifiers
Universal quantifier: 𝑥 𝑆 is true in a model 𝑚 iff
sentence 𝑆 is true with 𝑥 being each possible object in
the model
Existential quantifier: 𝑥 𝑆 is true in a model 𝑚 iff
sentence 𝑆 is true with 𝑥 being some possible object
in the model

Chapters 8, 9 18
Properties of quantifiers
𝑥 𝑦 is the same as 𝑦 𝑥 and as 𝑥, 𝑦, 𝑦, 𝑥
𝑥 𝑦 is the same as 𝑦 𝑥 and as 𝑥, 𝑦, 𝑦, 𝑥
𝑥 𝑦 is not the same as 𝑦 𝑥
𝑥 𝑦 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)
“There is a person who loves everyone in the world”
𝑦 𝑥 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)
“Everyone in the world is loved by at least one person”

Quantifier duality: each can be expressed using the other


𝑥 𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐼𝑐𝑒𝐶𝑟𝑒𝑎𝑚 𝑥 𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐼𝑐𝑒𝐶𝑟𝑒𝑎𝑚
𝑥 𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐵𝑟𝑜𝑐𝑐𝑜𝑙𝑖 𝑥 𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐵𝑟𝑜𝑐𝑐𝑜𝑙𝑖
Chapters 8, 9 19
2. Example: wumpus world
in FOL

Chapters 8, 9 20
Knowledge base for the wumpus world
Percepts:
𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑆𝑡𝑒𝑛𝑐ℎ, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝐺𝑙𝑖𝑡𝑡𝑒𝑟, 𝑁𝑜𝑛𝑒, 𝑁𝑜𝑛𝑒 , 5
Actions:
𝑇𝑢𝑟𝑛 𝑅𝑖𝑔ℎ𝑡 , 𝑇𝑢𝑟𝑛 𝐿𝑒𝑓𝑡 , 𝐹𝑜𝑟𝑤𝑎𝑟𝑑, 𝑆ℎ𝑜𝑜𝑡, 𝐺𝑟𝑎𝑏, 𝐶𝑙𝑖𝑚𝑏
Perception (reasoning about percepts):
𝑠, 𝑔, 𝑤, 𝑐, 𝑡 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑠, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝑔, 𝑤, 𝑐 , 𝑡 ⇒ 𝐵𝑟𝑒𝑒𝑧𝑒(𝑡)
𝑠, 𝑔, 𝑤, 𝑐, 𝑡 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑠, 𝑁𝑜𝑛𝑒, 𝑔, 𝑤, 𝑐 , 𝑡 ⇒ 𝐵𝑟𝑒𝑒𝑧𝑒(𝑡)
s, 𝑏, 𝑤, 𝑐, 𝑡 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑠, 𝑏, 𝐺𝑙𝑖𝑡𝑡𝑒𝑟, 𝑤, 𝑐 , 𝑡 ⇒ 𝐺𝑙𝑖𝑡𝑡𝑒𝑟(𝑡)
s, 𝑏, 𝑤, 𝑐, 𝑡 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑠, 𝑏, 𝑁𝑜𝑛𝑒, 𝑤, 𝑐 , 𝑡 ⇒ 𝐺𝑙𝑖𝑡𝑡𝑒𝑟 𝑡
Reflex behavior:
𝑡 𝐺𝑙𝑖𝑡𝑡𝑒𝑟 𝑡 ⇒ 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝐺𝑟𝑎𝑏, 𝑡)

Chapters 8, 9 21
Knowledge base for the wumpus world
REPRESENTING THE ENVIRONMENT
Squares: lists of coordinates
e.g [1,2] (= 𝐶𝑜𝑛𝑠(1, 𝐶𝑜𝑛𝑠(2, 𝑁𝑖𝑙)), syntactic sugar)
Adjacency of squares:
∀𝑥, 𝑦, 𝑎, 𝑏 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡 𝑥, 𝑦 , 𝑎, 𝑏 ⇔ 𝑥 = 𝑎 ∧ 𝑦 = 𝑏 − 1 ∨ 𝑦 = 𝑏 + 1 ∨
𝑦 =𝑏 ∧ 𝑥 = 𝑎−1∨𝑥 =𝑎+1
Agent’s location: 𝐴𝑡(𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡)
Wumpus’ location: 𝐴𝑡(𝑊𝑢𝑚𝑝𝑢𝑠, [1,3], 𝑡)

DEDUCING HIDDEN PROPERTIES


Properties of locations:
𝑠, 𝑡 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡 ∧ 𝐵𝑟𝑒𝑒𝑧𝑒 𝑡 ⇒ 𝐵𝑟𝑒𝑒𝑧𝑦 𝑠
𝑠 𝐵𝑟𝑒𝑒𝑧𝑦 𝑠 ⇔ 𝑟 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡(𝑟, 𝑠) ∧ 𝑃𝑖𝑡 𝑟
Successor-state axioms:
𝑡 𝐻𝑎𝑣𝑒𝐴𝑟𝑟𝑜𝑤 𝑡 + 1 ⇔ 𝐻𝑎𝑣𝑒𝐴𝑟𝑟𝑜𝑤 𝑡 ∧ 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛 𝑆ℎ𝑜𝑜𝑡, 𝑡
Chapters 8, 9 22
Interacting with KB of wumpus world
Suppose a wumpus-world agent is using a FOL KB and perceives a
stench and a breeze (but no glitter, bump or scream) at 𝑡 = 5:
𝑇𝐸𝐿𝐿(𝐾𝐵, 𝑃𝑒𝑟𝑐𝑒𝑝𝑡([𝑆𝑡𝑒𝑛𝑐ℎ, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝑁𝑜𝑛𝑒, 𝑁𝑜𝑛𝑒, 𝑁𝑜𝑛𝑒], 5))
𝐴𝑆𝐾(𝐾𝐵, 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝑎, 5)) → returns true/false
𝐴𝑆𝐾𝑉𝐴𝑅𝑆(𝐾𝐵, 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝑎, 5)) → returns {a/Grab}

{𝑎/𝐺𝑟𝑎𝑏} is a substitution (binding list)

Given a sentence 𝑆 and a substitution 𝜃,


𝑆𝜃denotes the result of plugging 𝜃 into 𝑆;
e.g., S = Smarter(x,y)
𝜃 = {x/Hillary, y/Bill}
S𝜃 = Smarter(Hillary, Bill)
𝐴𝑆𝐾𝑉𝐴𝑅𝑆(𝐾𝐵, 𝑆) returns some/all 𝜃 such that 𝐾𝐵 |= 𝑆𝜃
Chapters 8, 9 23
3. Inference in FOL

Chapters 8, 9 24
Inference

Model checking
• Enumeration of models

Propositionalization
• Transform FOL KB to propositional logic KB

Theorem proving - Application of inference rules


• Generalized modus ponens
• Resolution
• Forward chaining
• Backward chaining

Chapters 8, 9 25
Model Checking by Enumeration
Consider all possible models for constant symbols: 𝑅, 𝐽
R J R J R J R J R J R J

... ... ...

Models vary in how many objects they contain and in the


way the constant symbols map to objects.
The number of possible models is unbounded!
In FOL we cannot compute entailment by enumerating all
models like we did in propositional logic!

Chapters 8, 9 26
Universal instantiation (UI)
Every instantiation of a universally quantified sentence is
entailed by it:
𝑣 
𝑆𝑈𝐵𝑆𝑇( 𝑣/𝑔 , )
for any variable 𝑣 and ground term 𝑔
Ground term = term without variables

E.g., 𝑥 𝐾𝑖𝑛𝑔 𝑥  𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 ⇒ 𝐸𝑣𝑖𝑙(𝑥) yields


𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛  𝐺𝑟𝑒𝑒𝑑𝑦 𝐽𝑜ℎ𝑛 ⇒ 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
𝐾𝑖𝑛𝑔 𝑅𝑖𝑐ℎ𝑎𝑟𝑑  𝐺𝑟𝑒𝑒𝑑𝑦 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 ⇒ 𝐸𝑣𝑖𝑙(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
𝐾𝑖𝑛𝑔 𝐹𝑎𝑡ℎ𝑒𝑟 𝐽𝑜ℎ𝑛  𝐺𝑟𝑒𝑒𝑑𝑦 𝐹𝑎𝑡ℎ𝑒𝑟 𝐽𝑜ℎ𝑛
⇒ 𝐸𝑣𝑖𝑙(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))

Chapters 8, 9 27
Existential instantiation (EI)
For any sentence , variable 𝑣, and constant symbol 𝑘 that does not
appear elsewhere in the knowledge base:
𝑣 
𝑆𝑈𝐵𝑆𝑇( 𝑣/𝑘 , )
E.g., 𝑥 𝐶𝑟𝑜𝑤𝑛 𝑥  𝑂𝑛𝐻𝑒𝑎𝑑 𝑥, 𝐽𝑜ℎ𝑛 yields
𝐶𝑟𝑜𝑤𝑛 𝐶1  𝑂𝑛𝐻𝑒𝑎𝑑(𝐶1 , 𝐽𝑜ℎ𝑛)
provided 𝐶1 is a new constant symbol, called a Skolem constant

Another example: from 𝑥 𝑑(𝑥 𝑦 )/𝑑𝑦 = 𝑥 𝑦 we obtain


𝑑(𝑒 𝑦 )/𝑑𝑦 = 𝑒 𝑦
provided 𝑒 is a new constant symbol

Chapters 8, 9 28
Propositionalization
UI can be applied several times to add new sentences;
the new KB is logically equivalent to the old

EI can be applied once to replace the existential sentence;


the new KB is not equivalent to the old,
but is satisfiable iff the old KB was satisfiable

Idea: we can use UI and EI to propositionalize the FOL KB, then


apply inference procedures for propositional logic → not very
efficient, propositionalization adds many irrelevant facts to KB

Chapters 8, 9 29
Generalized Modus Ponens (GMP)

𝑝1′ , 𝑝2′ , … , 𝑝𝑛′ , (𝑝1  𝑝2  …  𝑝𝑛 ⇒ 𝑞)


𝑞𝜃
where 𝑝𝑖′ 𝜃 = 𝑝𝑖 𝜃 for all 𝑖

𝑝1′ is 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) 𝑝1 is 𝐾𝑖𝑛𝑔(𝑥)


𝑝2′ is 𝐺𝑟𝑒𝑒𝑑𝑦(𝑦) 𝑝2 is 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥)
𝜃 is {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛} 𝑞 is 𝐸𝑣𝑖𝑙(𝑥)
𝑞𝜃 is 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
GMP used with KB of definite clauses (exactly one positive literal)
All variables assumed universally quantified
Chapters 8, 9 30
Unification
How do we find the necessary substitutions?
E.g. we can get the inference immediately if we can find a substitution
𝜃 such that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦), i.e. 𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑈𝑁𝐼𝐹𝑌 𝛼, 𝛽 = 𝜃 if 𝛼𝜃 = 𝛽𝜃 → algorithm that finds substitutions
𝑝 𝑞 𝜃
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒)
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑂𝐽)
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦))
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽)

Chapters 8, 9 31
Unification
How do we find the necessary substitutions?
E.g. we can get the inference immediately if we can find a substitution
𝜃 such that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦 𝑦 , i.e. 𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑈𝑁𝐼𝐹𝑌 𝛼, 𝛽 = 𝜃 if 𝛼𝜃 = 𝛽𝜃 → algorithm that finds substitutions
𝑝 𝑞 𝜃
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑂𝐽)
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦))
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽)

Chapters 8, 9 32
Unification
How do we find the necessary substitutions?
E.g. we can get the inference immediately if we can find a substitution
𝜃 such that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦), i.e. 𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑈𝑁𝐼𝐹𝑌 𝛼, 𝛽 = 𝜃 if 𝛼𝜃 = 𝛽𝜃 → algorithm that finds substitutions
𝑝 𝑞 𝜃
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑂𝐽) {𝑥/𝑂𝐽, 𝑦/𝐽𝑜ℎ𝑛}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦))
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽)

Chapters 8, 9 33
Unification
How do we find the necessary substitutions?
E.g. we can get the inference immediately if we can find a substitution
𝜃 such that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦), i.e. 𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑈𝑁𝐼𝐹𝑌 𝛼, 𝛽 = 𝜃 if 𝛼𝜃 = 𝛽𝜃 → algorithm that finds substitutions
𝑝 𝑞 𝜃
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑂𝐽) {𝑥/𝑂𝐽, 𝑦/𝐽𝑜ℎ𝑛}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦)) {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛)}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽)

Chapters 8, 9 34
Unification
How do we find the necessary substitutions?
E.g. we can get the inference immediately if we can find a substitution
𝜃 such that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦), i.e. 𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑈𝑁𝐼𝐹𝑌 𝛼, 𝛽 = 𝜃 if 𝛼𝜃 = 𝛽𝜃 → algorithm that finds substitutions
𝑝 𝑞 𝜃
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑂𝐽) {𝑥/𝑂𝐽, 𝑦/𝐽𝑜ℎ𝑛}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦)) {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛)}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽) 𝑓𝑎𝑖𝑙

Chapters 8, 9 35
Unification
How do we find the necessary substitutions?
E.g. we can get the inference immediately if we can find a substitution
𝜃 such that 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦), i.e. 𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑈𝑁𝐼𝐹𝑌 𝛼, 𝛽 = 𝜃 if 𝛼𝜃 = 𝛽𝜃 → algorithm that finds substitutions
𝑝 𝑞 𝜃
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒) {𝑥/𝐽𝑎𝑛𝑒}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑂𝐽) {𝑥/𝑂𝐽, 𝑦/𝐽𝑜ℎ𝑛}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦)) {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛)}
𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥) 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽) 𝑓𝑎𝑖𝑙
Standardizing apart eliminates overlap of variables, e.g.,
𝐾𝑛𝑜𝑤𝑠(𝑥1 , 𝑂𝐽) instead of 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝑂𝐽) in last row
Chapters 8, 9 36
Resolution in FOL
Full first-order version:
𝑙1  …  𝑙𝑘 , 𝑚1  …  𝑚𝑛
𝑙1  …  𝑙𝑖−1  𝑙𝑖+1  …  𝑙𝑘  𝑚1  …  𝑚𝑗−1  𝑚𝑗+1  …  𝑚𝑛 𝜃
where UNIFY 𝑙𝑖 , 𝑚𝑗 = 𝜃.

For example,
𝑅𝑖𝑐ℎ 𝑥  𝑈𝑛ℎ𝑎𝑝𝑝𝑦 𝑥 , 𝑅𝑖𝑐ℎ 𝐾𝑒𝑛
𝑈𝑛ℎ𝑎𝑝𝑝𝑦 𝐾𝑒𝑛
with 𝜃 = {𝑥/𝐾𝑒𝑛}
Apply resolution steps to 𝐶𝑁𝐹 𝐾𝐵   ; complete for FOL

Chapters 8, 9 37
Conversion to CNF in FOL
Everyone who loves all animals is loved by someone:
𝑥 𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ⇒ 𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦 ⇒ [𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 ]
1. Eliminate biconditionals and implications:
𝑥 𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦 ⇒ [𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 ]
𝑥 𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦  [𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 ]
2. Move  inwards: 𝑥, 𝑝  𝑥 𝑝, 𝑥, 𝑝  𝑥 𝑝:
𝑥 𝑦  𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦  [𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 ]
𝑥 𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦  [𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 ]
𝑥 𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦  [𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 ]
3. Standardize variables: each quantifier should use a different
one
𝑥 𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦  𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦  [𝑧 𝐿𝑜𝑣𝑒𝑠 𝑧, 𝑥 ]
Chapters 8, 9 38
Conversion to CNF in FOL
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 :
𝐴𝑛𝑖𝑚𝑎𝑙 𝐹 𝑥  𝐿𝑜𝑣𝑒𝑠 𝐺 𝑥 , 𝑥 
[𝐿𝑜𝑣𝑒𝑠 𝑥, 𝐹 𝑥  𝐿𝑜𝑣𝑒𝑠 𝐺 𝑥 , 𝑥 ]

Chapters 8, 9 39
Example 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 Colonel West is a criminal

Chapters 8, 9 40
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:

Chapters 8, 9 41
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)

Chapters 8, 9 42
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles

Chapters 8, 9 43
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)

Chapters 8, 9 44
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West

Chapters 8, 9 45
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)

Chapters 8, 9 46
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:

Chapters 8, 9 47
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)

Chapters 8, 9 48
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
An enemy of America counts as “hostile”:

Chapters 8, 9 49
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
An enemy of America counts as “hostile”:
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)

Chapters 8, 9 50
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
An enemy of America counts as “hostile”:
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
West, who is American …

Chapters 8, 9 51
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
An enemy of America counts as “hostile”:
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
West, who is American …
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)

Chapters 8, 9 52
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
An enemy of America counts as “hostile”:
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
West, who is American …
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)
The country Nono, an enemy of America …

Chapters 8, 9 53
Example knowledge base contd.
… it is a crime for an American to sell weapons to hostile nations:
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
Nono … has some missiles, i.e., 𝑥 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥):
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 ) and 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 ) (existential instantiation)
… all of its missiles were sold to it by Colonel West
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
Missiles are weapons:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
An enemy of America counts as “hostile”:
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
West, who is American …
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)
The country Nono, an enemy of America …
𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Chapters 8, 9 54
Example knowledge base contd.
• 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
(𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 )𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
• 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1 )
• 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
• 𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝑥  𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
𝑥 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
• 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
• 𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎  𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
• 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)
• 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
Chapters 8, 9 55
Resolution example
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑦  𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧  𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥) 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑊𝑒𝑠𝑡

𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡  𝑊𝑒𝑎𝑝𝑜𝑛 𝑦  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧

𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑊𝑒𝑎𝑝𝑜𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧

𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑦  𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑦, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧

𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛 𝑁𝑜𝑛𝑜, 𝑥  𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜) 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑀1, 𝑧  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧

𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑁𝑜𝑛𝑜

𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑀1) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑁𝑜𝑛𝑜

𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎  𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑥 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑁𝑜𝑛𝑜

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

Chapters 8, 9 56
Forward chaining
Similar to forward chaining for propositional logic

Idea: start with the atomic sentences in the knowledge base and apply
Modus Ponens in the forward direction, adding new atomic sentences,
until no further inferences can be made.

Applicable to KB with first-order definite clauses

First order definite clause:


• Atomic sentence
• Implication with conjunction of positive literals as antecedent and
single positive literal as consequent.

E.g. 𝐾𝑖𝑛𝑔 𝑥  𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 ⇒ 𝐸𝑣𝑖𝑙 𝑥


𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
𝐺𝑟𝑒𝑒𝑑𝑦 𝑦

 is omitted, variables are assumed to be universally quantified!


Chapters 8, 9 57
Forward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Chapters 8, 9 58
Forward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

American(West) Missile(M1) Owns(Nono,M1) Enemy(Nono,America)

Chapters 8, 9 59
Forward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Weapon(M1) Sells(West,M1,Nono) Hostile(Nono)

American(West) Missile(M1) Owns(Nono,M1) Enemy(Nono,America)

Chapters 8, 9 60
Forward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West)

Weapon(M1) Sells(West,M1,Nono) Hostile(Nono)

American(West) Missile(M1) Owns(Nono,M1) Enemy(Nono,America)

Chapters 8, 9 61
Properties of forward chaining
Sound and complete for first-order definite clauses
May not terminate in general if  is not entailed (because of
function symbols)
This is unavoidable: entailment with definite clauses is
semidecidable
Matching = finding all possible unifiers such that the premise
of a rule unifies with a suitable set of facts in the KB. →
Matching can be expensive!

Matching conjunctive premises against known facts is NP-hard


Hint: match each rule whose premise contains a newly
added literal

Chapters 8, 9 62
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Chapters 8, 9 63
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West)

Chapters 8, 9 64
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West) {x/West}

American(x) Weapon(y) Sells(x,y,z) Hostile(z)

Chapters 8, 9 65
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West) {x/West}

American(West) Weapon(y) Sells(x,y,z) Hostile(z)


{}

Chapters 8, 9 66
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West) {x/West}

American(West) Weapon(y) Sells(x,y,z) Hostile(z)


{}

Missile(y)

Chapters 8, 9 67
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West) {x/West, y/M1}

American(West) Weapon(y) Sells(x,y,z) Hostile(z)


{}

Missile(y)

{y/M1}

Chapters 8, 9 68
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West) {x/West, y/M1, z/Nono}

American(West) Weapon(y) Sells(West,M1,z) Hostile(z)


{} {z/Nono}

Missile(y) Missile(M1) Owns(Nono,M1)

{y/M1}

Chapters 8, 9 69
Backward chaining proof tree
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥  𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑀1
𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1 )
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)

Criminal(West) {x/West, y/M1, z/Nono}

American(West) Weapon(y) Sells(West,M1,z) Hostile(Nono)


{} {z/Nono}

Missile(y) Missile(M1) Owns(Nono,M1) Enemy(Nono,America)

{y/M1} {} {} {}

Chapters 8, 9 70
Properties of backward chaining

Depth-first recursive proof search: space is linear in size of proof

Incomplete due to infinite loops


 fix by checking current goal against every goal on stack

Inefficient due to repeated subgoals (both success and failure)


 fix using caching of previous results (extra space!)

Widely used (without improvements!) for logic programming

Chapters 8, 9 71
Summary
• First-order logic:
• objects and relations are semantic primitives
• syntax: constants, functions, predicates, equality, quantifiers
• Increased expressive power: sufficient to define wumpus world
• Can use inference rules (universal instantiation and existential
instantiation) to propositionalize the inference problem → slow!
• The use of unification to identify appropriate substitutions for variables
is more efficient!
• Modus Ponens + unification = generalized Modus Ponens. Forward-
chaining and backward-chaining algorithms apply this rule to sets of
definite clauses.
• GMP is complete for definite clauses.
• Backward chaining is used in logic programming systems.
• The generalized resolution inference rule provides a complete proof
system for first-order logic, using knowledge bases in CNF.

Chapters 8, 9 72

You might also like