0% found this document useful (0 votes)
23 views

Cps170 Logic

1) The document discusses propositional logic and its use in artificial intelligence to represent knowledge and draw logical conclusions. 2) It provides an example of using propositional logic to represent a scenario where a roommate comes home wet, and logically concluding that the sprinklers must be on. 3) The key aspects of propositional logic covered include syntax, semantics, inference, translating knowledge into conjunctive normal form, and using resolution to perform logical inference.

Uploaded by

anand_sesham
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
23 views

Cps170 Logic

1) The document discusses propositional logic and its use in artificial intelligence to represent knowledge and draw logical conclusions. 2) It provides an example of using propositional logic to represent a scenario where a roommate comes home wet, and logically concluding that the sprinklers must be on. 3) The key aspects of propositional logic covered include syntax, semantics, inference, translating knowledge into conjunctive normal form, and using resolution to perform logical inference.

Uploaded by

anand_sesham
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 29

CPS 170: Artificial Intelligence

http://www.cs.duke.edu/courses/spring09/cps170/

Propositional Logic

Instructor: Vincent Conitzer


Logic and AI
• Would like our AI to have knowledge about
the world, and logically draw conclusions
from it
• Search algorithms generate successors and
evaluate them, but do not “understand” much
about the setting
• Example question: is it possible for a chess
player to have 8 pawns and 2 queens?
– Search algorithm could search through tons of
states to see if this ever happens, but…
A story
• You roommate comes home; he/she is completely wet
• You know the following things:
– Your roommate is wet
– If your roommate is wet, it is because of rain, sprinklers, or both
– If your roommate is wet because of sprinklers, the sprinklers must be on
– If your roommate is wet because of rain, your roommate must not be carrying
the umbrella
– The umbrella is not in the umbrella holder
– If the umbrella is not in the umbrella holder, either you must be carrying the
umbrella, or your roommate must be carrying the umbrella
– You are not carrying the umbrella

• Can you conclude that the sprinklers are on?


• Can AI conclude that the sprinklers are on?
Knowledge base for the story
• RoommateWet
• RoommateWet => (RoommateWetBecauseOfRain
V RoommateWetBecauseOfSprinklers)
• RoommateWetBecauseOfSprinklers =>
SprinklersOn
• RoommateWetBecauseOfRain =>
¬(RoommateCarryingUmbrella)
• UmbrellaGone
• UmbrellaGone => (YouCarryingUmbrella V
RoommateCarryingUmbrella)
• ¬(YouCarryingUmbrella)
Syntax
• What do well-formed sentences in the
knowledge base look like?
• A BNF grammar:
• Symbol → P, Q, R, …, RoommateWet, …
• Sentence → True | False | Symbol |
¬(Sentence) | (Sentence  Sentence) |
(Sentence V Sentence) | (Sentence =>
Sentence)
• We will drop parentheses sometimes, but
formally they really should always be there
Semantics
• A model specifies which of the proposition
symbols are true and which are false
• Given a model, I should be able to tell you
whether a sentence is true or false
• Truth table defines semantics of operators:
a b ¬(a) a b aVb a => b

false false true false false true

false true true false true true

true false false false true false

true true false true true true


• Given a model, can compute truth of sentence
recursively with these
Caveats
• TwoIsAnEvenNumber V
ThreeIsAnOddNumber
is true (not exclusive V)
• TwoIsAnOddNumber =>
ThreeIsAnEvenNumber
is true (if the left side is false it’s always true)
All of this is assuming those symbols are assigned their
natural values…
Tautologies
• A sentence is a tautology if it is true for any
setting of its propositional symbols
P Q PVQ ¬(P)  ¬(Q) (P V Q) V
(¬(P) 
¬(Q))
false false false true true

false true true false true

true false true false true

true true true false true

• (P V Q) V (¬(P)  ¬(Q)) is a tautology


Is this a tautology?
• (P => Q) V (Q => P)
Logical equivalences
• Two sentences are logically equivalent if they
have the same truth value for every setting of
their propositional variables
P Q PVQ ¬(¬(P)  ¬(Q))

false false false false

false true true true

true false true true

true true true true

• P V Q and ¬(¬(P)  ¬(Q)) are logically equivalent


• Tautology = logically equivalent to True
Famous logical equivalences
• (a V b) ≡ (b V a) commutatitvity
• (a  b) ≡ (b  a) commutatitvity
• ((a  b)  c) ≡ (a  (b  c)) associativity
• ((a V b) V c) ≡ (a V (b V c)) associativity
• ¬(¬(a)) ≡ a double-negation elimination
• (a => b) ≡ (¬(b) => ¬(a)) contraposition
• (a => b) ≡ (¬(a) V b) implication elimination
• ¬(a  b) ≡ (¬(a) V ¬(b)) De Morgan
• ¬(a V b) ≡ (¬(a)  ¬(b)) De Morgan
• (a  (b V c)) ≡ ((a  b) V (a  c)) distributitivity

• (a V (b  c)) ≡ ((a V b)  (a V c)) distributitivity


Inference
• We have a knowledge base of things that we know are
true
– RoommateWetBecauseOfSprinklers
– RoommateWetBecauseOfSprinklers => SprinklersOn
• Can we conclude that SprinklersOn?
• We say SprinklersOn is entailed by the knowledge base if,
for every setting of the propositional variables for which
the knowledge base is true, SprinklersOn is also true
RWBOS SprinklersOn Knowledge base
false false false
false true false
true false false
true true true
• SprinklersOn is entailed!
Simple algorithm for inference
• Want to find out if sentence a is entailed by knowledge
base…
• For every possible setting of the propositional variables,
– If knowledge base is true and a is false, return false
• Return true
• Not very efficient: 2#propositional variables settings
Inconsistent knowledge bases
• Suppose we were careless in how we specified our
knowledge base:
• PetOfRoommateIsABird => PetOfRoommateCanFly
• PetOfRoommateIsAPenguin => PetOfRoommateIsABird
• PetOfRoommateIsAPenguin => ¬(PetOfRoommateCanFly)
• PetOfRoommateIsAPenguin
• No setting of the propositional variables makes all of these
true
• Therefore, technically, this knowledge base implies anything
• TheMoonIsMadeOfCheese
Reasoning patterns
• Obtain new sentences directly from some
other sentences in knowledge base according
to reasoning patterns
• If we have sentences a and a => b , we can
correctly conclude the new sentence b
– This is called modus ponens
• If we have a  b , we can correctly conclude
a
• All of the logical equivalences from before
also give reasoning patterns
Formal proof that the sprinklers are on
1) RoommateWet
2) RoommateWet => (RoommateWetBecauseOfRain V RoommateWetBecauseOfSprinklers)
3) RoommateWetBecauseOfSprinklers => SprinklersOn
4) RoommateWetBecauseOfRain => ¬(RoommateCarryingUmbrella)
5) UmbrellaGone
6) UmbrellaGone => (YouCarryingUmbrella V RoommateCarryingUmbrella)
7) ¬(YouCarryingUmbrella)
8) YouCarryingUmbrella V RoommateCarryingUmbrella (modus ponens on 5 and 6)
9) ¬(YouCarryingUmbrella) => RoommateCarryingUmbrella (equivalent to 8)
10) RoommateCarryingUmbrella (modus ponens on 7 and 9)
11) ¬(¬(RoommateCarryingUmbrella) (equivalent to 10)
12) ¬(¬(RoommateCarryingUmbrella)) => ¬(RoommateWetBecauseOfRain) (equivalent to 4 by
contraposition)
13) ¬(RoommateWetBecauseOfRain) (modus ponens on 11 and 12)
14) RoommateWetBecauseOfRain V RoommateWetBecauseOfSprinklers (modus ponens on 1 and
2)
15) ¬(RoommateWetBecauseOfRain) => RoommateWetBecauseOfSprinklers (equivalent to 14)
16) RoommateWetBecauseOfSprinklers (modus ponens on 13 and 15)
17) SprinklersOn (modus ponens on 16 and 3)
Reasoning about penguins
1) PetOfRoommateIsABird => PetOfRoommateCanFly
2) PetOfRoommateIsAPenguin => PetOfRoommateIsABird
3) PetOfRoommateIsAPenguin => ¬(PetOfRoommateCanFly)
4) PetOfRoommateIsAPenguin
5) PetOfRoommateIsABird (modus ponens on 4 and 2)
6) PetOfRoommateCanFly (modus ponens on 5 and 1)
7) ¬(PetOfRoommateCanFly) (modus ponens on 4 and 3)
8) ¬(PetOfRoommateCanFly) => FALSE (equivalent to 6)
9) FALSE (modus ponens on 7 and 8)
10) FALSE => TheMoonIsMadeOfCheese (tautology)
11) TheMoonIsMadeOfCheese (modus ponens on 9 and 10)
Getting more systematic
• Any knowledge base can be written as a single
formula in conjunctive normal form (CNF)
– CNF formula: (… V … V …)  (… V …)  …
– … can be a symbol x, or ¬(x) (these are called literals)
– Multiple facts in knowledge base are effectively ANDed
together
RoommateWet => (RoommateWetBecauseOfRain
V RoommateWetBecauseOfSprinklers)
becomes
(¬(RoommateWet) V RoommateWetBecauseOfRain
V RoommateWetBecauseOfSprinklers)
Converting story problem to

conjunctive
RoommateWet
normal form
– RoommateWet

• RoommateWet => (RoommateWetBecauseOfRain V


RoommateWetBecauseOfSprinklers)
– ¬(RoommateWet) V RoommateWetBecauseOfRain V
RoommateWetBecauseOfSprinklers
• RoommateWetBecauseOfSprinklers => SprinklersOn
– ¬(RoommateWetBecauseOfSprinklers) V SprinklersOn
• RoommateWetBecauseOfRain => ¬(RoommateCarryingUmbrella)
– ¬(RoommateWetBecauseOfRain) V ¬(RoommateCarryingUmbrella)
• UmbrellaGone
– UmbrellaGone

• UmbrellaGone => (YouCarryingUmbrella V RoommateCarryingUmbrella)


– ¬(UmbrellaGone) V YouCarryingUmbrella V RoommateCarryingUmbrella
• ¬(YouCarryingUmbrella)

Unit resolution
• Unit resolution: if we have
• l1 V l 2 V … V l k
and
• ¬(li)
we can conclude
• l1 V l2 V … li-1 V li+1 V … V lk
• Basically modus ponens
Applying resolution to story problem
1) RoommateWet
2) ¬(RoommateWet) V RoommateWetBecauseOfRain V
RoommateWetBecauseOfSprinklers
3) ¬(RoommateWetBecauseOfSprinklers) V SprinklersOn
4) ¬(RoommateWetBecauseOfRain) V ¬(RoommateCarryingUmbrella)
5) UmbrellaGone
6) ¬(UmbrellaGone) V YouCarryingUmbrella V RoommateCarryingUmbrella
7) ¬(YouCarryingUmbrella)
8) ¬(UmbrellaGone) V RoommateCarryingUmbrella (6,7)
9) RoommateCarryingUmbrella (5,8)
10) ¬(RoommateWetBecauseOfRain) (4,9)
11) ¬(RoommateWet) V RoommateWetBecauseOfSprinklers (2,10)
12) RoommateWetBecauseOfSprinklers (1,11)
13) SprinklersOn (3,12)
Limitations of unit resolution
• PVQ
• ¬(P) V Q
• Can we conclude Q?
(General) resolution
• General resolution: if we have
• l1 V l2 V … V lk
and
• m1 V m2 V … V mn
where for some i,j, li = ¬(mj)
we can conclude
• l1 V l2 V … li-1 V li+1 V … V lk V m1 V m2 V … V mj-1 V
mj+1 V … V mn
• Same literal may appear multiple times; remove
those
Applying resolution to story problem (more clumsily)
1) RoommateWet
2) ¬(RoommateWet) V RoommateWetBecauseOfRain V
RoommateWetBecauseOfSprinklers
3) ¬(RoommateWetBecauseOfSprinklers) V SprinklersOn
4) ¬(RoommateWetBecauseOfRain) V ¬(RoommateCarryingUmbrella)
5) UmbrellaGone
6) ¬(UmbrellaGone) V YouCarryingUmbrella V RoommateCarryingUmbrella
7) ¬(YouCarryingUmbrella)
8) ¬(RoommateWet) V RoommateWetBecauseOfRain V SprinklersOn (2,3)
9) ¬(RoommateCarryingUmbrella) V ¬(RoommateWet) V SprinklersOn (4,8)
10) ¬(UmbrellaGone) V YouCarryingUmbrella V ¬(RoommateWet) V SprinklersOn
(6,9)
11) YouCarryingUmbrella V ¬(RoommateWet) V SprinklersOn (5,10)
12) ¬(RoommateWet) V SprinklersOn (7,11)
13) SprinklersOn (1,12)
Systematic inference?
• General strategy: if we want to see if sentence
a is entailed, add ¬(a) to the knowledge base
and see if it becomes inconsistent (we can
derive a contradiction)
• CNF formula for modified knowledge base is
satisfiable if and only if sentence a is not
entailed
– Satisfiable = there exists a model that makes the
modified knowledge base true = modified
knowledge base is consistent
Resolution algorithm
• Given formula in conjunctive normal form, repeat:
• Find two clauses with complementary literals,
• Apply resolution,
• Add resulting clause (if not already there)
• If the empty clause results, formula is not satisfiable
– Must have been obtained from P and ¬(P)

• Otherwise, if we get stuck (and we will eventually),


the formula is guaranteed to be satisfiable (proof in
a couple of slides)
Example
• Our knowledge base:
– 1) RoommateWetBecauseOfSprinklers
– 2) ¬(RoommateWetBecauseOfSprinklers) V
SprinklersOn
• Can we infer SprinklersOn? We add:
– 3) ¬(SprinklersOn)
• From 2) and 3), get
– 4) ¬(RoommateWetBecauseOfSprinklers)
• From 4) and 1), get empty clause
If we get stuck, why is
the formula satisfiable?
• Consider the final set of clauses C
• Construct satisfying assignment as follows:
• Assign truth values to variables in order x1, x2, …, xn
• If xj is the last chance to satisfy a clause (i.e., all the other variables in the
clause came earlier and were set the wrong way), then set xj to satisfy it
– Otherwise, doesn’t matter how it’s set
• Suppose this fails (for the first time) at some point, i.e., x j must be
set to true for one last-chance clause and false for another
• These two clauses would have resolved to something involving only
up to xj-1 (not to the empty clause, of course), which must be
satisfied
• But then one of the two clauses must also be satisfied -
contradiction
Special case: Horn clauses
• Horn clauses are implications with only positive literals
• x1  x2  x4 => x3  x6
• TRUE => x1
• Try to figure out whether some xj is entailed
• Simply follow the implications (modus ponens) as far as you
can, see if you can reach xj
• xj is entailed if and only if it can be reached (can set
everything that is not reached to false)
• Can implement this more efficiently by maintaining, for each
implication, a count of how many of the left-hand side
variables have been reached

You might also like