ÇÙØÐ Ò - UNL CSE

'
&
B.Y. Choueiry
Title:
Logial Agents
AIMA: Chapter 7 (Setions 7.4 and 7.5)
1
Introdution to Artiial Intelligene
CSCE 476-876, Spring 2008
URL: www.se.unl.edu/houeiry/S08-476-876
Instrutor's notes #11
April 7, 2008
Berthe Y. Choueiry (Shu-we-ri)
houeiryse.unl.edu, (402)472-5444
$
%
2
•
Login in general: models and entailment
•
Propositional (Boolean) logi
•
Equivalene, validity and satisability
•
Inferene:
Instrutor's notes #11
April 7, 2008
'
&
B.Y. Choueiry
Outline
By model heking
Using inferene rules
Resolution algorithm: Conjuntive Normal form
Horn theories: forward and bakward haining
$
%
'
&
B.Y. Choueiry
A logi onsists of:
1. A formal representation system:
(a) Syntax: how to make sentenes
(b) Semantis: systematis onstraints on how sentenes relate
to the states of aairs
3
2. Proof theory: a set of rules for deduing the entailment of a set
of sentenes
Example:
Instrutor's notes #11
April 7, 2008
√
√
Propositional logi (or Boolean logi)
First-order logi FOL
$
%
'
&
B.Y. Choueiry
Models (I)
A model is a world in whih a sentene is true under a partiular
General denition
interpretation.
4
Logiians typially think in terms of models, whih are formally
strutured worlds with respet to whih truth an be evaluated
We say
m
is a model of a sentene
α
if
α
is true in
m
Instrutor's notes #11
April 7, 2008
Typially, a sentene an be true in many models
$
%
'
&
B.Y. Choueiry
Models (II)
M (α)
is the set of all models of
5
Entailment:
A sentene
α
α
is entailed by a KB if the models of the
KB are all models ofα
KB
|= α
i all models of KB are models of
Instrutor's notes #11
April 7, 2008
Then KB
|= α
if and only if
α
(i.e.,
M (KB) ⊆ M (α))
M (KB) ⊆ M (α)
$
%
• Example of inferene proedure: dedution
'
&
B.Y. Choueiry
Inferene
• Validity of a sentene: always true (i.e., under all possible
interpretations)
The Earth is round or not round
→ Tautology
6
• Satisability of a sentene: sometimes true (i.e., ∃ some
interpretation(s) where it holds)
Alex is on ampus
• Insatisability of a sentene: never true (i.e., 6 ∃ any interpretation
where it holds)
Instrutor's notes #11
April 7, 2008
The Earth is round and the earth is not round
→ useful for refutation, as we will see later
Beauty of inferene:
Formal inferene allows the omputer to derive valid onlusions even
when the omputer does not know the interpretation you are using
$
%
'
&
B.Y. Choueiry
Syntax of Propositional Logi
Propositional logi is the simplest logiillustrates basi ideas
•
Symbols represent whole propositions, sentenes
D says the Wumpus is dead
7
The proposition symbols
•
Boolean onnetives:
onnet sentenes
P1 , P2 ,
∧, ∨, ¬, ⇒
et. are sentenes
(alternatively,
→, ⊃), ⇔,
S1 and S2 are sentenes, the following are sentenes
¬S1 , ¬S2 , S1 ∧ S2 , S1 ∨ S2 , S1 ⇒ S2 , S1 ⇔ S2
If
Instrutor's notes #11
April 7, 2008
Formal grammar of Propositional Logi:
too:
Bakus-Naur Form,
hek Figure 7.7 page 205 in AIMA
$
%
'
&
B.Y. Choueiry
Terminology
Atomi sentene:
single symbol
Complex sentene:
Literal:
ontains onnetives, parentheses
atomi sentene or its negation (e.g.,
Sentene (P ∧ Q) ⇒ R
P , ¬Q)
is an impliation, onditional, rule, if-then
8
statement
(P ∧ Q) is a premise, anteedent
R is a onlusion, onsequene
Instrutor's notes #11
April 7, 2008
Sentene (P ∧ Q) ⇔ R
Preedene order
is an equivalene, bionditional
resolves ambiguity (highest to lowest):
¬, ∧, ∨, ⇒, ⇔
E.g., ((¬P ) ∨ (Q ∧ R)) ⇒ S
A⇒B⇒C
Careful:
A∧B∧C
and
$
%
'
&
B.Y. Choueiry
Syntax of First-order logi
(Chapter 8)
First-Order Logi (FOL) is expressive enough to say almost
anything of interest and has a sound and omplete inferene
proedure
•
9
Instrutor's notes #11
April 7, 2008
•
Logial symbols:
parentheses
onnetives (¬, ⇒, the rest an be regenerated)
variables
equality symbol (optional)
Parameters:
quantier
∀
prediate symbols
onstant symbols
funtion symbols
$
%
'
&
B.Y. Choueiry
Semantis of Propositional Logi
Semantis is dened by speifying:
Interpretation of a proposition symbols and onstants (T/F)
Meaning of logial onnetives
Proposition symbol means what ever you want:
10
D says the Wumpus is dead
Breeze says the agent is feeling a breeze
Stenh says the agent is pereiving an unpleasant smell
Connetives are funtions: omplex sentenes meaning derived
from the meaning of its parts
Instrutor's notes #11
April 7, 2008
P
Q
:P
False
False
True
True
False
True
False
True
True
True
False
False
P
^Q
False
False
False
True
P
_Q
False
True
True
True
P
)Q
True
True
False
True
P
,Q
True
False
False
True
Note:
if P is true, Q is true, otherwise I am making no laim
$
%
P ⇒ Q:
'
&
B.Y. Choueiry
Models in propositional logi
Careful!
11
•
A model is a mapping from proposition symbols diretly to
•
The models of a sentene are the mappings that make the
truth or falsehood
sentene true
Example:
α:
Instrutor's notes #11
April 7, 2008
√
Model1:
×
Model2:
obj1 ∧ obj2
obj1 = 1 and obj2 =1
obj1 = 0 and obj2 =1
$
%
Pi,j :
Bi,j :
there is a pit in [i, j ℄
'
&
B.Y. Choueiry
Wumpus world in Propositional Logi
there is a breeze in [i, j ℄
• R1 : ¬P1,1
•
Pits ause breezes in adjaent squares
12
R2 : B1,1 ⇔ (P1,2 ∨ P2,1 )
R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1 )
Instrutor's notes #11
April 7, 2008
•
Perepts:
•
KB:
•
Questions: KB
R4 : ¬B1,1
R5 : B2,1
R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5
|= ¬P1,2 ?
KB
6|= P2,2 ?
$
%
'
&
B.Y. Choueiry
Wumpus world in Propositional Logi
Given KB:
R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5
Number of symbols: 7
Number of models: 2
7
=128
13
<See Figure 7.9, page 209>
KB is true in only 3 models
P1,2
is false but
Instrutor's notes #11
April 7, 2008
thus KB
P2,2
¬P1,2
holds in all 3 models of the KB,
|= ¬P1,2
is true in 2 models, false in third, thus KB
6|= P2,2
$
%
'
&
B.Y. Choueiry
Enumeration method in Propositional Logi
Let
α=A∨B
and
KB = (A ∨ C) ∧ (B ∨ ¬C)
Is it the ase that KB
|= α?
Chek all possible modelsα must be true wherever
14
Instrutor's notes #11
April 7, 2008
A
B
C
F
F
F
F
F
T
F
T
F
F
T
T
T
F
F
T
F
T
T
T
F
T
T
T
A∨C
B ∨ ¬C
KB
KB
is true
α
Complexity? Inferene is exponential in propositional logi
$
%
'
&
B.Y. Choueiry
Inferene by enumeration
•
Algorithm: TT-Entails?(KB,
α),
Figure 209
Identies all the symbols in kb
Performs a reursive enumeration of all possible assignments
(T/F) to symbols
15
In a depth-rst manner
Instrutor's notes #11
April 7, 2008
•
It terminates: there is only a nite number of models
•
It is sound: beause it implements denition of entailment
•
It is omplete, and works for any KB and
•
Time omplexity:
•
Alert: Entailment in Propositional Logi is o-NP-Complete
O(2n ),
for a KB with
n
α
symbols
$
%
'
&
B.Y. Choueiry
Important onepts
16
•
Logial equivalene
•
Validity
•
Dedution theorem: links validity to entailment
Satisability
Instrutor's notes #11
April 7, 2008
Refutation theorem: links satisability to entailment
$
%
Two sentenes are logially equivalent
models
α≡β
α |= β
if and only if
and
α⇔β
i true in same
'
&
B.Y. Choueiry
Logial equivalene
β |= α
17
Instrutor's notes #11
April 7, 2008
(α ∧ β)
≡
(β ∧ α)
ommutativity of
∧
(α ∨ β)
≡
(β ∨ α)
ommutativity of
∨
((α ∧ β) ∧ γ)
≡
(α ∧ (β ∧ γ))
assoiativity of
∧
((α ∨ β) ∨ γ)
≡
(α ∨ (β ∨ γ))
assoiativity of
∨
¬(¬α)
≡
α
(α =⇒ β)
≡
(¬β =⇒ ¬α)
(α =⇒ β)
≡
(¬α ∨ β)
(α ⇔ β)
≡
((α =⇒ β) ∧ (β =⇒ α))
¬(α ∧ β)
≡
(¬α ∨ ¬β)
de Morgan
de Morgan
double-negation elimination
ontraposition
impliation elimination
bionditional elimination
¬(α ∨ β)
≡
(¬α ∧ ¬β)
(α ∧ (β ∨ γ))
≡
((α ∧ β) ∨ (α ∧ γ))
distributivity of
∧
over
∨
(α ∨ (β ∧ γ))
≡
((α ∨ β) ∧ (α ∨ γ))
distributivity of
∨
over
∧
$
%
'
&
B.Y. Choueiry
Validity
A sentene is valid if it is true in all models
e.g.,
P ∨ ¬P ,
P ⇒ P,
(P ∧ (P ⇒ H)) ⇒ H
To establish validity, use truth tables:
18
P
H
False
False
True
True
False
True
False
True
P
_H
(P
_ H) ^:H
False
True
True
True
If every row is true, then he onlusion,
premises,
((P
_ H) ^ :H) ) P
False
False
True
False
P,
True
True
True
True
is entailed by the
((P ∨ H) ∧ ¬H)
Instrutor's notes #11
April 7, 2008
Use of validity: Dedution Theorem:
⇒ α)
TT-Entails?(KB, α)
KB
|= α
i (KB
is valid
heks the validity of (KB
⇒ α)
$
%
'
&
B.Y. Choueiry
Satisability
A sentene is satisable if it is true in some model
e.g.,
A ∨ B,
C
Satisability an be heked by enumerating the possible models
until one is found that satises the sentene (e.g., SAT!)
19
A sentene is unsatisable if it is true in no models
e.g.,
A ∧ ¬A
Satisability and validity are onneted:
Instrutor's notes #11
April 7, 2008
α
valid i
¬α
is unsatisable and
α
satisable i
¬α
is not valid
Use of satisability: refutation
KB
|= α
i.e., prove
i (KB
α
∧¬α)
is unsatisable
by redutio ad absurdum
$
%
Proof methods divide into (roughly) two kinds
'
&
B.Y. Choueiry
Proof methods
Model heking
•
Truth-table enumeration (sound & omplete but exponential)
•
Baktrak searh in model spae (sound & omplete)
20
•
e.g., Davis-Putnam Algorithm (DPLL) (Setion 7.6)
Heuristi searh in model spae (sound but inomplete)
e.g., the GSAT algorithm, the WalkSat algorithm (Setion 7.6)
Appliation of inferene rules
Instrutor's notes #11
April 7, 2008
•
Legitimate (sound) generation of new sentenes from old
•
Proof = a sequene of inferene rule appliations, an use
•
inferene rules as operators in a standard searh algorithm
Typially require translation of sentenes into a normal form
$
%
'
&
B.Y. Choueiry
Inferene rules for Propositional Logi (I)
Reasoning patterns
•
Modus Ponens (Impliation-Elimination)
α ⇒ β, α
β
21
Instrutor's notes #11
April 7, 2008
•
And-Elimination
•
We an also use all logial equivalenes as inferene rules:
α1 ∧ α2 ∧ . . . ∧ αn
αi
(α⇒β)∧(β⇒α)
α⇔β
(α⇒β)∧(β⇒α) and
α⇔β
Soundness of an inferene
rule an be veried by building a truth
table
$
%
Given KB:
Prove:
R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5
'
&
B.Y. Choueiry
Inferene rules and equivalenes in the wumpus world
¬P1,2
R2 : B1,1 ⇔ (P1,2 ∨ P2,1 )
⇒ (P1,2 ∨ P2,1 )) ∧ ((P1,2 ∨ P2,1 ) ⇒ B1,1 )
22
Instrutor's notes #11
April 7, 2008
•
Bionditional elimination to
•
And elimination to
•
Logial equivalene of ontrapositives:
•
Modus ponens on
•
De Morgan's rules:
R6 : (B1,1
R6 :
R7 : ((P1,2 ∨ P2,1 ) ⇒ B1,1 )
R8 : (¬B1,1 ⇒ ¬(P1,2 ∨ P2,1 ))
R8
R9 : ¬(P1,2 ∨ P2,1 )
and
R4 : ¬B1,1
R10 : ¬P1,2 ∧ ¬P2,1
$
%
'
&
B.Y. Choueiry
The job of an inferene proedure is to onstrut proofs by
nding appropriate sequenes of appliations of inferene rules
23
starting with sentenes initially in KB
and ulminating in the generation of the sentene
whose proof is desired
Instrutor's notes #11
April 7, 2008
$
%
'
&
B.Y. Choueiry
Complexity of propositional inferene
Truth-table:
n
2
Sound and omplete.
rows: exponential, thus impratial
24
Entailment is o-NP-Complete in Propositional Logi
Inferene rules:
sound (resolution gives ompleteness)
NP-omplete in general
However, we an fous on the sentenes and propositions of
Instrutor's notes #11
April 7, 2008
interest: The truth values of all propositions need not be
onsidered
$
%
'
&
B.Y. Choueiry
Monotoniity
the set of entailed sentenes an only inrease as information (new
sentenes) is added to the KB:
if KB
|= α
then (KB∧β )|=
α
25
Monotoniity allows us to apply inferene rules whenever suitable
premises appear in the KB: the onlusion of the rule follow
regardless of what else is in the KB
Instrutor's notes #11
April 7, 2008
PL, FOL are monotoni, probability theory is not
Monotoniity essential for soundness of inferene
$
%
•
Unit resolution:
l1 ∨ l2 , ¬l2
l1
'
&
B.Y. Choueiry
Resolution for ompleteness of inferene rules
More generally:
26
l1 ∨ · · · ∨ lk , m
l1 ∨ · · · ∨ li−1 ∨ li+1 ∨ · · · ∨ lk
where li and
•
m
Resolution:
Instrutor's notes #11
April 7, 2008
More generally:
are omplementary literals
l1 ∨ l2 , ¬l2 ∨ l3
l1 ∨ l3
l1 ∨ · · · ∨ lk , m1 ∨ · · · ∨ mn
l1 ∨ · · · ∨ li−1 ∨ li+1 ∨ · · · ∨ lk ∨ m1 ∨ · · · ∨ mj−1 ∨ mj+1 ∨ · · · ∨ mn
where li and
mj
are omplementary literals
$
%
'
&
B.Y. Choueiry
Resolution in the wumpus world
Agent goes [1, 1℄, [2, 1℄, [1, 1℄, [1, 2℄
Agent pereives a stenh but no breeze:
But
R12 : B1,2 ⇔ (P1,1 ∨ P2,2 ∨ P1,3
Applying bionditional elimination to
R11 : ¬B1,2
R12 ,
followed by
and-elimination, ontraposition, and nally modus ponens with
27
R11 , we get:
R13 : ¬P2,2 and R14 : ¬P1,3
R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1 )
R5 : B2,1
Now, applying bionditional elimination too
R3
and modus ponens
Instrutor's notes #11
April 7, 2008
R5 , we get:
R15 : P1,1 ∨ P2,2 ∨ P3,1
Resolving R13 and R15 : R16 : P1,1 ∨ P3,1
Resolving R16 and R1 : R17 : P3,1
with
$
%
'
&
B.Y. Choueiry
Soundness of the resolution rule
Resolution rule:
α∨β, ¬β∨γ
¬α⇒β, β⇒γ
or equivalently
α∨γ
¬α⇒γ
28
Instrutor's notes #11
April 7, 2008
_
: _ _
False
False
False
False
True
True
True
True
False
False
True
True
False
False
True
True
False
True
False
True
False
True
False
True
False
False
True
True
True
True
True
True
True
True
False
True
True
True
False
True
False
True
False
True
True
True
True
True
$
%
•
•
Inferene rules an be used as suessor funtions in a
'
&
B.Y. Choueiry
Resolution for ompleteness of inferene rules
searh-based agent
Any omplete searh algorithm, applying only the resolution
rule, an derive any onlusion entailed by any knowledge base
in propositional logi.
29
•
Refutation ompleteness:
Resolution an always be used to either prove or refute a
sentene
Instrutor's notes #11
April 7, 2008
−→
•
Resolution algorithm on CNF
Caveat:
Resolution annot be used to enumerate true sentenes.
Given
A
is true, resolution annot generate
A∨B
$
%
•
Resolution applies only to disjuntions of literals
•
We an transform any sentene in PL in CNF
•
A
'
&
B.Y. Choueiry
Conjuntive Normal Form
k -CNF has exatly k literals per lause:
(l1,1 ∨ · · · ∨ l1,k ) ∧ · · · ∧ (ln,1 ∨ · · · ∨ ln,k )
Conversion proedure:
30
Instrutor's notes #11
April 7, 2008
•
Eliminate
⇔
using bionditional elimination
•
Eliminate
⇒
using impliation elimination
•
Move
•
¬
inwards using (repeatedly) double-negation elimination
and de Morgan rules
Apply distributivity law, distributing
possible
∨
over
∧
whenever
Finally, the KB an be used as input to a resolution proedure
$
%
'
&
B.Y. Choueiry
Example of onversion to CNF
R2 : B1,1 ⇔ (P1,2 ∨ P2,1 )
⇒ using bionditional elimination
⇒ (P1,2 ∨ P2,1 )) ∧ ((P1,2 ∨ P2,1 ) ⇒ B1,1 )
31
•
Eliminate
•
Eliminate
•
Move
(B1,1
⇒ using impliation elimination
(¬B1,1 ∨ (P1,2 ∨ P2,1 )) ∧ (¬(P1,2 ∨ P2,1 ) ∨ B1,1 )
¬
inwards using (repeatedly) double-negation elimination
and de Morgan rules
Instrutor's notes #11
April 7, 2008
(¬B1,1 ∨ (P1,2 ∨ P2,1 )) ∧ (¬P1,2 ∧ ¬P2,1 ) ∨ B1,1 )
•
∨ over ∧ whenever
(¬B1,1 ∨ P1,2 ∨ P2,1 ) ∧ (¬P1,2 ∨ B1,1 ) ∧ (¬P2,1 ∨ B1,1 )
Apply distributivity law, distributing
possible
$
%
'
&
B.Y. Choueiry
Resolution algorithm
•
KB
|= α
•
(KB
i (KB
∧¬α)
∧¬α)
is unsatisable
is onverted to CNF
then we apply resolution rule repeatedly, until:
32
- no lause an be added (i.e., KB
- we derive the empty lause (i.e.,
<PL-Resolution(KB,
Instrutor's notes #11
April 7, 2008
•
α),
|= ¬α)
KB |= α)
Fig 7.12, page 216>
Ground resolution theorem:
If a set of lauses is unsatisable, then the resolution losure of
those lauses ontains the empty lause.
$
%