Logic and Planning/Propositional Inference and Logical Agents

Lesson 3.23,376 words

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.

Algorithm:PL-FC-Entails?\textsc{PL-FC-Entails?} — forward chaining over definite clauses
  1. 1
    input: KBKB, definite clauses; qq, a query symbol
  2. 2
    countcount \gets a table of the premise-count of each clause
  3. 3
    inferredinferred \gets a table, falsefalse for every symbol
  4. 4
    agendaagenda \gets a queue of the symbols known true in KBKB
  5. 5
    while agendaagenda is not empty do
  6. 6
    pPop(agenda)p \gets \textsc{Pop}(agenda)
  7. 7
    if p=qp = q then return truetrue
  8. 8
    if inferred[p]=falseinferred[p] = false then
  9. 9
    inferred[p]trueinferred[p] \gets true
  10. 10
    for each clause cc in KBKB with pp in its premise do
  11. 11
    decrement count[c]count[c]
  12. 12
    if count[c]=0count[c] = 0 then add the conclusion of cc to agendaagenda
  13. 13
    return falsefalse

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.

The AND-OR graph for the clauses , , , , plus facts and . A small arc crossing two incoming links marks a conjunction: both must be proved. Forward chaining sets the known leaves and propagates upward to prove .

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 .

A forward-chaining count trace for the AND-OR clauses. Each row shows a symbol popped from the agenda and the clause counts it decrements; a clause fires (adds its head) when its count reaches zero. The query is derived on the last firing.

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.
Algorithm:DPLL\textsc{DPLL} — decide satisfiability of a CNF sentence
  1. 1
    input: clausesclauses, a set of clauses; symbolssymbols, its unassigned symbols; modelmodel
  2. 2
    if every clause in clausesclauses is true in modelmodel then return truetrue
  3. 3
    if some clause in clausesclauses is false in modelmodel then return falsefalse
  4. 4
    P,valueFind-Pure-Symbol(symbols,clauses,model)P, value \gets \textsc{Find-Pure-Symbol}(symbols, clauses, model)
  5. 5
    if PP is non-null then
  6. 6
    return DPLL(clauses,symbolsP,model{P=value})\textsc{DPLL}(clauses, symbols - P, model \cup \{P = value\})
  7. 7
    P,valueFind-Unit-Clause(clauses,model)P, value \gets \textsc{Find-Unit-Clause}(clauses, model)
  8. 8
    if PP is non-null then
  9. 9
    return DPLL(clauses,symbolsP,model{P=value})\textsc{DPLL}(clauses, symbols - P, model \cup \{P = value\})
  10. 10
    PFirst(symbols)P \gets \textsc{First}(symbols); restRest(symbols)rest \gets \textsc{Rest}(symbols)
  11. 11
    return DPLL(clauses,rest,model{P=true})\textsc{DPLL}(clauses, rest, model \cup \{P = true\}) or
  12. 12
    DPLL(clauses,rest,model{P=false})\textsc{DPLL}(clauses, rest, model \cup \{P = false\})

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.
Unit propagation on . The unit forces false, which turns two clauses into new units forcing and false, which falsifies . DPLL reports unsatisfiable without branching. Each arrow is a forced assignment.

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.

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).

Algorithm:WalkSAT\textsc{WalkSAT} — local search for a satisfying model
  1. 1
    input: clausesclauses; pp, walk probability; max-flipsmax\text{-}flips, the flip budget
  2. 2
    modelmodel \gets a random assignment of truetrue/falsefalse to the symbols
  3. 3
    for i=1i = 1 to max-flipsmax\text{-}flips do
  4. 4
    if modelmodel satisfies clausesclauses then return modelmodel
  5. 5
    clauseclause \gets a randomly chosen clause that is false in modelmodel
  6. 6
    with probability pp do
  7. 7
    flip a randomly chosen symbol from clauseclause
  8. 8
    else
  9. 9
    flip the symbol in clauseclause that maximizes satisfied clauses
  10. 10
    return 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.

The satisfiability phase transition for random 3-SAT. The fraction of satisfiable instances (left curve) drops sharply from near 1 to near 0 as the clause-to-symbol ratio crosses about ; median solver runtime (right curve) peaks right at that crossover, where a random instance is as likely satisfiable as not.

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:

A successor-state axiom as a two-branch timeline for one fluent F. F is true at t+1 exactly when an action at t made it true (the CAUSE branch) or F held at t and no action undid it (the PERSIST branch). One such axiom per fluent replaces the frame axioms and dissolves the representational frame problem.

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

Algorithm:Hybrid-Wumpus-Agent\textsc{Hybrid-Wumpus-Agent} — deduce the safe map, plan a route through it
  1. 1
    input: perceptpercept, a list [stench, breeze, glitter, bump, scream]
  2. 2
    persistent: KBKB, initially the atemporal wumpus physics; t0t \gets 0; planplan, empty
  3. 3
    Tell(KB,Make-Percept-Sentence(percept,t))\textsc{Tell}(KB, \textsc{Make-Percept-Sentence}(percept, t))
  4. 4
    Tell\textsc{Tell} the KBKB the temporal physics sentences for time tt
  5. 5
    safe{[x,y]:Ask(KB,OKx,yt)=true}safe \gets \{[x,y] : \textsc{Ask}(KB, \mathit{OK}^t_{x,y}) = true\}
  6. 6
    if Ask(KB,Glittert)=true\textsc{Ask}(KB, \mathit{Glitter}^t) = true then
  7. 7
    plan[Grab]+Plan-Route(current,{[1,1]},safe)+[Climb]plan \gets [\mathit{Grab}] + \textsc{Plan-Route}(current, \{[1,1]\}, safe) + [\mathit{Climb}]
  8. 8
    if planplan is empty then
  9. 9
    unvisited{[x,y]:Ask(KB,Lx,yt)=false for all tt}unvisited \gets \{[x,y] : \textsc{Ask}(KB, L^{t'}_{x,y}) = false \text{ for all } t' \le t\}
  10. 10
    planPlan-Route(current,unvisitedsafe,safe)plan \gets \textsc{Plan-Route}(current, unvisited \cap safe, safe)
  11. 11
    if planplan is empty and Ask(KB,HaveArrowt)=true\textsc{Ask}(KB, \mathit{HaveArrow}^t) = true then
  12. 12
    possible{[x,y]:Ask(KB,¬Wx,y)=false}possible \gets \{[x,y] : \textsc{Ask}(KB, \lnot W_{x,y}) = false\}
  13. 13
    planPlan-Shot(current,possible,safe)plan \gets \textsc{Plan-Shot}(current, possible, safe)
  14. 14
    if planplan is empty then
  15. 15
    planPlan-Route(current,{[1,1]},safe)+[Climb]plan \gets \textsc{Plan-Route}(current, \{[1,1]\}, safe) + [\mathit{Climb}]
  16. 16
    actionPop(plan)action \gets \textsc{Pop}(plan)
  17. 17
    Tell(KB,Make-Action-Sentence(action,t))\textsc{Tell}(KB, \textsc{Make-Action-Sentence}(action, t))
  18. 18
    tt+1t \gets t + 1
  19. 19
    return actionaction

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.

The hybrid wumpus agent's cycle. The percept and the time-indexed axioms are told to the KB; the agent asks which squares are safe, unvisited, or possibly hold the wumpus; a route planner turns those answers into a plan; the popped action is told back to the KB and executed. Logic decides what is true; search decides what to do.

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.

Algorithm:SATPlan\textsc{SATPlan} — find a plan by translating to SAT and solving
  1. 1
    input: initinit, transitiontransition, goalgoal — a problem description; TmaxT_{\max}, a horizon bound
  2. 2
    for t=0t = 0 to TmaxT_{\max} do
  3. 3
    cnfTranslate-To-SAT(init,transition,goal,t)cnf \gets \textsc{Translate-To-SAT}(init, transition, goal, t)
  4. 4
    modelSAT-Solver(cnf)model \gets \textsc{SAT-Solver}(cnf)
  5. 5
    if modelmodel is not null then
  6. 6
    return Extract-Solution(model)\textsc{Extract-Solution}(model)
  7. 7
    return failure
SATPlan unrolls the problem to a fixed horizon t: the initial state, the successor-state axioms for every step, and the goal asserted at time t are conjoined into one CNF sentence. A SAT solver either returns a model, whose true action symbols are read off as the plan, or reports unsatisfiable, and the horizon is bumped. The first satisfiable horizon gives the shortest plan.

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.

The DPLL-to-CDCL lineage. Each layer keeps the one below and adds a pruning mechanism: unit propagation and branching from DPLL, then conflict analysis with learned clauses and backjumping, then the engineering (watched literals, VSIDS, restarts) that makes it fast at scale.

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

  1. 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.
  2. 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 .
  3. 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.
  4. 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.
  5. AIMA, §7.7.2 A Hybrid Agent; §7.7.3 Logical State Estimation: Hybrid-Wumpus-Agent (Figure 7.20) pairing Asked 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).
  6. 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 ╌╌