Propositional Inference and Logical Agents
Model checking and resolution decide entailment, but both can blow up. This part turns propositional logic into a practical engine and a working agent.
╌╌╌╌
This builds on Logical Agents and Propositional Logic, which set up the knowledge base, the entailment relation , and two complete but potentially exponential ways to decide it — truth-table enumeration and resolution. Here we make inference fast where we can, and give the agent a way to reason across time.
Horn clauses and chaining
Completeness is often unneeded. Many real knowledge bases restrict the form of their sentences, which allows a faster, still-sound inference method.1 A definite clause is a disjunction of literals with exactly one positive literal; a Horn clause relaxes this to at most one positive literal. Every definite clause is a Horn clause. The restriction matters for three reasons.
First, a definite clause reads naturally as an implication whose premise is a conjunction of positive literals (the body) and whose conclusion is a single positive literal (the head): becomes . A clause with a single positive literal, like , is a fact. Second, inference with Horn clauses runs through the forward-chaining and backward-chaining algorithms, whose steps are natural enough for a human to follow — the basis of logic programming. Third, deciding entailment with Horn clauses takes time linear in the size of the knowledge base.
Forward chaining is data-driven. It starts from the known facts and fires any
implication whose entire body is known, adding the head to the known set, until
the query appears or nothing more can fire. PL-FC-Entails? runs this in linear
time by keeping, for each clause, a count of premises not yet satisfied; each
time a symbol is confirmed, it decrements the counts of the clauses that mention
it, and fires a clause the moment its count hits zero.
- 1input: , definite clauses; , a query symbol
- 2a table of the premise-count of each clause
- 3a table, for every symbol
- 4a queue of the symbols known true in
- 5while is not empty do
- 6
- 7if then return
- 8if then
- 9
- 10for each clause in with in its premise do
- 11decrement
- 12if then add the conclusion of to
- 13return
Forward chaining is sound (every step is a Modus Ponens) and complete for definite
clauses: at the fixed point where nothing more fires, the inferred table is a
model of , so every entailed atom has already been derived. The dual algorithm,
backward chaining, is goal-driven: to prove , find the implications whose
head is and try to prove their bodies, recursing until it bottoms out at known
facts. It touches only propositions relevant to the query, so it is often far
cheaper than linear.
Both algorithms have a clean reading as search over an AND–OR graph. Multiple links joined by an arc form a conjunction — all of them must be proved — while links without an arc form a disjunction — any one suffices. Forward chaining sets the known leaves and propagates upward, waiting at each conjunction until all its inputs are known; backward chaining walks the same graph downward from the goal.
To see forward chaining run, trace it on the definite clauses ,
, , ,
with facts and , querying . Initialize each clause's count to the
number of premises: the and
clauses start at 2, the clause at 2,
at 1. The agenda begins as .
Each fact confirmed decrements the counts of the clauses that mention it; a clause fires the instant its count hits zero, and its head joins the agenda. The whole run touches each clause a constant number of times, which is what makes it linear.
Effective model checking
Resolution and chaining prove entailment. But since entailment reduces to
unsatisfiability, and unsatisfiability is a SAT question, the fastest general
propositional reasoners are SAT solvers: algorithms that decide whether a set of
clauses has a satisfying model. Two families dominate, and both improve on the
brute enumeration of TT-Entails?.2
DPLL
The Davis–Putnam–Logemann–Loveland algorithm — DPLL — takes a CNF sentence and
does a recursive, depth-first search over models, exactly like TT-Entails?, but
with three improvements that prune vast subtrees.
- Early termination. A clause is already true if any one of its literals is true, and the whole sentence already false if any clause is false — either can be detected before the model is complete, letting the search abandon a subtree early.
- Pure symbols. A symbol that appears with the same sign in every remaining clause is pure; assigning it to satisfy those clauses can never hurt, so DPLL fixes pure symbols without branching.
- Unit clauses. A clause with a single unassigned literal (the rest already false) forces that literal's value. Assigning it can turn another clause into a unit clause, and so on — a cascade called unit propagation, which reduces to forward chaining when the clauses are definite.
- 1input: , a set of clauses; , its unassigned symbols;
- 2if every clause in is true in then return
- 3if some clause in is false in then return
- 4
- 5if is non-null then
- 6return
- 7
- 8if is non-null then
- 9return
- 10;
- 11return or
- 12
To see the pruning at work, run DPLL on a small unsatisfiable set. Let the clauses be over symbols . Brute enumeration would test up to models; DPLL closes the case with no branching at all:
- is a unit clause, forcing .
- With false, becomes the unit , forcing ; likewise forces .
- Now is — a falsified clause — so the branch fails, and since no choice was ever made, the whole set is unsatisfiable.
Real solvers layer more tricks on this skeleton — component analysis, degree-based variable ordering, conflict-clause learning with intelligent backtracking, random restarts, and fast dynamic indexing of clauses. With them, modern DPLL descendants decide sentences with tens of millions of variables, and have made hardware and protocol verification routine where hand-guided proofs once ruled.
WalkSAT and local search
The second family abandons systematic search for local search over complete
assignments. Start with a random model and repeatedly flip the truth value of one
symbol, guided by an evaluation function that counts unsatisfied clauses.
WalkSAT is the canonical example: on each step it picks an unsatisfied clause,
then either flips the symbol in it that minimizes total unsatisfied clauses (a
greedy min-conflicts
move) or, with probability , flips a random symbol in
it (a random walk
move to escape local minima).
- 1input: ; , walk probability; , the flip budget
- 2a random assignment of / to the symbols
- 3for to do
- 4if satisfies then return
- 5a randomly chosen clause that is false in
- 6with probability do
- 7flip a randomly chosen symbol from
- 8else
- 9flip the symbol in that maximizes satisfied clauses
- 10return failure
The trade is fundamental. When WalkSAT returns a model, the sentence is definitely
satisfiable; but when it returns failure, the cause is ambiguous — the sentence may
be unsatisfiable, or the flip budget may simply have run out. Local search cannot
reliably prove unsatisfiability, which is what deciding entailment demands. So an
agent can use WalkSAT to say I couldn't find a world where this square is unsafe,
a strong empirical hint, but never a proof. DPLL, being complete, gives the proof
when one is needed.
The hardest random SAT instances cluster near a clause-to-symbol ratio around : far below it, problems are underconstrained and models are dense and easy to stumble onto; far above, they are overconstrained and quickly seen to have no model; right at the threshold, an instance is as likely satisfiable as not, and both DPLL and WalkSAT slow sharply.
Agents based on propositional logic
The lesson opened with a knowledge-based agent that Tells its percepts and
Asks for an action, and everything since has built the inference machinery that
answers the Ask. What it has not yet built is a rich enough for a situated
agent that acts over time. The wumpus sentences through describe a
single snapshot. A real agent moves, and after it moves the sentence "the agent is
in " is no longer true. To reason across time we need proposition symbols
that carry a time index, and axioms that say how the world changes.3
The device is the fluent: a proposition whose truth varies with time, written with a time superscript. means "the agent is in at time "; means it still holds its arrow at time ; means it executes at time . Symbols for permanent facts — for a pit, for the wumpus — carry no superscript and are atemporal. The percept-to-property links now read at a particular time: for any and square ,
The frame problem
The hard part is stating how fluents change. The obvious move is an effect axiom: if the agent is at facing east at time and goes forward, then at time it is at and no longer at .
Assert and the agent can prove — so far so good.
But Ask the whether holds and it cannot prove it
either way. The effect axiom said what the action changed; it said nothing about
what stayed the same, so the arrow's status simply drops out of the deducible
facts. This is the frame problem: an action leaves almost everything untouched,
and stating all of it is the difficulty.4
One repair is a frame axiom for every fluent an action leaves alone — , and one like it for the wumpus's life, the gold's location, and so on. With actions and fluents this is axioms, most of them asserting that nothing happened — the representational frame problem. Real worlds have many fluents but each action changes only a small number of them (the world has locality), so the fix should cost , not .
Successor-state axioms
The fix is to stop writing axioms about actions and write one axiom per fluent instead. A fluent is true at in exactly two cases: the action at made it true, or it was already true at and the action did not make it false. That schema is the successor-state axiom:
The arrow is the simplest case. Nothing reloads it, so the made true
branch is
empty and the axiom is just persistence minus the one action that spends it:
Location is more involved, because several actions and orientations can put the agent in a square. holds if the agent was already at and did not move off it (either the action was not , or it walked into a wall and bumped), or it moved forward into from an adjacent square facing the right way:
Given a complete set of successor-state axioms plus the percept-property links, the
agent can Ask any answerable question about the current state. Running the six
percepts and actions from the opening story through the , the agent proves
(it knows where it is), and (it has pinned the
wumpus and a pit), and, with a safety axiom , it proves
— square is safe to enter. A sound and complete solver
like DPLL answers each such query in milliseconds for small caves.
A hybrid agent
Deduction tells the agent what is true; it does not by itself tell the agent what
to do. The hybrid agent couples the propositional with the
problem-solving search of the earlier modules: it Asks the which squares are
safe, then plans a route through them with . Its starts with the
atemporal wumpus physics
and, each step, gains the new percept sentence and the
-indexed axioms (the successor-state axioms among them).5
- 1input: , a list [stench, breeze, glitter, bump, scream]
- 2persistent: , initially the atemporal wumpus physics; ; , empty
- 3
- 4the the temporal physics sentences for time
- 5
- 6if then
- 7
- 8if is empty then
- 9
- 10
- 11if is empty and then
- 12
- 13
- 14if is empty then
- 15
- 16
- 17
- 18
- 19return
The goals sit in a strict priority order: grab visible gold and head home; else route to the nearest unvisited safe square; else, if armed, plan a shot at a possible wumpus square (one where is not provable); else take a calculated risk on a not-provably-unsafe square; else climb out. Each branch pairs a logical query — is this square safe, unvisited, possibly-wumpus — with an route through allowed squares.
One weakness stays hidden in the loop: the calls to Ask grow more expensive as
climbs, because each inference reaches further back through more time-indexed
symbols. An agent whose per-step cost grows with its lifetime is untenable. The
fix is logical state estimation — cache a belief state, a single sentence
over the current time step's symbols that stands in for the whole percept history,
and update it in place each step. The exact belief state can need a formula of size
exponential in the number of symbols, so a common approximation keeps it as a
1-CNF conjunction of literals: prove and for each symbol and
keep whichever holds. This is a conservative approximation — it may forget a
disjunction like that names no single provable literal, so
its set of possible worlds is an outer envelope around the true one, never a subset.
SATPlan: planning as satisfiability
The hybrid agent deduces safety with Ask but plans routes with . It can
plan by logic alone. Recall the refutation identity: entailment reduces to
satisfiability. Planning has a dual reduction — a plan exists iff a certain
sentence is satisfiable, and the satisfying model is the plan. SATPlan
builds that sentence and hands it to a SAT solver.6
The sentence conjoins three parts, all over symbols indexed up to a horizon : the initial state ; the successor-state axioms for every action at every step up to ; and the goal asserted at time , for the wumpus . A satisfying model assigns truth values to the action symbols across time; reading off the ones set true yields a sequence of actions that reaches the goal. Because the agent does not know the plan length in advance, SATPlan tries horizons up to and returns the first that succeeds, which is the shortest plan.
- 1input: , , — a problem description; , a horizon bound
- 2for to do
- 3
- 4
- 5if is not null then
- 6return
- 7return failure
The subtlety is that a good enough for Ask is not good enough for SATPlan,
and what separates them is the gap between entailment and satisfiability. Ask
proves the goal only from what is forced; SATPlan is free to set any unforced
symbol to whatever makes the goal true. Give it and the goal
and it finds not only the honest plan but also the absurd
— by quietly assigning true, placing the agent in
two squares at once, since nothing forbade it. Three families of extra axioms close
these leaks:
- Location/state constraints. Assert the agent is in exactly one square (and has one orientation) each step, e.g. for every ; the successor-state axioms then carry the constraint forward.
- Precondition axioms. The successor-state axioms predict that an
ill-preconditioned action does nothing, but do not forbid selecting it —
SATPlan will
shoot
with no arrow. Adding rules that out. - Action-exclusion axioms. Without them a model can set and both true. For each interfering pair add ; imposing exclusion only on pairs that truly conflict leaves room for legitimate simultaneous actions, and since SATPlan finds the shortest legal plan it uses that room.
With the initial state, successor-state axioms, precondition axioms, and
action-exclusion axioms, every model of the sentence is a valid plan — no spurious
solutions survive. A DPLL-style solver handles the 11-step wumpus plan without
difficulty. That SATPlan surfaces missing constraints as bogus plans makes it a
sharp debugging tool for a knowledge base: each absurd solution names an axiom the
forgot to state. This closes the knowledge-based-agent loop the lesson opened —
the same Tell/Ask interface now perceives across time, tracks a belief state,
and selects actions, all by propositional inference.
CDCL and the modern SAT revolution
AIMA's DPLL is the 1962 skeleton. The solvers that made SAT an industrial tool descend from a single idea layered on top of it: conflict-driven clause learning (CDCL). When search hits a falsified clause, DPLL merely backtracks one level; a CDCL solver instead analyzes the conflict, computes the assignment that caused it, and adds a new learned clause that forbids that assignment from ever recurring, then jumps back non-chronologically to the earliest decision that matters. The learned clauses accumulate into a memory of dead ends. Marques-Silva and Sakallah's GRASP (1996, IEEE Trans. Computers) introduced conflict analysis and non-chronological backtracking; Chaff (Moskewicz, Madigan, Zhao, Zhang, and Malik, DAC 2001) added the two-watched-literals scheme, which makes unit propagation cheap by watching only two literals per clause instead of scanning all of them, and the VSIDS decision heuristic, which biases branching toward variables that appear in recent conflicts. MiniSat (Eén and Sörensson, SAT 2003) distilled the whole design into a few thousand lines that became the template for a generation of solvers.
Two threads extend the reach of SAT further. The annual SAT Competition, running
since 2002, drives benchmark-measured progress and has repeatedly shown
CDCL solvers dispatching structured industrial instances that random 3-SAT theory
would call impossibly large. And SMT — satisfiability modulo theories — bolts a
CDCL core to decision procedures for richer theories (linear arithmetic, bit-vectors,
arrays, uninterpreted functions), so a solver can reason about and
rather than opaque Boolean symbols. Barrett and Tinelli's survey (in the
Handbook of Model Checking, 2018) and solvers like Z3 (de Moura and Bjørner, TACAS
2008) made SMT the engine behind program verifiers, symbolic-execution bug finders,
and type checkers. The lesson's DPLL is where all of this starts: the propagate-branch
loop is still the core, wrapped in decades of learning and engineering.
Footnotes
- AIMA, §7.5.3 Horn and Definite Clauses; §7.5.4 Forward and Backward Chaining: definite versus Horn clauses, body and head,
PL-FC-Entails?in linear time, the fixed-point completeness argument, backward chaining as goal-directed reasoning, and the AND–OR graph. ↩ - AIMA, §7.6 Effective Propositional Model Checking: DPLL with early termination, pure-symbol and unit-clause heuristics, unit propagation, the extra tricks in modern solvers, WalkSAT local search, and the satisfiability threshold near ratio . ↩
- AIMA, §7.7 Agents Based on Propositional Logic; §7.7.1 The Current State of the World: time-indexed fluents, atemporal symbols, and the percept-property links that connect what is sensed at a time to permanent properties of squares. ↩
- AIMA, §7.7.1: effect axioms and the frame problem — an effect axiom fails to state what an action leaves unchanged, so a fluent's status can become unprovable; frame axioms fix it at (the representational frame problem), while locality means only should be needed. ↩
- AIMA, §7.7.2 A Hybrid Agent; §7.7.3 Logical State Estimation:
Hybrid-Wumpus-Agent(Figure 7.20) pairingAsked safety queries with route planning under a priority of goals; belief states as sentences, the exponential blow-up of exact state estimation, and the 1-CNF conservative approximation (Figure 7.21). ↩ - AIMA, §7.7.4 Making Plans by Propositional Inference:
SATPlan(Figure 7.22), the init/transition/goal sentence unrolled to horizon , the entailment-versus-satisfiability gap that admits spurious plans, and the location, precondition, and action-exclusion axioms that make every model a valid plan. ↩
╌╌ END ╌╌