First Order Logic (FOL) and...
Transcript of First Order Logic (FOL) and...
First Order Logic (FOL) and InferenceCE417: Introduction to Artificial IntelligenceSharif University of TechnologySpring 2018
Soleymani
“Artificial Intelligence: A Modern Approach”, 3rd Edition, Chapter 8 & 9
Why FOL?
2
To represent knowledge of complex environments concisely
Expressive enough to represent a good deal of of our knowledge
E.g., “pits cause breezes in adjacent squares” needs many rules in
propositional logic but one rule in FOL
Natural language elements & FOL elements
Some basic elements of natural language (included also in FOL):
Nouns and noun phrases referring to objects (squares, pits, wumpus)
Some of objects are defined as functions of other objects
Verbs and verb phrases referring to relation among objects (is breezy,is adjacent to, shoot)
Examples:
Objects: people, houses, numbers, baseball games,…
Relations
Unary relation or property: red, round, prime,…
𝑛-ary: brother of, bigger than, inside, part of, owns, comes between,…
Functions: father of, best friend, one more than, beginning of,…
FOL does not include all elements of natural language.
3
Symbols & interpretations
Types of symbols
Constant for objects
Predicate for relations
Function for functional relations
4
Example
5
𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛) = 𝐻𝑒𝑛𝑟𝑦
𝑀𝑎𝑟𝑟𝑖𝑒𝑑(𝐹𝑎𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑),𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))
∀𝑥 𝐾𝑖𝑛𝑔 𝑥 ⇒ 𝑃𝑒𝑟𝑠𝑜𝑛 𝑥
∃𝑥 𝐶𝑟𝑜𝑤𝑛 𝑥 ⇒ 𝑂𝑛𝐻𝑒𝑎𝑑 𝑥, 𝐽𝑜ℎ𝑛
∃𝑥, 𝑦 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑥, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 ∧ 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑦, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 ∧ ¬(𝑥 = 𝑦)
¬𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
𝑥, 𝑦 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑥, 𝑦) [ 𝑥 = 𝑦 ∃𝑚, 𝑓 (𝑚 = 𝑓) 𝑃𝑎𝑟𝑒𝑛𝑡(𝑚, 𝑥) 𝑃𝑎𝑟𝑒𝑛𝑡(𝑓, 𝑥) 𝑃𝑎𝑟𝑒𝑛𝑡(𝑚, 𝑦) 𝑃𝑎𝑟𝑒𝑛𝑡(𝑓, 𝑦)]
Syntax of FOL: Basic elements
Logical elements
Connectives ,,,,
Quantifiers ,
Domain specific elements
Constants 𝐽𝑜ℎ𝑛, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, …
Predicates 𝐵𝑟𝑜𝑡ℎ𝑒𝑟, ...
Functions 𝐿𝑒𝑓𝑡𝐿𝑒𝑔𝑂𝑓,...
Non-logical general elements
Variables 𝑥, 𝑦, 𝑎, 𝑏, …
Equality =
6
Syntax of FOL: Atomic sentences
Atomic Sentence → Predicate | Predicate (Term,…, Term) |Term=Term
Term → Constant| variable| Function(Term,…)
Constant → Richard |A | X1|…
Variable → a | x | s | …
Function → Mother | LeftLeg |…
Predicate → True | False | After | Loves | Hascolor | ….
7
ObjectRelation
1) 𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
2) 𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛) = 𝐻𝑒𝑛𝑟𝑦
3) 𝑀𝑎𝑟𝑟𝑖𝑒𝑑(𝐹𝑎𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑),𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))
Syntax of FOL (BNF Grammar)
8
Sentence → Atomic Sentence | ComplexSentenceAtomic Sentence → Predicate | Predicate (Term,…, Term) |Term=Term
ComplexSentence → ( Sentence ) | ¬ Sentence| Sentence ∧ Sentence | Sentence ∨ Sentence| Sentence Sentence | Sentence ⇔ Sentence| Quantifier variable, …Sentence
Term → Function(Term,…)
| Constant| variable
Quantifier → ∀ | ∃
Constant → A | X1…
Variable → a | x | s | …
Predicate → True | False | After | Loves | Hascolor | ….
Function → Mother | LeftLeg |…
𝑂𝑝𝑒𝑟𝑎𝑡𝑜𝑟 𝑃𝑟𝑒𝑐𝑒𝑑𝑒𝑛𝑐𝑒: ¬,=,∧,∨,⇒,⟺
Universal quantification
𝑥 𝑃(𝑥) is true in a model 𝑚 iff 𝑃(𝑥) is true with 𝑥 beingeach possible object in the model
conjunction of instantiations of 𝑃(𝑥)
9
Existential quantification
𝑥 𝑃(𝑥) is true in a model 𝑚 iff 𝑃(𝑥) is true with 𝑥 beingsome possible object in the model
disjunction of instantiations of 𝑃(𝑥)
10
Properties of quantifiers
𝑥 𝑦 𝑃 is the same as 𝑦 𝑥 𝑃 𝑥 𝑦 𝑃 is the same as 𝑦 𝑥 𝑃 𝑥 𝑦 𝑃 is not the same as 𝑦 𝑥 𝑃
𝑥 𝑦 𝑀𝑜𝑡ℎ𝑒𝑟(𝑥, 𝑦) “There is a person who is mother of everyone in the world”
𝑦 𝑥 𝑀𝑜𝑡ℎ𝑒𝑟(𝑥, 𝑦) “Everyone in the world has a mother”
Quantifier duality 𝑥 𝑃 ⇔ 𝑥𝑃 𝑥 𝑃 ⇔ ¬∀𝑥 𝑃
11
FOL: Kinship domain example
Objects people
Functions
Predicates
12
FOL: Kinship domain example
Objects: people
Functions:𝑀𝑜𝑡ℎ𝑒𝑟, 𝐹𝑎𝑡ℎ𝑒𝑟
Predicates:
Unary:𝑀𝑎𝑙𝑒, 𝐹𝑒𝑚𝑎𝑙𝑒
Binary:𝑃𝑎𝑟𝑒𝑛𝑡, 𝑆𝑖𝑏𝑙𝑖𝑛𝑔, 𝐵𝑟𝑜𝑡ℎ𝑒𝑟, 𝑆𝑖𝑠𝑡𝑒𝑟, 𝐶ℎ𝑖𝑙𝑑, 𝐷𝑎𝑢𝑔ℎ𝑡𝑒𝑟, 𝑆𝑜𝑛, 𝑆𝑝𝑜𝑢𝑠𝑒,
𝑊𝑖𝑓𝑒, 𝐻𝑢𝑠𝑏𝑎𝑛𝑑, 𝐺𝑟𝑎𝑛𝑑𝑝𝑎𝑟𝑒𝑛𝑡, 𝐺𝑟𝑎𝑛𝑑𝑐ℎ𝑖𝑙𝑑, 𝐶𝑜𝑢𝑠𝑖𝑛, 𝐴𝑢𝑛𝑡, 𝑈𝑛𝑐𝑙𝑒
13
FOL: Kinship domain example
14
Sample sentences:
𝑚, 𝑐 𝑀𝑜𝑡ℎ𝑒𝑟 𝑐 = 𝑚 ⇔ (𝐹𝑒𝑚𝑎𝑙𝑒(𝑚) ∧ 𝑃𝑎𝑟𝑒𝑛𝑡(𝑚, 𝑐))
𝑝, 𝑐 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑐 ⇔ 𝐶ℎ𝑖𝑙𝑑(𝑐, 𝑝)
𝑔, 𝑐 𝐺𝑟𝑎𝑛𝑑𝑝𝑎𝑟𝑒𝑛𝑡 𝑔, 𝑐 ⇔ ∃𝑝 𝑃𝑎𝑟𝑒𝑛𝑡 𝑔, 𝑝 ∧ 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑐
𝑥, 𝑦 𝑆𝑖𝑏𝑖𝑙𝑖𝑛𝑔 𝑥, 𝑦 ⇔ 𝑥 ≠ 𝑦 ∧ ∃𝑝 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑥 ∧ 𝑃𝑎𝑟𝑒𝑛𝑡 𝑝, 𝑥
Assertions & queries in FOL KBs
Assertions: sentences added to 𝐾𝐵 using 𝑇𝐸𝐿𝐿
𝑇𝑒𝑙𝑙(𝐾𝐵, 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛))
𝑇𝑒𝑙𝑙(𝐾𝐵, (∀𝑥 𝐾𝑖𝑛𝑔 𝑥 ⇒ 𝑃𝑒𝑟𝑠𝑜𝑛 𝑥 ))
Queries or goals: questions asked from 𝐾𝐵 using 𝐴𝑆𝐾
𝐴𝑆𝐾 𝐾𝐵, 𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
𝐴𝑆𝐾 𝐾𝐵, ∃𝑥 𝐾𝑖𝑛𝑔 𝑥
Substitution or binding list:AskVars
In KB of Horn clauses, every way of making the query true will bind thevariables to specific values
AskVars(𝐾𝐵, 𝐾𝑖𝑛𝑔(𝑥)): answer {𝑥/𝐽𝑜ℎ𝑛}
If KB contains 𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛 ∨ 𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑), there is no binding although𝐴𝑆𝐾 𝐾𝐵, ∃𝑥 𝐾𝑖𝑛𝑔 𝑥 is true
15
FOL: Set domain example
16
Objects: sets, elements
Functions: 𝑠1 ∩ 𝑠2, 𝑠1 ∪ 𝑠2, {𝑥|𝑠}
Predicates: Unary: Set
Binary: 𝑥 ∈ 𝑠, 𝑠1 ⊆ 𝑠2
𝑠 𝑆𝑒𝑡(𝑠) ⇔ (𝑠 = {}) ∨ (∃𝑥, 𝑠2 𝑆𝑒𝑡(𝑠2) 𝑠 = {𝑥|𝑠2})
𝑥, 𝑠 {𝑥|𝑠} = {} 𝑥, 𝑠 𝑥 ∈ 𝑠 ⇔ 𝑠 = {𝑥|𝑠}
𝑥, 𝑠 𝑥 ∈ 𝑠 ⇔ ∃𝑦, 𝑠2 (𝑠 = {𝑦|𝑠2} (𝑥 = 𝑦 ∨ 𝑥 ∈ 𝑠2))] 𝑠1, 𝑠2 𝑠1𝑠2 (𝑥 𝑥𝑠1 𝑥 ∈ 𝑠2) 𝑠1, 𝑠2 (𝑠1 = 𝑠2) (𝑠1 𝑠2 𝑠2 𝑠1) 𝑥, 𝑠1, 𝑠2 𝑥 ∈ (𝑠1𝑠2) (𝑥 ∈ 𝑠1 𝑥 ∈ 𝑠2)
𝑥, 𝑠1, 𝑠2 𝑥 ∈ (𝑠1𝑠2) (𝑥 ∈ 𝑠1 𝑥 ∈ 𝑠2)
FOL: Wumpus world example
17
Environment
Objects: pairs identifying squares [𝑖, 𝑗], 𝐴𝑔𝑒𝑛𝑡,𝑊𝑢𝑚𝑝𝑢𝑠
Relations:𝑃𝑖𝑡, 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡, 𝐵𝑟𝑒𝑒𝑧𝑦, 𝑆𝑡𝑒𝑛𝑐ℎ𝑦,
𝑃𝑒𝑟𝑐𝑒𝑝𝑡, 𝐴𝑐𝑡𝑖𝑜𝑛, 𝐴𝑡, 𝐻𝑎𝑣𝑒𝐴𝑟𝑟𝑜𝑤,…
FOL: Wumpus world example
Perceptions: perceives a smell, a breeze, and glitter at 𝑡 = 5:
𝑃𝑒𝑟𝑐𝑒𝑝𝑡 𝑆𝑡𝑒𝑛𝑐ℎ, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝐺𝑙𝑖𝑡𝑡𝑒𝑟, 𝑁𝑜𝑛𝑒, 𝑁𝑜𝑛𝑒 , 5
Actions: 𝑇𝑢𝑟𝑛(𝐿𝑒𝑓𝑡), 𝑇𝑢𝑟𝑛(𝑅𝑖𝑔ℎ𝑡), 𝐹𝑜𝑟𝑤𝑎𝑟𝑑, 𝑆ℎ𝑜𝑜𝑡, 𝐺𝑟𝑎𝑏, 𝐶𝑙𝑖𝑚𝑏
Perceptions implies facts about current state
∀𝑡, 𝑠, 𝑔,𝑚, 𝑐 𝑃𝑒𝑟𝑐𝑒𝑝𝑡( 𝑠, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝑔,𝑚, 𝑐 , 𝑡) ⇒ 𝐵𝑟𝑒𝑒𝑧𝑒(𝑡)
Simple reflex behavior
∀𝑡 𝐺𝑙𝑖𝑡𝑡𝑒𝑟(𝑡) ⇒ 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝐺𝑟𝑎𝑏, 𝑡)
AskVars(∃𝑎 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝑎, 5))
Binding list: e.g., {𝑎/𝐺𝑟𝑎𝑏}
18
FOL: Wumpus world example
19
Samples of rules:
∀𝑥, 𝑦, 𝑎, 𝑏 𝐴𝑑𝑗 𝑥, 𝑦 , 𝑎, 𝑏 ⇔ 𝑥 = 𝑎 ∧ 𝑦 = 𝑏 − 1 ∨ 𝑦 = 𝑏 − 1
∨ 𝑦 = 𝑏 ∧ 𝑥 = 𝑎 − 1 ∨ 𝑥 = 𝑎 + 1
𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡
∃𝑥, 𝑦 ∀𝑡 𝐴𝑡(𝑊𝑢𝑚𝑝𝑢𝑠, [𝑥, 𝑦], 𝑡)
∀𝑠, 𝑡 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡 ∧ 𝐵𝑟𝑒𝑒𝑧𝑒 𝑡 ⇒ 𝐵𝑟𝑒𝑒𝑧𝑦 𝑠
∀𝑥, 𝑠1, 𝑠2, 𝑡 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠1, 𝑡 ∧ 𝐴𝑡 𝐴𝑔𝑒𝑛𝑡, 𝑠2, 𝑡 ⇒ 𝑠1 = 𝑠2 ∀𝑠, 𝑡 𝐵𝑟𝑒𝑒𝑧𝑦 𝑠 ⇒ ∃𝑟 𝐴𝑑𝑗 𝑟, 𝑠 ∧ 𝑃𝑖𝑡 𝑟
One successor-state axiom for each predicate
∀𝑡 𝐻𝑎𝑣𝑒𝐴𝑟𝑟𝑜𝑤 𝑡 + 1 ⇔ ( 𝐻𝑎𝑣𝑒𝐴𝑟𝑟𝑜𝑤 𝑡 ∧ ¬𝐴𝑐𝑡𝑖𝑜𝑛 𝑆ℎ𝑜𝑜𝑡, 𝑡 )
Knowledge Engineering (KE) in FOL
1) Identify the task
2) Assemble the relevant knowledge
3) Decide on a vocabulary of predicates, functions, and
constants (Ontology)
4) Encode general knowledge about the domain
5) Encode a description of the specific problem instance
6) Pose queries to the inference procedure and get answers
7) Debug the knowledge base
20
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
21
FOL to PL
22
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
Universal instantiation (UI)
Every instantiation of a universally quantified sentence is entailed by
it:
∀𝑣 𝛼
𝑆𝑢𝑏𝑠𝑡( 𝑣 𝑔 , 𝛼)
Example
𝛼: 𝑥 𝐾𝑖𝑛𝑔(𝑥) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) ⇒ 𝐸𝑣𝑖𝑙(𝑥)
𝑆𝑢𝑏𝑠𝑡 𝑥 𝐽𝑜ℎ𝑛 , 𝛼 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛) ⇒ 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)𝑆𝑢𝑏𝑠𝑡 𝑥 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 , 𝛼 𝐾𝑖𝑛𝑔 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 ∧ 𝐺𝑟𝑒𝑒𝑑𝑦 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 ⇒ 𝐸𝑣𝑖𝑙 𝑅𝑖𝑐ℎ𝑎𝑟𝑑𝑆𝑢𝑏𝑠𝑡 𝑥 𝐹𝑎𝑡ℎ𝑒𝑟 𝐽𝑜ℎ𝑛 , 𝛼 𝐾𝑖𝑛𝑔(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛)) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))⇒ 𝐸𝑣𝑖𝑙(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))
23
Existential instantiation (EI)
For any sentence 𝛼, variable 𝑣, and a new constant symbol 𝑘:
∃𝑣 𝛼
𝑆𝑢𝑏𝑠𝑡( 𝑣 𝑘 , 𝛼)
Example, 𝛼: 𝑥 𝐶𝑟𝑜𝑤𝑛(𝑥) ∧ 𝑂𝑛𝐻𝑒𝑎𝑑(𝑥, 𝐽𝑜ℎ𝑛) 𝑆𝑢𝑏𝑠𝑡 𝑥 𝐶1 , 𝛼
𝐶𝑟𝑜𝑤𝑛(𝐶1) ∧ 𝑂𝑛𝐻𝑒𝑎𝑑(𝐶1, 𝐽𝑜ℎ𝑛)
𝐶1 is a new constant symbol, called a Skolem constant
EI can be applied one time (existentially quantified sentence
can be discarded after it)
24
Reduction to propositional inference: Example
25
KB of FOL sentences:
𝑥 𝐾𝑖𝑛𝑔 𝑥 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
𝐺𝑟𝑒𝑒𝑑𝑦 𝐽𝑜ℎ𝑛
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛
𝑥 𝐶𝑟𝑜𝑤𝑛(𝑥) ∧ 𝑂𝑛𝐻𝑒𝑎𝑑(𝑥, 𝐽𝑜ℎ𝑛)
A universally quantified sentence is replaced by all possible instantiations & anexistentially quantified sentence by one instantiation:
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) 𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛) ⇒ 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) 𝐺𝑟𝑒𝑒𝑑𝑦(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐸𝑣𝑖𝑙(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛)
𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛)
𝐶𝑟𝑜𝑤𝑛 𝐶1 𝑂𝑛𝐻𝑒𝑎𝑑 𝐶1, 𝐽𝑜ℎ𝑛
Propositionalization
26
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 𝑡𝑟𝑢𝑒
Propositionalization (Cont.)
27
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.
Propositionalization is inefficient
Generates lots of irrelevant sentences
Example:
𝐾𝑖𝑛𝑔 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 𝐺𝑟𝑒𝑒𝑑𝑦 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 𝐸𝑣𝑖𝑙 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 is irrelevant.
𝑝 𝑘-ary predicates and 𝑛 constants
𝑝 × 𝑛𝑘 instantiations
28
𝑥 𝐾𝑖𝑛𝑔 𝑥 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
𝐺𝑟𝑒𝑒𝑑𝑦 𝐽𝑜ℎ𝑛
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛
KB
𝐸𝑣𝑖𝑙(𝑥)
Query
Lifting & Unification
29
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.
Unification: Simple example
30
Example: Infer immediately when finding a substitution θ suchthat 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) match 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and
𝐺𝑟𝑒𝑒𝑑𝑦(𝑦)
𝑥 𝐾𝑖𝑛𝑔 𝑥 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
∀𝑦 𝐺𝑟𝑒𝑒𝑑𝑦 𝑦
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛
KB
𝐸𝑣𝑖𝑙(𝑥)
Query
Unification: examples
31
𝑈𝑁𝐼𝐹𝑌 𝑝, 𝑞 = 𝜃 where 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 = 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)
𝜃𝑞𝑝
{𝑥/𝐽𝑎𝑛𝑒}𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
{ 𝑥 𝐵𝑖𝑙𝑙, 𝑦/𝐽𝑜ℎ𝑛}𝐾𝑛𝑜𝑤𝑠(𝑦, 𝐵𝑖𝑙𝑙)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
{ 𝑥 𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛), 𝑦/𝐽𝑜ℎ𝑛}𝐾𝑛𝑜𝑤𝑠(𝑦,𝑀𝑜𝑡ℎ𝑒𝑟(𝑦))𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
𝑓𝑎𝑖𝑙𝐾𝑛𝑜𝑤𝑠(𝑥, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
Unification: examples
32
𝑈𝑁𝐼𝐹𝑌 𝑝, 𝑞 = 𝜃 where 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝 = 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)
𝜃𝑞𝑝
{𝑥/𝐽𝑎𝑛𝑒}𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
{ 𝑥 𝐵𝑖𝑙𝑙, 𝑦/𝐽𝑜ℎ𝑛}𝐾𝑛𝑜𝑤𝑠(𝑦, 𝐵𝑖𝑙𝑙)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
{ 𝑥 𝑀𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛), 𝑦/𝐽𝑜ℎ𝑛}𝐾𝑛𝑜𝑤𝑠(𝑦,𝑀𝑜𝑡ℎ𝑒𝑟(𝑦))𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
𝑓𝑎𝑖𝑙𝐾𝑛𝑜𝑤𝑠(𝑥, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
Unification: complications
33
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, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ)𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥)
Unification (MGU)
𝑈𝑁𝐼𝐹𝑌( 𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝑥 , 𝐾𝑛𝑜𝑤𝑠 𝑦, 𝑧 ) 𝜃1 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑧 }
𝜃2 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝐽𝑜ℎ𝑛, 𝑧/𝐽𝑜ℎ𝑛}
𝜃1 is more general
There is a single most general unifier (MGU) that is unique upto renaming of variables.
34
Generalized Modus Ponens (GMP)
35
For atomic sentences 𝑝𝑖 , 𝑝𝑖′, 𝑞 & 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝𝑖
′ = 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝𝑖 for
all 𝑖
𝑝1′ , 𝑝2
′ , … , 𝑝𝑛′ , (𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝𝑛 ⇒ 𝑞)
𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)
𝑝1′ : 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) 𝑝1 : 𝐾𝑖𝑛𝑔(𝑥)
𝑝2′ :𝐺𝑟𝑒𝑒𝑑𝑦(𝑦) 𝑝2 : 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥)
𝑞:𝐸𝑣𝑖𝑙(𝑥)𝜃 = {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛}
𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞) is 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
𝐾𝑖𝑛𝑔 𝑥 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛
𝐺𝑟𝑒𝑒𝑑𝑦 𝑦
…
KB
𝐸𝑣𝑖𝑙(𝑥)
Query
GMP is sound
36
Universal instantiation:𝑝 ⊨ 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑝)
1)𝑝1′ ∧ … ∧ 𝑝𝑛
′
𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝1′ ∧ …∧ 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑝𝑛
′ )
2)𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝𝑛 ⇒𝑞
𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝1 ∧ … ∧ 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝𝑛 ⇒ 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)
3) 𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞) follows by Modus Ponens since we have
𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝𝑖′ = 𝑆𝑢𝑏𝑠𝑡 𝜃, 𝑝𝑖 .
𝑝1′ , 𝑝2
′ , … , 𝑝𝑛′ , (𝑝1 ∧ 𝑝2 ∧ … ∧ 𝑝𝑛 ⇒ 𝑞)
𝑆𝑢𝑏𝑠𝑡(𝜃, 𝑞)
KB of definite clauses
37
Definite clause: disjunctions of literals of which exactly
one is positive.
Atomic:𝑃1, 𝑃2, …
Implication: 𝑃1 ∧ 𝑃2 ∧… ∧ 𝑃𝑘 ⇒ 𝑃𝑘+1
First order definite clause examples:
𝐾𝑖𝑛𝑔 𝑥 ∧ 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 ⇒ 𝐸𝑣𝑖𝑙 𝑥
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
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 is American.”
Question: Prove that ColonelWest is a criminal
38
KB of first order definite clauses: Example
39
“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 is American.”
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∧ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧) 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
KB of first order definite clauses: Example
40
“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 is American.”
𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
KB of first order definite clauses: Example
41
“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 is American.”
𝑥 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥)
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜,𝑀1) ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)
KB of first order definite clauses: Example
42
“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 is American.”
𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ∧ 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥) 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
KB of first order definite clauses: Example
43
“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 is American.”
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)
KB of first order definite clauses: Example
44
“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 is American.”
We need to know missiles are weapons:
We need to know an enemy of America counts as “hostile”:
𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
KB of first order definite clauses: Example
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∧ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧) 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜,𝑀1) ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ∧ 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥) 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)
𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥)𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎) 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
45
FC algorithm
46
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 𝑓𝑎𝑙𝑠𝑒
FC: example
47
1) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Known facts
FC: example
48
1) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
2) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
3) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
4) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
{𝑥/𝑀1}
{𝑥/𝑀1}
{𝑥/𝑁𝑜𝑛𝑜}
FC: example
49
1) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
2) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
3) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
4) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
{𝑥/𝑀1}
{𝑥/𝑀1}
{𝑥/𝑁𝑜𝑛𝑜}
{𝑥/𝑊𝑒𝑠𝑡, 𝑦/𝑀1,𝑧/𝑁𝑜𝑛𝑜}
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
50
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 leastone 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)
51
Backward Chaining (BC)
52
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)
BC algorithm
(depth-first recursive proof search)
53
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 𝜃′′
Backward chaining example
54
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
55
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
56
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
57
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
58
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
59
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
60
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
61
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Backward chaining example
62
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
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
63
Resolution algorithm
64
General theorem proving
Apply resolution rule to 𝐶𝑁𝐹(𝐾𝐵 ∧ ¬𝛼)
Refutation-complete for FOL
Resolution
65
PL resolution: 𝑙𝑖 and 𝑚𝑗 are complement
𝑙1 ∨ 𝑙2 ∨ ⋯∨ 𝑙𝑘 , 𝑚1∨𝑚2 ∨ ⋯∨𝑚𝑛
𝑙1 ∨ …∨ 𝑙𝑖−1 ∨ 𝑙𝑖+1 ∨ ⋯∨ 𝑙𝑘 ∨ 𝑚1 ∨ …∨𝑚𝑗−1 ∨ 𝑚𝑗+1 ∨ ⋯∨𝑚𝑛
First-order resolution UNIFY 𝑙𝑖 ,𝑚𝑗 = 𝜃 Clauses are assumed to be standardized apart (sharing no variables).
𝑙1 ∨ 𝑙2 ∨ ⋯∨ 𝑙𝑘 , 𝑚1∨ 𝑚2 ∨ ⋯∨ 𝑚𝑛
SUBST(𝜃, 𝑙1 ∨ …∨ 𝑙𝑖−1 ∨ 𝑙𝑖+1 ∨ ⋯∨ 𝑙𝑘 ∨ 𝑚1 ∨ …∨ 𝑚𝑗−1 ∨ 𝑚𝑗+1 ∨ ⋯ ∨ 𝑚𝑛)
Example:𝑅𝑖𝑐ℎ 𝑥 ∨ 𝑈𝑛ℎ𝑎𝑝𝑝𝑦 𝑥 , 𝑅𝑖𝑐ℎ(𝐾𝑒𝑛)
𝑈𝑛ℎ𝑎𝑝𝑝𝑦(𝐾𝑒𝑛)𝜃 = {𝑥/𝐾𝑒𝑛}
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)
𝑥 [∃𝑦 𝐴𝑛𝑖𝑚𝑎𝑙(𝑦) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦)] [𝑧 𝐿𝑜𝑣𝑒𝑠(𝑧, 𝑥)]
66
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 theenclosing universally quantified variables.
𝑥 [𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥))] ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
5) Drop universal quantifiers:[𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∧ ¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥))] ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
6) Distribute over :[𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)] ∧ [¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)]
67
Properties of resolution
68
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
Resolution: definite clauses example
69
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∧ 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∧ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∧ 𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) 𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
1) 𝐸𝑛𝑒𝑚𝑦(𝑁𝑜𝑛𝑜, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎)
2) 𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜,𝑀1 ∧ 𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑀1
3) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑊𝑒𝑠𝑡
4) ¬𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∨ ¬𝑂𝑤𝑛𝑠 𝑁𝑜𝑛𝑜, 𝑥 ∨ 𝑆𝑒𝑙𝑙𝑠 𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜
5) ¬𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛 𝑥 ∨ ¬𝑊𝑒𝑎𝑝𝑜𝑛 𝑦 ∨ ¬𝑆𝑒𝑙𝑙𝑠 𝑥, 𝑦, 𝑧 ∨ ¬𝐻𝑜𝑠𝑡𝑖𝑙𝑒 𝑧 ∨ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙 𝑥
6) ¬𝑀𝑖𝑠𝑠𝑖𝑙𝑒 𝑥 ∨ 𝑊𝑒𝑎𝑝𝑜𝑛 𝑥
7) ¬𝐸𝑛𝑒𝑚𝑦 𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎 ∨ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)
Convert to CNF
Resolution: definite clauses example
70
𝐾𝐵 ¬𝛼
Resolution: general example
71
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?
𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
Resolution: general example
72
CNF (𝐾𝐵 ∧ ¬𝛼): 𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
¬𝐿𝑜𝑣𝑒𝑠(𝑥, 𝐹(𝑥)) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
¬𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥) ∨ ¬𝐴𝑛𝑖𝑚𝑎𝑙(𝑧) ∨ ¬𝐾𝑖𝑙𝑙𝑠(𝑥, 𝑧)
¬𝐴𝑛𝑖𝑚𝑎𝑙(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐽𝑎𝑐𝑘, 𝑥)
𝐾𝑖𝑙𝑙𝑠 𝐽𝑎𝑐𝑘, 𝑇𝑢𝑛𝑎 ∨ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
𝐶𝑎𝑡(𝑇𝑢𝑛𝑎)
¬ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
Query:“Who killed the cat”?
𝛼: ∃𝑤 𝐾𝑖𝑙𝑙𝑠(𝑤, 𝑇𝑢𝑛𝑎)
The binding {𝑤/𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦} in one of steps
Resolution: general example
73
Query:“Who killed the cat”?
𝛼: ∃𝑤 𝐾𝑖𝑙𝑙𝑠(𝑤, 𝑇𝑢𝑛𝑎)
The binding {𝑤/𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦} in one of steps
Prolog (Programming in logic)
Basis: backward chaining with Horn clauses
Depth-first, left-to-right BC
Program = set of clauses
Fact
e.g., american(west).
Rule: head :- literal1, … ,literaln.
e.g., criminal(X) :- american(X), weapon(Y), sells(X,Y,Z),
hostile(Z).
74
Prolog: Example
Appending two lists to produce a third:
append([],Y,Y).
append([X|L],Y,[X|Z]) :- append(L,Y,Z).
query: append(A,B,[1,2]) ?
answers: A=[] B=[1,2]
A=[1] B=[2]
A=[1,2] B=[]
75
Summary
76
First order logic
Inference
Lifting and unification
Inference on KB of definite clauses
Forward chaining
Backward chaining
Inference on general KB of FOL
Resolution