c1 propositional logic
TRANSCRIPT
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 1/39
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 2/39
2
The Wumpus Game
Stench in the square containing the wumpus andin the directly adjacent squares
Breeze in the squares directly adjacent to a pit
Glitter in the square where the gold is
Bump when an agent walks into a wall
Scream when the wumpus is killed
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 3/39
3
The Wumpus Game
Agents percept : [Stench, Breeze, Glitter, Bump, Scream]
Agents actions:
Go forward, turn right 90o, turn left 90o
Grab to pick up an object in the same square
Fire 1 arrow in a straight line in the faced direction
Climb to leave the cave
Death if entering a square of a pit or a live wumpus Agents goal: find and bring the gold back to the
start
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 4/39
4
The Wumpus Game
Stench Breeze
Breeze
Stench
Gold
Breeze
Stench
OK
Breeze
Start
A
Breeze
OK
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 5/39
5
The Wumpus Game
Stench Breeze
Breeze
Stench
Gold
Breeze
Stench
OK P?
Breeze
Start
V
Breeze
A P?
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 6/39
6
The Wumpus Game
Stench Breeze
BreezeStench
Gold
Breeze
Stench
A OK
Breeze
Start
V
Breeze
V
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 7/39
7
The Wumpus Game
Stench Breeze
BreezeStench
Gold
Breeze
Stench
V A
Breeze
Start
V
Breeze
V
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 8/39
8
The Wumpus Game
Stench Breeze
BreezeStench
Gold A
Breeze
Stench
V V
Breeze
Start
V
Breeze
V
Breeze
A = Agent
B = Breeze
G = Glitter/Gold
OK = Safe square
P = Pit
S = Stench
V = Visited
W = Wumpus
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 9/39
9
Propositional Logic Syntax
Logical constants: true, false
Propositional symbols: P, Q,
Logical connectives: , , , ,
Sentences (formulas):
Logical constants
Proposition symbols
If E is a sentence, then so are E and (E)
If E and F are sentences, then so are E FE F
E F, and E F
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 10/39
10
Propositional Logic Semantics
Interpretation: propositional symbol p true/false
The truth value of a sentence is defined by thetruth table
P Q P P Q P Q P Q P Q
false false true false false true true
false true true false true true false
true false false false true false false
true true false true true true true
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 11/39
11
Propositional Logic Semantics
Satisfiable: true under an interpretation
Valid: true under all interpretations
P Q P P (P Q) Q ((P Q) Q) P
false false false false true
false true false false true
true false false true true
true true false false true
satisfiableunsatisfiable valid
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 12/39
12
Propositional Logic Semantics
Model: an interpretation under which the sentenceis true
Q
P Q
P Q
P Q
P
Q
P Q
P Q
P Q
P
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 13/39
13
Propositional Logic Semantics
Entailment : KB `! E iff every model of KB is a modelof E
E is a logical consequence of KB
P Q P Q P Q, P
false false true false
false true true false
true false false false
true true true true
{P Q, P} `! Q
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 14/39
14
Propositional Logic Semantics
Equivalence: E| F iff E `! F and F `! E
P Q P Q P Q
false false true true
false true true true
true false false false
true true true true
P Q | P Q
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 15/39
15
Propositional Logic Semantics
Theorems:
E `! F iff E F is valid
KB `! E can be proved by validity KB E
E `! F iff E F is unsatisfiable
KB `! E can be proved by refutation of KB E
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 16/39
16
Inference Rules
Rule R:Premises: E1, E2, , En
Conclusion: F
Soundness: R is sound iff {E1, E2, , En} `! F
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 17/39
17
Inference Rules
Modus Ponens:E F, E
F
-Elimination:E1 E2 En
Ei
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 18/39
18
Inference Rules
-Introduction:E1, E2, , En
E1 E2 En
-Introduction:Ei
E1 E2 En
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 19/39
19
Inference Rules
Double-negation elimination:E
E
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 20/39
20
Resolution
Unit resolution:
P1 Pi Pn, QPi | Q (all Pi and Q are literals)
P1 Pi-1 Pi+1 Pn
Full resolution:
P1 Pi Pn, Q1 Q j Qm
Pi | Q j P1 Pi-1 Pi+1 Pn Q1 Q j-1 Q j+1 Qm
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 21/39
21
Resolution
Conjunctive normal form (CNF): conjunction of disjunctions of literals
(L11 L1k) (Ln1 Lnm)
clause
k-CNF: each clause contains at most k literals
Every sentence can be written in CNF
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 22/39
22
Inference Algorithms
To derive/assert a sentence given a knowledge baseas a set of sentences
Inference rules + a searching algorithm
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 23/39
23
Inference Algorithms
Algorithm PL-Resolution(KB, E)
input: KB and E are PL sentences
output: true (to assert KB `! E) or false (otherwise)
Clauses = set of clauses in the CNF representation of KB E
New = {}
loop
for each Ci, C j in Clauses do
Resolvents = PL-Resolve(Ci, C j)
if Resolvents contains an empty clause then return true
New = New Resolvents
if New Clauses then return false
Clauses = Clauses New
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 24/39
24
Inference Algorithms
Soundness: every deduced answer is correct
if PL-Resolution returns true then KB `! E
Completeness: every correct answer is deducible
if KB `! Ethen PL-Resolution returns true
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 25/39
25
Inference Algorithms
PL-Resolution is sound and complete
Modus Ponens with any searching algorithm is not complete
KB = {P Q, Q R}, E = P R
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 26/39
26
Inference Algorithms
Horn clause: disjunction of literals of which at most one is positive
P1 P2 Pn Q
orP1 P2 Pn Q
Forward or backward chaining can be used forinference on Horn clauses
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 27/39
27
Satisfiability Problem
SAT problem: to determine if a sentence is satisfiable
(to determine if the symbols in the sentence can be assignedtrue/false as to make it evaluate to true)
(D B C) (B A C) (C B E)
(E D B) (B E C)
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 28/39
28
Satisfiability Problem
SAT problem in propositional logic is NP-complete
This does not mean all instances of PL inference has the
exponential complexity
Polynomial-time inference procedures for Horn clauses
Many combinatorial problems in computer sciencecan be reduced to SAT
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 29/39
29
Satisfiability Problem
Backtracking algorithms
Davis and Putnam (1960)
Davis, Logemann, Loveland (1962)
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 30/39
30
Satisfiability Problem
DPLL algorithm:
Recursive, depth-first enumeration of possible models
Early termination: a clause is true if any literal is true
( A B) ( A C) is true if A is true regardless of B and C
Pure symbol: has the same sign in all clauses
( A B) (B C) (C A)
A model would have the literals of pure symbols assigned true
Satisfied clause removal makes new pure symbols
Unit clause: has just one literal
Unit clause satisfaction makes new unit clauses (unit propagation)
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 31/39
31
Satisfiability Problem
Local search algorithms
Evaluation function counts the number of unsatisfied clauses
Randomness to escape local minima
Flipping the truth value of one symbol at a time
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 32/39
32
Statisfiability Problem
Algorithm WalkSAT(Clauses, p, max_flips)
input: p is flipping probability, max_flips is number of flips allowed
output: a model or failure
Model = a random assignment of truth values to the symbols
for i = 1 to max_flips do
if Model satisfies Clauses then return Model
C = a randomly selected clause from Clauses that is false in Model
with probability p flip the value in Model of a symbol from C
else flip whichever symbol in C to maximizes no. of satisfied clauses
return failure
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 33/39
33
Satisfiability Problem
Complexity depends on the clause/symbol ratio
Hard when the ratio is from than 4.3
WalkSAT is much faster than DPLL
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 34/39
34
Inference Monotonicity
Monotonicity: the set of entailed sentences canonly increase when information is added to theKB
if KB1 `! E then (KB1KB2) `! E
Propositional logic is monotone
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 35/39
35
An Agent for the Wumpus Game
Knowledge Base: X ij = column i, row j
S11 B11 R1: S11 W11 W12 W21
S21 B21 R2: S21 W11 W21 W22 W31
S12 B12 R3: S12 W11 W12 W22 W13
R4: S12 W13 W12 W22 W11
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 36/39
36
Agent for the Wumpus Game
Finding the wumpus:
Modus Ponens (S11 + R1): W11 W12 W21
-Elimination: W11 W12 W21
Modus Ponens (S21 + R2): W11 W21 W22 W31
-Elimination: W11 W21 W22 W31
Modus Ponens (S12 + R4): W13 W12 W22 W11
Unit resolution (W11 + W13 W12 W22 W11):
W13 W12 W22 Unit resolution (W22 + W13 W12 W22): W13 W12
Unit resolution (W12 + W13 W12): W13
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 37/39
37
Agent for the Wumpus Game
Translating knowledge into action:
A11 East A W21 Forward
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 38/39
38
Agent for the Wumpus Game
Problems with the propositional agent:
Too many propositions to handle:
"Dont go forward if the wumpus is in front of you!" requires 16 x
4 = 64 propositions.
Hard to deal with time and change
Not expressive enough to represent or answer aquestion like "What action should the agent take?",
8/8/2019 C1 Propositional Logic
http://slidepdf.com/reader/full/c1-propositional-logic 39/39
39
Homework
In Russell & Norvigs AIMA (2nd ed.): Exercises of Chapter 7.