Logical Agents
Chapter 7 (continued)

Outline: Inference
Resolution in CNF
Sound and Complete
Forward and Backward Chaining using Modus Ponens in Horn Form
Sound and Complete

Proof methods
Proof methods divide into (roughly) two kinds:
Application of inference rules
Legitimate (sound) generation of new sentences from old
Proof = a sequence of inference rule applications
Can use inference rules as operators in a standard search algorithm
Typically require transformation of sentences into a normal form
Model checking
truth table enumeration (always exponential in n)
improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL)
heuristic search in model space (sound but incomplete)
e.g., min-conflicts like hill-climbing algorithms

Inference by enumeration
Depth-first enumeration of all models is sound and complete
For n symbols, time complexity is O(2n), space complexity is O(n)

Wumpus world sentences
Let Pi,j be true if there is a pit in [i, j].
Let Bi,j be true if there is a breeze in [i, j].
ØP1,1
ØB1,1
B2,1
"Pits cause breezes in adjacent squares"
B1,1  Û (P1,2 Ú P2,1)
B2,1  Û (P1,1 Ú P2,2 Ú P3,1)

Truth tables for inference

Proof methods
Proof methods divide into (roughly) two kinds:
Application of inference rules
Legitimate (sound) generation of new sentences from old
Proof = a sequence of inference rule applications
Can use inference rules as operators in a standard search algorithm
Typically require transformation of sentences into a normal form
Model checking
truth table enumeration (always exponential in n)
improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL)
heuristic search in model space (sound but incomplete)
e.g., min-conflicts like hill-climbing algorithms

Reasoning Patterns in Prop Logic
Given(s)
Conclusion
A Þ B, A
B
B Ù A
A
Rules that allow us to introduce new propositions while preserving truth values: logically equivalent
Two Examples:
Modus Ponens
And Elimination

Logical equivalence
Two sentences are logically equivalent iff true in same models: α ≡ ß iff α╞ β and β╞ α

Resolution
Conjunctive Normal Form (CNF)
   conjunction of disjunctions of literals
clauses
E.g., (A Ú ØB) Ù (B Ú ØC Ú ØD)
Resolution inference rule (for CNF):
li ÚÚ lk, m1 ÚÚ mn
li ÚÚ li-1 Ú li+1 ÚÚ lk Ú m1 ÚÚ mj-1 Ú mj+1 Ú... Ú mn
where li and mj are complementary literals.
E.g., P1,3 Ú P2,2, ØP2,2
     P1,3
Resolution is sound and complete
for propositional logic

Resolution example
KB = (B1,1 Û (P1,2Ú P2,1)) ÙØ B1,1
α = ØP1,2 (negate the premise for proof by refutation)

The power of false
Given: (P) Ù (ØP)
Prove: Z
Can we prove ØZ using the givens above?

Applying inference rules
Equivalent to a search problem
KB state = node
Inference rule application = edge

Inference
Define: KB ├i α = sentence α can be derived from KB by procedure i
Soundness: i is sound if whenever KB ├i α, it is also true that KB╞ α
Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α
Preview: we will define a logic (first-order logic) which is expressive enough to say almost anything of interest, and for which there exists a sound and complete inference procedure.
That is, the procedure will answer any question whose answer follows from what is known by the KB.

Completeness
Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α
An incomplete inference algorithm cannot reach all possible conclusions
Equivalent to completeness in search (chapter 3)

Resolution
Conjunctive Normal Form (CNF)
   conjunction of disjunctions of literals
clauses
E.g., (A Ú ØB) Ù (B Ú ØC Ú ØD)
Resolution inference rule (for CNF):
li ÚÚ lk, m1 ÚÚ mn
li ÚÚ li-1 Ú li+1 ÚÚ lk Ú m1 ÚÚ mj-1 Ú mj+1 Ú... Ú mn
where li and mj are complementary literals.
E.g., P1,3 Ú P2,2, ØP2,2
     P1,3
Resolution is sound and complete
for propositional logic

Resolution
Soundness of resolution inference rule:
Ø(li ÚÚ li-1 Ú li+1 ÚÚ lk) Þ li
       Ømj Þ (m1 ÚÚ mj-1 Ú mj+1 Ú... Ú mn)
Ø(li ÚÚ li-1 Ú li+1 ÚÚ lk) Þ (m1 ÚÚ mj-1 Ú mj+1 Ú... Ú mn)
where li and mj are complementary literals.
What if li and Ømj are false?
What if li and Ømj are true?

Completeness of Resolution
That is, that resolution can decide the truth value of S
S = set of clauses
RC(S) = Resolution closure of S = Set of all clauses that can be derived from S by the resolution inference rule.
RC(S) has finite cardinality (finite number of symbols P1, P2, … Pk), thus resolution refutation must terminate.

Completeness of Resolution (cont)
Ground resolution theorem = if S unsatisfiable, RC(S) contains empty clause.
Prove by proving contrapositive:
i.e., if RC(S) doesn’t contain empty clause, S is satisfiable
Do this by constructing a model:
For each Pi, if there is a clause in RC(S) containing ØPi and all other literals in the clause are false, assign Pi = false
Otherwise Pi = true
This assignment of Pi is a model for S.

Forward and backward chaining
Horn Form (restricted)
KB = conjunction of Horn clauses
Horn clause =
proposition symbol;  or
(conjunction of symbols) Þ symbol
E.g., C Ù (B Þ A) Ù (C Ù D Þ B)
Modus Ponens (for Horn Form): complete for Horn KBs
α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 example

Forward chaining example

Forward chaining example

Proof of completeness
FC derives every atomic sentence that is entailed by KB (only for clauses in Horn form)
FC reaches a fixed point (the deductive closure) where no new atomic sentences are derived
Consider the final state as a model m, assigning true/false to symbols
Every clause in the original KB is true in m
  a1 Ù  Ù  ak Þ b
Hence m is a model of KB
If KB╞ q, q is true in every model of KB, including m

Backward chaining example

Backward chaining example

Backward chaining example

Proof methods
Proof methods divide into (roughly) two kinds:
Application of inference rules
Legitimate (sound) generation of new sentences from old
Proof = a sequence of inference rule applications
Can use inference rules as operators in a standard search algorithm
Typically require transformation of sentences into a normal form
Model checking
truth table enumeration (always exponential in n)
improved backtracking, e.g., Davis-Putnam-Logemann-Loveland (DPLL)
heuristic search in model space (sound but incomplete)
e.g., min-conflicts like hill-climbing algorithms

Efficient propositional inference
Two families of efficient algorithms for propositional inference:
Complete backtracking search algorithms
DPLL algorithm (Davis, Putnam, Logemann, Loveland)
Incomplete local search algorithms
WalkSAT algorithm

The DPLL algorithm
Determine if an input propositional logic sentence (in CNF) is satisfiable.
Improvements over truth table enumeration:
Early termination
A clause is true if any literal is true.
A sentence is false if any clause is false.
Pure symbol heuristic
Pure symbol: always appears with the same "sign" in all clauses.
e.g., In the three clauses (A Ú ØB), (ØB Ú  ØC), (C Ú A), A and B are pure, C is impure.
Make a pure symbol literal true.
Unit clause heuristic
Unit clause: only one literal in the clause
The only literal in a unit clause must be true.

The DPLL algorithm

The WalkSAT algorithm
Incomplete, local search algorithm
Evaluation function: The min-conflict heuristic of minimizing the number of unsatisfied clauses
Balance between greediness and randomness

The WalkSAT algorithm

Hard satisfiability problems
Consider random 3-CNF sentences. e.g.,
(ØD Ú ØB Ú C) Ù (B Ú ØA Ú ØC) Ù (ØC Ú  ØB Ú E) Ù (E Ú ØD Ú B) Ù (B Ú E Ú ØC)
m = number of clauses
n = number of symbols
Hard problems seem to cluster near m/n = 4.3 (critical point)

Hard satisfiability problems

Hard satisfiability problems
Median runtime for 100 satisfiable random 3-CNF sentences, n = 50

Inference-based agents in the wumpus world
A wumpus-world agent using propositional logic:
ØP1,1
ØW1,1
Bx,y Û (Px,y+1 Ú Px,y-1 Ú Px+1,y Ú Px-1,y)
Sx,y Û (Wx,y+1 Ú Wx,y-1 Ú Wx+1,y Ú Wx-1,y)
W1,1 Ú W1,2 ÚÚ W4,4
ØW1,1 Ú ØW1,2
ØW1,1 Ú ØW1,3
Þ 64 distinct proposition symbols, 155 sentences

Slide 38

Expressiveness limitation of propositional logic
We didn’t keep track of location and time in the KB.  To do this we need more variables:
L1,1 to show that agent in L1,1.  Does this work?
KB contains "physics" sentences for every single square
For every time t and every location [x,y],
L x,y Ù FacingRight t Ù Forward t Þ L x+1,y
Rapid proliferation of clauses

Summary
Logical agents apply inference to a knowledge base to derive new information and make decisions
Basic concepts of logic:
syntax: formal structure of sentences
semantics: truth of sentences wrt models
entailment: necessary truth of one sentence given another
inference: deriving sentences from other sentences
soundness: derivations produce only entailed sentences
completeness: derivations can produce all entailed sentences
Wumpus world requires the ability to represent partial and negated information, reason by cases, etc.
Resolution is complete for propositional logic
Forward, backward chaining are linear-time, complete for Horn clauses
Propositional logic lacks expressive power