FIRST ORDER LOGIC
&
INFERENCE IN FIRST ORDER LOGIC
By
Predicate Logic
C.PABITHA., AP
1/17/16
Propositional Logic
Propositional logic isnt powerful enough as a
general knowledge representation language.
Impossible to make general statements. E.g.,
all students sit exams or if any student sits
an exam they either pass or fail.
So we need predicate logic.
Wumpus World and propositional logic
Find Pits in Wumpus world
Bx,y (Px,y+1 Px,y-1 Px+1,y Px-1,y) (Breeze next to Pit)
16 rules
Find Wumpus
Sx,y (Wx,y+1 Wx,y-1 Wx+1,y Wx-1,y) (stench next to Wumpus) 16 rules
At least one Wumpus in world
W1,1 W1,2 W4,4 (at least 1 Wumpus) 1 rule
At most one Wumpus
W1,1 W1,2 (155 RULES)
Predicate Logic
1/17/16
Predicate Logic: First order Logic
More expressive logic than propositional
Constants are objects: john, apples
Predicates are properties and relations:
likes(john, apples)
Functions transform objects:
likes(john, fruit_of(apple_tree))
Variables represent any object: likes(X, apples)
Quantifiers qualify values of variables
True for all objects (Universal):
X. likes(X, apples)
Exists at least one object (Existential): X. likes(X, apples)
First-order logic
Whereas propositional logic assumes the world
contains facts,
first-order logic (like natural language) assumes
the world contains
Objects: people, houses, numbers, colors, baseball
games, wars,
Relations: red, round, prime, brother of, bigger
than, part of, comes between,
Functions: father of, best friend, one more than,
plus,
Predicate Logic
1/17/16
Syntax of FOL: Basic elements
Constants King, John, 2, NUS,...
Predicates Brother, >,...
Functions
Variables
Connectives
Equality
Quantifiers
Predicate Logic
Sqrt( ), LeftLegOf,...
x, y, a, b,...
, , , ,
,
1/17/16
Terms
Term = logical expression that refers to an object.
There are 2 kinds of terms:
constant symbols: Table, Computer
function symbols: LeftLeg(Pete), Sqrt(3), Plus(2,3) etc
Functions can be nested:
Pat_Grandfather(x) = father(father(x))
Terms can contain variables.
No variables = ground term.
7
Predicate Logic
1/17/16
Atomic Sentences
Atomic sentences state facts using terms and predicate symbols
P(x,y) interpreted as x is P of y
Examples:
LargerThan(2,3) is false.
Brother_of(Mary,Pete) is false.
Married(Father(Richard), Mother(John)) could be true or false
Note: Functions do not state facts and form no sentence:
Brother(Pete) refers to John (his brother) and is neither true nor false.
Brother_of(Pete,Brother(Pete)) is True.
Binary relation
Predicate Logic
Function
1/17/16
Complex Sentences
We make complex sentences with connectives (just
like in propositional logic).
property
Brother (LeftLeg (Richard ), John ) (Democrat (Bush ))
binary
relation
function
objects
connectives
Predicate Logic
1/17/16
Universal Quantification
means for all
Allows
Can
us to make statements about all objects that have certain properties
now state general rules:
x King(x) => Person(x)
x Person(x) => HasHead(x)
i
Integer(i) => Integer(plus(i,1))
Note that
x King(x) Person(x) is not correct!
This would imply that all objects x are Kings and are People
x King(x) => Person(x) is the correct way to say
10
Predicate Logic
1/17/16
Existential Quantification
x means there exists an x such that.
(at least one object x)
Allows us to make statements about some object without naming it
Examples:
King(x)
Lives_in(John, Castle(x))
Integer(i) GreaterThan(i,0)
Note that is the natural connective to use with
(And => is the natural connective to use with )
11
Predicate Logic
1/17/16
A Common Mistake to Avoid
Typically is the main connective with
Common mistake: using as the main
connective with
x At(x, KSU) Smart(x)
12
Predicate Logic
1/17/16
Another Common Mistake to Avoid
Typically, is the main connective with
Common mistake: using as the main
connective with
13
Predicate Logic
1/17/16
Examples
Everyone likes McDonalds
x, likes(x, McDonalds)
Someone likes McDonalds
x, likes(x, McDonalds)
All children like McDonalds
x, child(x) likes(x, McDonalds)
Everyone likes McDonalds unless they are allergic to it
x, likes(x, McDonalds) allergic(x, McDonalds)
x, allergic (x, McDonalds) likes(x, McDonalds)
14
Predicate Logic
1/17/16
All students are smart.
x ( Student(x) Smart(x) )
There exists a student.
x Student(x).
There exists a smart student.
x ( Student(x) Smart(x) )
Every student loves some student.
x ( Student(x) y ( Student(y) Loves(x,y) ))
15
Predicate Logic
1/17/16
Every student loves some other student.
x ( Student(x) y ( Student(y) (x = y) Loves(x,y) ))
There is a student who is loved by every other student.
x ( Student(x) y ( Student(y) (x = y) Loves(y,x) ))
Bill is a student.
Student(Bill)
Bill takes either Analysis or Geometry (but not both)
Takes(Bill, Analysis) Takes(Bill, Geometry)
Bill takes Analysis or Geometry (or both).
Takes(Bill, Analysis) Takes(Bill, Geometry)
Bill takes Analysis and Geometry.
Takes(Bill, Analysis) Takes(Bill, Geometry)
Bill does not take Analysis.
Takes(Bill, Analysis).
16
Predicate Logic
1/17/16
No student loves Bill.
x ( Student(x) Loves(x, Bill) )
Bill has at least one sister.
x SisterOf(x,Bill)
Bill has no sister.
x SisterOf(x,Bill)
Bill has at most one sister.
x, y ( SisterOf(x, Bill) SisterOf(y, Bill) x = y )
Bill has exactly one sister.
x ( SisterOf(x, Bill) y ( SisterOf(y, Bill) x = y ))
Bill has at least two sisters.
x, y ( SisterOf(x, Bill) SisterOf(y, Bill) (x = y) )
17
Predicate Logic
1/17/16
Properties of Quantifiers
x y is the same as y x
x y is the same as y x
x y is not the same as y x
x y Loves(x, y)
There is a person who loves everyone in the world
y x Loves(x, y)
Everyone in the world is loved by at least one person
18
Predicate Logic
1/17/16
Nesting Quantifiers
Everyone likes some kind of food
y x, food(x) likes(y, x)
There is a kind of food that everyone likes
x y, food(x) likes(y, x)
Someone likes all kinds of food
y x, food(x) likes(y, x)
Every food has someone who likes it
x y, food(x) likes(y, x)
19
Predicate Logic
1/17/16
Example Domains
Kinship domain
What is a second cousin once removed, anyway?
Numbers, sets, and lists
This one is a classic. You should understand these, even if
you dont memorize them.
The Wumpus World
Note how much simpler the description is in FOL!
Whatever your domain, if the axioms correctly and
completely describe how the world works, any
complete logical inference procedure will infer the
strongest possible description of the world, given
the available percepts
20
Predicate Logic
1/17/16
Remember:
proposition
al
logic
21
Predicate Logic
1/17/16
Reminder
Ground term: A term that does not contain a
variable.
A constant symbol
A function applies to some ground term
{x/a}: substitution/binding list
22
Predicate Logic
1/17/16
Proofs
23
Predicate Logic
1/17/16
Proofs
The three new inference rules for FOL (compared to propositional logic) are:
Universal Elimination (UE):
for any sentence , variable x and ground term g,
x
{x/g}
Existential Elimination (EE):
for any sentence , variable x and constant symbol k not in KB,
x
{x/k}
Existential Introduction (EI):
for any sentence , variable x not in and ground term g in ,
x {g/x}
24
Predicate Logic
1/17/16
Proofs
The three new inference rules for FOL (compared to propositional logic) are:
Universal Elimination (UE):
for any sentence , variable x and ground term ,
x e.g., from x Likes(x, Candy) and {x/Joe}
{x/} we can infer Likes(Joe, Candy)
Existential Elimination (EE):
for any sentence , variable x and constant symbol k not in KB,
x e.g., from x Kill(x, Victim) we can infer
{x/k} Kill(Murderer, Victim), if Murderer new symbol
Existential Introduction (EI):
for any sentence , variable x not in and ground term g in ,
e.g., from Likes(Joe, Candy) we can infer
x {g/x} x Likes(x, Candy)
25
Predicate Logic
1/17/16
Knowledge engineering in FOL
Identify the task
Assemble the relevant knowledge
Decide on a vocabulary of predicates, functions, and constants
Encode general knowledge about the domain
Encode a description of the specific problem instance
Pose queries to the inference procedure and get answers
26
Debug the knowledge base.
Predicate Logic
See text for full example: electric circuit knowledge base.
1/17/16
Identify the task
The
task will determine what knowledge must be represented in order to connect
problem instances to answers. This step is analogous to the PEAS process for designing
agents.
PEAS
(Performance, Environment, Actuators, Sensors) or
PAGE
(Percept, Action, Goal, Environment) description
Assemble
The
the relevant knowledge
knowledge engineer might already be an expert in the domain, or might need to
work with real experts to extract what they know-a process called knowledge
acquisition
Decide
That
27
on a vocabulary of predicates, functions, and constants
is, translate the important domain-level concepts into logic-level names.
Predicate Logic
1/17/16
Encode general knowledge about the domain
The knowledge engineer writes down the axioms for all the vocabulary terms. This
pins down (to the extent possible) the meaning of the terms, enabling the expert to
check the content
Encode a description of the specific problem instance
For a logical agent, problem instances are supplied by the sensors/ percepts
Pose queries to the inference procedure and get
answers
Debug the knowledge base.
28
Predicate Logic
1/17/16
Inference in first-order logic
30
Predicate Logic
1/17/16
Universal instantiation (UI)
Every instantiation of a universally quantified sentence is
entailed by it:
v
Subst({v/g}, )
for any variable v and ground term g
E.g., x King(x) Greedy(x) Evil(x) yields:
King(John) Greedy(John) Evil(John)
King(Richard) Greedy(Richard) Evil(Richard)
King(Father(John)) Greedy(Father(John)) Evil(Father(John))
.
.
.
31
Predicate Logic
1/17/16
Existential instantiation (EI)
For any sentence , variable v, and constant
symbol k that does not appear elsewhere in
the knowledge base:
v
Subst({v/k}, )
E.g., x Crown(x) OnHead(x,John) yields:
Crown(C1) OnHead(C1,John)
provided C1 is a new constant symbol, called
a Skolem constant
32
Predicate Logic
1/17/16
FC: Example Knowledge Base
The law says that it is a crime for an American
to sell weapons to hostile nations. The country
Nono, an enemy America, has some missiles,
and all of its missiles were sold to it by Col.
West, who is an American.
Prove that Col. West is a criminal.
33
FC: Example Knowledge Base
it is a crime for an American to sell weapons to
hostile nations
34
FC: Example Knowledge Base
it is a crime for an American to sell weapons to
hostile nations
x ,y,z American(x) Weapon(y) Sells(x,y,z) Hostile(z)
Criminal(x)
35
FC: Example Knowledge Base
it is a crime for an American to sell weapons to
hostile nations
x ,y,z American(x) Weapon(y) Sells(x,y,z) Hostile(z)
Criminal(x)
Nonohas some missiles
36
FC: Example Knowledge Base
it is a crime for an American to sell weapons to
hostile nations
x ,y,z American(x) Weapon(y) Sells(x,y,z) Hostile(z)
Criminal(x)
Nonohas some missiles
x Owns(Nono, x) Missiles(x)
37
FC: Example Knowledge Base
it is a crime for an American to sell weapons to
hostile nations
x ,y,z American(x) Weapon(y) Sells(x,y,z) Hostile(z)
Criminal(x)
Nonohas some missiles
x Owns(Nono, x) Missiles(x)
all of its missiles were sold to it by Col. West
38
FC: Example Knowledge Base
it is a crime for an American to sell weapons to hostile
nations
x ,y,z American(x) Weapon(y) Sells(x,y,z) Hostile(z)
Criminal(x)
Nonohas some missiles
x Owns(Nono, x) Missiles(x)
Owns(Nono, M1) and Missle(M1)
all of its missiles were sold to it by Col. West
x Missile(x) Owns(Nono, x) Sells( West, x, Nono)
39
FC: Example Knowledge Base
it is a crime for an American to sell weapons to hostile nations
x ,y,z American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
Nonohas some missiles
x Owns(Nono, x) Missiles(x)
Owns(Nono, M1) and Missle(M1)
all of its missiles were sold to it by Col. West
x Missle(x) Owns(Nono, x) Sells( West, x, Nono)
Missiles are weapons
Missle(x) Weapon(x)
40
FC: Example Knowledge Base
An enemy of America counts as hostile
Enemy( x, America ) Hostile(x)
Col. West who is an American
American( Col. West )
The country Nono, an enemy of America
Enemy(Nono, America)
PROVE WEST IS CRIMINAL
41
Unification
We can get the inference immediately if we can find a substitution such that King(x) and
Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p q
Knows(John,x)
Knows(John,x)
Knows(John,x)
Knows(John,x)
Knows(John,Jane)
Knows(y,OJ)
Knows(y,Mother(y))
Knows(x,OJ)
{x/Jane}}
Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)
Unification
We can get the inference immediately if we can find a substitution such that King(x) and
Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p q
Knows(John,x)
Knows(John,x)
Knows(John,x)
Knows(John,x)
Knows(John,Jane) {x/Jane}}
Knows(y,OJ) {x/OJ,y/John}}
Knows(y,Mother(y))
Knows(x,OJ)
Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)
Unification
We can get the inference immediately if we can find a substitution such that King(x) and
Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p q
Knows(John,x)
Knows(John,x)
Knows(John,x)
Knows(John,x)
Knows(John,Jane) {x/Jane}}
Knows(y,OJ) {x/OJ,y/John}}
Knows(y,Mother(y))
{y/John,x/Mother(John)}}
Knows(x,OJ)
Standardizing apart eliminates overlap of variables, e.g., Knows(z17,OJ)
Unification
We can get the inference immediately if we can find a substitution such
that King(x) and Greedy(x) match King(John) and Greedy(y)
= {x/John,y/John} works
Unify(,) = if =
p q
Knows(John,x)
Knows(John,x)
Knows(John,Jane)
{x/Jane}}
Knows(y,OJ) {x/OJ,y/John}}
Knows(John,x)
Knows(John,x)
Knows(y,Mother(y))
Knows(x,OJ) {fail}
{y/John,x/Mother(John)}}
Unification
Examples
UNIFY(Knows(John,x), Knows(John,Jane)) = {x/Jane}
UNIFY(Knows(John,x), Knows(y,Bill)) = {x/Bill, y/John}
UNIFY(Knows(John,x), Knows(y,Mother(y))= {y/John, x/Mother(John)
UNIFY(Knows(John,x), Knows(x,Elizabeth)) = fail
Last example fails because x would have to be both John and Elizabeth
We can avoid this problem by standardizing:
The two statements now read
UNIFY(Knows(John,x), Knows(z,Elizabeth))
This is solvable:
UNIFY(Knows(John,x), Knows(z,Elizabeth)) = {x/Elizabeth,z/John}
Unification
To unify Knows(John,x) and Knows(y,z)
Can use = {y/John, x/z }
Or = {y/John, x/John, z/John}
The first unifier is more general than the
second.
There is a single most general unifier
(MGU) that is unique up to renaming of
variables.
MGU = { y/John, x/z }
Unification
Unification algorithm:
Recursively explore the two expressions side by
side
Build up a unifier along the way
Fail if two corresponding points do not match
FORWARD CHAINING
&
BACKWARD CHAINING
49
Predicate Logic
1/17/16
Forward Chaining
Forward Chaining
Idea:
Start with atomic sentences in the KB
Apply Modus Ponens
Add new atomic sentences until no further inferences
can be made
Works well for a KB consisting of Situation
Response clauses when processing newly arrived
data
Forward chaining proof
Forward chaining proof
Forward chaining proof
Backward Chaining
Idea:
Given a query, find all substitutions that satisfy
the query.
Algorithm:
Work on lists of goals, starting with original query
Algo finds every clause in the KB that unifies with the
positive literal (head) and adds remainder (body) to list
of goals
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
Backward chaining example
THANK YOU
63
Predicate Logic
1/17/16