First Order Logic for Agents

First Order
Logic for
Agents
First Order Logic for Agents
Summary
First Order
Logic for
Agents
♦
♦
♦
FOL
Wumpus world in FOL
Situation calculus
Pros and cons of propositional logic
First Order
Logic for
Agents
Propositional logic is declarative: pieces of syntax
correspond to facts
Propositional logic allows partial/disjunctive/negated
information
(unlike most data structures and databases)
Propositional logic is compositional:
meaning of
P1,2
B1,1 ∧ P1,2
is derived from meaning of
B1,1
and of
Meaning in propositional logic is context-independent
(unlike natural language, where meaning depends on context)
Propositional logic has very limited expressive power
(unlike natural language)
E.g., cannot say pits cause breezes in adjacent squares
except by writing one sentence for each square
Components of First Order Logic
First Order
Logic for
Agents
Objects, Relations, Functions
Whereas propositional logic assumes world contains facts,
rst-order logic (like natural language) assumes the world contains: Objects, Relations, Functions.
Objects: people, houses, numbers, theories, colors, football
games, wars, centuries
···
Relations: red, round, multistoried
···,
brother of, bigger than, inside, part of, has color, occurred
after, owns, comes between,
···
Functions: father of, best friend, second half of, one more
than, beginning of
···
The Language: Logical Symbols
First Order
Logic for
Agents
Logical Symbols
A rst order language
L
is built upon the following sets of sym-
bols:
¬,∧,∨
=⇒ and ⇐⇒ );
propositional connectives:
(plus the shortcuts
propositional constants
>
and
⊥
(represent True and False respectively);
equality
=
(not always included);
a denumerable set of individual variable symbols:
x1 , x2 , · · · ;
universal quantication
∀;
existentional quantication
∃;
Denition of FOL Formulas
First Order
Logic for
Agents
FOL formulas
Inductive denition of basic components
1 Terms
E.g.,
c , x , f (x , y ), f (g (c ), y ), plus (plus (x , 1), 3), . . .
2 Atomic Formulas
E.g.,
P (x ), Q (x , c ), R (x , f (x , y + c )), · · ·
First Order Formulas
First Order
Logic for
Agents
Well-Formed Formulas
The set of formulae of
L
is inductively dened as follows:
Every atom is a formula;
A is a formula ¬A is a formula;
If ◦ is a binary operator, A and B
If
are formulas, then
A◦B
is a formula;
A is a formula, x
∃xA are formulas
If
is a free variable in
A then ∀xA and
All formulas are generated by a nite number of
applications of the above rules.
Example (FOL Formulas)
P (x ), ∃xQ (x , c ), ∀xR (x , f (x , y + c )), · · ·
Interpretations in FOL
First Order
Logic for
Agents
In Prop. Logic an Interpretation for a formula
G
is an
assignment of truth values to each atoms occuring in the
formula
In FOL we have to do more than that:
1 Specify a domain of interest (e.g., real numbers)
2 An assignment to constants, function symbols and
predicate symbols
Example (Interpretation)
Consider the set of formulas:
{∀xP (x ), ∃xQ (x )};
An interpretation will need to specify a domain, e.g.
D = {1, 2}
and an assignment for all predicate symbol from D to the set
{T , F }, for example {P (1) = T , P (2) = F }
{Q (1) = F , Q (2) = T }.
and
Interpretation: Example
First Order
Logic for
Agents
Example (Interpretation)
∀x ∃yP (x , y )
D , the set of human beings
P A (a, b) = true i b is father of a
All human beings have a father
D , the set of human beings
0
P A (a, b) = true i b is mother of a
All human beings have a mother
D the set of natural numbers
00
P A (a, b) = true i a < b
For every nat number there is a greater one
Evaluation of FOL formulas
First Order
Logic for
Agents
Given an interpretation
I = hD , Ai,
FOL formulas are evaluated
to true or false according to the following rules:
S is an atomic formula and S , P (t1 , · · · , tn ), S is true
A A
A
i P (t1 , · · · , tn ) = >
If S is an atomic formula and S , t1 = t2 , S is true i
t1A = t2A .
If S is a formula evaluated to true then ¬S is false.
If S and T are two formulas then S ∧ T is true i A and
T are true.
If S and T are two formulas then S ∨ T is true i A or T
If
are true
S , ∀xG
If S , ∃xG
d ∈ D.
If
G
is true i G
is true i
is true for every element
d ∈ D.
is true for at least one element
Examples of FOL formula evaluation
First Order
Logic for
Agents
Example (Example of evaluation)
G , ∀x ∃yP (x , y )
I for G
D = 1, 2 and P A (x , y ) = true i x < y
To evaluate G we have to evaluate for each element d ∈ D the
formula H , ∃yP (d , y ).
x = 1 we have to check whether there is at least one
0
A
0
element d ∈ D such that P (1, d ) holds, i.e. such that
0
1 < d . We observe that 1 < 2 holds, thus for x = 1 the
formula H is true.
x = 2 however H is false.
Thus G is false under I
Interpretation
Models, validity, satisability
First Order
Logic for
Agents
Given the notion of interpretion, the concepts of model, validity
and satisability can be dened as for propositional logic.
Denition (Model)
An interpretation
under
I.
I
We write
is a model for
I |= G .
G
i
G
is evaluated to true
Denition (Validity)
A formula
G
is valid i it is evaluated to true under all its
interpretations. We write
|= G
Denition (Inconsistency)
A formula
G
is inconsistent i it is evaluated to false under all
its interpretations
Logical consequence
First Order
Logic for
Agents
Denition (Logical consequence)
A formula
G
is a logical consequence of formulas
i for every interpretation
I |= G .
I
if
I |= F1 ∧ · · · ∧ Fn
{F1 , · · · , Fn }
we have that
The following theorems hold also for First Order Logic
Theorem (Deduction Theorem)
Given a set of formulas {F1 , · · · , Fn } and a formula G,
F1 ∧ · · · ∧ Fn |= G i |= F1 ∧ · · · ∧ Fn =⇒ G
Theorem (Proof by Refutation)
Given a set of formulas {F1 , · · · , Fn } and a formula G,
|= F1 ∧ · · · ∧ Fn =⇒ G i F1 ∧ · · · ∧ Fn ∧ ¬G is inconsistent.
A common mistake to avoid
First Order
Logic for
Agents
Typically,
=⇒
is the main connective with
Common mistake: using
∧
∀
as the main connective with
∀ x At (x , Berkeley ) =⇒ Smart (x )
means Everyone that is at Berkeley is smart
∀ x At (x , Berkeley ) ∧ Smart (x )
means Everyone is at Berkeley and everyone is smart
∀:
Another common mistake to avoid
First Order
Logic for
Agents
Typically,
∧
is the main connective with
Common mistake: using
=⇒
∃
as the main connective with
∃ x At (x , Stanford ) ∧ Smart (x )
is true if there is someone at standford that is smart
∃ x At (x , Stanford ) =⇒ Smart (x )
is true if there is anyone who is not at Stanford!
Properties of quantiers
First Order
Logic for
Agents
∀x
∃x
∃x
∃x
∀ y is the same as ∀ y ∀ x (why??)
∃ y is the same as ∃ y ∃ x (why??)
∀ y is not the same as ∀ y ∃ 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
Quantier duality: each can be expressed using the other
∀ x Likes (x , IceCream)
∃ x Likes (x , Broccoli )
¬∃ x ¬Likes (x , IceCream)
¬∀ x ¬Likes (x , Broccoli )
∃:
Interacting with FOL KBs
First Order
Logic for
Agents
Suppose a wumpus-world agent is using an FOL KB
and perceives a smell and a breeze (but no glitter) at
t = 5:
Tell (KB , Percept ([Smell , Breeze , None ], 5))
Ask (KB , ∃ a Action(a, 5))
I.e., does KB entail any particular actions at t = 5?
Answer: Yes , {a/Shoot }
← substitution (binding list)
Given a sentence S and a substitution σ ,
S σ denotes the result of plugging σ into S ; e.g.,
S = Smarter (x , y )
σ = {x /Hillary , y /Bill }
S σ = Smarter (Hillary , Bill )
Ask (KB , S ) returns some/all σ such that KB |= S σ
Knowledge base for the wumpus world
First Order
Logic for
Agents
Perception and Actions
Perception
∀ b, g , t Percept ([Smell , b, g ], t ) =⇒ Smelt (t )
∀ s , b, t Percept ([s , b, Glitter ], t ) =⇒ AtGold (t )
Reex: ∀ t AtGold (t ) =⇒ Action (Grab , t )
Reex with internal state: do we have the gold already?
∀ t AtGold (t ) ∧ ¬Holding (Gold , t ) =⇒ Action(Grab, t )
Holding (Gold , t ) cannot be observed
⇒ keeping track of changes is essential
Deducing hidden properties I
First Order
Logic for
Agents
Properties of the world
Properties of locations (based on perception):
∀ x , t At (Agent , x , t ) ∧ Smelt (t ) =⇒ Smelly (x )
∀ x , t At (Agent , x , t ) ∧ Breeze (t ) =⇒ Breezy (x )
Deducing hidden properties II
First Order
Logic for
Agents
Properties of locations (based on environment rules):
E.g., Squares are breezy near a pit:
Diagnostic ruleinfer cause from eect
∀ y Breezy (y ) =⇒ ∃ x Pit (x ) ∧ Adjacent (x , y )
Causal ruleinfer eect from cause
∀ x , y Pit (x ) ∧ Adjacent (x , y ) =⇒ Breezy (y )
Neither of these is completee.g., the causal rule doesn't say
whether squares far away from pits can be breezy
Denition for the
Breezy
predicate:
∀ y Breezy (y ) ⇔ [∃ x Pit (x ) ∧ Adjacent (x , y )]
Keeping track of changes
First Order
Logic for
Agents
Facts hold in situations, rather than eternally
E.g.,
Holding (Gold , Now ) rather than just Holding (Gold )
Situation calculus is one way to represent changes in FOL:
Adds a situation argument to each non-eternal predicate
Holding (Gold , Now ) denotes a situation
Situations are connected by the Result function
Result (a, s ) is the situation that results from doing a in s
E.g.,
Now
in
Describing actions I
First Order
Logic for
Agents
Eect axiomdescribe changes due to action
∀ s AtGold (s ) =⇒ Holding (Gold , Result (Grab, s ))
Frame axiomdescribe non-changes due to action
∀ s HaveArrow (s ) =⇒ HaveArrow (Result (Grab, s ))
Frame problem: nd an elegant way to handle non-change
(a) representationavoid frame axioms
(b) inferenceavoid repeated copy-overs to keep track of
state
Qualication problem: true descriptions of real actions require
endless caveatswhat if gold is slippery or nailed down or
...
Ramication problem: real actions have many secondary
consequenceswhat about the dust on the gold, wear and tear
on gloves,
...
Describing actions II
First Order
Logic for
Agents
Successor-state axioms solve the representational frame problem
Each axiom is about a predicate (not an action per se):
P true afterwards
⇔
[an
∨
P true already and no action
action made P true
made P false]
For holding the gold:
∀ a, s Holding (Gold , Result (a, s )) ⇔
[(a = Grab ∧ AtGold (s ))
∨ (Holding (Gold , s ) ∧ a 6= Release )]
Making plans
First Order
Logic for
Agents
Initial condition in KB:
At (Agent , [1, 1], S0 )
At (Gold , [1, 2], S0 )
Query: Ask (KB , ∃ s Holding (Gold , s ))
i.e., in what situation will I be holding the gold?
Answer:
{s /Result (Grab, Result (Forward , S0 ))}
i.e., go forward and then grab the gold
This assumes that the agent is interested in plans starting at
and that
S0
is the only situation described in the KB
S0
Making plans: A better way
First Order
Logic for
Agents
Represent plans as action sequences
[a1 , a2 , . . . , an ]
PlanResult (p , s ) is the result of executing p in s
Then the query Ask (KB , ∃ p Holding (Gold , PlanResult (p , S0 )))
has the solution {p /[Forward , Grab ]}
Denition of PlanResult in terms of Result :
∀ s PlanResult ([ ], s ) = s
∀ a, p , s PlanResult ([a|p ], s ) = PlanResult (p , Result (a, s ))
Planning systems are special-purpose reasoners designed to do
this type of inference more eciently than a general-purpose
reasoner
Summary
First Order
Logic for
Agents
First-order logic:
objects and relations are semantic primitives
syntax: constants, functions, predicates, equality, quantiers
Increased expressive power: sucient to dene wumpus world
Situation calculus:
conventions for describing actions and change in FOL
can formulate planning as inference on a situation calculus
KB