0% found this document useful (0 votes)
62 views

2021 Lecture08 FirstOrderLogic PDF

The document discusses representation in artificial intelligence using first-order logic. It introduces the syntax and semantics of first-order logic, including terms, variables, atomic sentences, complex sentences, and quantifiers. Models in first-order logic contain a domain of objects and relations among them. Sentences are evaluated based on their truth in all possible models.

Uploaded by

Minh Châu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

2021 Lecture08 FirstOrderLogic PDF

The document discusses representation in artificial intelligence using first-order logic. It introduces the syntax and semantics of first-order logic, including terms, variables, atomic sentences, complex sentences, and quantifiers. Models in first-order logic contain a domain of objects and relations among them. Sentences are evaluated based on their truth in all possible models.

Uploaded by

Minh Châu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 97

Artificial Intelligence

FIRST-ORDER LOGIC

Nguyễn Ngọc Thảo – Nguyễn Hải Minh


{nnthao, nhminh}@fit.hcmus.edu.vn
Outline
• Representation revisited
• Syntax and semantics of first-order logic (FOL)
• Writing FOL sentences: Case studies
• Propositional vs. First-order inference
• Unification and lifting
• Forward chaining
• Backward chaining
• Resolution

2
Representation
revisited

3
Programming languages
• By far the largest class of formal languages in common use
• E.g., C++, Java or Lisp, etc.
• Data structures represent facts and programs express
computational processes
• E.g., implement the Wumpus world as a 4 × 4 array, “World[2,2] ←
Pit” states that “There is a pit in square [2,2].”

4
Programming languages
• Lack of general mechanisms to derive facts from other facts
• Update to a data structure is done by a domain-specific procedure
• Lack of expressiveness to handle partial information
• E.g., to say “There is a pit in [2,2] or [3,1]”, a program stores a single
value for each variable and allows the value to be “unknown”
• The propositional logic sentence, 𝑃2,2 ∨ 𝑃3,1 , is more intuitive

5
Propositional logic
• Propositional logic is a declarative language.
• Semantics is based on the truth relation between sentences and
possible worlds.
• Handle partial information using disjunction and negation.
• Compositional: desirable in representation languages
• The meaning of a sentence is a function of the meaning of its parts
• E.g., The meaning of 𝑆1,4 ∧ 𝑆1,2 relates the meanings of 𝑆1,4 and 𝑆1,2 .

6
Propositional logic
• Meaning in propositional logic is context-independent.
• The natural language, on the other hand, are dependent on context.
• Limited expressive power
• E.g., we cannot say “Pits cause breezes in adjacent squares“, except
by writing one sentence for each square
𝐵1,1 ⇔ 𝑃1,2 ∨ 𝑃2,1 , 𝐵2,2 ⇔ 𝑃1,2 ∨ 𝑃2,1 ∨ 𝑃3,2 ∨ 𝑃3,1 , etc.

7
First-order logic

• Referred by nouns and noun phrases


Objects
• E.g., people, numbers, colors, Joe, games, etc.

• Referred by verbs and verb phrases


• Unary relation (properties): red, prime, etc.
Relations
• 𝑛-ary relation: brother of, bigger than, part of,
comes between, etc.

• Relations that have only one “value” for a


Functions given “input”
• E.g., father of, best friend, sum of, etc.
8
First-order logic: Some examples
• “One plus two equals three.”
• Object: one, two, three, one plus two
• Relation: equal • Function: plus

• “Squares neighboring the Wumpus are smelly.”


• Object: squares, Wumpus
• Property: smelly • Relation: neighboring

• “The intelligent AlphaGo beat the world champion in 2016.”


• Object: AlphaGo, world champion, 2016
• Property: intelligent • Relation: beat

9
Types of logics
Epistemological
Ontological Commitment Commitment
Language
(What exists in the world) (What an agent believes
about facts)

Propositional logic Facts True/false/unknown

First-order logic Facts, objects, relations True/false/unknown


Facts, objects, relations,
Temporal logic True/false/unknown
time
Probability logic Facts Degree of belief ∈ [0,1]
Facts with degree of truth
Fuzzy logic Known interval value
∈ [0,1]

10
FOL
Syntax and
Semantics

1
1
Models for a logic language
• A model for first-order logic contains a set of objects
(domain) and relations among them.
• Each object is called a domain element.
• Nonempty — Every possible world must contain at least one
object
• It doesn’t matter what these objects are but how many there are in
each model.

12
Models for FOL: A concrete example

• 5 objects
• 2 binary relations
• 3 unary relations
• 1 unary function
13
Models for FOL: A concrete example
• 5 objects

Richard the Lionheart King John The left The left A crown
(King of England (King of England leg of leg of
1189-1199) 1199-1215) Richard John

14
Models for FOL: A concrete example
• Binary relations
• The brotherhood relation
{ Richard the Lionheart, King John, King John, Richard the Lionheart }
• The “on head” relation
{ The crown, King John }
• Unary relations: “person”, “king”, “crown”
• Functions: “left leg”
• Richard the Lionheart → Richard’s left leg
• King John → John’s left leg

15
FOL concepts: Symbols
• Constant symbols represents objects.
• E.g., Richard, John, etc.
• Predicate symbols stand for relations.
• E.g., Brother , OnHead, Person, King, and Crown, etc.
• Function symbols stand for functions.
• E.g., LeftLeg
• Each predicate or function symbol comes with an arity that
fixes the number of arguments.
• E.g., Brother(x,y) → binary, LeftLeg(x) → unary, etc.
• These symbols begins with uppercase letters by convention.

16
Symbols and intended interpretation

• Interpretation specifies exactly which objects, relations and


functions are referred to by the symbol.
• Each model includes an (intended) interpretation.
• For example,
• Richard the Lionheart and King John refers two Kings in England.
• Brother refers to the brotherhood relation, OnHead refers to the “on
head” relation that holds between the crown and King John
• Person, King, and Crown refer to the sets of objects that are
persons, kings, and crowns, respectively.
• LeftLeg refers to the “left leg” function

17
First-order logic: Syntax

18
18
First-order logic: Syntax

* The precedence of quantifiers is such that a quantifier holds over everything to


the right of it.

19
Possible models in FOL
• Like propositional logic, entailment, validity, and so on are
defined in terms of all possible models.

137,506,194,466 models with six or fewer objects

• The number of possible models is unbounded.


→ checking entailment by the enumeration is infeasible

20
FOL concepts: Term and Variable
• A term is a logical expression that refers to an object.
• E.g., John, LeftLeg(John), etc.

Term = function(term1,...,termn) or constant or variable

Complex term

• A complex term is formed by a function symbol followed by a


parenthesized list of terms as arguments.
• A variable may serve as the argument of a function.
• E.g., in predicates 𝐾𝑖𝑛𝑔(𝑥) or in function 𝐿𝑒𝑓𝑡𝐿𝑒𝑔(𝑥).
• A term with no variable is called a ground term.
21
Terms and intended interpretation
• Consider a term, 𝑓(𝑡1 , . . , 𝑡𝑛 ), that refers to some function 𝐹
• The arguments refer to objects in the domain, 𝑑1 , . . , 𝑑𝑛 .
• The whole term refers to the object that is the value of
applying 𝐹 to 𝑑1 , . . , 𝑑𝑛 .
• For example,
• The 𝐿𝑒𝑓𝑡𝐿𝑒𝑔 function symbol refers to the mapping between a
person and his left leg, and John refers to King John.
• 𝐿𝑒𝑓𝑡𝐿𝑒𝑔(𝐽𝑜ℎ𝑛) refers to King John’s left leg.
• In this way, the interpretation fixes the referent of every term.

22
FOL concepts: Atomic sentence
• An atomic sentence states facts by using a predicate symbol
followed by a parenthesized list of terms.
• E.g., Brother(Richard, John), Married(Father(Richard), Mother(John))

Atomic sentence = predicate(term1,...,termn)

• It is true if the relation referred to by the predicate symbol


holds among the objects referred to by the arguments

23
FOL concepts: Complex sentence
• A complex sentence is made from atomic sentences using
logical connectives.
• For example,
•  𝐵𝑟𝑜𝑡ℎ𝑒𝑟 (𝐿𝑒𝑓𝑡𝐿𝑒𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑), 𝐽𝑜ℎ𝑛)
• 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 (𝑅𝑖𝑐ℎ𝑎𝑟𝑑 , 𝐽𝑜ℎ𝑛) ∧ 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 (𝐽𝑜ℎ𝑛, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
• 𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ∨ 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
•  𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
• …
• Sentences are true with respect to a model and an
interpretation.

24
Quantifiers: Universal quantification

• Expressions of general rules <variables> <sentence>


• E.g., “All kings are persons.”: 𝑥 𝐾𝑖𝑛𝑔(𝑥) ⇒ 𝑃𝑒𝑟𝑠𝑜𝑛(𝑥)
• E.g., “Students of FIT are smart.”: 𝑥 𝑆𝑡𝑢𝑑𝑒𝑛𝑡(𝑥, 𝐹𝐼𝑇) ⇒ 𝑆𝑚𝑎𝑟𝑡(𝑥)

x P is true in a model m iff P is true with x being each possible


object in the model.

• It is equivalent to the conjunction of instantiations of 𝑃.


Student(Lan, FIT) ⇒ Smart(Lan)
 Student(Tuan, FIT) ⇒ Smart(Tuan)
 Student(Long, FIT) ⇒ Smart(Long)
…
25
Quantifiers: Existential quantification

• Expressions of “some cases” <variables> <sentence>


• E.g., “Some students of FIT are smart.”
∃𝑥 𝑆𝑡𝑢𝑑𝑒𝑛𝑡(𝑥, 𝐹𝐼𝑇) ∧ 𝑆𝑚𝑎𝑟𝑡(𝑥)

 x P is true in a model m iff P is true with x being some possible


object in the model.

• It is equivalent to the disjunction of instantiations of 𝑃.


Student(Lan, FIT)  Smart(Lan)
 Student(Tuan, FIT)  Smart(Tuan)
 Student(Long, FIT)  Smart(Long)
…
26
Quantifiers: A common mistake to avoid

• Typically,  is the main connective with 


• The conclusion of the rule is just for those objects for whom the
premise is true
• It says nothing at all about individuals for whom the premise is false.

• Common mistake: using  as the main connective with 


• 𝑥 𝑆𝑡𝑢𝑑𝑒𝑛𝑡(𝑥, 𝐹𝐼𝑇) ∧ 𝑆𝑚𝑎𝑟𝑡(𝑥)
• It means “Everyone is a student of FIT and Everyone is smart.”
• Too strong implication

27
Quantifiers: A common mistake to avoid

• Typically,  is the main connective with 


• Common mistake: using  as the main connective with 
• 𝑥 𝑆𝑡𝑢𝑑𝑒𝑛𝑡(𝑥, 𝐹𝐼𝑇) ⇒ 𝑆𝑚𝑎𝑟𝑡(𝑥)
• It is true even with anyone who is not at FIT.
• Too weak implication

28
Quantifiers: Nested quantifiers
• Multiple quantifiers enable more complex sentences.
• Simplest cases: Quantifiers are of the same type
• ∀𝑥∀𝑦 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑥, 𝑦 ⇒ 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑥, 𝑦)
• ∀𝑥∀𝑦 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑥, 𝑦) ⇔ 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑦, 𝑥)
• Mixtures
• ∀𝑥∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) − “Everybody loves somebody.”
• ∃𝑥∀𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥 − “There is someone loved by everyone.”
• The order of quantification is therefore very important.

29
Quantifiers: Nested quantifiers
• Two quantifiers used with the same variable name leads to
confusion.
∀𝑥 (𝐶𝑟𝑜𝑤𝑛 𝑥 ∨ ∃𝑥 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝑥 )
• Rule: The variable belongs to the innermost quantifier that
mentions it.
• Workaround: Use different variable names with nested
quantifiers, e.g., ∃𝑧 𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝑧

30
Quantifiers: Rules for duality
•  and  relate to each other through negation.
• For example,
• ∀𝑥 𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐼𝑐𝑒𝐶𝑟𝑒𝑎𝑚 ¬∃𝑥 ¬𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐼𝑐𝑒𝐶𝑟𝑒𝑎𝑚
• ∃𝑥 𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐵𝑟𝑜𝑐𝑜𝑙𝑖 ¬∀𝑥 ¬𝐿𝑖𝑘𝑒𝑠 𝑥, 𝐼𝑐𝑒𝐶𝑟𝑒𝑎𝑚
• De Morgan’s rules

31
Equality symbol =
• 𝑡𝑒𝑟𝑚1 = 𝑡𝑒𝑟𝑚2 is true under a given interpretation iff 𝑡𝑒𝑟𝑚1
and 𝑡𝑒𝑟𝑚2 refer to the same object
• E.g., 𝐹𝑎𝑡ℎ𝑒𝑟 𝐽𝑜ℎ𝑛 = 𝐻𝑒𝑛𝑟𝑦 means that 𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛) and 𝐻𝑒𝑛𝑟𝑦
refer to the same object.
• It states facts about a given function
• The negation insists that two terms are not the same.
∃𝑥, 𝑦 𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑥, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ∧ 𝐵𝑟𝑜𝑡ℎ𝑒𝑟(𝑦, 𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ∧ ¬(𝑥 = 𝑦)

32
Writing FOL sentences:
Case studies

33
The kinship
domain

• Unary predicates
• Male and Female
• Binary predicates represent kinship relations.
• Parenthood, brotherhood, marriage, etc.
• Parent, Sibling, Brother , Sister, Child, Daughter, Son, Spouse, Wife,
Husband, Grandparent , Grandchild , Cousin, Aunt, and Uncle.
• Functions
• Mother and Father, each person has exactly one of each of these.
34
The kinship domain: Axioms
• One’s mother is one’s female parent
∀𝑚, 𝑐 𝑀𝑜𝑡ℎ𝑒𝑟(𝑐) = 𝑚 ⇔ 𝐹𝑒𝑚𝑎𝑙𝑒(𝑚) ∧ 𝑃𝑎𝑟𝑒𝑛𝑡(𝑚, 𝑐)
• One’s husband is one’s male spouse:
∀𝑤, ℎ 𝐻𝑢𝑠𝑏𝑎𝑛𝑑(ℎ, 𝑤) ⇔ 𝑀𝑎𝑙𝑒(ℎ) ∧ 𝑆𝑝𝑜𝑢𝑠𝑒(ℎ, 𝑤)
• Male and female are disjoint categories:
∀𝑥 𝑀𝑎𝑙𝑒(𝑥) ⇔ ¬𝐹𝑒𝑚𝑎𝑙𝑒(𝑥)
• Parent and child are inverse relations:
∀𝑝, 𝑐 𝑃𝑎𝑟𝑒𝑛𝑡(𝑝, 𝑐) ⇔ 𝐶ℎ𝑖𝑙𝑑(𝑐, 𝑝)
• A grandparent is a parent of one’s parent:
∀𝑔, 𝑐 𝐺𝑟𝑎𝑛𝑑𝑝𝑎𝑟𝑒𝑛𝑡(𝑔, 𝑐) ⇔ ∃𝑝 𝑃𝑎𝑟𝑒𝑛𝑡(𝑔, 𝑝) ∧ 𝑃𝑎𝑟𝑒𝑛𝑡(𝑝, 𝑐)
• A sibling is another child of one’s parents:
∀𝑥, 𝑦 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑥, 𝑦) ⇔ ¬(𝑥 = 𝑦) ∧ ∃𝑝 𝑃𝑎𝑟𝑒𝑛𝑡(𝑝, 𝑥) ∧ 𝑃𝑎𝑟𝑒𝑛𝑡(𝑝, 𝑦)

35
The kinship domain: Theorems
• Theorems: logical sentences that are entailed by the axioms
• E.g., ∀𝑥, 𝑦 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑥, 𝑦) ⇔ 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑦, 𝑥)
• Theorems reduce the cost of deriving new sentences.
• They do not increase the set of conclusions that follow from 𝐾𝐵 → no
value from a pure logical point of view
• They are essential from a practical point of view.

36
The set domain
• Sets are the empty set and those made by adjoining something to a set.
• 𝑠 𝑆𝑒𝑡(𝑠) ⇔ (𝑠 = { } ) ∨ (∃𝑥, 𝑠2 𝑆𝑒𝑡(𝑠2)  𝑠 = {𝑥|𝑠2})
• The empty set has no elements adjoined into it.
• 𝑥, 𝑠 {𝑥|𝑠} = { }
• Adjoining an element already in the set has no effect:
• 𝑥, 𝑠 𝑥 ∈ 𝑠 ⇔ 𝑠 = {𝑥|𝑠}
• The only members of a set are the elements that were adjoined into it.
• 𝑥, 𝑠 𝑥 ∈ 𝑠 ⇔ ∃𝑦, 𝑠2 (𝑠 = {𝑦|𝑠2}  (𝑥 = 𝑦 ∨ 𝑥 ∈ 𝑠2))]

37
The set domain
• Can you interpret the following sentences?
• 𝑠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 )

38
The Wumpus world: Input – Output

• Typical percept sentence


• Percept([Stench, Breeze, Glitter, None, None]. 5)
• Actions
• Turn(Right), Turn(Left), Forward, Shoot, Grab, Release, Climb
• To determine the best action, construct a query
• 𝐴𝑆𝐾𝑉𝐴𝑅𝑆(∃𝑎 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝑎, 5))
• Returns a binding list such as {𝑎/𝐺𝑟𝑎𝑏}

39
The Wumpus world: The KB
• Perception
•  𝑡, 𝑠, 𝑔, 𝑚, 𝑐 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 ([𝑠, 𝐵𝑟𝑒𝑒𝑧𝑒, 𝑔, 𝑚, 𝑐], 𝑡) ⇒ 𝐵𝑟𝑒𝑒𝑧𝑒(𝑡)
•  𝑡, 𝑠, 𝑏, 𝑚, 𝑐 𝑃𝑒𝑟𝑐𝑒𝑝𝑡 ([𝑠, 𝑏, 𝐺𝑙𝑖𝑡𝑡𝑒𝑟, 𝑚, 𝑐], 𝑡) ⇒ 𝐺𝑙𝑖𝑡𝑡𝑒𝑟 (𝑡) …
• Reflex
• 𝑡 𝐺𝑙𝑖𝑡𝑡𝑒𝑟(𝑡) ⇒ 𝐵𝑒𝑠𝑡𝐴𝑐𝑡𝑖𝑜𝑛(𝐺𝑟𝑎𝑏, 𝑡)
• Environment definition:
𝑥, 𝑦, 𝑎, 𝑏 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡([𝑥, 𝑦], [𝑎, 𝑏]) ⇔
𝑥 =𝑎 ∧ 𝑦 =𝑏−1 ∨ 𝑦 =𝑏 + 1
∨ (𝑦 = 𝑏 ∧ (𝑥 = 𝑎 − 1 ∨ 𝑥 = 𝑎 + 1))

40
The Wumpus world: Hidden properties

• Properties of squares
𝑠, 𝑡 𝐴𝑡(𝐴𝑔𝑒𝑛𝑡, 𝑠, 𝑡) ∧ 𝐵𝑟𝑒𝑒𝑧𝑒(𝑡) ⇒ 𝐵𝑟𝑒𝑒𝑧𝑦(𝑠)
• Squares are breezy near a pit
• Diagnostic rule --- infer cause from effect
𝑠 𝐵𝑟𝑒𝑒𝑧𝑦(𝑠) ⇔ ∃𝑟 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡(𝑟, 𝑠) ∧ 𝑃𝑖𝑡(𝑟)
• Causal rule --- infer effect from cause
𝑟 𝑃𝑖𝑡(𝑟) ⇔ [∀𝑠 𝐴𝑑𝑗𝑎𝑐𝑒𝑛𝑡(𝑟, 𝑠) ⇒ 𝐵𝑟𝑒𝑒𝑧𝑦(𝑠)]

41
Quiz 01: Writing FOL sentences
• Represent the following sentences with first-order logic using
the given predicates
• 𝑆𝑡𝑢𝑑𝑒𝑛𝑡(𝑥) means 𝑥 is student.
• 𝑆𝑚𝑎𝑟𝑡(𝑥) means 𝑥 is smart.
• 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) means 𝑥 loves 𝑦.

1. All students are smart.


2. There exists a smart student.
3. Every student loves some student.
4. Every student loves some other student
5. There is a student who is loved by every other student.
42
First-order
inference ∀𝑥. 𝐶𝑎𝑡(𝑥) ⇒ 𝐶𝑢𝑡𝑒(𝑥)

43
Universal Instantiation (UI)
• It is possible to infer any sentence obtained by substituting a
ground term for the variable.
• Let 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝛼) be the result of applying the substitution 𝜃 to
the sentence 𝛼.
• Then the rule of Universal Instantiation is written as
𝒗 𝜶
𝑺𝑼𝑩𝑺𝑻({𝒗/𝒈}, 𝜶)
• for any variable 𝑣 and ground term 𝑔.

44
Universal Instantiation: An example
• Suppose our knowledge base contains
∀𝒙 𝑲𝒊𝒏𝒈 𝒙 ∧ 𝑮𝒓𝒆𝒆𝒅𝒚(𝒙) ⇒ 𝑬𝒗𝒊𝒍(𝒙)
• Then it is permissible to infer any of the following sentences
𝐾𝑖𝑛𝑔 𝐽𝑜ℎ𝑛 ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛) ⇒ 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
𝐾𝑖𝑛𝑔 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐸𝑣𝑖𝑙(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
𝐾𝑖𝑛𝑔 𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦 𝐹𝑎𝑡ℎ𝑒𝑟 𝐽𝑜ℎ𝑛
⇒ 𝐸𝑣𝑖𝑙(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))

with substitutions {𝑥/𝐽𝑜ℎ𝑛}, {𝑥/𝑅𝑖𝑐ℎ𝑎𝑟𝑑}, and
{𝑥/𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛)}, respectively
45
Existential Instantiation (EI)
• It is possible to replace the variable by a single new
constant symbol.
• The rule of Existential Instantiation is written as
∃𝒗 𝜶
𝑺𝑼𝑩𝑺𝑻({𝒗/𝒌}, 𝜶)
• for any sentence 𝛼, variable 𝑣, and constant symbol 𝑘 that does not
appear elsewhere in 𝐾𝐵.

• For example, from ∃𝑥 𝐶𝑟𝑜𝑤𝑛 𝑥 ∧ 𝑂𝑛𝐻𝑒𝑎𝑑 𝑥, 𝐽𝑜ℎ𝑛


infer 𝐶𝑟𝑜𝑤𝑛(𝐶1 ) ∧ 𝑂𝑛𝐻𝑒𝑎𝑑(𝐶1 , 𝐽𝑜ℎ𝑛)
• 𝐶1 does not appear in 𝐾𝐵, and it is called Skolem constant.

46
Universal / Existential Instantiation
• The UI rule can be applied many times to produce different
consequences.
• The EI rule can be applied once, and then the existentially
quantified sentence is discarded.
• E.g., discard ∃𝑥 𝐾𝑖𝑙𝑙(𝑥, 𝑉𝑖𝑐𝑡𝑖𝑚) after adding 𝐾𝑖𝑙𝑙(𝑀𝑢𝑟𝑑𝑒𝑟𝑒𝑟, 𝑉𝑖𝑐𝑡𝑖𝑚)
• The new 𝐾𝐵 is not logically equivalent to the old but shown to be
inferentially equivalent.

47
Reduction to propositional inference

• Every first-order 𝐾𝐵 and query can be propositionalized in


such a way that entailment is preserved.
• A ground sentence is entailed by new 𝐾𝐵 iff entailed by original 𝐾𝐵.
• For example, suppose the 𝐾𝐵 contains just the sentences
∀𝑥 𝐾𝑖𝑛𝑔(𝑥) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) ⇒ 𝐸𝑣𝑖𝑙(𝑥)
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛)
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛
• Apply UI with substitutions, {𝑥/𝐽𝑜ℎ𝑛} and {𝑥/𝑅𝑖𝑐ℎ𝑎𝑟𝑑}
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝐽𝑜ℎ𝑛) ⇒ 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)
𝐾𝑖𝑛𝑔(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) ⇒ 𝐸𝑣𝑖𝑙(𝑅𝑖𝑐ℎ𝑎𝑟𝑑)
48
Reduction to propositional inference

• Problem: When the 𝐾𝐵 includes a function symbol, the set


of possible ground-term substitutions is infinite.
• E.g., the 𝐹𝑎𝑡ℎ𝑒𝑟 symbol, infinitely many nested terms such as
𝐹𝑎𝑡ℎ𝑒𝑟(𝐹𝑎𝑡ℎ𝑒𝑟(𝐹𝑎𝑡ℎ𝑒𝑟(𝐽𝑜ℎ𝑛))) can be constructed.

• Herbrand’s Theorem (1930): If an original FOL 𝐾𝐵 ⊨ 𝛼, 𝛼 is


entailed by a finite subset of the propositionalized 𝐾𝐵.
• For 𝑛 = 0 𝑡𝑜 ∞ do
• Create a propositional 𝐾𝐵 by instantiating with depth-n terms
• See if 𝛼 is entailed by this 𝐾𝐵
• 𝑛 = 0: 𝑅𝑖𝑐ℎ𝑎𝑟𝑑 and 𝐽𝑜ℎ𝑛
• 𝑛 = 1: 𝐹𝑎𝑡ℎ𝑒𝑟(𝑅𝑖𝑐ℎ𝑎𝑟𝑑) and 𝐹𝑎𝑡ℎ𝑒𝑟 𝐽𝑜ℎ𝑛 , etc.
49
Reduction to propositional inference

• Problem: The inference works if sentence 𝛼 is entailed, but


it loops if 𝛼 is not entailed.
• Theorems of Turing (1936) and Church (1936): The
question of entailment for first-order logic is semidecidable.
• Algorithms exist that say yes to every entailed sentence, but no
algorithm exists that also says no to every non-entailed sentence.

50
Unification
and Lifting
A first-order inference rule
• If there is some substitution 𝜃 making each of the conjuncts
of the premise identical to sentences already in the 𝐾𝐵
• Then the conclusion can be asserted after applying 𝜃.
• For example,
∀𝑥 𝐾𝑖𝑛𝑔 𝑥 ∧ 𝐺𝑟𝑒𝑒𝑑𝑦 𝑥 ⇒ 𝐸𝑣𝑖𝑙 𝑥
∀𝑦 𝐺𝑟𝑒𝑒𝑑𝑦(𝑦)
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛)
𝐵𝑟𝑜𝑡ℎ𝑒𝑟 𝑅𝑖𝑐ℎ𝑎𝑟𝑑, 𝐽𝑜ℎ𝑛
• Applying the substitution {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛} to 𝐾𝑖𝑛𝑔(𝑥) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥),
𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) and 𝐺𝑟𝑒𝑒𝑑𝑦(𝑦) will make them identical in pairs.
• Thus, infer the conclusion of the implication

52
Generalized Modus Ponens (GMP)
• For atomic sentences 𝑝𝑖 , 𝑝𝑖′ and 𝑞, where there exists 𝜃 such
that 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑝𝑖′ ) = 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑝𝑖 ), for all 𝑖,
𝒑′𝟏 , 𝒑′𝟐 , … , 𝒑′𝒏 , (𝒑𝟏 , 𝒑𝟐 , … , 𝒑𝒏 ⇒ 𝒒)
𝑺𝑼𝑩𝑺𝑻(𝜽, 𝒒)

• For example, 𝑝1 is 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛) 𝑝1 is 𝐾𝑖𝑛𝑔(𝑥)
𝑝2′ is 𝐺𝑟𝑒𝑒𝑑𝑦(𝑦) 𝑝2 is 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥)
𝜃 is {𝑥/𝐽𝑜ℎ𝑛, 𝑦/𝐽𝑜ℎ𝑛} 𝑞 is 𝐸𝑣𝑖𝑙(𝑥)
𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑞) is 𝐸𝑣𝑖𝑙(𝐽𝑜ℎ𝑛)

• All variables assumed universally quantified


• A lifted version of Modus Ponens → sound inference rule
53
Unification
• Find substitutions that make different logical expressions
look identical
𝑼𝑵𝑰𝑭𝒀(𝒑, 𝒒) = 𝜽 where 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑝) = 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑞)

• For example,
p q θ
Knows(John, x) Knows(John, Jane) {x/Jane}
Knows(John, x) Knows(y, Steve) {x/Steve, y/John}
Knows(John, x) Knows(y, Mother(y)) {x/Mother(John), y/John}
Knows(John, x) Knows(x, Steve) fail

Problem is due to use of same Standardizing apart eliminates


variable 𝒙 in both sentences overlap of variables
Knows(z, Steve)
54
Most General Unifier (MGU)
• 𝑈𝑁𝐼𝐹𝑌(𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥), 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑧)) = 𝜃
1. 𝜃 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑧 }
2. 𝜃 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝐽𝑜ℎ𝑛, 𝑧/𝐽𝑜ℎ𝑛}
• The first unifier is more general than the second
• There is a single Most General Unifier (MGU) that is unique
up to renaming of variables.
𝑀𝐺𝑈 = {𝑦/𝐽𝑜ℎ𝑛, 𝑥/𝑧}

55
MGU: Some examples

𝝎𝟏 𝝎𝟐 𝑴𝑮𝑼
𝐴(𝐵, 𝐶) 𝐴(𝑥, 𝑦) {𝑥/𝐵, 𝑦/𝐶)
𝐴(𝑥, 𝑓(𝐷, 𝑥)) 𝐴(𝐸, 𝑓(𝐷, 𝑦)) {𝑥/𝐸, 𝑦/𝐸}
𝐴(𝑥, 𝑦) 𝐴(𝑓(𝐶, 𝑦), 𝑧) {𝑥/𝑓(𝐶, 𝑦), 𝑦/𝑧}
𝑃(𝐴, 𝑥, 𝑓(𝑔(𝑦))) 𝑃(𝑦, 𝑓(𝑧), 𝑓(𝑧)) {𝑦/𝐴, 𝑥/𝑓(𝑧), 𝑧/𝑔(𝐴)}
𝑃(𝑥, 𝑔(𝑓(𝐴)), 𝑓(𝑥)) 𝑃(𝑓(𝑦), 𝑧, 𝑦) No MGU
𝑃(𝑥, 𝑓(𝑦)) 𝑃(𝑧, 𝑔(𝑤)) No MGU

56
The unification algorithm
function UNIFY(x , y, θ) returns a substitution to make x and y identical
inputs: x , a variable, constant, list, or compound expression
y, a variable, constant, list, or compound expression
θ, the substitution built up so far (optional, defaults to empty)
if θ = failure then return failure
else if x = y then return θ
else if VARIABLE?(x) then return UNIFY-VAR(x , y, θ)
else if VARIABLE?(y) then return UNIFY-VAR(y, x , θ)
else if COMPOUND?(x) and COMPOUND?(y) then
return UNIFY(x.ARGS, y.ARGS, UNIFY(x.OP, y.OP, θ))
else if LIST?(x) and LIST?(y) then
return UNIFY(x.REST, y.REST, UNIFY(x.FIRST, y.FIRST, θ))
else return failure

57
The unification algorithm

function UNIFY-VAR(var, x , θ) returns a substitution


if {var /val} ∈ θ then return UNIFY(val, x , θ)
else if {x/val} ∈ θ then return UNIFY(var, val, θ)
else if OCCUR-CHECK?(var, x) then return failure
else return add {var/x} to θ

58
a is a constant

59
60
Quiz 02: Find the MGU
• Find the MGU when performing 𝑈𝑁𝐼𝐹𝑌(𝑝, 𝑞)

𝝎𝟏 𝝎𝟐 𝑴𝑮𝑼
𝑃(𝑓 𝐴 , 𝑔(𝑥)) 𝑃(𝑦, 𝑦) ?
𝑃(𝐴, 𝑥, ℎ(𝑔 𝑧 )) 𝑃(𝑧, ℎ 𝑦 , ℎ 𝑦 ) ?
𝑃(𝑥, 𝑓(𝑥), 𝑧) 𝑃(𝑔(𝑦), 𝑓(𝑔(𝑏)), 𝑦) ?
𝑃(𝑥, 𝑓(𝑥)) 𝑃(𝑓(𝑦), 𝑦) ?
𝑃(𝑥, 𝑓(𝑧)) 𝑃(𝑓 𝑦 , 𝑦) ?

61
Forward Chaining
62
First-order definite clause
• A definite clause is a disjunction of literals of which exactly
one is positive.
• It is either atomic or an implication whose antecedent is a
conjunctions of positive literals and consequent is a positive literal.
• E.g., 𝐾𝑖𝑛𝑔(𝑥) ∧ 𝐺𝑟𝑒𝑒𝑑𝑦(𝑥) ⇒ 𝐸𝑣𝑖𝑙(𝑥), 𝐾𝑖𝑛𝑔(𝐽𝑜ℎ𝑛), 𝐺𝑟𝑒𝑒𝑑𝑦(𝑦)
• First-order literals can include variables, which are assumed
to be universally quantified.
• Not every 𝐾𝐵 can be converted into a set of definite clauses
due to the single-positive-literal restriction.

63
FOL definite clause: An example
• Consider the following problem

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.

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

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

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

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥) 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑊𝑒𝑠𝑡)

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


64
A simple forward chaining algorithm function FOL-FC-ASK(KB,α) returns a substitution or false
inputs: KB, the knowledge base, a set of first-order definite clauses
α, the query, an atomic sentence
local variables: new, the new sentences inferred on each iteration
repeat until new is empty
new ← { }
for each rule in KB do
(𝑝1 ∧ ⋯ ∧ 𝑝𝑛 ⇒ 𝑞)← STANDARDIZE-VARIABLES(rule)
for each θ such that SUBST(θ, 𝑝1 ∧ ⋯ ∧ 𝑝𝑛 ) = SUBST(θ,𝑝1′ ∧ ⋯ ∧ 𝑝𝑛′ )
for some 𝑝1′ , … , 𝑝𝑛′ in KB
𝑞′ ← SUBST(θ,q)
if 𝑞′ does not unify with some sentence already in KB or new then
add 𝑞 ′ to new
φ← UNIFY(𝑞′ ,α)
if φ is not fail then return φ
add new to KB
return false
65
Forward chaining: An example

66
Forward chaining: An example
𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ∧ 𝑂𝑤𝑛𝑠(𝑁𝑜𝑛𝑜, 𝑥) ⇒ 𝑆𝑒𝑙𝑙𝑠(𝑊𝑒𝑠𝑡, 𝑥, 𝑁𝑜𝑛𝑜)

𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) ⇒ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑥)
𝐸𝑛𝑒𝑚𝑦(𝑥, 𝐴𝑚𝑒𝑟𝑖𝑐𝑎) ⇒ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑥)

67
Forward chaining: An example
𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∧ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧) ∧ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)

Fixed point

68
Forward chaining
• Soundness?
• YES, every inference is just an application of GMP.
• Completeness?
• YES for definite clause knowledge bases.
• It answers every query whose answers are entailed by any 𝐾𝐵 of
definite clauses.
• Terminate for Datalog in finite number of iterations
• Datalog = first-order definite clauses + no functions
• Entailment with definite clauses is semidecidable.
• May not terminate in general if 𝛼 is not entailed, unavoidable.

69
Renaming
• A fact is not “new” if it is just a renaming of a known fact.
• One sentence is a renaming of another if they are identical
except for the names of the variables.
• E.g., Likes(x, IceCream) vs. Likes(y, IceCream)

70
Definite clauses with function symbols

• Inference can explode forward and may never terminate.

𝐸𝑣𝑒𝑛(𝑥) ⇒ 𝐸𝑣𝑒𝑛(𝑝𝑙𝑢𝑠(𝑥, 2))


𝐼𝑛𝑡𝑒𝑔𝑒𝑟(𝑥) ⇒ 𝐸𝑣𝑒𝑛(𝑡𝑖𝑚𝑒𝑠(2, 𝑥))
𝐸𝑣𝑒𝑛(𝑥) ⇒ 𝐼𝑛𝑡𝑒𝑔𝑒𝑟(𝑥)
𝐸𝑣𝑒𝑛(2)

71
Efficient forward chaining
• Incremental forward chaining
• No need to match a rule on iteration 𝑘 if a premise was not added on
iteration 𝑘 − 1 → match each rule whose premise contains a newly
added positive literal
• Matching itself can be expensive
• Database indexing allows 𝑂(1) retrieval of known facts
• E.g., query 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑥) retrieves 𝑀𝑖𝑠𝑠𝑖𝑙𝑒(𝑀1)
• Widely used in deductive databases

72
Quiz 03: Forward chaining
• Given a KB containing the following sentence
1. 𝑃𝑎𝑟𝑒𝑛𝑡(𝑥, 𝑦) ∧ 𝑀𝑎𝑙𝑒(𝑥) ⇒ 𝐹𝑎𝑡ℎ𝑒𝑟(𝑥, 𝑦)
2. 𝐹𝑎𝑡ℎ𝑒𝑟(𝑥, 𝑦) ∧ 𝐹𝑎𝑡ℎ𝑒𝑟(𝑥, 𝑧) ⇒ 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑦, 𝑧)
3. 𝑃𝑎𝑟𝑒𝑛𝑡(𝑇𝑜𝑚, 𝐽𝑜ℎ𝑛)
4. 𝑀𝑎𝑙𝑒(𝑇𝑜𝑚)
5. 𝑃𝑎𝑟𝑒𝑛𝑡(𝑇𝑜𝑚, 𝐹𝑟𝑒𝑑)
• Perform the forward chaining until a fixed point is reached.

73
Backward Chaining
74
A backward chaining algorithm
function FOL-BC-ASK(KB,query) returns a generator of substitutions
return FOL-BC-OR(KB,query, { })
generator FOL-BC-OR(KB,goal, θ) yields a substitution
for each rule (lhs  rhs) in FETCH-RULES-FOR-GOAL(KB, goal) do
(lhs, rhs) ← STANDARDIZE-VARIABLES((lhs, rhs))
for each θ’ in FOL-BC-AND(KB,lhs, UNIFY(rhs, goal, θ)) do
yield θ’
generator FOL-BC-AND(KB,goals, θ) yields a substitution
if θ = failure then return
else if LENGTH(goals) = 0 then yield θ
else do
first,rest ← FIRST(goals), REST(goals)
for each θ’ in F'OL-BC-OR(KB, SUBST(θ, first), θ) do
for each θ’’ in FOL-BC-AND(KB,rest, θ’) do
yield θ’’ 75
Backward chaining: An example

76
Backward chaining: An example

77
Backward chaining: An example

78
Backward chaining: An example

79
Backward chaining: An example

80
Backward chaining: An example

81
Backward chaining: An example

82
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 (success and failure)
• Fix using caching of previous results (extra space)
• Widely used for logic programming

83
Quiz 04: Backward chaining
• Given a KB containing the following sentence
1. 𝑃𝑎𝑟𝑒𝑛𝑡(𝑥, 𝑦) ∧ 𝑀𝑎𝑙𝑒(𝑥) ⇒ 𝐹𝑎𝑡ℎ𝑒𝑟(𝑥, 𝑦)
2. 𝐹𝑎𝑡ℎ𝑒𝑟(𝑥, 𝑦) ∧ 𝐹𝑎𝑡ℎ𝑒𝑟(𝑥, 𝑧) ⇒ 𝑆𝑖𝑏𝑙𝑖𝑛𝑔(𝑦, 𝑧)
3. 𝑃𝑎𝑟𝑒𝑛𝑡(𝑇𝑜𝑚, 𝐽𝑜ℎ𝑛)
4. 𝑀𝑎𝑙𝑒(𝑇𝑜𝑚)
5. 𝑃𝑎𝑟𝑒𝑛𝑡(𝑇𝑜𝑚, 𝐹𝑟𝑒𝑑)
• Find solution(s) to each of the following queries
• Parent(Tom, x) • Father(f, s)
• Father(Tom, s) • Sibling(a, b)

84
Quiz 04: Backward chaining
• Query: Parent(Tom,x)
• Answers: ( {x/John}, {x/Fred})

• Query: Father(Tom,s)
• Subgoal: Parent(Tom,s) ∧ Male(Tom)
• {s/John}
• Subgoal: Male(Tom)

• Answer: {s/John}
• {s/Fred}
• Subgoal: Male(Tom)
• Answer: {s/Fred}

• Answers: ({s/John}, {s/Fred})


85
Resolution
86
CNF for First-order logic
• First-order resolution requires that sentences be in CNF.
• For example, the sentence
∀𝑥 𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∧ 𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∧ 𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧) ∧ 𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ⇒ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)
becomes, in CNF,
¬𝐴𝑚𝑒𝑟𝑖𝑐𝑎𝑛(𝑥) ∨ ¬𝑊𝑒𝑎𝑝𝑜𝑛(𝑦) ∨ ¬𝑆𝑒𝑙𝑙𝑠(𝑥, 𝑦, 𝑧) ∨ ¬𝐻𝑜𝑠𝑡𝑖𝑙𝑒(𝑧) ∨ 𝐶𝑟𝑖𝑚𝑖𝑛𝑎𝑙(𝑥)

• Every sentence of first-order logic can be converted into an


inferentially equivalent CNF sentence.
• The CNF sentence will be unsatisfiable just when the original
sentence is unsatisfiable → perform proofs by contraction.

87
Conversion to CNF
Everyone who loves all animals is loved by someone.
∀𝑥 ∀𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ⇒ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) ⇒ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)

1. Eliminate implications
∀𝑥 ¬∀𝑦 ¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ∨ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) ∨ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)
2. Move  inwards: ¬∀𝑥 𝑝 ≡ ∃𝑥¬𝑝, ¬∃𝑥 𝑝 ≡ ∀𝑥 ¬𝑝

∀𝑥 ∃𝑦 ¬ ¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ∨ 𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦 ∨ ∃𝑦 𝐿𝑜𝑣𝑒𝑠 𝑦, 𝑥

∀𝑥 ∃𝑦 ¬¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ∧ ¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦 ∨ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)


∀𝑥 ∃𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ∧ ¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦 ∨ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)

88
Conversion to CNF
Everyone who loves all animals is loved by someone.
∀𝑥 ∀𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ⇒ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) ⇒ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)

3. Standardize variables: each quantifier uses a different one


∀𝑥 ∃𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ∧ ¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝑦 ∨ ∃𝑧 𝐿𝑜𝑣𝑒𝑠(𝑧, 𝑥)
4. Skolemize: remove existential quantifiers by elimination
• Simple case: translate ∃𝑥 𝑃(𝑥) into 𝑃(𝐴), where 𝐴 is a new constant.
• However, ∀𝑥 𝐴𝑛𝑖𝑚𝑎𝑙 𝐴 ∧ ¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝐴 ∨ 𝐿𝑜𝑣𝑒𝑠(𝐵, 𝑥) has an entirely
different meaning.
• The arguments of the Skolem function are all universally quantified
variables in whose scope the existential quantifier appears.
∀𝑥 𝐴𝑛𝑖𝑚𝑎𝑙 𝐹(𝑥) ∧ ¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝐹(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
89
Conversion to CNF
Everyone who loves all animals is loved by someone.
∀𝑥 ∀𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ⇒ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) ⇒ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)

5. Drop universal quantifiers


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

6. Distribute ∨ over ∧
𝐴𝑛𝑖𝑚𝑎𝑙 𝐹(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥) ∧
¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝐹(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)

90
The resolution inference rule
• Simply a lifted version of the propositional resolution rule
• Formulation 𝑙1 ∨ ⋯ ∨ 𝑙𝑘
𝑚1 ∨ ⋯ ∨ 𝑚𝑛
𝐒𝐔𝐁𝐒𝐓(𝜽, 𝑙1 ∨ ⋯ ∨ 𝑙𝑖−1 ∨ 𝑙𝑖+1 ∨ ⋯ ∨ 𝑙𝑘 ∨ 𝑚1 ∨ ⋯ ∨ 𝑚𝑗−1 ∨ 𝑚𝑗+1 ∨ ⋯ ∨ 𝑚𝑛

• where 𝑈𝑁𝐼𝐹𝑌 𝑙𝑖 , ¬𝑚𝑗 = 𝜃

• For example,
𝐴𝑛𝑖𝑚𝑎𝑙 𝐹(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠 𝐺 𝑥 , 𝑥
¬𝐿𝑜𝑣𝑒𝑠 𝑢, 𝑣 ∨ ¬𝐾𝑖𝑙𝑙𝑠 𝑢, 𝑣
𝜃 = {𝑢Τ𝐺 𝑥 , 𝑣Τ𝑥}
𝐴𝑛𝑖𝑚𝑎𝑙 𝐹(𝑥) ∨ ¬𝐾𝑖𝑙𝑙𝑠 𝐺(𝑥), 𝑥

91
Resolution: An example

92
Resolution: Another example
Everyone 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 named Tuna.
Did Curiosity kill the cat?

A. ∀𝑥 ∀𝑦 𝐴𝑛𝑖𝑚𝑎𝑙 𝑦 ⇒ 𝐿𝑜𝑣𝑒𝑠(𝑥, 𝑦) ⇒ ∃𝑦 𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)


B. ∀𝑥 ∃𝑧 𝐴𝑛𝑖𝑚𝑎𝑙 𝑧 ∧ 𝐾𝑖𝑙𝑙𝑠(𝑥, 𝑧) ⇒ ∀𝑦 ¬𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥)
C. ∀𝑥 𝐴𝑛𝑖𝑚𝑎𝑙 𝑥 ⇒ 𝐿𝑜𝑣𝑒𝑠(𝐽𝑎𝑐𝑘, 𝑥)
D. 𝐾𝑖𝑙𝑙𝑠 𝐽𝑎𝑐𝑘, 𝑇𝑢𝑛𝑎 ∨ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
E. 𝐶𝑎𝑡(𝑇𝑢𝑛𝑎)
F. ∀𝑥 𝐶𝑎𝑡(𝑥) ⇒ 𝐴𝑛𝑖𝑚𝑎𝑙 𝑥
G. ¬ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
93
Resolution: Another example
Everyone 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 named Tuna.
Did Curiosity kill the cat?

A. 𝐴𝑛𝑖𝑚𝑎𝑙(𝐹(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
¬𝐿𝑜𝑣𝑒𝑠 𝑥, 𝐹(𝑥) ∨ 𝐿𝑜𝑣𝑒𝑠(𝐺(𝑥), 𝑥)
B. ¬𝐿𝑜𝑣𝑒𝑠(𝑦, 𝑥) ∨ ¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑧 ∨ ¬𝐾𝑖𝑙𝑙𝑠(𝑥, 𝑧)
C. ¬𝐴𝑛𝑖𝑚𝑎𝑙 𝑥 ∨ 𝐿𝑜𝑣𝑒𝑠(𝐽𝑎𝑐𝑘, 𝑥)
D. 𝐾𝑖𝑙𝑙𝑠 𝐽𝑎𝑐𝑘, 𝑇𝑢𝑛𝑎 ∨ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑢𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎)
E. 𝐶𝑎𝑡(𝑇𝑢𝑛𝑎)
F. ¬𝐶𝑎𝑡(𝑥) ∨ 𝐴𝑛𝑖𝑚𝑎𝑙 𝑥
G. ¬ 𝐾𝑖𝑙𝑙𝑠(𝐶𝑢𝑟𝑖𝑜𝑠𝑖𝑡𝑦, 𝑇𝑢𝑛𝑎) 94
Resolution: Another example
Suppose Curiosity did not kill Tuna. We know that either Jack or Curiosity
did; thus Jack must have. Now, Tuna is a cat and cats are animals, so
Tuna is an animal. Because anyone who kills an animal is loved by no
one, we know that no one loves Jack. On the other hand, Jack loves all
animals, so someone loves him; so we have a contradiction.
Therefore, Curiosity killed the cat.

95
Quiz 05: Resolution
• Given a KB of the following sentences
• Anyone whom Mary loves is a football star.
• Any student who does not pass does not play.
• John is a student.
• Any student who does not study does not pass.
• Anyone who does not play is not a football star.
• Prove that If John does not study, Mary does not love John.
• Write the FOL sentences using only the given predicates
Loves(x, y): “x loves y” Star(x): “x is a football star”
Student(x): “x is a student” Pass(x): “x passes”
Play(x): “x plays” Study(x): “x studies”

96
THE END

97

You might also like