CS488 CH 7 Propositional Logic
CS488 CH 7 Propositional Logic
Mar-2023, AA
Ch-7
Knowledge Representation and Reasoning
Propositional Logic
Agenda:
• Knowledge base agents
• The wampus worlds
• Logic in general
• Sentences in PL: Syntax and Semantics.
• Truth value of sentences: implication & truth table
• Validity and Satisfiability.
• Equivalence and Inference rules for Reasoning; proof and inference
• Pros and cons of propositional logic
Figure 7.2 A typical wumpus world. The agent is in the bottom left corner, facing right.
Dec-23 Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 14
KR and Reasoning: The Wumpus World
Actuators
▪ move Forward, TurnLeft, or TurnRight.
▪ dies if the agent enters a square containing a pit or a live wumpus.
▪ If it bumps into a wall, it does not move.
▪ Grab picks up the gold if it is in the same square as the agent.
▪ Releasing drops the gold in same square
▪ Shoot firs an arrow and kills wumpus if the agent is facing it
▪ Shoot uses up the only arrow the agent has.
▪ Climb to climb out of the cave, but only from square [1,1].
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 26
KR and Reasoning: Logic in General
Entailment in wumpus world
▪ We can apply the same kind of analysis to the wumpus-world
reasoning example given in the preceding section.
▪ Consider the situation in Figure 7.3(b): the agent has detected
nothing in [1,1] and a breeze in [2,1].
▪ These percepts, combined with the agent’s knowledge of the
rules of the wumpus world, constitute the KB.
▪ The agent is interested (among other things) in whether the
adjacent squares [1,2], [2,2], and [3,1] contain pits.
▪ Each of the three squares might or might not contain a pit, 3
Boolean choices
=> 23 =8 possible models.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 27
KR and Reasoning: Logic in General
Wumpus models
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 28
KR and Reasoning: Logic in General
Wumpus models
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 30
KR and Reasoning: Logic in General
Inference
▪ The preceding example not only illustrates entailment but also shows how the
definition of entailment can be applied to derive conclusions—that is, to carry out
logical inference.
▪ The inference algorithm illustrated in Figure 7.5 is called model checking, because
it enumerates all possible models to check that α is true in all models in which KB
is true, that is, M(KB) ⊆ M(α).
▪ In understanding entailment and inference, it might help to think of the set of all
consequences of KB as a haystack and of α as a needle. Entailment is like the
needle being in the haystack; inference is like finding it.
▪ This distinction is embodied in some formal notation: if an inference algorithm i
can derive α from KB, we write
which is read “α is derived from KB by i” or “i derives α from KB.”
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 31
KR and Reasoning: Logic in General
Inference
▪ Soundness: An inference algorithm that derives only entailed sentences is called sound or
truth preserving.
▪ For real haystacks, which are finite in extent, it seems obvious that a systematic
examination can always decide whether the needle is in the haystack.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 32
KR and Reasoning: Propositional Logic
Syntax
▪ Propositional logic is a simple but powerful logic.
▪ The syntax of propositional logic defines the allowable sentences.
▪ Atomic sentences consist of a single proposition symbol. Each such symbol
stands for a proposition that can be true or false.
▪ We use symbols that start with an uppercase letter and may contain other
letters or subscripts, for example: P, Q, R, B1,3, P1,1 etc.
▪ Complex sentences are constructed from simpler sentences, using
parentheses and logical connectives.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 33
KR and Reasoning: Propositional Logic
Syntax
▪There are five connectives in common use:
─ not (negation): If P is a sentence, ⌐P is a sentence
─ and (conjunction): if P and Q are sentences, P ˄ Q is a sentence
─ or (disjunction): if P and Q are sentences, P V Q is a sentence
─ implication: if P and Q are sentences, P => Q is a sentence
─ bi-implication: if P and Q are sentences, P <=> Q is a sentence
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 34
KR and Reasoning: Propositional Logic
Semantics
▪ Each model species true/false for each proposition symbol
─ E.g. m1 = P1,2 = false, P2,2 = false, P3,1 = true
─ With these symbols, 8 possible models, can be enumerated automatically.
▪ Rules for evaluating truth with respect to a model m:
─ ⌐P is true iff P is false
─ P ^ Q is true iff P is true and Q is true
─ P V Q is true iff P is true or Q is true
─ P => Q is true iff P is false or Q is true
i.e., P => Q is false iff P is true and Q is false
─ P ⬄ Q is true iff P => Q is true and Q => P is true
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 35
KR and Reasoning: Propositional Logic
Semantics
▪ Truth table for connectives
▪ Simple recursive process evaluates an arbitrary sentence, for example, ⌐P1,2 ^ (P2,2
V P3,1) evaluated in m1 gives the following.
▪ ⌐P1,2 ^ (P2,2 V P3,1) = (not)false ^ (false V true)= true ^ true= true
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 36
KR and Reasoning: Propositional Logic
Semantics
▪ The biconditional, P ⇔ Q, is true whenever both P ⇒ Q and Q ⇒ P are true.
▪ In English, this is often written as “P if and only if Q.”
▪ Many of the rules of the wumpus world are best written using ⇔.
▪ For example, a square is breezy if a neighboring square has a pit, and a
square is breezy only if a neighboring square has a pit.
▪ So we need a biconditional,
─ B1,1 ⇔ (P1,2 ∨ P2,1) ,
─ where B1,1 means that there is a breeze in [1,1].
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 37
KR and Reasoning: Propositional Logic
A simple knowledge base
▪ Now that we have defined the semantics for propositional logic, we can
construct a knowledge base for the wumpus world.
▪ For now, we need the following symbols for each [x, y] location:
─ Px,y is true if there is a pit in [x, y].
─ Wx,y is true if there is a wumpus in [x, y], dead or alive.
─ Bx,y is true if the agent perceives a breeze in [x, y].
─ Sx,y is true if the agent perceives a stench in [x, y].
▪ The sentences we write will suffice to derive ¬P1,2 (there is no pit in [1,2]),
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 38
KR and Reasoning: Propositional Logic
A simple knowledge base
▪ There is no pit in [1,1]:
─ R1 : ¬P1,1 .
▪ ‘A square is breezy if and only if there is a pit in a neighboring square.’
─ R2 : B1,1 ⇔ (P1,2 ∨ P2,1) .
─ R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1) .
▪ The preceding sentences are true in all wumpus worlds.
▪ Now we include the breeze percepts for the first two squares visited in the
specific world the agent is in.
─ R4 : ¬B1,1 .
─ R5 : B2,1 .
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 39
KR and Reasoning: Propositional Logic
A simple inference procedure: enumeration a
Figure 7.9 A truth table constructed for the knowledge base given in the text. KB is true if R1 through R5 are true, which
occurs in just 3 of the 128 rows (the ones underlined in the right-hand column). In all 3 rows, P1,2 is false, so there is no pit in
[1,2]. On the other hand, there might (or might not) be a pit in [2,2].
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 40
KR and Reasoning: Propositional Logic
A simple inference procedure
▪ Depth-first enumeration
of all models is sound and
complete
▪ Time O(2n) for n symbols;
▪ Space O(n)
Figure 7.10 A truth-table enumeration algorithm for deciding propositional entailment. (TT stands for truth table.)
PL-TRUE? returns true if a sentence holds within a model. The variable model represents a partial model—an assignment
to some of the symbols. The keyword “and” is used here as a logical operation on its two arguments, returning true or
false.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 41
KR and Reasoning: Propositional Logic
Logical Equivalence
▪ Two sentences α and β are logically equivalent if they are true in the same set of
models. We write this as
o α ≡ β.
▪ An alternative definition of equivalence is as follows: any two sentences α and β
are equivalent only if each of them entails the other:
o α ≡ β iff α|= β and β|= α .
▪ For example, we can easily show (using truth tables) that P ∧ Q and Q ∧ P are
logically equivalent; Figure 7.11 shows other equivalences.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 42
KR and Reasoning: Propositional Logic
Logical equivalence
Figure 7.11 Standard logical equivalences. The symbols α, β, and γ stand for arbitrary
sentences of propositional logic.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 43
KR and Reasoning: Propositional Logic
Validity
▪ A sentence is valid if it is true in all models.
▪ For example, True, A V ⌐A, A ⇒ A, (A ∧ (A ⇒ B)) ⇒ B
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 44
KR and Reasoning: Propositional Logic
Satisfiability
▪ A sentence is satisfiable if it is true in, or satisfied by, some model.
o For example, the KB given earlier, (R1 ∧ R2 ∧ R3 ∧ R4 ∧ R5), is
satisfiable because there are three models in which it is true, as shown in
Figure 7.9.
o A V B,
o C
▪ A sentence is unsatisfiable if it is true in no models
o examples, A ^ ⌐A
▪ Many problems in computer science are really satisfiability problems.
o For example, all the constraint satisfaction problems in Chapter 6 ask whether
the constraints are satisfiable by some assignment.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 45
KR and Reasoning: Propositional Logic
Satisfiability
▪ Validity and satisfiability are connected:
o α is valid iff ¬α is unsatisfiable; contrapositively,
o α is satisfiable iff ¬α is not valid.
▪ We also have the following useful result
α |= β iff (α ∧ ¬β) is unsatisfiable.
▪ Proving β from α by checking the unsatisfiability of (α ∧ ¬β) corresponds
exactly to the standard mathematical proof by refutation or proof by
contradiction.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 46
KR and Reasoning: Propositional Logic
Proof methods
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 47
KR and Reasoning: Propositional Logic
Inference and proofs
▪ inference rules can be applied to derive a proof
▪ Proof is a chain of conclusions that leads to the desired goal.
▪ The best-known rule is called Modus Ponens (Latin for mode that affirms) and is
written
▪ The notation means that, whenever any sentences of the form α ⇒ β and α are
given, then the sentence β can be inferred.
▪ For example, if (WumpusAhead ∧ WumpusAlive) ⇒ Shoot and (WumpusAhead
∧ WumpusAlive) are given, then Shoot can be inferred.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 48
KR and Reasoning: Propositional Logic
Inference and proofs
▪ Another useful inference rule is And-Elimination, which says that, from a
conjunction, any of the conjuncts can be inferred:
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 49
KR and Reasoning: Propositional Logic
Inference and proofs
▪ All of the logical equivalences in Figure 7.11 can be used as inference rules.
▪ For example, the equivalence for biconditional elimination yields the two
inference rules.
▪ Let us see how these inference rules and equivalences can be used in the
wumpus world.
▪ We start with the knowledge base containing R1 through R5 and show how to
prove ¬P1,2, (there is no pit in [1,2]).
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 50
KR and Reasoning: Propositional Logic
Inference and proofs
▪ First, we apply biconditional elimination to R2 to obtain
R6: (B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1) .
▪ Then we apply And-Elimination to R6 to obtain
R7: ((P1,2 ∨ P2,1) ⇒ B1,1) .
▪ Logical equivalence for contrapositives gives
R8: (¬B1,1 ⇒ ¬(P1,2 ∨ P2,1)) .
▪ Modus Ponens with R8 and the percept R4 (i.e., ¬B1,1), to obtain
R9 : ¬(P1,2 ∨ P2,1) .
▪ Finally, we apply De Morgan’s rule, giving the conclusion
R10 : ¬P1,2 ∧ ¬P2,1 .
▪ That is, neither [1,2] nor [2,1] contains a pit.
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 51
KR and Reasoning: Propositional Logic
Inference and proofs
▪ One final property of logical systems is monotonicity, which says that
the set of entailed sentences can only increase as information is added to
the knowledge base.
▪ For any sentences α and β,
if KB |= α then KB ∧ β |= α .
Dec-23
Fantahun B.(PhD) Based on AI a Modern Approach 3e&others 53