# First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

First-Order Logic
Introduction to Artiﬁcial Intelligence Steven Bethard
Department of Computer Science University of Colorado

CSCI 3202

1 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Outline
1

2

First Order Logic Motivation Core Components Quantiﬁers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Uniﬁcation Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
2 / 56

3

4

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Motivation Core Components Quantiﬁers

Outline
1

2

First Order Logic Motivation Core Components Quantiﬁers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Uniﬁcation Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
3 / 56

3

4

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers What’s Wrong with Propositional Logic? Translate: All squares adjacent to pits are breezy 4 / 56 .

2 ∨ P1..2 ∨ P2.1 ⇔ (P1.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers What’s Wrong with Propositional Logic? Translate: All squares adjacent to pits are breezy Problem: Propositional Logic B1.1 ⇔ (P1..2 ∨ P2.2 ⇔ (P1.3 ) B2.1 ∨ P2. 4 / 56 .1 ∨ P2.1 ) .1 ) B1.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers What’s Wrong with Propositional Logic? Translate: All squares adjacent to pits are breezy Problem: Propositional Logic B1.2 ∨ P2.2 ∨ P1.1 ) B1. Solution: First Order Logic (Preview) ∀s Breezy(s) ⇔ ∃r Adjacent(r .1 ) .1 ∨ P2...1 ∨ P2.3 ) B2.1 ⇔ (P1.2 ∨ P2.1 ⇔ (P1.2 ⇔ (P1. s) ∧ Pit(r ) 4 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Core Ideas of First Order Logic Propositional Logic World consists of facts All facts are either true or false 5 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Core Ideas of First Order Logic Propositional Logic World consists of facts All facts are either true or false First Order Logic World consists of objects and relations Statements that a relation R holds between objects X1 . . . . Xn are either true or false 5 / 56 . .

. . . after. houses. comes-between. . . . round. . brother-of. prime. . .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Core Ideas of First Order Logic Propositional Logic World consists of facts All facts are either true or false First Order Logic World consists of objects and relations Statements that a relation R holds between objects X1 . numbers. Xn are either true or false Objects people. Relations blonde. colors. 5 / 56 . multi-storied. years. has-color. .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Constants Key Idea Constants represent named objects in the world Examples RichardTheLionheart RonaldMcDonald Blue 42 12pm 6 / 56 .

e. x ∩ y 7 / 56 .e. x + y i. y ). y ). Sum(x .e. √ i. x i.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Functions Key Idea Functions relate object(s) to exactly one other object Examples LeftLegOf(x ) LengthOf(x ) SquareRoot(x ). Intersection(x .

x ⊆ y 8 / 56 .e. x ∈ y SubsetOf(x . i. y ) Positive(x ). i.e. i.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Predicates Key Idea Predicates describe relations between objects (or a property of a single object) Examples Person(x ) Female(x ) BrotherOf(x . x > 0 MemberOf(x . y ).e. y ).

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Connectives Connectives in First-Order Logic Used to construct more complex sentences Semantics match those of Propositional Logic Examples ¬Brother(LeftLeg(Richard). 100) Male(Pat) ∨ Female(Pat ) ¬LaysEggs(Whale) ⇒ ¬Bird(Whale) 9 / 56 . John) Positive(42) ∧ LessThan(42.

} 10 / 56 . 1 . . . .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Truth in First Order Logic Key Ideas Relations are (possibly inﬁnite) sets of tuples R(Term1 . 3 . . . . Termn ∈ R Example Given the relation: SquareRoot = { 1. . 9. 2 . . . . Termn ) is true iff Term1 . 4. .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Truth in First Order Logic Key Ideas Relations are (possibly inﬁnite) sets of tuples R(Term1 . . 2 . . 9. . Termn ) is true iff Term1 . 3 . 2) is 10 / 56 . . . 1 . . Termn ∈ R Example Given the relation: SquareRoot = { 1. . . 4. . . .} Then SquareRoot(4.

. . 2 . 2) is true because 4. . 3 . . .} Then SquareRoot(4. . 2 ∈ SquareRoot 10 / 56 . 1 . . . . 9.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Truth in First Order Logic Key Ideas Relations are (possibly inﬁnite) sets of tuples R(Term1 . Termn ) is true iff Term1 . Termn ∈ R Example Given the relation: SquareRoot = { 1. 4. . .

. Termn ∈ R Example Given the relation: SquareRoot = { 1. 3 .} Then SquareRoot(4. . . Termn ) is true iff Term1 . . . 2 ∈ SquareRoot And SquareRoot(2.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Truth in First Order Logic Key Ideas Relations are (possibly inﬁnite) sets of tuples R(Term1 . 4. 2 . 1 . 2) is true because 4. . . 9. . 2) is 10 / 56 . . . .

. . . .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Truth in First Order Logic Key Ideas Relations are (possibly inﬁnite) sets of tuples R(Term1 . . Termn ) is true iff Term1 . Termn ∈ R Example Given the relation: SquareRoot = { 1.} Then SquareRoot(4. 2) is true because 4. 4. . . 2 ∈ SquareRoot 10 / 56 . 2) is false because 2. . 2 ∈ SquareRoot And SquareRoot(2. . 9. . 3 . 2 . . 1 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Quantiﬁers Predicating over Constants If I know: ¬LaysEggs(Whale) ⇒ ¬Bird(Whale) What can I say here? ¬LaysEggs(Steve) ⇒? 11 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Quantiﬁers Predicating over Constants If I know: ¬LaysEggs(Whale) ⇒ ¬Bird(Whale) What can I say here? ¬LaysEggs(Steve) ⇒? Nothing! 11 / 56 .

e.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Quantiﬁers Predicating over Constants If I know: ¬LaysEggs(Whale) ⇒ ¬Bird(Whale) What can I say here? ¬LaysEggs(Steve) ⇒? Nothing! Quantiﬁers and Variables Quantiﬁers allow statements about classes of objects.g. ∀x ¬LaysEggs(x ) ⇒ ¬Bird(x ) 11 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation (∀) Deﬁnition ∀x P is true in model m iff: P is true when we bind x to each of the objects in m 12 / 56 .

. 12 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation (∀) Deﬁnition ∀x P is true in model m iff: P is true when we bind x to each of the objects in m Example So ∀x Bird(x ) ⇒ LaysEggs(x ) is true because: Bird(Swallow) ⇒ LaysEggs(Swallow) is true Bird(Emu) ⇒ LaysEggs(Emu) is true Bird(Badger) ⇒ LaysEggs(Badger) is true ..

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation (∀) Deﬁnition ∀x P is true in model m iff: P is true when we bind x to each of the objects in m Example So ∀x Bird(x ) ⇒ LaysEggs(x ) is true because: Bird(Swallow) ⇒ LaysEggs(Swallow) is true Bird(Emu) ⇒ LaysEggs(Emu) is true Bird(Badger) ⇒ LaysEggs(Badger) is true ... But ∀x LaysEggs(x ) ⇒ Bird(x ) is false because: 12 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation (∀) Deﬁnition ∀x P is true in model m iff: P is true when we bind x to each of the objects in m Example So ∀x Bird(x ) ⇒ LaysEggs(x ) is true because: Bird(Swallow) ⇒ LaysEggs(Swallow) is true Bird(Emu) ⇒ LaysEggs(Emu) is true Bird(Badger) ⇒ LaysEggs(Badger) is true . But ∀x LaysEggs(x ) ⇒ Bird(x ) is false because: LaysEggs(Platypus) ⇒ Bird(Platypus) is false 12 / 56 ...

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation in Translation Common Mistake What does this mean? ∀x Bird(x ) ∧ LaysEggs(x ) 13 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation in Translation Common Mistake What does this mean? ∀x Bird(x ) ∧ LaysEggs(x ) Answer: Everything is a bird and everything lays eggs Intended statement: ∀x Bird(x ) ⇒ LaysEggs(x ) 13 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Universal Quantiﬁcation in Translation Common Mistake What does this mean? ∀x Bird(x ) ∧ LaysEggs(x ) Answer: Everything is a bird and everything lays eggs Intended statement: ∀x Bird(x ) ⇒ LaysEggs(x ) Rule of Thumb Use implication (⇒) with universal quantiﬁcation (∀) 13 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation Deﬁnition ∃x P is true in model m iff: P is true when we bind x to any of the objects in m 14 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation Deﬁnition ∃x P is true in model m iff: P is true when we bind x to any of the objects in m Example So ∃x Mammal(x ) ∧ LaysEggs(x ) is true because: 14 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation Deﬁnition ∃x P is true in model m iff: P is true when we bind x to any of the objects in m Example So ∃x Mammal(x ) ∧ LaysEggs(x ) is true because: Mammal(Platypus) ∧ LaysEggs(Platypus) is true 14 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation Deﬁnition ∃x P is true in model m iff: P is true when we bind x to any of the objects in m Example So ∃x Mammal(x ) ∧ LaysEggs(x ) is true because: Mammal(Platypus) ∧ LaysEggs(Platypus) is true But ∃x Mammal(x ) ∧ ¬Animal(x ) is false because: 14 / 56 .

. 14 / 56 ..First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation Deﬁnition ∃x P is true in model m iff: P is true when we bind x to any of the objects in m Example So ∃x Mammal(x ) ∧ LaysEggs(x ) is true because: Mammal(Platypus) ∧ LaysEggs(Platypus) is true But ∃x Mammal(x ) ∧ ¬Animal(x ) is false because: Mammal(Person) ∧ ¬Animal(Person) is false Mammal(Platypus) ∧ ¬Animal(Platypus) is false Mammal(Spam) ∧ ¬Animal(Spam) is false .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation in Translation Common Mistake What does this mean? ∃x Mammal(x ) ⇒ LaysEggs(x ) 15 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation in Translation Common Mistake What does this mean? ∃x Mammal(x ) ⇒ LaysEggs(x ) Answer: There is something that is not a mammal or lays eggs Intended statement: ∃x Mammal(x ) ∧ LaysEggs(x ) 15 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Existential Quantiﬁcation in Translation Common Mistake What does this mean? ∃x Mammal(x ) ⇒ LaysEggs(x ) Answer: There is something that is not a mammal or lays eggs Intended statement: ∃x Mammal(x ) ∧ LaysEggs(x ) Rule of Thumb Use conjunction (∧) with existential quantiﬁcation (∃) 15 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Quantiﬁer Properties Nesting Quantiﬁers Mixed quantiﬁers cannot be exchanged: ∀x ∃y Loves(x . y ) “everyone loves someone” ∃x ∀y Loves(x . y ) “one person is loved by everyone” 16 / 56 .

AI) ≡ ¬∃x ¬Enjoys(x . y ) “everyone loves someone” ∃x ∀y Loves(x . DB) ≡ ¬∀x ¬Enjoys(x . DB) 16 / 56 . y ) “one person is loved by everyone” Relation between ∀ and ∃ Conversion is roughly like DeMorgan’s: ∀x Enjoys(x . AI) ∃x Enjoys(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Motivation Core Components Quantiﬁers Quantiﬁer Properties Nesting Quantiﬁers Mixed quantiﬁers cannot be exchanged: ∀x ∃y Loves(x .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Motivation Core Components Quantiﬁers

Equality Relations
Problem What’s wrong with this deﬁnition? ∀x , y Sibling(x , y ) ⇔ ∃p Parent(p, x ) ∧ Parent(p, y )

17 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Motivation Core Components Quantiﬁers

Equality Relations
Problem What’s wrong with this deﬁnition? ∀x , y Sibling(x , y ) ⇔ ∃p Parent(p, x ) ∧ Parent(p, y ) Both x and y can be the same thing! Sibling(Steve, Steve)

17 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Motivation Core Components Quantiﬁers

Equality Relations
Problem What’s wrong with this deﬁnition? ∀x , y Sibling(x , y ) ⇔ ∃p Parent(p, x ) ∧ Parent(p, y ) Both x and y can be the same thing! Sibling(Steve, Steve) Solution: Equality Specify when two variables refer to the same objects: ∀x , y Sibling(x , y ) ⇔ x = y ∧ ∃p Parent(p, x ) ∧ Parent(p, y )
17 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Outline 1 2 First Order Logic Motivation Core Components Quantiﬁers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Uniﬁcation Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution 18 / 56 3 4 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy ∃x Bird(x ) ∧ ¬Flies(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy ∃x Bird(x ) ∧ ¬Flies(x ) Animals that ﬂy have wings 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy ∃x Bird(x ) ∧ ¬Flies(x ) Animals that ﬂy have wings ∀x Animal(x ) ∧ Flies(x ) ⇒ HasWings(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy ∃x Bird(x ) ∧ ¬Flies(x ) Animals that ﬂy have wings ∀x Animal(x ) ∧ Flies(x ) ⇒ HasWings(x ) Not all swimming animals have ﬁns 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy ∃x Bird(x ) ∧ ¬Flies(x ) Animals that ﬂy have wings ∀x Animal(x ) ∧ Flies(x ) ⇒ HasWings(x ) Not all swimming animals have ﬁns ¬∀x Animal(x ) ∧ Swim(x ) ⇒ HasFins(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations All horses are mammals ∀x Horse(x ) ⇒ Mammal(x ) All birds have wings ∀x Bird(x ) ⇒ HasWings(x ) Some mammals lay eggs ∃x Mammal(x ) ∧ LaysEggs(x ) Some birds don’t ﬂy ∃x Bird(x ) ∧ ¬Flies(x ) Animals that ﬂy have wings ∀x Animal(x ) ∧ Flies(x ) ⇒ HasWings(x ) Not all swimming animals have ﬁns ¬∀x Animal(x ) ∧ Swim(x ) ⇒ HasFins(x ) ∃x Animal(x ) ∧ Swim(x ) ∧ ¬HasFins(x ) 19 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations An animal gives birth to animals of the same species 20 / 56 .

y ) ⇒ Animal(y ) ∧ Species(x ) = Species(y ) ∧ x = y 20 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations An animal gives birth to animals of the same species ∀x . y Animal(x ) ∧ GivesBirth(x .

y Animal(x ) ∧ GivesBirth(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations An animal gives birth to animals of the same species ∀x . y ) ⇒ Animal(y ) ∧ Species(x ) = Species(y ) ∧ x = y Bats have exactly two wings 20 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Animal Kingdom Translations An animal gives birth to animals of the same species ∀x . w ) ⇒ w = y ∨ w = z 20 / 56 . y ) ∧ HasWing(x . z HasWing(x . y ) ⇒ Animal(y ) ∧ Species(x ) = Species(y ) ∧ x = y Bats have exactly two wings ∀x Bat(x ) ⇒ ∃y . z ) ∧ y = z ∧ ∀w HasWing(x . y Animal(x ) ∧ GivesBirth(x .

1] 21 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3. 1] Breezy([3. 1]) 21 / 56 .

1]) The Wumpus is lives in [2.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3. 1] Breezy([3. 2] 21 / 56 .

1]) The Wumpus is lives in [2. 2] 21 / 56 . 1] Breezy([3. 2] Home(Wumpus) = [2.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3.

2] Home(Wumpus) = [2. 1] Breezy([3. he eats you 21 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3. 1]) The Wumpus is lives in [2. 2] If you are in the Wumpus’s square.

2] If you are in the Wumpus’s square. t ) 21 / 56 . t ) ⇒ HasEaten(Wumpus. 2] Home(Wumpus) = [2. Agent. 1] Breezy([3. Home(Wumpus). 1]) The Wumpus is lives in [2.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3. he eats you ∀t Location(Agent.

Home(Wumpus). Agent. t ) You should grab the gold when you are in its square 21 / 56 . 2] Home(Wumpus) = [2. 1]) The Wumpus is lives in [2. 1] Breezy([3.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3. 2] If you are in the Wumpus’s square. he eats you ∀t Location(Agent. t ) ⇒ HasEaten(Wumpus.

t ) 21 / 56 . Agent. 1] Breezy([3. 2] If you are in the Wumpus’s square. Home(Wumpus). 2] Home(Wumpus) = [2. he eats you ∀t Location(Agent. t ) ⇒ HasEaten(Wumpus. t ) You should grab the gold when you are in its square ∀s.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations There is a breeze in [3. t HasGold(s) ∧ Location(Agent. s. 1]) The Wumpus is lives in [2. Agent. t ) ⇒ BestAction(Grab.

y )) 22 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations Diagnostic Rules From effect. determine cause: ∀y Breezy(y ) ⇒ (∃x Pit(x ) ∧ Adjacent(x .

determine effect: ∀x . y )) ⇒ Breezy(y ) 22 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations Diagnostic Rules From effect. y )) Causal Rules From cause. determine cause: ∀y Breezy(y ) ⇒ (∃x Pit(x ) ∧ Adjacent(x . y (Pit(x ) ∧ Adjacent(x .

determine cause: ∀y Breezy(y ) ⇒ (∃x Pit(x ) ∧ Adjacent(x . y )) ⇒ Breezy(y ) Deﬁnition Rules Bidirectional: ∀y Breezy(y ) ⇔ (∃x Pit(x ) ∧ Adjacent(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Wumpus World Translations Diagnostic Rules From effect. y )) Causal Rules From cause. determine effect: ∀x . y )) 22 / 56 . y (Pit(x ) ∧ Adjacent(x .

Two among our number hold only nettle wine. One among us seven will let you move ahead. niether is your friend. however slyly the poison tries to hide You will always ﬁnd some on nettle wine’s left side. as you see clearly. waiting hidden in line.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Harry Potter’s 7 Potions Puzzle Danger lies before you. Third. different are those who stand at either end. we give you these clues four: First. while safety lies behind. Neither dwarf nor giant holds death in their insides. To help you in your choice. Second. But if you would move forward. 23 / 56 . Two of us will help you. whichever you would ﬁnd. unless you wish to stay here forevermore. though different at ﬁrst sight. Three of us are killers. the second left and second on the right Are twins once you taste them. Fourth. Another will transport the drinker back instead. Choose. all are different size.

Wine. Backward. [Forward.. 24 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter One Harry Potter’s 7 Potions Solution ∀p Potions(p) ⇔ Permutation(p. Poison. Poison]) PoisonIsLeftOfWine(p) ∧ EndsAreDifferent(p) ∧ EndsAreNotForward(p) ∧ SmallestIsNotPoison(p) ∧ LargestIsNotPoison(p) SecondsAreTheSame(p) ∧ .. Poison. Wine.

. . p7 ] ∧ p1 = p7 . Wine. p7 p = [p1 . Poison. p2 .. ∀p EndsAreDifferent(p) ⇔ ∃p1 . Backward. p4 . p3 . Wine. [Forward. p2 . p5 . .. . Poison]) PoisonIsLeftOfWine(p) ∧ EndsAreDifferent(p) ∧ EndsAreNotForward(p) ∧ SmallestIsNotPoison(p) ∧ LargestIsNotPoison(p) SecondsAreTheSame(p) ∧ . Poison.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter One Harry Potter’s 7 Potions Solution ∀p Potions(p) ⇔ Permutation(p... 24 / 56 . p6 .

. Backward. .. [Forward. Wine. p2 . p7 p = [p1 . Poison]) PoisonIsLeftOfWine(p) ∧ EndsAreDifferent(p) ∧ EndsAreNotForward(p) ∧ SmallestIsNotPoison(p) ∧ LargestIsNotPoison(p) SecondsAreTheSame(p) ∧ . . pi ) ∧ pi = Poison 24 / 56 . Wine. p3 .. p5 . Poison.. p4 . ∀p LargestIsNotPoison(p) ⇔ ∃pi Largest(p. p2 .. . ∀p EndsAreDifferent(p) ⇔ ∃p1 . p6 . p7 ] ∧ p1 = p7 . Poison.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter One Harry Potter’s 7 Potions Solution ∀p Potions(p) ⇔ Permutation(p.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Animal Kingdom Wumpus World Harry Potter Prolog Demo 25 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Outline 1 2 First Order Logic Motivation Core Components Quantiﬁers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Uniﬁcation Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution 26 / 56 3 4 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Universal Instantiation Key Idea If we know ∀x P (x ). then we can conclude: P (Badger) P (Spam) .. 27 / 56 ..

Formal Rule Given a ground term g : ∀v α S UBST({v /g }.. α) 27 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Universal Instantiation Key Idea If we know ∀x P (x ). then we can conclude: P (Badger) P (Spam) ..

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Propositionalization Uniﬁcation

Existential Instantiation
Key Idea If we know ∃x P (x ), then we can just give a name to x : P (ThingThatPIsTrueFor) This works as long as the name isn’t already in use

28 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Propositionalization Uniﬁcation

Existential Instantiation
Key Idea If we know ∃x P (x ), then we can just give a name to x : P (ThingThatPIsTrueFor) This works as long as the name isn’t already in use Formal Rule Given a constant k that is not in the knowledge base: ∃v α S UBST({v /k }, α) The constant k is called a Skolem constant
28 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Propositionalization Uniﬁcation

Reduction to Propositional Logic
First-Order Logic ∃x Mammal(x ) ∧ LaysEggs(x ) ∀x Mammal(x ) ⇒ WarmBlooded(x ) Mammal(Platypus) ¬WarmBlooded(Crocodile)

29 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Reduction to Propositional Logic First-Order Logic ∃x Mammal(x ) ∧ LaysEggs(x ) ∀x Mammal(x ) ⇒ WarmBlooded(x ) Mammal(Platypus) ¬WarmBlooded(Crocodile) Propositional Logic 29 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Reduction to Propositional Logic First-Order Logic ∃x Mammal(x ) ∧ LaysEggs(x ) ∀x Mammal(x ) ⇒ WarmBlooded(x ) Mammal(Platypus) ¬WarmBlooded(Crocodile) Propositional Logic Mammal(EggLayer) ∧ LaysEggs(EggLayer) 29 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Reduction to Propositional Logic First-Order Logic ∃x Mammal(x ) ∧ LaysEggs(x ) ∀x Mammal(x ) ⇒ WarmBlooded(x ) Mammal(Platypus) ¬WarmBlooded(Crocodile) Propositional Logic Mammal(EggLayer) ∧ LaysEggs(EggLayer) Mammal(Platypus) ⇒ WarmBlooded(Platypus) Mammal(Crocodile) ⇒ WarmBlooded(Crocodile) 29 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Reduction to Propositional Logic First-Order Logic ∃x Mammal(x ) ∧ LaysEggs(x ) ∀x Mammal(x ) ⇒ WarmBlooded(x ) Mammal(Platypus) ¬WarmBlooded(Crocodile) Propositional Logic Mammal(EggLayer) ∧ LaysEggs(EggLayer) Mammal(Platypus) ⇒ WarmBlooded(Platypus) Mammal(Crocodile) ⇒ WarmBlooded(Crocodile) Mammal(Platypus) 29 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Reduction to Propositional Logic First-Order Logic ∃x Mammal(x ) ∧ LaysEggs(x ) ∀x Mammal(x ) ⇒ WarmBlooded(x ) Mammal(Platypus) ¬WarmBlooded(Crocodile) Propositional Logic Mammal(EggLayer) ∧ LaysEggs(EggLayer) Mammal(Platypus) ⇒ WarmBlooded(Platypus) Mammal(Crocodile) ⇒ WarmBlooded(Crocodile) Mammal(Platypus) ¬WarmBlooded(Crocodile) 29 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Simple Approach Remove ∀ and ∃ Treat all ﬁrst-order terms as simple symbols Solve using resolution for propositional logic 30 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Simple Approach Remove ∀ and ∃ Treat all ﬁrst-order terms as simple symbols Solve using resolution for propositional logic Example: WarmBlooded(Platypus)? ¬WarmBlooded(Platypus) ¬Mammal(Platypus) ∨ WarmBlooded(Platypus) ¬Mammal(Platypus) Mammal(Platypus) false 30 / 56 .

..First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Problem: Inﬁnite Terms Mammal(Steve) Mammal(Mother(Steve)) Mammal(Mother(Mother(Steve))) . 31 / 56 .

. Solution: Iterative Deepening Try proof with terms up to depth 1 Try proof with terms up to depth 2 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Problem: Inﬁnite Terms Mammal(Steve) Mammal(Mother(Steve)) Mammal(Mother(Mother(Steve))) .. 31 / 56 ...

.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Problem: Inﬁnite Terms Mammal(Steve) Mammal(Mother(Steve)) Mammal(Mother(Mother(Steve))) ... Proof found if exists 31 / 56 . Solution: Iterative Deepening Try proof with terms up to depth 1 Try proof with terms up to depth 2 ..

Proof found if exists... else inﬁnite loop 31 / 56 ..First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Problem: Inﬁnite Terms Mammal(Steve) Mammal(Mother(Steve)) Mammal(Mother(Mother(Steve))) .. Solution: Iterative Deepening Try proof with terms up to depth 1 Try proof with terms up to depth 2 .

Proof found if exists..First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Simple First-Order Inference Problem: Inﬁnite Terms Mammal(Steve) Mammal(Mother(Steve)) Mammal(Mother(Mother(Steve))) . Solution: Iterative Deepening Try proof with terms up to depth 1 Try proof with terms up to depth 2 ... else inﬁnite loop (semidecidable) 31 / 56 ..

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Problems with Propositionalization Prove: WarmBlooded(Scooby) Dog(Scooby) Dog(Scrappy) ∀x Dog(x ) ⇒ Mammal(x ) ∀y Mammal(y ) ⇒ WarmBlooded(y ) Problem: Many Irrelevant Facts Produced Dog(Scrappy) Dog(Scrappy) ⇒ Mammal(Scrappy) Mammal(Scrappy) ⇒ WarmBlooded(Scrappy) 32 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. q ) 33 / 56 . p) = S UBST(θ. q ) = θ where S UBST(θ.

p) = S UBST(θ. y )? p q θ 33 / 56 . q ) Example: Eats(Panda.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. q ) = θ where S UBST(θ.

Leaves) 33 / 56 . p) = S UBST(θ. y )? p q θ Eats(Panda. q ) Example: Eats(Panda. q ) = θ where S UBST(θ.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. y ) Eats(Panda.

p) = S UBST(θ. y )? p q θ Eats(Panda. q ) = θ where S UBST(θ. y ) Eats(Panda.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. q ) Example: Eats(Panda. Leaves) {y =Leaves} 33 / 56 .

p) = S UBST(θ. Pizza) 33 / 56 . q ) Example: Eats(Panda. y )? p q θ Eats(Panda. y ) Eats(x . Leaves) {y =Leaves} Eats(Panda. q ) = θ where S UBST(θ. y ) Eats(Panda.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. q ) Example: Eats(Panda. Leaves) {y =Leaves} Eats(Panda. p) = S UBST(θ. y )? p q θ Eats(Panda. y =Pizza} 33 / 56 . y ) Eats(x . Pizza) {x =Panda. q ) = θ where S UBST(θ. y ) Eats(Panda.

y ) Eats(x . Pizza) {x =Panda. q ) = θ where S UBST(θ.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. y ) Eats(x . FavFood(x )) 33 / 56 . y )? p q θ Eats(Panda. p) = S UBST(θ. Leaves) {y =Leaves} Eats(Panda. q ) Example: Eats(Panda. y ) Eats(Panda. y =Pizza} Eats(Panda.

y ) Eats(x . FavFood(x )) {x =Panda. p) = S UBST(θ. y =Pizza} Eats(Panda. y )? p q θ Eats(Panda. q ) Example: Eats(Panda. y =FavFood(Panda)} 33 / 56 . Leaves) {y =Leaves} Eats(Panda.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Propositionalization Uniﬁcation Uniﬁcation Key Idea Assign variables to make two expressions look the same Formally U NIFY(p. y ) Eats(x . q ) = θ where S UBST(θ. y ) Eats(Panda. Pizza) {x =Panda.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Outline 1 2 First Order Logic Motivation Core Components Quantiﬁers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Uniﬁcation Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution 34 / 56 3 4 .

pn ) = θ S UBST(θ.. U NIFY(pn .. pn p1 ∧ p2 ∧ . ∧ pn ⇒ q U NIFY(p1 . p2 ) = θ .. p1 ) = θ U NIFY(p2 . .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Generalized Modus Ponens Deﬁnition p1 p2 .. . q ) 35 / 56 .

U NIFY(pn . . q ) Example Odd(17) ∀x Odd(x ) ⇒ Mod(x . pn ) = θ S UBST(θ.. . ∧ pn ⇒ q U NIFY(p1 . 1) 35 / 56 . p1 ) = θ U NIFY(p2 .. pn p1 ∧ p2 ∧ .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Generalized Modus Ponens Deﬁnition p1 p2 . 2. Odd(x )) = {x = 17} Mod(17. 1) U NIFY(Odd(17).. 2.. p2 ) = θ .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Key Ideas Repeatedly apply Generalized Modus Ponens Stop when nothing new can be inferred 36 / 56 .

Mammal(Platypus) Implications like p1 ∧ p2 ∧ .g. ∧ pn ⇒ q 36 / 56 . .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Key Ideas Repeatedly apply Generalized Modus Ponens Stop when nothing new can be inferred Details KB must be only ﬁrst-order deﬁnite clauses. one of: Atomic clauses. . e.

query): 37 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Code def forward_chaining(knowledge_base.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Code def forward_chaining(knowledge_base. query): # keep adding to the KB until no new sentences are generated new = True while sentences: new = set() for sentence in knowledge_base: 37 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Code def forward_chaining(knowledge_base.body) if assignment is not None: 37 / 56 . sentence. n): assignment = unify(subset.body) for subset in all_subsets(knowledge_base. query): # keep adding to the KB until no new sentences are generated new = True while sentences: new = set() for sentence in knowledge_base: # find something that unifies with the sentence body n = len(sentence.

substitute(sentence. query): # keep adding to the KB until no new sentences are generated new = True while sentences: new = set() for sentence in knowledge_base: # find something that unifies with the sentence body n = len(sentence.body) for subset in all_subsets(knowledge_base.body) if assignment is not None: # conclude the sentence head head = assignment.head) if head not in knowledge_base + new: new.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Code def forward_chaining(knowledge_base. n): assignment = unify(subset.add(head) 37 / 56 . sentence.

body) for subset in all_subsets(knowledge_base.add(head) # return if the query is concluded result = unify(head. query) if result is not None: return result knowledge_base. sentence. query): # keep adding to the KB until no new sentences are generated new = True while sentences: new = set() for sentence in knowledge_base: # find something that unifies with the sentence body n = len(sentence.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Code def forward_chaining(knowledge_base.head) if head not in knowledge_base + new: new.substitute(sentence. n): assignment = unify(subset.body) if assignment is not None: # conclude the sentence head head = assignment.update(new) 37 / 56 .

y ) ⇒ Buys(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Example If you’re rich and someone sells something you want. you buy it Rich(x ) ∧ Wants(x . you want ice cream Hot(x ) ∧ IceCream(y ) ⇒ Wants(x . y ) ∧ Sells(z . y ) If you’re hot. y ) Glacier sells all kinds of ice cream IceCream(y ) ⇒ Sells(Glacier. y ) One ﬂavor of ice cream is mint IceCream(Mint) Bill is rich Rich(Bill) Bill is hot Hot(Bill) 38 / 56 .

y ) Wants(Bill.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Example Hot(Bill) IceCream(Mint) Hot(x ) ∧ IceCream(y ) ⇒ Wants(x . Mint) 39 / 56 .

y ) Sells(Glacier. Mint) 39 / 56 . Mint) IceCream(Mint) IceCream(y ) ⇒ Sells(Glacier. y ) Wants(Bill.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Example Hot(Bill) IceCream(Mint) Hot(x ) ∧ IceCream(y ) ⇒ Wants(x .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Example Hot(Bill) IceCream(Mint) Hot(x ) ∧ IceCream(y ) ⇒ Wants(x . y ) Sells(Glacier. y ) Buys(Bill. Mint) Rich(x ) ∧ Wants(x . Mint) Rich(Bill) Wants(Bill. Mint) IceCream(Mint) IceCream(y ) ⇒ Sells(Glacier. y ) Wants(Bill. Mint) Sells(Glacier. y ) ∧ Sells(z . y ) ⇒ Buys(x . Mint) 39 / 56 .

uses Generalized Modus Ponens Complete .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound .proof similar to propositional logic Works only with deﬁnite clauses 40 / 56 .

n constants.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound . p predicates.proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions. and at most k arguments per predicate: 40 / 56 .uses Generalized Modus Ponens Complete .

uses Generalized Modus Ponens Complete .proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions. n constants. p predicates.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound . and at most k arguments per predicate: Maximum Facts: 40 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound .uses Generalized Modus Ponens Complete . p predicates. n constants. and at most k arguments per predicate: Maximum Facts: pnk 40 / 56 .proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions.

n constants. p predicates. and at most k arguments per predicate: Maximum Facts: pnk Maximum Iterations: 40 / 56 .proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound .uses Generalized Modus Ponens Complete .

n constants.uses Generalized Modus Ponens Complete .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound . and at most k arguments per predicate: Maximum Facts: pnk Maximum Iterations: pnk 40 / 56 . p predicates.proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions.

uses Generalized Modus Ponens Complete . p predicates. n constants.proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions. and at most k arguments per predicate: Maximum Facts: pnk Maximum Iterations: pnk With functions: 40 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound .

proof similar to propositional logic Works only with deﬁnite clauses Termination With no functions.uses Generalized Modus Ponens Complete . and at most k arguments per predicate: Maximum Facts: pnk Maximum Iterations: pnk With functions: may never terminate 40 / 56 . p predicates. n constants.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Forward Chaining Properties Basic Properties Sound .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Optimizing Forward Chaining Indexing Treat facts like database relations Index by predicate + arguments Can get O (1) fact retrieval Standard time/space tradeoffs 41 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Optimizing Forward Chaining Indexing Treat facts like database relations Index by predicate + arguments Can get O (1) fact retrieval Standard time/space tradeoffs Rule Checking Don’t check all rules on each iteration Check rules when new part of premise is satisﬁed 41 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Key Ideas Start with the terms in the query Look for sentences that can conclude those terms using Generalized Modus Ponens Recurse as necessary to ﬁnd simple terms Details KB must be only ﬁrst-order deﬁnite clauses 42 / 56 .

goals. assignment): 43 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Code def backward_chaining(knowledge_base.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Code def backward_chaining(knowledge_base. goals. generate the assignment if not goals: yield assignment 43 / 56 . assignment): # if all goals have been resolved.

assignment): # if all goals have been resolved.substitute(goals[0]) for sentence in knowledge_base: 43 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Code def backward_chaining(knowledge_base. goals. check the first goal and then recurse else: term = assignment. generate the assignment if not goals: yield assignment # otherwise.

check the first goal and then recurse else: term = assignment. term) if new_assignment is None: continue 43 / 56 . assignment): # if all goals have been resolved. generate the assignment if not goals: yield assignment # otherwise.head.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Code def backward_chaining(knowledge_base. goals.substitute(goals[0]) for sentence in knowledge_base: # try to unify the sentence with the first goal new_assignment = unify(sentence.

body) new_goals. assignment): # if all goals have been resolved. check the first goal and then recurse else: term = assignment. generate the assignment if not goals: yield assignment # otherwise. goals. term) if new_assignment is None: continue # add the sentence’s premise to the remaining goals new_goals = list(sentence.extend(goals[1:]) new_assignment = new_assignment.head.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Code def backward_chaining(knowledge_base.compose(assignment) 43 / 56 .substitute(goals[0]) for sentence in knowledge_base: # try to unify the sentence with the first goal new_assignment = unify(sentence.

assignment): # if all goals have been resolved. check the first goal and then recurse else: term = assignment.substitute(goals[0]) for sentence in knowledge_base: # try to unify the sentence with the first goal new_assignment = unify(sentence.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Code def backward_chaining(knowledge_base. goals. new_assignment for result in backward_chaining(*args): yield result 43 / 56 . new_goals.head.body) new_goals.compose(assignment) # recursively search for the remaining goals args = knowledge_base.extend(goals[1:]) new_assignment = new_assignment. term) if new_assignment is None: continue # add the sentence’s premise to the remaining goals new_goals = list(sentence. generate the assignment if not goals: yield assignment # otherwise.

y ) ⇒ Buys(x . y ) 44 / 56 . y ) Hot(x ) ∧ IceCream(y ) ⇒ Wants(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Given: Rich(x ) ∧ Wants(x . y ) ∧ Sells(z . y ) IceCream(y ) ⇒ Sells(Glacier. y ) IceCream(Mint) Rich(Bill) Hot(Bill) Query: Buys(x .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals Assignment 45 / 56 .

y )] Assignment {} 45 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals Assignment [Buys(x . y )] {} 45 / 56 . y )] {} [Rich(x ). Sells(z . y ). Wants(x .

y )] [Wants(x . Sells(z .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x . y ). y ). Sells(z . y )] [Rich(x ). Wants(x . y )] Assignment {} {} {x =Bill} 45 / 56 .

Wants(x . y )] [Hot(x ). y )] [Wants(x . Sells(z . Sells(z . Sells(z . y ). y )] [Rich(x ).First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x . IceCream(y ). y )] Assignment {} {} {x =Bill} {x =Bill} 45 / 56 . y ).

Sells(z . Sells(z . y ). y )] [Wants(x . y )] [Rich(x ). Sells(z . y )] [Hot(x ). IceCream(y ).First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x . y ). y )] Assignment {} {} {x =Bill} {x =Bill} {x =Bill} 45 / 56 . y )] [IceCream(y ). Wants(x . Sells(z .

Sells(z . y ). Sells(z . y =Mint} 45 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x . y )] [Rich(x ). y )] Assignment {} {} {x =Bill} {x =Bill} {x =Bill} {x =Bill. y )] [Sells(z . Sells(z . IceCream(y ). Wants(x . y )] [Hot(x ). y )] [Wants(x . Sells(z . y )] [IceCream(y ). y ).

y )] [Hot(x ). IceCream(y ). y =Mint} {x =Bill. y )] [IceCream(y ). z=Glacier} 45 / 56 . y ).First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x . y )] [IceCream(y )] Assignment {} {} {x =Bill} {x =Bill} {x =Bill} {x =Bill. y )] [Wants(x . Sells(z . Sells(z . y =Mint. Wants(x . y )] [Sells(z . Sells(z . y )] [Rich(x ). Sells(z . y ).

y =Mint} {x =Bill. IceCream(y ). Wants(x . y )] [Sells(z . y =Mint. z=Glacier} {x =Bill. Sells(z . y )] [Hot(x ). y )] [Wants(x . y ). y )] [IceCream(y )] [] Assignment {} {} {x =Bill} {x =Bill} {x =Bill} {x =Bill. z=Glacier} 45 / 56 . y ). Sells(z . Sells(z . Sells(z . y )] [Rich(x ). y =Mint.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Example Goals [Buys(x . y )] [IceCream(y ).

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties 46 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound 46 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound Yes. uses Generalized Modus Ponens 46 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound Complete Yes. uses Generalized Modus Ponens 46 / 56 .

uses Generalized Modus Ponens Complete No.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound Yes. could hit inﬁnite loops 46 / 56 .

could hit inﬁnite loops ⇒ ﬁx by keeping track of goals already seen 46 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound Yes. uses Generalized Modus Ponens Complete No.

uses Generalized Modus Ponens Complete No.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound Yes. could hit inﬁnite loops ⇒ ﬁx by keeping track of goals already seen Space 46 / 56 .

uses Generalized Modus Ponens Complete No.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backward Chaining Properties Properties Sound Yes. could hit inﬁnite loops ⇒ ﬁx by keeping track of goals already seen Space Linear in size of proof (depth-ﬁrst search) 46 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Prolog Prolog Overview Backward chaining + many optimizations Millions of logical inferences per second 47 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Forward Chaining Backward Chaining Prolog Resolution

Prolog
Prolog Overview Backward chaining + many optimizations Millions of logical inferences per second Prolog Syntax Head ﬁrst, then body Predicates lowercase, variables uppercase Comma for ∧, semicolon for ∨
factorial(1, 1). factorial(N, _) :- N =< 0, fail. factorial(N, F) :- N > 1, N1 is N - 1, factorial(N1, F1), F is F1 * N.
47 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Forward Chaining Backward Chaining Prolog Resolution

Prolog Examples

48 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Forward Chaining Backward Chaining Prolog Resolution

Backwards Chaining Backtracking
Prove: Connected(A, F ) Given: ∀x , z Edge(x , z ) ⇒ Connected(x , z ) ∀x , y , z Edge(x , y ) ∧ Connected(y , z ) ⇒ Connected(x , z ) Edge(A, B ) ∧ Edge(B , C ) ∧ Edge(B , D ) ∧ Edge(D , F )

49 / 56

z Edge(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. B ) ∧ Edge(B . y ) ∧ Connected(y . F ) 49 / 56 . z Edge(x . F ) Connected(A. z ) Edge(A. y . D ) ∧ Edge(D . z ) ⇒ Connected(x . z ) ∀x . C ) ∧ Edge(B . F ) Given: ∀x . z ) ⇒ Connected(x .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Forward Chaining Backward Chaining Prolog Resolution

Backwards Chaining Backtracking
Prove: Connected(A, F ) Given: ∀x , z Edge(x , z ) ⇒ Connected(x , z ) ∀x , y , z Edge(x , y ) ∧ Connected(y , z ) ⇒ Connected(x , z ) Edge(A, B ) ∧ Edge(B , C ) ∧ Edge(B , D ) ∧ Edge(D , F ) Connected(A, F ) Edge(A, F )

49 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Forward Chaining Backward Chaining Prolog Resolution

Backwards Chaining Backtracking
Prove: Connected(A, F ) Given: ∀x , z Edge(x , z ) ⇒ Connected(x , z ) ∀x , y , z Edge(x , y ) ∧ Connected(y , z ) ⇒ Connected(x , z ) Edge(A, B ) ∧ Edge(B , C ) ∧ Edge(B , D ) ∧ Edge(D , F ) Connected(A, F ) Edge(A, F ) fail

49 / 56

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms

Forward Chaining Backward Chaining Prolog Resolution

Backwards Chaining Backtracking
Prove: Connected(A, F ) Given: ∀x , z Edge(x , z ) ⇒ Connected(x , z ) ∀x , y , z Edge(x , y ) ∧ Connected(y , z ) ⇒ Connected(x , z ) Edge(A, B ) ∧ Edge(B , C ) ∧ Edge(B , D ) ∧ Edge(D , F ) Connected(A, F )

49 / 56

z ) ∀x . C ) ∧ Edge(B . z ) Edge(A. z ) ⇒ Connected(x . D ) ∧ Edge(D . z Edge(x . F ) Edge(A.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. F ) Connected(A. z ) ⇒ Connected(x . y ) ∧ Connected(y . F ) 49 / 56 . B ) ∧ Edge(B . z Edge(x . y . y ) Connected(y . F ) Given: ∀x .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. D ) ∧ Edge(D . z ) ⇒ Connected(x . z ) ∀x . F ) 49 / 56 . F ) Given: ∀x . C ) ∧ Edge(B . z Edge(x . F ) Edge(A. B ) Connected(y . B ) ∧ Edge(B . z Edge(x . y ) ∧ Connected(y . z ) ⇒ Connected(x . F ) Connected(A. z ) Edge(A. y ) Edge(A. y .

B ) Edge(A. z ) ∀x . B ) ∧ Edge(B . D ) ∧ Edge(D . z ) ⇒ Connected(x . C ) ∧ Edge(B . F ) Edge(A. F ) Connected(A.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. F ) 49 / 56 . z ) ⇒ Connected(x . y . z ) Edge(A. B ) Connected(B . z Edge(x . F ) Given: ∀x . y ) ∧ Connected(y . z Edge(x .

B ) Connected(B . F ) Edge(B . D ) ∧ Edge(D . B ) ∧ Edge(B . z Edge(x . z ) ∀x . y .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. z ) ⇒ Connected(x . F ) Given: ∀x . F ) Edge(A. y ) Connected(y . B ) Edge(A. C ) ∧ Edge(B . F ) 49 / 56 . z Edge(x . F ) Connected(A. z ) Edge(A. y ) ∧ Connected(y . z ) ⇒ Connected(x .

z ) ⇒ Connected(x . D ) ∧ Edge(D . F ) . B ) Connected(B . B ) ∧ Edge(B . z ) ∀x . y ) ∧ Connected(y . y ) Edge(B . z ) Edge(A.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. F ) Edge(A. C ) ∧ Edge(B . F ) Given: ∀x . C ) 49 / 56 Connected(y . z Edge(x . B ) Edge(A. y . z Edge(x . z ) ⇒ Connected(x . F ) Connected(A. F ) Edge(B .

y ) ∧ Connected(y . C ) Edge(B . F ) Given: ∀x . B ) ∧ Edge(B . y . F ) Connected(A. D ) ∧ Edge(D . z ) ⇒ Connected(x . C ) 49 / 56 Connected(C . z ) Edge(A. C ) ∧ Edge(B . z Edge(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. F ) Edge(B . z ) ⇒ Connected(x . z ) ∀x . B ) Edge(A. z Edge(x . F ) . F ) Edge(A. B ) Connected(B .

z Edge(x . z ) Edge(A. y . . z Edge(x . F ) Edge(B . y ) ∧ Connected(y . . fail . 49 / 56 . z ) ⇒ Connected(x . B ) Edge(A. F ) Given: ∀x . F ) . C ) ∧ Edge(B . z ) ∀x . . C ) Connected(C . B ) ∧ Edge(B . z ) ⇒ Connected(x . D ) ∧ Edge(D . F ) Edge(A. C ) Edge(B . . F ) Connected(A. B ) Connected(B .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. B ) Connected(B . z ) ⇒ Connected(x . D ) ∧ Edge(D . z ) ∀x . z Edge(x . z ) Edge(A. F ) Edge(A. B ) Edge(A. y ) ∧ Connected(y . C ) ∧ Edge(B . F ) Edge(B . y . F ) 49 / 56 . z ) ⇒ Connected(x . y ) Connected(y . B ) ∧ Edge(B . F ) Connected(A. z Edge(x . F ) Given: ∀x .

F ) Edge(A. z Edge(x . F ) Given: ∀x . z ) ⇒ Connected(x . F ) . D ) 49 / 56 Connected(y . y ) Edge(B .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. B ) Connected(B . y . F ) Connected(A. B ) Edge(A. z ) Edge(A. y ) ∧ Connected(y . F ) Edge(B . z ) ⇒ Connected(x . B ) ∧ Edge(B . C ) ∧ Edge(B . z Edge(x . D ) ∧ Edge(D . z ) ∀x .

z Edge(x . F ) Edge(B . F ) Given: ∀x . F ) Edge(A. z Edge(x . z ) ⇒ Connected(x . B ) ∧ Edge(B . D ) ∧ Edge(D . F ) . y . z ) Edge(A. C ) ∧ Edge(B . F ) Connected(A. B ) Edge(A.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. y ) ∧ Connected(y . z ) ⇒ Connected(x . D ) Edge(B . z ) ∀x . B ) Connected(B . D ) 49 / 56 Connected(D .

D ) Edge(B . z ) ∀x . F ) Given: ∀x . z ) ⇒ Connected(x . F ) Edge(B . F ) Connected(A.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Backwards Chaining Backtracking Prove: Connected(A. F ) Edge(A. F ) Edge(D . F ) 49 / 56 . C ) ∧ Edge(B . D ) ∧ Edge(D . y . B ) ∧ Edge(B . B ) Connected(B . D ) Connected(D . z Edge(x . B ) Edge(A. z Edge(x . z ) ⇒ Connected(x . y ) ∧ Connected(y . z ) Edge(A.

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Prolog Example 50 / 56 .

. qj −1 ∨ qj +1 . ∨ pn ∨q1 ∨ . . ¬qj ) = θ S UBST(θ. . ∨ qm ) 51 / 56 . ∨ pn q1 ∨ . p1 ∨ . .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Deﬁnition p1 ∨ . . ∨ qm U NIFY(pi . . . . . . pi −1 ∨ pi +1 . . .

. . p1 ∨ . ¬qj ) = θ S UBST(θ.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Deﬁnition p1 ∨ . ∨ qm ) Example ¬Mammal(x ) ∨ WarmBlooded(x ) Mammal(Platypus) WarmBlooded(Platypus) 51 / 56 . qj −1 ∨ qj +1 . . ∨ qm U NIFY(pi . . pi −1 ∨ pi +1 . ∨ pn ∨q1 ∨ . . . . . ∨ pn q1 ∨ . . . . .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Resolution Procedure 1 2 3 4 Convert knowledge base to CNF Convert query to CNF Assume ¬ query Apply resolution until false is concluded 52 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Resolution Procedure 1 2 3 4 Convert knowledge base to CNF Convert query to CNF Assume ¬ query Apply resolution until false is concluded CNF Complications Negations moved through ∀ and ∃ All quantiﬁers must have different variable names Quantiﬁer scopes handled through skolemization 52 / 56 .

y ) ∨ Buys(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example Given: ¬Rich(x ) ∨ ¬Wants(x . y ) ¬IceCream(y ) ∨ Sells(Glacier. y ) IceCream(Mint) Rich(Bill) Hot(Bill) Prove: Buys(x . y ) ∨ ¬Sells(z . y ) 53 / 56 . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x .

y ) 54 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x .

y ) 54 / 56 . y ) ¬Rich(x ) ∨ ¬Wants(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) ∨ Buys(x .

y ) ¬Rich(x ) ∨ ¬Wants(x . y ) 54 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) ∨ Buys(x . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x .

y ) ∨ Buys(x . y ) ∨ ¬Sells(z . y ) Rich(Bill) 54 / 56 . y ) ¬Rich(x ) ∨ ¬Wants(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x .

y ) ∨ ¬Sells(z . y ) ∨ Buys(x . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) Rich(Bill) ¬Wants(Bill.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) 54 / 56 . y ) ∨ ¬Sells(z .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) Rich(Bill) ¬Wants(Bill. y ) ∨ ¬Sells(z . y ) ∨ Buys(x . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ∨ ¬Sells(z . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) 54 / 56 .

y ) Rich(Bill) ¬Wants(Bill. y ) ∨ ¬Sells(z . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ∨ Buys(x . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) 54 / 56 . y ) ∨ ¬Sells(z . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x .

y ) ∨ ¬Sells(z . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) 54 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ¬IceCream(y ) ∨ Sells(Glacier. y ) Rich(Bill) ¬Wants(Bill. y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) ∨ Buys(x . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z . y ) ∨ ¬Sells(z .

y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) ∨ Buys(x . y ) ∨ ¬Sells(z .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) Rich(Bill) ¬Wants(Bill. y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) 54 / 56 . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ¬IceCream(y ) ∨ Sells(Glacier.

y ) ¬Hot(Bill) ∨ ¬IceCream(y ) IceCream(Mint) 54 / 56 . y ) ¬IceCream(y ) ∨ Sells(Glacier. y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) Rich(Bill) ¬Wants(Bill. y ) ∨ Buys(x . y ) ∨ ¬Sells(z . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) ∨ ¬Sells(z . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x .

y ) Rich(Bill) ¬Wants(Bill. y ) ¬IceCream(y ) ∨ Sells(Glacier. y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ∨ Buys(x . y ) ∨ ¬Sells(z . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) IceCream(Mint) ¬Hot(Bill) 54 / 56 . y ) ∨ ¬Sells(z .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x .

y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z . y ) ¬IceCream(y ) ∨ Sells(Glacier. y ) ∨ Buys(x . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) IceCream(Mint) ¬Hot(Bill) Hot(Bill) 54 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ ¬Sells(z . y ) ∨ ¬Sells(z . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) Rich(Bill) ¬Wants(Bill. y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) ∨ ¬Sells(z .

y ) ¬IceCream(y ) ∨ Sells(Glacier. y ) ∨ ¬Sells(z . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) IceCream(Mint) ¬Hot(Bill) Hot(Bill) false 54 / 56 . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) ¬Hot(Bill) ∨ ¬IceCream(y ) ∨ ¬Sells(z . y ) ¬Hot(x ) ∨ ¬IceCream(y ) ∨ Wants(x . y ) ¬Rich(x ) ∨ ¬Wants(x . y ) Rich(Bill) ¬Wants(Bill.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Example ¬Buys(x . y ) ∨ Buys(x . y ) ∨ ¬Sells(z . y ) ∨ ¬Sells(z .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Chaining Properties Properties Sound 55 / 56 .

uses Resolution 55 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Chaining Properties Properties Sound Yes.

uses Resolution Sound Complete 55 / 56 .First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Chaining Properties Properties Yes.

uses Resolution Sound Complete No.First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Chaining Properties Properties Yes. if only binary resolution is used Yes. with factoring to combine uniﬁable literals 55 / 56 .

First Order Logic Example Translations First-Order Logic Inference Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution Resolution Chaining Properties Properties Yes. if only binary resolution is used Yes. uses Resolution Sound Complete No. with factoring to combine uniﬁable literals Other Properties Requires extra work to retrieve substitutions Can produce useless answers for existential goals 55 / 56 .

Key Ideas Translating First-Order Logic Identify objects (terms) and relations (predicates) Generally. use ⇒ with ∀ and ∧ with ∃ Use inequality to specify unique objects First-Order Logic Inference Forward chaining on deﬁnite clauses is sound and complete Backward chaining on deﬁnite clauses is sound Resolution is sound and complete 56 / 56 .