Professional Documents
Culture Documents
First-Order Logic
Introduction to Articial 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
First Order Logic Motivation Core Components Quantiers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Unication Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
2 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Outline
1
First Order Logic Motivation Core Components Quantiers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Unication Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
3 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
4 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
4 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
5 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
5 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Constants
Key Idea Constants represent named objects in the world Examples RichardTheLionheart RonaldMcDonald Blue 42 12pm
6 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Functions
Key Idea Functions relate object(s) to exactly one other object Examples LeftLegOf(x ) LengthOf(x ) SquareRoot(x ), Sum(x , y ), Intersection(x , y ), i.e. x i.e. x + y i.e. x y
7 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Predicates
Key Idea Predicates describe relations between objects (or a property of a single object) Examples Person(x ) Female(x ) BrotherOf(x , y ) Positive(x ), i.e. x > 0 MemberOf(x , y ), i.e. x y SubsetOf(x , y ), i.e. x y
8 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Connectives
Connectives in First-Order Logic Used to construct more complex sentences Semantics match those of Propositional Logic Examples Brother(LeftLeg(Richard), John) Positive(42) LessThan(42, 100) Male(Pat) Female(Pat ) LaysEggs(Whale) Bird(Whale)
9 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
10 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
10 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
10 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
10 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Quantiers
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
Quantiers
Predicating over Constants If I know: LaysEggs(Whale) Bird(Whale) What can I say here? LaysEggs(Steve) ? Nothing!
11 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Quantiers
Predicating over Constants If I know: LaysEggs(Whale) Bird(Whale) What can I say here? LaysEggs(Steve) ? Nothing! Quantiers and Variables Quantiers allow statements about classes of objects, e.g. x LaysEggs(x ) Bird(x )
11 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Universal Quantication ()
Denition x P is true in model m iff: P is true when we bind x to each of the objects in m
12 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Universal Quantication ()
Denition 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 ...
12 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Universal Quantication ()
Denition 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
Universal Quantication ()
Denition 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
13 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
13 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
13 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Existential Quantication
Denition 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
Existential Quantication
Denition 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
Existential Quantication
Denition 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
Existential Quantication
Denition 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
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Existential Quantication
Denition 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 ...
14 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
15 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
15 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
15 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Quantier Properties
Nesting Quantiers Mixed quantiers cannot be exchanged: x y Loves(x , y ) everyone loves someone x y Loves(x , y ) one person is loved by everyone
16 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Quantier Properties
Nesting Quantiers Mixed quantiers cannot be exchanged: x y Loves(x , y ) everyone loves someone x y Loves(x , y ) one person is loved by everyone Relation between and Conversion is roughly like DeMorgans: x Enjoys(x , AI) x Enjoys(x , AI) x Enjoys(x , DB) x Enjoys(x , DB)
16 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Equality Relations
Problem Whats wrong with this denition? 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
Equality Relations
Problem Whats wrong with this denition? 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
Equality Relations
Problem Whats wrong with this denition? 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
Outline
1
First Order Logic Motivation Core Components Quantiers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Unication Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
18 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
19 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
20 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
An animal gives birth to animals of the same species x , y Animal(x ) GivesBirth(x , y ) Animal(y ) Species(x ) = Species(y ) x = y
20 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
An animal gives birth to animals of the same species x , y Animal(x ) GivesBirth(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
An animal gives birth to animals of the same species x , y Animal(x ) GivesBirth(x , y ) Animal(y ) Species(x ) = Species(y ) x = y Bats have exactly two wings x Bat(x ) y , z HasWing(x , y ) HasWing(x , z ) y = z w HasWing(x , w ) w = y w = z
20 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
21 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
22 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
22 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
24 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
24 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Prolog Demo
25 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Outline
1
First Order Logic Motivation Core Components Quantiers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Unication Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
26 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Universal Instantiation
Key Idea If we know x P (x ), then we can conclude: P (Badger) P (Spam) ...
27 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Universal Instantiation
Key Idea If we know x P (x ), then we can conclude: P (Badger) P (Spam) ... 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 Unication
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 isnt already in use
28 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
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 isnt 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 Unication
29 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
29 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
29 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
29 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
30 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
31 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
31 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q )
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q Eats(Panda, y ) Eats(Panda, Leaves)
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q Eats(Panda, y ) Eats(Panda, Leaves) {y =Leaves}
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q Eats(Panda, y ) Eats(Panda, Leaves) {y =Leaves} Eats(Panda, y ) Eats(x , Pizza)
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q Eats(Panda, y ) Eats(Panda, Leaves) {y =Leaves} Eats(Panda, y ) Eats(x , Pizza) {x =Panda, y =Pizza}
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q Eats(Panda, y ) Eats(Panda, Leaves) {y =Leaves} Eats(Panda, y ) Eats(x , Pizza) {x =Panda, y =Pizza} Eats(Panda, y ) Eats(x , FavFood(x ))
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Propositionalization Unication
Unication
Key Idea Assign variables to make two expressions look the same Formally U NIFY(p, q ) = where S UBST(, p) = S UBST(, q ) Example: Eats(Panda, y )?
p q Eats(Panda, y ) Eats(Panda, Leaves) {y =Leaves} Eats(Panda, y ) Eats(x , Pizza) {x =Panda, y =Pizza} Eats(Panda, y ) Eats(x , FavFood(x )) {x =Panda, y =FavFood(Panda)}
33 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Outline
1
First Order Logic Motivation Core Components Quantiers Example Translations Animal Kingdom Wumpus World Harry Potter First-Order Logic Inference Propositionalization Unication Inference Algorithms Forward Chaining Backward Chaining Prolog Resolution
34 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
35 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Forward Chaining
Key Ideas Repeatedly apply Generalized Modus Ponens Stop when nothing new can be inferred
36 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Forward Chaining
Key Ideas Repeatedly apply Generalized Modus Ponens Stop when nothing new can be inferred Details KB must be only rst-order denite clauses, one of: Atomic clauses, e.g. Mammal(Platypus) Implications like p1 p2 . . . pn q
36 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
37 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
37 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
37 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
37 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
39 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
39 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
40 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
40 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
40 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
40 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
40 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
40 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
41 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
41 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
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 denite clauses
42 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
43 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
43 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
43 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
43 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
43 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
44 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
45 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Properties
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Properties Sound
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Properties Sound Yes, uses Generalized Modus Ponens Complete No, could hit innite loops
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Properties Sound Yes, uses Generalized Modus Ponens Complete No, could hit innite loops x by keeping track of goals already seen
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Properties Sound Yes, uses Generalized Modus Ponens Complete No, could hit innite loops x by keeping track of goals already seen Space
46 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Properties Sound Yes, uses Generalized Modus Ponens Complete No, could hit innite 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
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
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
Prolog Examples
48 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Connected(y , F )
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Connected(C , F )
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
49 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Connected(y , F )
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Connected(D , F )
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Prolog Example
50 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution
Denition p1 . . . pn q1 . . . qm U NIFY(pi , qj ) = S UBST(, p1 . . . pi 1 pi +1 . . . pn q1 . . . qj 1 qj +1 . . . qm )
51 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution
Denition p1 . . . pn q1 . . . qm U NIFY(pi , qj ) = S UBST(, p1 . . . pi 1 pi +1 . . . pn q1 . . . qj 1 qj +1 . . . qm ) Example Mammal(x ) WarmBlooded(x ) Mammal(Platypus) WarmBlooded(Platypus)
51 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
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
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 quantiers must have different variable names Quantier scopes handled through skolemization
52 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Given: Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Hot(x ) IceCream(y ) Wants(x , y ) IceCream(y ) Sells(Glacier, y ) IceCream(Mint) Rich(Bill) Hot(Bill) Prove: Buys(x , y )
53 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill)
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y ) IceCream(y ) Sells(Glacier, y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y ) IceCream(y ) Sells(Glacier, y ) Hot(Bill) IceCream(y )
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y ) IceCream(y ) Sells(Glacier, y ) Hot(Bill) IceCream(y ) IceCream(Mint)
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y ) IceCream(y ) Sells(Glacier, y ) Hot(Bill) IceCream(y ) IceCream(Mint) Hot(Bill)
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y ) IceCream(y ) Sells(Glacier, y ) Hot(Bill) IceCream(y ) IceCream(Mint) Hot(Bill) Hot(Bill)
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
Resolution Example
Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Buys(x , y ) Rich(x ) Wants(x , y ) Sells(z , y ) Rich(Bill) Wants(Bill, y ) Sells(z , y ) Hot(x ) IceCream(y ) Wants(x , y ) Hot(Bill) IceCream(y ) Sells(z , y ) IceCream(y ) Sells(Glacier, y ) Hot(Bill) IceCream(y ) IceCream(Mint) Hot(Bill) Hot(Bill) false
54 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
55 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
55 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
55 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
55 / 56
First Order Logic Example Translations First-Order Logic Inference Inference Algorithms
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 denite clauses is sound and complete Backward chaining on denite clauses is sound Resolution is sound and complete
56 / 56