(Part 1) Propositional Logic 2
(Part 1) Propositional Logic 2
Lecture 5
Propositional Logic 2
10-11-2022
Outline
Wumpus World Example
Definite clauses and Horn clauses
Backward and Forward Chaining
Wumpus World Example
The Wumpus world is a cave consisting of rooms
connected by passageways.
Somewhere in the cave is the terrible wumpus, a beast
that eats anyone who enters its room.
The wumpus can be shot by an agent, but the agent has
only one arrow.
Some rooms contain pits.
The cave contains a heap of gold.
The agent’s goal is to find the gold and bring it back to
the start, where it will climb out of the cave, without
getting killed.
Wumpus World Example
Performance measure
• +1000 for going out of the cave with the
gold.
• -1000 for filling into the pit or eaten by the
Wumpus.
• -1 per each action.
• -10 for using the arrow.
• The game ends either when the agent dies
or when the agent climbs out of the cave.
Wumpus World description
Environment
4 x 4 grid of rooms.
The agent always starts in square [1, 1] facing the right.
Squares adjacent to wumpus are smelly.
Squares adjacent to pit are breezy.
Glitter if gold is in the same square.
Shooting kills wumpus if you are facing it.
Shooting uses up the only arrow.
Grabbing picks up gold if in same square.
Releasing drops the gold in same square.
Wumpus World description
Discrete Yes
The 8 possible
models for squares
[1, 2], [2, 2], [3, 1]
Wumpus models
[1, 2]
𝛼 = P1,2
Truth tables for inference
by resolution
P3,1
Note
𝛼 in CNF ¬(F∧D) ∨ P
¬ F ∨ ¬D ∨ P
Example (cont.)
KB and ¬𝛼 ≡ (¬ (¬ F ∨ ¬D ∨ P) ≡ F ∧ D ∧ ¬ P)
¬F ∨ P ∨ ¬D F D ¬P
P ∨ ¬D
▢
Then KB ⊨𝛼
Definite clauses
Disjunction () of literals with exactly one positive,
e.g., ¬ A ¬B C (≡ A B C )
¬ A B C is not definite clause (has 2 positive
literals).
Horn clauses
Disjunction of literals with at most one positive literal,
◼ proposition symbol (e.g. C); or
◼ (conjunction of symbols) symbol
◼ E.g., C (B A) (C D B)
◼ ¬ A ¬B C
◼ ¬ A , goal
All definite clauses are Horn clauses.
Clauses with No positive literals are called goal
clauses.
Note
P ∨ Q ⇒ R is definite clause:
¬ (P ∨ Q) ∨ R ≡ (¬ P ∧ ¬Q) ∨ R
≡ (¬ P ∨ R ) ∧ (¬Q ∨ R)
Inference with Horn clauses
Inference with Horn clauses can be done through
the forward chaining and backward-chaining
algorithms.
This type of inference is the basis for logic
programming.
Forward and backward chaining
Horn Form (restricted)
KB = conjunction of Horn clauses
α1, … ,αn, α1 … α n β
β
Can be used with forward chaining or backward chaining.
These algorithms are very natural and run-in linear time.
Forward Chaining (FC)
Idea: fire any rule whose premises are satisfied in the KB,
add its conclusion to the KB, until query is found
KB is
• It is desired to prove the goal Q
• Begin from the facts A and B
A B A B L Modus Pones
• From
𝐿
• Add L to the KB
B L B LM
• From 𝑀
• Add M to the KB
L M L MP
• From 𝑃
• Add P to the KB
P P Q
• From 𝑄
Backward Chaining (BC)
Idea: work backwards from the query Q:
to prove Q by BC,
check if Q is known already, or
prove by BC all premises of some rule concluding Q
Avoid loops: check if new subgoal is already on the
goal stack
Avoid repeated work: check if new subgoal
1. has already been proved true, or
2. has already failed
Backward chaining example
• Begin from the query Q
• For Q to be true, P must be true
• For P to be true, L and M should
be true
• To prove L, A and B should be
true; A and B are true then L is
true
• Since L is true and B is true then
M is true.
Forward vs. backward chaining
FC BC
Start with facts Start with goal
Test all rules Test some rules
Data-driven Goal-driven
May do lots of work that is irrelevant Searches only the part of the KB that
to the goal-it infer every statement is relevant to the goal
possible from the KB