Lecture 2 · Normal Forms, SAT Solving and Resolution

Introduction to Automated Reasoning · Lecture 02。个人学习讲义与配套实验,按主题整理并持续修订。

课程源码 ZIP ↓

个人整理的学习笔记,非官方讲义;课程来源与整理说明见课程介绍。配套示例未逐一运行验证。

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 2 · Thu 01/08/2026 · Propositional logic: normal forms, SAT solving, resolution (Caroline Trippel). Homework 1 was released that day. Reading: Bradley & Manna, The Calculus of Computation (CC) §1.6–1.7; Enderton, A Mathematical Introduction to Logic (MI) §1.6. Basis: The Stanford slides are on Canvas and not public. This lecture follows the official topic list and reading, and two public decks of the Iowa course CS:4980 (Cesare Tinelli, Spring 2024): Normal Forms in Propositional Logic and Decision Procedures for Satisfiability in Propositional Logic. Both state that they are adapted from slides by Clark Barrett, Caroline Trippel and Andrew (Haoze) Wu at Stanford. “The slides” below means those decks. Their examples are reused here:

  • the exercises ¬((p∨¬q)⇒r)\neg((p \vee \neg q) \Rightarrow r) and ¬(a⇒(¬b⇒a))\neg(a \Rightarrow (\neg b \Rightarrow a));
  • the NNF blow-up of (a1⇔a2)⇔(a3⇔a4)(a_1 \Leftrightarrow a_2) \Leftrightarrow (a_3 \Leftrightarrow a_4);
  • the naming of p1⇔(p2⇔…(p5⇔p6))p_1 \Leftrightarrow (p_2 \Leftrightarrow \dots (p_5 \Leftrightarrow p_6)) and its “32 vs 4 copies of p6p_6”;
  • the seven-name clausal-form table;
  • the DIMACS example;
  • the resolution refutation of {p1,p2},{p1,¬p2},{¬p1,p3},{¬p1,¬p3}\{p_1, p_2\}, \{p_1, \neg p_2\}, \{\neg p_1, p_3\}, \{\neg p_1, \neg p_3\};
  • the four Davis–Putnam transformations and the two complete DP runs.

These notes add proofs (termination of NNF, the parity lower bound, correctness of Tseitin and Plaisted–Greenbaum, soundness and refutational completeness of resolution, correctness of DP with model reconstruction), the modeling patterns of §8, and four experiments that measure every claim. The experiments and their code were designed for these notes and do not reflect what was said in class. Code: code/lecture02/ (4 scripts + 3 modules; Python standard library only, matplotlib optional; about 2 to 12 seconds each) Reading time: 4 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Convert a formula to NNF, DNF and CNF by rewriting, and explain when each conversion is linear and when it explodes.
  2. Prove that some formulas (parity) have no small equivalent CNF, and explain why converting to DNF cannot be a shortcut to SAT.
  3. Define equisatisfiability, apply Tseitin’s transformation by hand, prove it correct, and explain what the Plaisted–Greenbaum variant saves and loses.
  4. Use a SAT solver for a validity question correctly (encode the negation).
  5. Read and write the DIMACS format, and use the vocabulary of clause sets: literal, complement, unit, Horn, tautology, subsumption, empty clause vs empty set.
  6. Apply the resolution rule, write and check a resolution refutation, and prove resolution sound and refutationally complete.
  7. Run the Davis–Putnam procedure by hand, reconstruct a model from it, and explain its memory explosion.
  8. Explain, with measured numbers, why the pigeonhole formulas are hard for every resolution-based method.

0.2 Prerequisites and scope

Assumed (Lecture 1)Introduced hereDeveloped later
formulas as trees, structural inductionnormal forms, rewriting to completionrewriting systems for theories (Lectures 10–13)
interpretations, satisfiability, equivalenceequisatisfiability, projection of modelsSkolemization keeps only equisatisfiability too (Lecture 7)
the semantic-argument methodresolution, saturation, DPproof systems in general (Lecture 3), DPLL (Lecture 4), CDCL (Lecture 5)
the adder miter and its exponential wallTseitin encoding of circuits, DIMACSbit-blasting (Lecture 16), model checking (Lecture 9)

0.3 Map

§1  why normal forms; equivalent vs equisatisfiable
§2  negation normal form: rules, termination, the ⇔ blow-up, polarity                       ← code 01
§3  DNF and CNF by distribution; the parity lower bound; why DNF is no shortcut             ← code 01
§4  Tseitin's transformation and Plaisted–Greenbaum; correctness; validity via negation      ← code 02
§5  clause sets: vocabulary, the DIMACS format                                              ← code 02
§6  resolution: the rule, refutations and their checking, completeness, saturation, pigeonholes ← code 03
§7  the Davis–Putnam procedure: four transformations, model reconstruction, memory          ← code 04
§8  modeling with clauses: cardinality constraints and benchmark families
§9 summary   §10 common pitfalls   §11 exercises   §12 further reading   §13 next lecture

Suggested order: §1–§3 → run 01 → §4–§5 → run 02 → §6 → run 03 → §7 → run 04 → §8.

0.4 Notation (additions to Lecture 1)

SymbolMeaning
ll, l1,l2,…l_1, l_2, \dotsliterals: a variable pp or its negation ¬p\neg p
lˉ\bar lthe complement of ll: pˉ=¬p\bar p = \neg p and ¬p‾=p\overline{\neg p} = p
C,DC, Dclauses: disjunctions of literals, written as sets {l1,…,lk}\{l_1, \dots, l_k\}
{}\{\}the empty clause (unsatisfiable)
Δ\Deltaa clause set (a conjunction of clauses); ∅\emptyset is the empty clause set (satisfiable)
F≈GF \approx GFF and GG are equisatisfiable (both satisfiable or both unsatisfiable)
Δ⊢ResC\Delta \vdash_{\mathrm{Res}} CCC can be derived from Δ\Delta by resolution
1,−3,…1, -3, \dotsDIMACS literals: variable pip_i is the integer ii, ¬pi\neg p_i is −i-i

0.5 The code of this lecture

Three new modules extend logic.py from Lecture 1 (imported, not copied, through the small helper course_path.py):

  • cnf.py — the CNF class (integer literals with names, printing, DIMACS reading and writing), truth tables of clause sets for cross-checks, NNF, a step-by-step rewriting engine for the slides’ rules, DNF/CNF by distribution with a size budget, and Tseitin / Plaisted–Greenbaum.
  • sat_families.py — problems as clause sets: pigeonholes, graph coloring, n-queens, Sudoku, random k-SAT, the adder miters of Lecture 1, parity chains, cardinality constraints. (The planned name was encodings.py; that is the name of a Python standard-library package, so the file could never have been imported.)
  • resolution.py — the resolution rule, derivations, refutation printing, an independent proof checker, saturation (a complete decision procedure), unit resolution, and the Davis–Putnam procedure with model reconstruction.

Lectures 4 and 5 build their solvers on cnf.py and test them on sat_families.py.


1. Why normal forms?

1.1 The lesson of Lecture 1

Lecture 1 ended with two decision procedures and a measured disappointment. The semantic-argument method has ten rules, one per connective and sign, and on random CNF formulas it needed 44,254 lines where a truth table needs 16 rows. One reason: the cases of a β-rule overlap, and nothing in the method knows which subformulas have already been satisfied.

A reasoning engine works best on a small, uniform input language. If every input has the same shape, the engine needs fewer rules, its data structures can be specialized, and its invariants are easier to state and prove. This is the job of a normal form: a restricted sub-language into which every formula can be translated.

Intuition. Think of a compiler. Source programs are written in a rich language with loops, functions and expressions nested in any way. The compiler first lowers them into a simple intermediate representation (three-address code, SSA). Optimizations then deal with only a few instruction shapes. Normal forms are the intermediate representation of automated reasoning.

1.2 Three normal forms, two kinds of translation

The slides name three normal forms used everywhere:

Normal formShapeTypical use
NNF (negation normal form)only ∧,∨,¬\wedge, \vee, \neg; ¬\neg only in front of atomsfirst step of the other two; polarity reasoning
DNF (disjunctive normal form)a disjunction of cubes (conjunctions of literals)satisfiability is trivial; model enumeration
CNF (conjunctive normal form)a conjunction of clauses (disjunctions of literals)the input format of SAT solvers

There are two ways to translate into a normal form, and the difference between them is the main idea of this lecture:

  • Equivalent translation: the result has exactly the same models, over the same variables. Every formula has an equivalent NNF, DNF and CNF — but the DNF and CNF can be exponentially larger (§3).
  • Equisatisfiable translation: the result may use new variables; it is satisfiable exactly when the input is. Tseitin’s transformation produces an equisatisfiable CNF of linear size (§4).

For a SAT solver, which only answers “satisfiable or not?” (and, if so, gives a model), equisatisfiability is enough — provided the models can be translated back, which Tseitin’s can (§4.3).


2. Negation normal form

2.1 Definition and the rewrite rules

A formula is in NNF if it uses only ∧,∨,¬\wedge, \vee, \neg, and ¬\neg appears only in front of atoms (pp, ⊤\top, ⊥\bot). The slides’ grammar:

⟨Literal⟩::=⟨Atom⟩∣¬⟨Atom⟩⟨Formula⟩::=⟨Literal⟩∣⟨Formula⟩∨⟨Formula⟩∣⟨Formula⟩∧⟨Formula⟩\langle\text{Literal}\rangle ::= \langle\text{Atom}\rangle \mid \neg\langle\text{Atom}\rangle \qquad \langle\text{Formula}\rangle ::= \langle\text{Literal}\rangle \mid \langle\text{Formula}\rangle \vee \langle\text{Formula}\rangle \mid \langle\text{Formula}\rangle \wedge \langle\text{Formula}\rangle

To convert, apply these rewrite rules to the formula and its subformulas, in any order, until none applies (“to completion”):

RuleRewriteWhy it is allowed
⇔ eliminationα⇔β  →  (α⇒β)∧(β⇒α)\alpha \Leftrightarrow \beta \;\to\; (\alpha \Rightarrow \beta) \wedge (\beta \Rightarrow \alpha)definition of ⇔
⇒ eliminationα⇒β  →  ¬α∨β\alpha \Rightarrow \beta \;\to\; \neg\alpha \vee \betatruth table of ⇒
¬ into ∧¬(α∧β)  →  ¬α∨¬β\neg(\alpha \wedge \beta) \;\to\; \neg\alpha \vee \neg\betaDe Morgan
¬ into ∨¬(α∨β)  →  ¬α∧¬β\neg(\alpha \vee \beta) \;\to\; \neg\alpha \wedge \neg\betaDe Morgan
¬¬ elimination¬¬α  →  α\neg\neg\alpha \;\to\; \alphadouble negation
¬⊥, ¬⊤¬⊥→⊤\neg\bot \to \top, ¬⊤→⊥\neg\top \to \bottruth tables

Each rule replaces a subformula by an equivalent one, so by the substitution of equivalents (Lecture 1, §6.3) every step preserves the meaning of the whole formula. The rules of DNF and CNF (§3) are of the same kind.

Script 01 runs the rules step by step. On the slides’ first exercise:

start            ¬(p ∨ ¬q ⇒ r)
⇒ elimination    ¬(¬(p ∨ ¬q) ∨ r)
¬ into ∨         ¬¬(p ∨ ¬q) ∧ ¬r
¬¬ elimination   (p ∨ ¬q) ∧ ¬r

On the second, ¬(a⇒(¬b⇒a))\neg(a \Rightarrow (\neg b \Rightarrow a)) becomes a∧¬b∧¬aa \wedge \neg b \wedge \neg a in six steps: a single conjunction containing both aa and ¬a\neg a, so the formula is unsatisfiable.

2.2 Why the rewriting stops

“Apply the rules until none applies” is only a procedure if it always stops. Could the rules undo each other forever? The standard way to prove termination is a measure: a natural number that every rewrite step strictly decreases. Natural numbers cannot decrease forever, so no rewrite sequence is infinite.

Define a weight ww by structural recursion (Lecture 1, §3.4):

w(p)=w(⊤)=w(⊥)=2w(¬α)=2w(α)w(α∧β)=w(α∨β)=w(α)+w(β)+1w(α⇒β)=2w(α)+w(β)+2w(α⇔β)=2w(α)+2w(β)+w(α)+w(β)+6\begin{aligned} w(p) = w(\top) = w(\bot) &= 2 & w(\neg\alpha) &= 2^{w(\alpha)}\\ w(\alpha \wedge \beta) = w(\alpha \vee \beta) &= w(\alpha) + w(\beta) + 1 & w(\alpha \Rightarrow \beta) &= 2^{w(\alpha)} + w(\beta) + 2\\ w(\alpha \Leftrightarrow \beta) &= 2^{w(\alpha)} + 2^{w(\beta)} + w(\alpha) + w(\beta) + 6 \end{aligned}

Write a=w(α)≥2a = w(\alpha) \ge 2 and b=w(β)≥2b = w(\beta) \ge 2 and check each rule:

ruleweight beforeweight after
⇔ elimination2a+2b+a+b+62^a + 2^b + a + b + 6(2a+b+2)+(2b+a+2)+1(2^a + b + 2) + (2^b + a + 2) + 1 — smaller by 1
⇒ elimination2a+b+22^a + b + 22a+b+12^a + b + 1
¬ into ∧, ¬ into ∨2a+b+12^{a+b+1}2a+2b+12^a + 2^b + 1 — much smaller, since a,b≥2a, b \ge 2
¬¬ elimination22a2^{2^a}aa
¬⊤, ¬⊥22=42^2 = 422

Every rule decreases the weight of the subformula it rewrites. Every line of the definition is strictly increasing in w(α)w(\alpha) and w(β)w(\beta), so a smaller subformula makes the whole formula smaller, wherever the rewrite happens. Hence every rewrite step lowers the weight of the whole formula, and the rewriting terminates, in any order. The exponentials are what make the ¬-pushing rules decrease: a ¬ above a big subformula is “expensive”, and pushing it down splits it into cheaper pieces.

The code does not rewrite step by step (except to show traces). It computes the NNF in one recursive pass that carries a polarity (§2.4); structural recursion terminates by construction.

2.3 How large is the NNF?

The slides state:

Theorem 1. Every formula without ⇔ has an equivalent NNF with a linear increase in size (e.g. in the number of variable occurrences).

Indeed, without ⇔ no rule copies a subformula: ⇒ elimination and De Morgan only move and add ¬ symbols. Script 01 (Part 2) checks it on 5,000 random formulas with ¬, ∧, ∨, ⇒: the number of variable occurrences was unchanged in all 5,000, and the size grew by a factor of at most 1.47.

With ⇔ it is different: α⇔β\alpha \Leftrightarrow \beta becomes (¬α∨β)∧(¬β∨α)(\neg\alpha \vee \beta) \wedge (\neg\beta \vee \alpha), with two copies of each side, one positive and one negative. Nested ⇔ multiply the copies. On the balanced ⇔ trees of script 01 (depth 2 is the slides’ (a1⇔a2)⇔(a3⇔a4)(a_1 \Leftrightarrow a_2) \Leftrightarrow (a_3 \Leftrightarrow a_4)):

depth123456
variable occurrences in the input248163264
variable occurrences in the NNF416642561,0244,096
NNF tree size9391596392,55910,239
NNF DAG size72355119247503

The slides’ example goes from 4 variable occurrences to 16. In general the NNF of a depth-dd ⇔ tree has 4d4^d occurrences for 2d2^d variables: quadratic in the input, and for a chain of nested ⇔ (each ⇔ inside the next) it is exponential in the chain length.

The last row is the first hint of the cure. Every subformula appears in the NNF in only two versions, positive and negative. If equal subformulas are stored once (a DAG, Lecture 1 §10.6), the NNF stays linear: 503 nodes at depth 6 instead of 10,239. Tseitin’s transformation (§4) turns this sharing into clauses.

2.4 Polarity: computing the NNF in one pass

Instead of rewriting until nothing changes, the code computes the NNF in one recursive pass that carries a polarity: nnf(g, positive) returns the NNF of gg, nnf(g, negative) the NNF of ¬g\neg g.

nnf+(α∧β)=nnf+(α)∧nnf+(β)nnf−(α∧β)=nnf−(α)∨nnf−(β)nnf+(α⇒β)=nnf−(α)∨nnf+(β)nnf−(α⇒β)=nnf+(α)∧nnf−(β)nnf±(¬α)=nnf∓(α)nnf−(p)=¬p\begin{aligned} \mathrm{nnf}^+(\alpha \wedge \beta) &= \mathrm{nnf}^+(\alpha) \wedge \mathrm{nnf}^+(\beta) & \mathrm{nnf}^-(\alpha \wedge \beta) &= \mathrm{nnf}^-(\alpha) \vee \mathrm{nnf}^-(\beta)\\ \mathrm{nnf}^+(\alpha \Rightarrow \beta) &= \mathrm{nnf}^-(\alpha) \vee \mathrm{nnf}^+(\beta) & \mathrm{nnf}^-(\alpha \Rightarrow \beta) &= \mathrm{nnf}^+(\alpha) \wedge \mathrm{nnf}^-(\beta)\\ \mathrm{nnf}^{\pm}(\neg\alpha) &= \mathrm{nnf}^{\mp}(\alpha) & \mathrm{nnf}^-(p) &= \neg p \end{aligned}

and similarly for ∨ and ⇔. This view introduces a notion used again in §4.4: the polarity of a subformula occurrence. An occurrence is positive if it sits under an even number of negations (counting the left side of ⇒ as a negation), negative if under an odd number, and it has both polarities under ⇔. Polarity tells which direction of truth matters: making a positive subformula more true can only make the whole formula more true (monotonicity), and conversely for negative ones.


3. DNF and CNF, and why they explode

3.1 Definitions and the distributive laws

A cube is a conjunction of literals; a DNF is a disjunction of cubes. A clause is a disjunction of literals; a CNF is a conjunction of clauses:

DNF: ⋁i⋀jlijCNF: ⋀i⋁jlij\text{DNF: } \bigvee_i \bigwedge_j l_{ij} \qquad\qquad \text{CNF: } \bigwedge_i \bigvee_j l_{ij}

To convert an NNF to DNF, apply the distributive law of ∧ over ∨ (and flatten nested conjunctions and disjunctions); for CNF, the dual law of ∨ over ∧:

DNF: α∧(β∨γ)→(α∧β)∨(α∧γ)CNF: α∨(β∧γ)→(α∨β)∧(α∨γ)\text{DNF: } \alpha \wedge (\beta \vee \gamma) \to (\alpha \wedge \beta) \vee (\alpha \wedge \gamma) \qquad\qquad \text{CNF: } \alpha \vee (\beta \wedge \gamma) \to (\alpha \vee \beta) \wedge (\alpha \vee \gamma)

Each step copies α\alpha. That copy is the source of the explosion. On the slides’ first exercise the DNF needs one distribution step, copying ¬r\neg r into both cubes: (p∧¬r)∨(¬q∧¬r)(p \wedge \neg r) \vee (\neg q \wedge \neg r), while the NNF (p∨¬q)∧¬r(p \vee \neg q) \wedge \neg r is already a CNF.

The code works on sets rather than formula trees, which is the same computation, organized:

clauses(α∧β)=clauses(α)∪clauses(β)clauses(α∨β)={ C∪D:C∈clauses(α), D∈clauses(β) }\mathrm{clauses}(\alpha \wedge \beta) = \mathrm{clauses}(\alpha) \cup \mathrm{clauses}(\beta) \qquad \mathrm{clauses}(\alpha \vee \beta) = \{\, C \cup D : C \in \mathrm{clauses}(\alpha),\ D \in \mathrm{clauses}(\beta) \,\}

The second line is the distributive law: (C1∧C2)∨(D1∧D2)≡(C1∨D1)∧(C1∨D2)∧(C2∨D1)∧(C2∨D2)(C_1 \wedge C_2) \vee (D_1 \wedge D_2) \equiv (C_1 \vee D_1) \wedge (C_1 \vee D_2) \wedge (C_2 \vee D_1) \wedge (C_2 \vee D_2). Tautological clauses (p∨¬p∨…p \vee \neg p \vee \dots) and duplicates are dropped on the way, which changes nothing semantically.

3.2 Measured: three linear families, three exponential normal forms

Script 01 (Part 3) converts three families whose formulas grow linearly:

n24681012
(x1∧y1)∨⋯∨(xn∧yn)(x_1 \wedge y_1) \vee \dots \vee (x_n \wedge y_n): size71523313947
… its CNF: clauses416642561,0244,096
parity p1⇔(p2⇔…pn)p_1 \Leftrightarrow (p_2 \Leftrightarrow \dots p_n): size3711151923
… its CNF: clauses28321285122,048
… its CNF: literals4321921,0245,12024,576
(x1∨y1)∧⋯∧(xn∨yn)(x_1 \vee y_1) \wedge \dots \wedge (x_n \vee y_n): its DNF, cubes416642561,0244,096

Equivalent normal forms explode

Every equivalent normal form doubles with each nn. The first family is the textbook example: a clause of the CNF must pick one of xi,yix_i, y_i from every pair, and all 2n2^n choices are needed.

3.3 Is it the method’s fault? The parity lower bound

Maybe a cleverer algorithm would find a smaller equivalent CNF? For parity, provably not.

Proposition. Every CNF equivalent to p1⊕⋯⊕pnp_1 \oplus \dots \oplus p_n (or to its negation, the ⇔ chain) has at least 2n−12^{n-1} clauses.

Proof. Drop tautological clauses; they change nothing. Let CC be a clause of an equivalent CNF, and suppose CC does not mention some variable xx. CC is not a tautology, so some interpretation II falsifies it. Then II falsifies the whole CNF, so II makes the parity function false. Flip the value of xx in II: CC is still false (it does not mention xx), so the CNF is still false — but the parity function is now true. Contradiction. So every clause mentions all nn variables, and is then false in exactly one row of the truth table. Each of the 2n−12^{n-1} false rows of the parity function must be excluded by some clause, so there are at least 2n−12^{n-1} clauses. ∎

Script 01 confirms the shape for n=8n = 8: 128 clauses, every clause has all 8 variables, and the truth table has 128 false rows.

The conversion also works harder than its output suggests. Under ⇔, the NNF contains both versions of every subformula, and distribution combines one with the other; almost all the products are tautologies that are thrown away. Script 01 counts the clause pairs combined: 1,751 for n=8n = 8 (128 clauses produced), 355,675 for n=12n = 12 (2,048 clauses) — the work grows about 4-fold per variable while the output doubles.

3.4 Why not just convert to DNF?

A DNF is satisfiable iff at least one cube is free of complementary literals — a linear scan. Dually, a CNF is valid iff every clause is a tautology. Script 01 (Part 4) checks both tests against truth tables on 2,000 random formulas: 2,000/2,000 agreement each.

So why not convert every formula to DNF and decide satisfiability in linear time? Because the conversion does the hard work. A 3-CNF with mm clauses (ai∨bi∨ci)(a_i \vee b_i \vee c_i) over disjoint variables has 3m3^m cubes: 59,049 for m=10m = 10 (script 01). In general, if DNF conversion were polynomial, SAT would be in P. The slides’ conclusion:

DNFCNF
satisfiabilitylinear timeNP-complete
equivalent conversionexponential in the worst caseexponential in the worst case
equisatisfiable conversion—linear (Tseitin, §4)

Modern SAT solvers expect CNF-like input. They choose to tackle the hardness of the satisfiability problem at run time, where clever search often avoids the worst case, rather than at transformation time, where the worst case is unavoidable.

3.5 Why CNF is the natural input format

Beyond the existence of a linear equisatisfiable conversion, CNF fits how problems are stated:

  • Constraints accumulate conjunctively. A specification is a list of requirements, each of which must hold. “Every pigeon sits in a hole” is one clause per pigeon; “no two pigeons share a hole” is one clause per pair (§8).
  • A clause is a local, checkable requirement. Under a partial assignment a clause is satisfied, falsified, or “waiting”; when all but one literal are false, the last one is forced (a unit clause). This makes propagation cheap — the engine of DPLL and CDCL (Lectures 4–5).
  • Learning adds clauses. A solver that learns from a conflict expresses the lesson as one more clause; the input language is closed under what the solver produces.

4. Tseitin’s transformation: equisatisfiable and linear

4.1 Naming subformulas

The slides’ recipe for a “space-efficient CNF transformation”, from Tseitin (1968):

  1. Take a non-literal subformula α\alpha of the formula φ\varphi.
  2. Introduce a new name nn for it: a fresh variable.
  3. Add a definition n⇔αn \Leftrightarrow \alpha.
  4. Replace α\alpha in φ\varphi by nn.

Repeat until every formula is small, then convert each small definition to CNF by the standard method — which is cheap, because each definition has a fixed shape. On the slides’ chain φ=p1⇔(p2⇔(p3⇔(p4⇔(p5⇔p6))))\varphi = p_1 \Leftrightarrow (p_2 \Leftrightarrow (p_3 \Leftrightarrow (p_4 \Leftrightarrow (p_5 \Leftrightarrow p_6)))), naming every inner ⇔ gives

p1⇔(p2⇔n3),n3⇔(p3⇔n4),n4⇔(p4⇔n5),n5⇔(p5⇔p6).p_1 \Leftrightarrow (p_2 \Leftrightarrow n_3),\quad n_3 \Leftrightarrow (p_3 \Leftrightarrow n_4),\quad n_4 \Leftrightarrow (p_4 \Leftrightarrow n_5),\quad n_5 \Leftrightarrow (p_5 \Leftrightarrow p_6).

The slides claim that the CNF of φ\varphi by distribution contains 32 copies of p6p_6, and the CNF of the named set only 4. Script 02 (Part 2) counts:

conversionvarsclausesliteralsoccurrences of p6p_6
distribution63219232
Tseitin1121614

(The parity CNF has 32 clauses and each mentions every variable, §3.3. Of the named set, only the 4 clauses of n5⇔(p5⇔p6)n_5 \Leftrightarrow (p_5 \Leftrightarrow p_6) mention p6p_6.)

4.2 The clause patterns

Applied systematically, naming gives every non-literal subformula g=a∘bg = a \circ b its own variable ngn_g, writes the definition ng⇔(lit(a)∘lit(b))n_g \Leftrightarrow (\mathrm{lit}(a) \circ \mathrm{lit}(b)), where lit(x)\mathrm{lit}(x) is the literal that stands for xx (a variable, its negation, or xx‘s name), and finally asserts the root’s literal. Each definition becomes a fixed handful of clauses:

definition”nn ⇒ definition”“definition ⇒ nn”
n⇔a∧bn \Leftrightarrow a \wedge b{¬n,a}\{\neg n, a\}, {¬n,b}\{\neg n, b\}{¬a,¬b,n}\{\neg a, \neg b, n\}
n⇔a∨bn \Leftrightarrow a \vee b{¬n,a,b}\{\neg n, a, b\}{¬a,n}\{\neg a, n\}, {¬b,n}\{\neg b, n\}
n⇔(a⇒b)n \Leftrightarrow (a \Rightarrow b){¬n,¬a,b}\{\neg n, \neg a, b\}{a,n}\{a, n\}, {¬b,n}\{\neg b, n\}
n⇔(a⇔b)n \Leftrightarrow (a \Leftrightarrow b){¬n,¬a,b}\{\neg n, \neg a, b\}, {¬n,a,¬b}\{\neg n, a, \neg b\}{n,a,b}\{n, a, b\}, {n,¬a,¬b}\{n, \neg a, \neg b\}
n⇔¬an \Leftrightarrow \neg a{¬n,¬a}\{\neg n, \neg a\}{n,a}\{n, a\}

You can derive every line yourself: n⇒(a∧b)n \Rightarrow (a \wedge b) is ¬n∨(a∧b)\neg n \vee (a \wedge b), which distributes into two clauses; (a∧b)⇒n(a \wedge b) \Rightarrow n is ¬a∨¬b∨n\neg a \vee \neg b \vee n.

The slides’ worked example is φ=¬((p⇒q)∧(p∧q⇒r)⇒(p⇒r))\varphi = \neg((p \Rightarrow q) \wedge (p \wedge q \Rightarrow r) \Rightarrow (p \Rightarrow r)), the negation of a valid formula. Script 02 (Part 1) reproduces the slides’ table exactly, with names in pre-order (n1n_1 is the whole formula):

namesubformuladefinitionclauses
n1n_1¬((p⇒q)∧(p∧q⇒r)⇒(p⇒r))\neg((p \Rightarrow q) \wedge (p \wedge q \Rightarrow r) \Rightarrow (p \Rightarrow r))n1⇔¬n2n_1 \Leftrightarrow \neg n_2¬n1∨¬n2\neg n_1 \vee \neg n_2, n1∨n2n_1 \vee n_2
n2n_2(p⇒q)∧(p∧q⇒r)⇒(p⇒r)(p \Rightarrow q) \wedge (p \wedge q \Rightarrow r) \Rightarrow (p \Rightarrow r)n2⇔(n3⇒n7)n_2 \Leftrightarrow (n_3 \Rightarrow n_7)¬n2∨¬n3∨n7\neg n_2 \vee \neg n_3 \vee n_7, n3∨n2n_3 \vee n_2, ¬n7∨n2\neg n_7 \vee n_2
n3n_3(p⇒q)∧(p∧q⇒r)(p \Rightarrow q) \wedge (p \wedge q \Rightarrow r)n3⇔(n4∧n5)n_3 \Leftrightarrow (n_4 \wedge n_5)¬n3∨n4\neg n_3 \vee n_4, ¬n3∨n5\neg n_3 \vee n_5, ¬n4∨¬n5∨n3\neg n_4 \vee \neg n_5 \vee n_3
n4n_4p⇒qp \Rightarrow qn4⇔(p⇒q)n_4 \Leftrightarrow (p \Rightarrow q)¬n4∨¬p∨q\neg n_4 \vee \neg p \vee q, p∨n4p \vee n_4, ¬q∨n4\neg q \vee n_4
n5n_5p∧q⇒rp \wedge q \Rightarrow rn5⇔(n6⇒r)n_5 \Leftrightarrow (n_6 \Rightarrow r)¬n5∨¬n6∨r\neg n_5 \vee \neg n_6 \vee r, n6∨n5n_6 \vee n_5, ¬r∨n5\neg r \vee n_5
n6n_6p∧qp \wedge qn6⇔(p∧q)n_6 \Leftrightarrow (p \wedge q)¬n6∨p\neg n_6 \vee p, ¬n6∨q\neg n_6 \vee q, ¬p∨¬q∨n6\neg p \vee \neg q \vee n_6
n7n_7p⇒rp \Rightarrow rn7⇔(p⇒r)n_7 \Leftrightarrow (p \Rightarrow r)¬n7∨¬p∨r\neg n_7 \vee \neg p \vee r, p∨n7p \vee n_7, ¬r∨n7\neg r \vee n_7

plus the root clause n1n_1: 10 variables, 21 clauses, and unsatisfiable, as it must be. Solvers do not name negations: ¬g\neg g simply becomes the literal ¬ng\neg n_g. That saves one name and two clauses here (9 variables, 19 clauses, root clause ¬n1\neg n_1).

4.3 Why it is correct

Write T(φ)T(\varphi) for the clause set: all definition clauses plus the root unit clause. VV is the set of variables of φ\varphi.

Theorem (Tseitin). (a) If I⊨T(φ)I \models T(\varphi), then II restricted to VV satisfies φ\varphi. (b) Every interpretation JJ of VV with J⊨φJ \models \varphi extends in exactly one way to a model of T(φ)T(\varphi). Hence φ≈T(φ)\varphi \approx T(\varphi), and the two have the same number of models.

Proof. (a) By structural induction on the named subformulas gg, bottom-up: if II satisfies the definition clauses, then I(ng)=I(g)I(n_g) = I(g). For a leaf-level gate, the clauses of n⇔(a∘b)n \Leftrightarrow (a \circ b) say exactly that nn has the value of a∘ba \circ b; for higher gates, the induction hypothesis says the child names already carry the children’s values. So I(root)=I(φ)I(\mathrm{root}) = I(\varphi), and the root clause makes it true. (b) Extend JJ by ng:=J(g)n_g := J(g) for every named gg. All definitions hold, and the root literal is true because J⊨φJ \models \varphi. The extension is unique, because the definitions force every name’s value. ∎

Two consequences matter in practice:

  • Model translation is free: a model of T(φ)T(\varphi) returned by a solver, restricted to VV, is a model of φ\varphi. This is why a SAT solver can answer satisfiability questions about arbitrary formulas and still return meaningful counterexamples.
  • Model counting is preserved (full Tseitin only), which model counters rely on.

Script 02 (Part 3) checks all claims by truth table on 3,000 random formulas with up to 12 connectives (some with constants):

checkholds for
full Tseitin: satisfiable iff the formula is3,000 / 3,000
full Tseitin: projected models = models of ff3,000 / 3,000
full Tseitin: #models(clauses) = #models(ff)3,000 / 3,000
Plaisted–Greenbaum: projected models = models of ff3,000 / 3,000
Plaisted–Greenbaum: #models(clauses) > #models(ff)1,292 / 3,000

Size. Each distinct subformula costs one variable and at most four clauses of at most three literals, so T(φ)T(\varphi) is linear in the number of distinct subformulas — the DAG size. Shared subformulas get one name.

4.4 Plaisted–Greenbaum: only the direction you need

Look again at the two columns of the clause table. If a subformula occurs only positively (§2.4), the formula can only become more true when ngn_g is replaced by something stronger than gg. So it suffices to say ng⇒gn_g \Rightarrow g (“if the name is true, the subformula really is true”); the other direction never helps satisfy the formula. Dually, a negative occurrence needs only g⇒ngg \Rightarrow n_g; an occurrence under ⇔ needs both.

Plaisted and Greenbaum (1986) proved that this halved encoding is still equisatisfiable, and its models still project onto models of φ\varphi — script 02 confirms both on all 3,000 formulas. What is lost is uniqueness: a name is now only bounded on one side, so a model of φ\varphi can extend in several ways. That raised the model count in 1,292 of the 3,000 formulas. PG saved 4.71 clauses per formula on average there, and about 10% on the adder miters below, where most gates sit under ⊕ (that is, under ⇔, which needs both directions).

4.5 A pitfall: validity needs the negation

Tseitin’s transformation preserves satisfiability, not validity. The valid formula p∨¬pp \vee \neg p becomes

{¬p,n1}, {p,n1}, {n1}\{\neg p, n_1\},\ \{p, n_1\},\ \{n_1\}

which has 2 models out of 4: setting n1n_1 false falsifies it. Script 02 (Part 4) found that all 226 valid formulas among 2,000 random ones have a non-valid Tseitin encoding. The correct way to ask a SAT solver whether φ\varphi is valid is the duality of Lecture 1:

⊨φiff¬φ is unsatisfiableiffT(¬φ) is unsatisfiable,\models \varphi \quad\text{iff}\quad \neg\varphi \text{ is unsatisfiable} \quad\text{iff}\quad T(\neg\varphi) \text{ is unsatisfiable,}

which agreed with the truth table on 2,000/2,000 formulas. Every verification tool asks its questions this way: the “bad behaviour” is encoded, and UNSAT means “no bad behaviour exists”.

4.6 The adder miters of Lecture 1, revisited

Lecture 1’s equivalence check of two adders hit an exponential wall: the miter has 4n4^n truth-table rows. Script 02 (Part 5) converts the ripple-carry vs majority-carry miter both ways:

bits12468163264
formula tree size381014141,4835,4681.3e68.6e103.7e20
formula DAG size2037711051392755471,091
CNF by distribution: clauses4162564,096––––
Tseitin: variables7214977105217441889
Tseitin: clauses15571372172976171,2572,537
Plaisted–Greenbaum: clauses13491211932655531,1292,281

Tseitin vs distribution

By distribution the clause count is 4n4^n: the exponential wall of Lecture 1 moved from time to space. By naming, every gate costs a constant number of clauses: about 40 per bit, 2,537 clauses for two 64-bit adders. The majority carry whose formula tree had 10,485,751 nodes at 20 bits (Lecture 1, §10.6) becomes 136 variables and 289 clauses.

The input is now small. Whether it can be solved fast is a different question, taken up by the rest of this lecture (resolution, DP) and by Lectures 4–5.

Run it. python3 02_tseitin.py (about 4 seconds): the slides’ table, the copies of p6p_6, the correctness checks, the validity pitfall, the adder sizes and the DIMACS output of §5.


5. Clause sets

5.1 Clauses as sets

From now on the slides work only with clause sets. A clause l1∨⋯∨lkl_1 \vee \dots \vee l_k is identified with the set {l1,…,lk}\{l_1, \dots, l_k\}: order and repetition do not matter. A clause set is satisfiable iff some interpretation makes at least one literal of every clause true. Example from the slides: Δ={{p1,p3},{¬p1,p2,¬p3}}\Delta = \{\{p_1, p_3\}, \{\neg p_1, p_2, \neg p_3\}\} is satisfied by {p1↦1,p2↦1,p3↦0}\{p_1 \mapsto 1, p_2 \mapsto 1, p_3 \mapsto 0\}.

Two edge cases deserve to be memorized, because they are opposite:

objectmeaningsatisfiable?why
the empty clause {}\{\}a disjunction of nothingnono literal can be made true (“no options to choose”)
the empty clause set ∅\emptyseta conjunction of nothingyesthere is nothing to satisfy (“no constraints”)

Vocabulary used for the rest of the course:

termmeaningexample
unit clauseexactly one literal{¬p}\{\neg p\}: pp must be false
tautologycontains ll and lˉ\bar l{p,¬p,q}\{p, \neg p, q\}: true in every interpretation, can be dropped
Horn clauseat most one positive literal{¬x1,¬x2,x3}\{\neg x_1, \neg x_2, x_3\}, i.e. x1∧x2⇒x3x_1 \wedge x_2 \Rightarrow x_3
DD subsumes CCD⊆CD \subseteq C{p}\{p\} subsumes {p,q}\{p, q\}: every model of DD satisfies CC, so CC is redundant
pure literalll occurs in Δ\Delta, lˉ\bar l does not§7
clausal form of φ\varphia clause set equisatisfiable with φ\varphithe output of Tseitin

The slides distinguish CNF (an equivalent conjunction of clauses) from clausal form (an equisatisfiable set of clauses). The big advantage of clausal form: any formula can be converted in almost linear time.

5.2 The DIMACS format

The standard text format for clause sets, read by practically every SAT solver:

c example.cnf            comment lines start with c
p cnf 3 2                problem line: p cnf <#variables> <#clauses>
1 -3 0                   p1 ∨ ¬p3      (a literal is a signed variable index; 0 ends the clause)
2 3 -1 0                 p2 ∨ p3 ∨ ¬p1

Variables are numbered from 1, ¬pi\neg p_i is −i-i, and 00 cannot be a literal because −0=0-0 = 0. Our to_dimacs additionally writes c var i name comments so that parse_dimacs can restore the names (other tools ignore comments). Script 02 (Part 6) writes the 64-bit ripple-carry vs or-carry miter: 826 variables, 2,348 clauses, 3,176 lines, and reads it back unchanged.

The same integer representation is used inside the code of the course: the complement of literal l is -l, and its variable is abs(l). All solvers since the 1990s do this; it makes the most frequent operation, “is this literal false?”, a single array lookup.


6. Resolution

6.1 One rule

On clause sets, a single inference rule suffices for a complete refutation method. The resolution rule (Robinson 1965; for propositional clauses already in Davis–Putnam 1960):

C∪{p}D∪{¬p}C∪D\frac{C \cup \{p\} \qquad D \cup \{\neg p\}}{C \cup D}

The conclusion is a resolvent, pp the pivot. The slides’ example: {p1,p3}\{p_1, p_3\} and {p2,¬p3}\{p_2, \neg p_3\} resolve on p3p_3 to {p1,p2}\{p_1, p_2\}.

Intuition. Case analysis on the pivot. If pp is true, the second clause must be satisfied by something in DD; if pp is false, the first by something in CC. Either way, something in C∪DC \cup D is true. The pivot has been “used up” and disappears.

Soundness. {C∪{p},D∪{¬p}}⊨C∪D\{C \cup \{p\}, D \cup \{\neg p\}\} \models C \cup D, by exactly that case analysis. Script 03 (Part 1) checks it on 20,000 random clashing pairs: 20,000/20,000. The converse (resolvent ⊨ premises) held for only 594: resolution derives consequences; it does not preserve equivalence.

One pivot at a time. {p,q}\{p, q\} and {¬p,¬q}\{\neg p, \neg q\} clash on two variables. Resolving on pp gives {q,¬q}\{q, \neg q\}, on qq gives {p,¬p}\{p, \neg p\}: tautologies, useless but harmless. Removing both pivots at once would give {}\{\} — yet the set has 2 models. That step would be unsound, and it is a classic exam mistake.

6.2 Refutations, and how to check one

A resolution derivation of CC from Δ\Delta is a sequence of clauses, each either in Δ\Delta or a resolvent of two earlier ones, ending with CC. A refutation is a derivation of {}\{\}. Since each derived clause is entailed by Δ\Delta and {}\{\} is unsatisfiable, a refutation proves that Δ\Delta is unsatisfiable.

The slides’ example, as found and printed by script 03 (Part 2):

   1. {p1, p2}     input
   2. {p1, ¬p2}    input
   3. {¬p1, p3}    input
   4. {¬p1, ¬p3}   input
   5. {p1}         resolve 1, 2 on p2
   6. {p3}         resolve 5, 3 on p1
   7. {¬p3}        resolve 5, 4 on p1
   8. {}           resolve 6, 7 on p3

Finding a refutation may take a long search; checking one is easy. The function check_refutation trusts nothing: for each line it re-checks that an input line really is an input clause, that a resolvent line cites two earlier lines whose pivot clashes, and that the clause is exactly their resolvent; finally that the last line is {}\{\}. Script 03 shows it accepting the proof above and rejecting four tampered copies (wrong resolvent, forward reference, made-up input, missing final line), each with a precise message.

This asymmetry — hard to find, easy to check — is what makes proofs useful as certificates. When a SAT solver answers UNSAT, it can emit a proof that a tiny, trusted program re-checks (Lecture 5). Lecture 3 turns “a proof is something a fast program can check” into the definition of a proof system.

6.3 Refutational completeness

Resolution cannot derive every consequence: from {p}\{p\} it derives nothing, yet {p}⊨{p,q}\{p\} \models \{p, q\}. What it can do is refute every unsatisfiable set.

Theorem (refutational completeness). If a finite clause set Δ\Delta is unsatisfiable, then Δ⊢Res{}\Delta \vdash_{\mathrm{Res}} \{\}.

The proof rests on a lemma that is also the heart of the Davis–Putnam procedure (§7). For a variable xx, let PP be the clauses of Δ\Delta containing xx, NN those containing ¬x\neg x, and

Resx(Δ)=(Δ∖(P∪N))  ∪  { (C∖{x})∪(D∖{¬x}):C∈P, D∈N }(tautologies removed).\mathrm{Res}_x(\Delta) = (\Delta \setminus (P \cup N)) \;\cup\; \{\, (C \setminus \{x\}) \cup (D \setminus \{\neg x\}) : C \in P,\ D \in N \,\} \quad\text{(tautologies removed).}

Lemma (elimination). Δ\Delta is satisfiable iff Resx(Δ)\mathrm{Res}_x(\Delta) is. Moreover, Resx(Δ)\mathrm{Res}_x(\Delta) does not mention xx.

Proof. (⇒) Every clause of Resx(Δ)\mathrm{Res}_x(\Delta) is in Δ\Delta or a resolvent of clauses of Δ\Delta, hence entailed. (⇐) Let II satisfy Resx(Δ)\mathrm{Res}_x(\Delta) (II need not assign xx). If every C∖{x}C \setminus \{x\} with C∈PC \in P is true under II, set xx false: then PP is satisfied by those remainders and NN by ¬x\neg x. Otherwise some C∈PC \in P has C∖{x}C \setminus \{x\} false under II. Take any D∈ND \in N. If their resolvent is not a tautology, it is in Resx(Δ)\mathrm{Res}_x(\Delta) and true under II; its CC-part is false, so D∖{¬x}D \setminus \{\neg x\} is true. If it is a tautology, some literal l∈C∖{x}l \in C \setminus \{x\} has lˉ∈D∖{¬x}\bar l \in D \setminus \{\neg x\}; ll is false, so lˉ\bar l is true. Either way every D∖{¬x}D \setminus \{\neg x\} is true, so setting xx true satisfies PP (by xx) and NN (by the remainders). ∎

Proof of the theorem. Eliminate the variables of Δ\Delta one by one. Each step preserves unsatisfiability (lemma) and removes one variable. When no variable is left, the clause set is either ∅\emptyset (satisfiable — impossible) or {{}}\{\{\}\}. So {}\{\} was produced, and every clause produced along the way is a resolvent of clauses produced earlier: that is a resolution refutation. ∎

6.4 Saturation: resolution as a decision procedure

The slides turn the rule into a satisfiability proof system with states ⟨Δ,Φ⟩\langle \Delta, \Phi \rangle (Φ\Phi collects discarded tautologies) and four rules:

\textscResolveC1,C2∈Δp∈C1¬p∈C2C=(C1∖{p})∪(C2∖{¬p})C∉Δ∪ΦΔ:=Δ∪{C}\textscClashC∈Δp,¬p∈CΔ:=Δ∖{C}Φ:=Φ∪{C}\textscUnsat{}∈ΔUNSAT\textscSatno other rule appliesSAT\begin{aligned} &\textsc{Resolve}\quad \frac{C_1, C_2 \in \Delta \quad p \in C_1 \quad \neg p \in C_2 \quad C = (C_1 \setminus \{p\}) \cup (C_2 \setminus \{\neg p\}) \quad C \notin \Delta \cup \Phi}{\Delta := \Delta \cup \{C\}}\\[4pt] &\textsc{Clash}\quad \frac{C \in \Delta \quad p, \neg p \in C}{\Delta := \Delta \setminus \{C\} \quad \Phi := \Phi \cup \{C\}} \qquad \textsc{Unsat}\quad \frac{\{\} \in \Delta}{\mathit{UNSAT}} \qquad \textsc{Sat}\quad \frac{\text{no other rule applies}}{\mathit{SAT}} \end{aligned}

Apply Clash or Resolve until the empty clause appears (UNSAT) or neither applies (SAT). It terminates: over nn variables there are at most 3n3^n different clauses (each variable absent, positive or negative), and each Resolve adds a new one. It is correct: soundness gives the UNSAT direction; refutational completeness gives the SAT direction (if Δ\Delta were unsatisfiable, {}\{\} would be derivable, and a saturated set contains everything derivable). Lecture 3 makes “sound, complete, terminating” precise for any such system.

The code (saturate) adds two standard refinements:

  • Given-clause loop with shortest-first order. Clauses wait in a queue; the shortest waiting clause is resolved against all processed ones. Short clauses are strong (a unit {p}\{p\} cuts every clause containing ¬p\neg p), and {}\{\} is the shortest of all.
  • Forward subsumption. A new resolvent is dropped if an existing clause is a subset of it. This keeps completeness: a subsumed clause can never be needed in a refutation that its subsuming clause could not replace.

Script 03 (Part 3) on 2,000 random 2-CNF and 3-CNF sets (3–8 variables): saturation agreed with the truth table 2,000/2,000 times (1,318 satisfiable, 682 unsatisfiable), and all 682 refutations passed the independent checker. Subsumption matters a lot on satisfiable sets, which must be closed under all their consequences before SAT can be declared:

varsclausessubsumptionkeptgenerated
412yes / no27 / 30306 / 396
515yes / no53 / 1381,002 / 10,250
618yes / no86 / 4772,069 / 152,159

(Measured while developing the code, not printed by the scripts: plain saturation of satisfiable random 3-CNF over 8 variables kept 6,050 of the 6,560 possible non-empty clauses over 8 variables, after computing 31.8 million resolvents in about 40 seconds.)

6.5 Unit resolution: fast but incomplete

Unit resolution restricts one premise to be a unit clause {l}\{l\}: from {l}\{l\} and {lˉ}∪D\{\bar l\} \cup D derive DD. It is what unit propagation does in every modern solver. Alone, it is not refutationally complete: {p,q},{p,¬q},{¬p,q},{¬p,¬q}\{p, q\}, \{p, \neg q\}, \{\neg p, q\}, \{\neg p, \neg q\} is unsatisfiable but has no unit clause, so the rule never applies. Script 03 found that unit resolution refuted 0 of the 682 unsatisfiable random 2- and 3-CNF sets (none contains a unit clause), but all 300 unsatisfiable random Horn sets: for Horn clauses unit resolution is complete, which is why Horn-SAT is decidable in linear time (Dowling and Gallier 1984).

The slides’ remark points ahead: modern SAT solvers use unit resolution plus backtracking search. Guessing a value for a variable creates a unit clause, and unit resolution takes over. That is DPLL (Lecture 4).

6.6 How long must a refutation be? The pigeonhole formulas

PHPn\mathrm{PHP}_n says that n+1n+1 pigeons sit in nn holes, one pigeon per hole: variables pi,jp_{i,j} (“pigeon ii in hole jj”), one clause pi,1∨⋯∨pi,np_{i,1} \vee \dots \vee p_{i,n} per pigeon, and ¬pi,j∨¬pk,j\neg p_{i,j} \vee \neg p_{k,j} for every hole and pair of pigeons. A human sees the contradiction instantly — by counting. Script 03 (Part 4) runs saturation:

holes nnvarsclauseskeptgeneratedproof steps (DAG)proof steps (tree)truth-table rows
1236322222^2
269621201214262^6
312221,1418,020662012122^{12}
4204539,2561,361,0923623,4562202^{20}
53081> 60,000 (stopped)–––2302^{30}

Resolution on the pigeonhole formulas

The input grows like n3n^3; the resolvents generated grow ×40, ×67, ×170 per extra hole. This is not a weakness of our implementation:

Theorem (Haken 1985). Every resolution refutation of PHPn\mathrm{PHP}_n contains 2Ω(n)2^{\Omega(n)} clauses.

Resolution reasons clause by clause and cannot express “count the pigeons”. Since the search of DPLL and CDCL can be read as resolution proofs (Lectures 4–5), no such solver can be fast on these formulas. Stronger proof systems (cutting planes, extended resolution) have short pigeonhole proofs; Lecture 3 places them in a hierarchy.

6.7 Proofs as DAGs, proofs as trees

A derived clause can be used many times. Written as a DAG, it is derived once; written as a tree, it is re-derived at every use. The two shapes correspond to two classes of solvers: a DPLL search tree yields a tree-like refutation (Lecture 4), a CDCL run a DAG-like one (Lecture 5). Script 03 (Part 5), on random unsatisfiable 3-CNF with 7 clauses per variable (averages over 5 instances):

varsclauseskept by saturationproof steps (DAG)proof steps (tree)tree / DAG
64213917.029.21.67
85627325.661.42.34
107051034.4170.25.14
128482738.2194.44.64

The refutations are a small fraction of what saturation keeps — most of the search is wasted on clauses the proof never uses — and the tree versions are several times longer. On the pigeonholes the gap reached ×9.5 (3,456 vs 362 steps at n=4n = 4). It is known that tree-like resolution can require exponentially longer proofs than general resolution on some families, one theoretical reason why CDCL beats DPLL.

Run it. python3 03_resolution.py (about 12 seconds).


7. The Davis–Putnam procedure

7.1 Four satisfiability-preserving transformations

Davis and Putnam (1960) gave the first procedure that did something smarter than truth tables. It repeatedly applies four transformations, each of which preserves satisfiability (not equivalence):

transformationpremiseeffectjustification
unit propagation (1-literal rule)a unit clause {l}\{l\}remove every clause containing ll; remove lˉ\bar l from every other clausell must be true: clauses with ll are satisfied, lˉ\bar l can no longer help
pure-literal eliminationll occurs, lˉ\bar l does notremove every clause containing llany model can be changed to make ll true without breaking a clause
tautology eliminationp,¬p∈Cp, \neg p \in Cremove CCCC is true in every interpretation
elimination by resolutionpp occurs positively and negativelyreplace P∪NP \cup N by all non-tautological resolvents on ppthe elimination lemma (§6.3)

The first two shrink the set; the third removes useless clauses; the fourth removes a variable for good but may multiply clauses. Repeated, they end either with {}\{\} (UNSAT) or with ∅\emptyset (SAT).

Script 04 (Part 1) replays the slides’ examples. Unit propagation (the slide prints the second clause as {p1,p4}\{p_1, p_4\}, but its stated result requires {¬p1,p4}\{\neg p_1, p_4\}, so we use that):

start       {p1}, {¬p1, p4}, {¬p1, p2, p3}
UP p1       {p4}, {p2, p3}
UP p4       {p2, p3}

Elimination of p1p_1: {p1,p2},{¬p1,p3},{¬p1,¬p3,p4},{p2,¬p4}\{p_1, p_2\}, \{\neg p_1, p_3\}, \{\neg p_1, \neg p_3, p_4\}, \{p_2, \neg p_4\} becomes {p2,p3},{p2,¬p4},{p2,¬p3,p4}\{p_2, p_3\}, \{p_2, \neg p_4\}, \{p_2, \neg p_3, p_4\}. The slides ask: if a variable occurs positively in 3 clauses and negatively in 3, how many clauses after elimination? Up to 3×3=93 \times 3 = 9, replacing 6.

The slides’ two complete runs:

DP example 1                                       DP example 2
start   {¬p2, p5}, {p1, p2, p3}, {p2, ¬p3, ¬p6}    start   {p1, p2}, {p1, ¬p2}, {¬p1, p3}, {¬p1, ¬p3}
Res p2  {p1, p3, p5}, {¬p3, p5, ¬p6}               Res p2  {p1}, {¬p1, p3}, {¬p1, ¬p3}
Res p3  {p1, p5, ¬p6}                              UP p1   {p3}, {¬p3}
PL p1   ∅            -> SAT                        Res p3  {}           -> UNSAT

Our automatic strategy (unit propagation first, then pure literals, then the cheapest elimination) finishes example 1 with three pure literals and no resolution at all.

7.2 A model, not just “SAT”

DP never assigns variables, so where does a model come from? From the records of the run, undone in reverse order:

  • a unit or pure literal ll: make ll true;
  • an eliminated variable xx: give still-unassigned variables of its removed clauses P∪NP \cup N the value false, then choose the value of xx that satisfies all of P∪NP \cup N. One exists: the resolvents, which later steps have already satisfied, say exactly that (the (⇐) direction of the lemma, now run as an algorithm).

On example 1 this gives p1,¬p2,¬p3,¬p4,¬p5,¬p6p_1, \neg p_2, \neg p_3, \neg p_4, \neg p_5, \neg p_6. Script 04 (Part 2) checks DP on 2,000 random clause sets: both elimination orders agreed with the truth table 2,000/2,000 times, and all 1,241 reconstructed models satisfied their input. The same reconstruction is used by modern preprocessors that eliminate variables before search.

7.3 The memory explosion

Each elimination replaces ∣P∣+∣N∣|P| + |N| clauses by up to ∣P∣⋅∣N∣|P| \cdot |N|: a quadratic step, repeated once per variable. The slides warn that for large formulas this “can quickly exhaust the available memory”. Script 04 (Part 3) measures the peak number of clauses DP holds, on random 3-CNF, for two densities and two elimination orders: min_product eliminates the variable with the fewest possible resolvents first; first uses a fixed order. Runs are stopped (B) before an elimination that would push the total number of clause pairs combined above 2,000,000.

clauses/varordervarsoutcome (3 instances)peak clauses
2min_product20 / 60 / 100all SAT40, 40, 40 / 120, 120, 403 / 200, 1,636, 200
4.26min_product10S S S78, 66, 61
4.26min_product15S S U503, 468, 602
4.26min_product20S U S2,047, 1,953, 2,972
4.26min_product25B B B> 8,798, > 6,947, > 6,855
2first20S S S83, 88, 238
2first30S B S566, > 9,072, 786
2first40B B B> 13,655, > 10,565, > 7,010
4.26first15S S B1,748, 2,482, > 5,005

DP memory

Three lessons:

  1. Sparse instances are easy. At 2 clauses per variable with a good order, the peak is usually the input itself, even at 100 variables (one instance peaks at 1,636 clauses): most eliminations remove more clauses than they add.
  2. Dense random instances explode. Near 4.26 clauses per variable — the hardest region for random 3-SAT, as Lecture 4 will measure — the peak grows 4 to 8 times per 5 extra variables, and at 25 variables every run exceeds the budget.
  3. The order matters as much as the instance. On the same instances, the fixed order is stopped at 40 variables where min_product needs at most 208 clauses. Finding the best order is NP-hard: the cost of DP is governed by the induced width (treewidth) of the variable graph along the elimination order (Dechter and Rish 1994), so practical tools use greedy heuristics.

7.4 Where DP shines, and where it drowns

Script 04 (Part 4):

instanceclausesstatusunit stepseliminationspeak clauses
implication chain, 1,000 vars1,001UNSAT1,00001,001
pigeonhole, 3 holes22UNSAT11122
pigeonhole, 4 holes45UNSAT119113
pigeonhole, 5 holes81UNSAT1292,402
8-bit adder miter (Tseitin)276UNSAT296348
16-bit adder miter (Tseitin)572UNSAT2200828
32-bit adder miter (Tseitin)1,164UNSAT24081,788
  • Implication chains need unit propagation only.
  • The adder miters — hopeless for truth tables beyond about 12 bits in Lecture 1 — are decided with a peak at most 1.6 times the input, even at 32 bits. Circuits are “thin”: every variable meets only a few others, so a greedy order keeps every elimination small. This is DP’s strength.
  • Pigeonholes are its weakness: every variable meets many others, and the peak grows ×5 from 3 to 4 holes and ×21 from 4 to 5. DP is a resolution procedure, so Haken’s bound applies.

Notice the contrast with saturation (§6.6): on PHP4\mathrm{PHP}_4, saturation kept 39,256 clauses; DP never held more than 113. A good strategy for applying the same rule makes an enormous difference — a theme of Lecture 3.

7.5 From DP to DPLL, and DP today

DP keeps the whole, growing problem in memory. Davis, Logemann and Loveland (1962) replaced the elimination step with splitting: choose a literal ll, check Δ∪{{l}}\Delta \cup \{\{l\}\} recursively, and if that fails, check Δ∪{{lˉ}}\Delta \cup \{\{\bar l\}\}. The unit clause {l}\{l\} immediately triggers unit propagation. Memory stays linear; the price is backtracking time. That procedure, DPLL, is Lecture 4, and its descendant CDCL is Lecture 5.

Variable elimination did not disappear. Modern solvers run it as preprocessing, eliminating a variable only when that does not increase the number of clauses (“bounded variable elimination”, Eén and Biere 2005, as reported in the SAT literature), and reconstruct the model exactly as in §7.2.

Run it. python3 04_davis_putnam.py (about 6 seconds).


8. Modeling with clauses

Clauses are a modeling language. Most encodings combine a few patterns, provided by sat_families.py:

Cardinality constraints. “At least one of l1,…,lkl_1, \dots, l_k” is one clause. “At most one” has two standard encodings:

encodingnew variablesclausesidea
pairwise0k(k−1)/2k(k-1)/2¬li∨¬lj\neg l_i \vee \neg l_j for every pair
sequential counter (Sinz 2005)k−1k - 13k−43k - 4sis_i = “one of the first ii is true”; a true lil_i forbids every earlier one through si−1s_{i-1}

Both have the same models on l1,…,lkl_1, \dots, l_k (the second after projecting away the sis_i, checked by truth table for k≤6k \le 6 in sat_families.py). The sequential one is equisatisfiable in the sense of §4: linear instead of quadratic, at the cost of new variables.

Benchmark families used from now on:

familyvariablesclausessatisfiable?
pigeonhole PHPn\mathrm{PHP}_nn(n+1)n(n+1)(n+1)+n(n+12)(n+1) + n\binom{n+1}{2}never
graph kk-coloringk⋅∣V∣k \cdot \lvert V \rvert∣V∣(1+(k2))+k∣E∣\lvert V \rvert (1 + \binom{k}{2}) + k \lvert E \rvertdepends on the graph
nn-queensn2n^2“exactly one per row, at most one per column and diagonal”for n=1n = 1 and n≥4n \ge 4
9 × 9 Sudoku72911,988 + one unit clause per givenfor a proper puzzle
random kk-CNFnnmm, each over kk distinct random variableslikely iff m/nm/n is small
adder mitersabout 14 per bitabout 40 per bit (Tseitin)iff the adders differ

Testing an encoding the way Lecture 1 did — counting its models and comparing with an independent count — catches most mistakes. The self-test of sat_families.py does this: nn-queens has 1, 0, 0, 2 solutions for n=1..4n = 1..4, a triangle has 6 proper 3-colorings and no 2-coloring, the 3-bit adder miter is unsatisfiable and its buggy version is not.


9. Summary

  1. Normal forms give reasoning engines a small, uniform input language. NNF, DNF and CNF exist for every formula, but the equivalent DNF and CNF can be exponentially larger; NNF is linear except under ⇔.
  2. For some formulas the blow-up is unavoidable: every CNF of parity has 2n−12^{n-1} clauses. DNF makes satisfiability trivial, which is exactly why its conversion must be expensive.
  3. Equisatisfiability is enough for SAT. Tseitin’s transformation names every subformula, adds a fixed handful of clauses per name, and gives a linear-size clause set whose models project exactly onto the models of the input (full Tseitin even preserves the count). Plaisted–Greenbaum keeps only the direction the polarity needs.
  4. To decide validity with a SAT solver, encode the negation: ⊨φ\models \varphi iff T(¬φ)T(\neg\varphi) is unsatisfiable.
  5. Clause sets have a standard vocabulary (unit, Horn, tautology, subsumption; {}\{\} is unsatisfiable, ∅\emptyset satisfiable) and a standard file format, DIMACS.
  6. Resolution is one sound rule that is refutationally complete; saturation turns it into a decision procedure. Refutations are certificates: easy to check by an independent program.
  7. Unit resolution is fast and complete for Horn clauses but incomplete in general; DPLL completes it with splitting.
  8. Davis–Putnam eliminates variables by resolution, propagates units and pure literals, and reconstructs a model. It shines on thin, structured instances (adders) and drowns in memory on dense ones; the elimination order is crucial.
  9. Pigeonhole formulas need exponentially long resolution proofs (Haken): a limit for every resolution-based solver, measured here on saturation and DP.

10. Common pitfalls

PitfallWhy it is wrongCorrect view
“Tseitin’s output is equivalent to the input”It has new variables; an interpretation of the old ones can be extended wronglyIt is equisatisfiable; models project onto models (§4.3)
Checking validity as “is T(φ)T(\varphi) valid?”T(φ)T(\varphi) is never valid if it names anything (all 226 valid formulas tested)Check that T(¬φ)T(\neg\varphi) is unsatisfiable (§4.5)
Confusing {}\{\} and ∅\emptysetOne is a clause, the other a clause set{}\{\}: unsatisfiable; ∅\emptyset: satisfiable (§5.1)
Resolving on two pivots at once{p,q},{¬p,¬q}\{p, q\}, \{\neg p, \neg q\} is satisfiableOne pivot per step; double clashes give tautologies (§6.1)
“Resolution derives every consequence”From {p}\{p\} it derives nothing, though {p}⊨{p,q}\{p\} \models \{p, q\}It is refutationally complete: it derives {}\{\} from every unsatisfiable set
“Unit propagation decides SAT”It cannot even start without a unit clauseComplete only for Horn clauses; DPLL adds splitting
Expecting a smarter algorithm to find a small CNF for parityEvery equivalent CNF has 2n−12^{n-1} clauses (§3.3)Use Tseitin (21 clauses for 6 variables)
Converting to DNF to “solve” SATThe DNF itself can be exponential (3m3^m cubes)DNF-SAT is easy because the conversion is hard
Believing DP’s cost depends only on the instanceFixed order: stopped at 40 variables; greedy order: ≤ 208 clauses on the same instancesThe elimination order (treewidth) decides
Naming a module encodings.py (or random.py, logic.py in another project…)A standard-library module of the same name winsChoose names that do not shadow the standard library

11. Exercises

Answers are collapsed; try each exercise first.

1. (normal forms) Convert ¬(p⇒(q∧¬r))∨(q⇔r)\neg(p \Rightarrow (q \wedge \neg r)) \vee (q \Leftrightarrow r) to NNF, then to CNF and to DNF by the rewrite rules. Check with rewrite_trace(parse("..."), CNF_RULES) and cnf_by_distribution.

Answer

NNF: ¬(p⇒(q∧¬r))\neg(p \Rightarrow (q \wedge \neg r)) becomes p∧(¬q∨r)p \wedge (\neg q \vee r), and q⇔rq \Leftrightarrow r becomes (¬q∨r)∧(¬r∨q)(\neg q \vee r) \wedge (\neg r \vee q), so the NNF is p∧(¬q∨r)∨(¬q∨r)∧(¬r∨q)p \wedge (\neg q \vee r) \vee (\neg q \vee r) \wedge (\neg r \vee q). CNF: the rewrite rules alone give four clauses, (p∨¬q∨r)∧(p∨¬r∨q)∧(¬q∨r∨¬q∨r)∧(¬q∨r∨¬r∨q)(p \vee \neg q \vee r) \wedge (p \vee \neg r \vee q) \wedge (\neg q \vee r \vee \neg q \vee r) \wedge (\neg q \vee r \vee \neg r \vee q). Removing the repeated literals in the third and the tautological fourth clause (what cnf_by_distribution does) leaves (p∨¬q∨r)∧(p∨q∨¬r)∧(¬q∨r)(p \vee \neg q \vee r) \wedge (p \vee q \vee \neg r) \wedge (\neg q \vee r). The first clause is even subsumed by the third, so (p∨q∨¬r)∧(¬q∨r)(p \vee q \vee \neg r) \wedge (\neg q \vee r) is an equivalent, smaller CNF. DNF: (p∧¬q)∨(p∧r)∨(¬q∧¬r)∨(q∧r)(p \wedge \neg q) \vee (p \wedge r) \vee (\neg q \wedge \neg r) \vee (q \wedge r), after dropping the contradictory cubes ¬q∧q\neg q \wedge q and r∧¬rr \wedge \neg r.

2. (termination) In the weight ww of §2.2, why must w(¬α)w(\neg\alpha) be exponential in w(α)w(\alpha)? Try w(¬α)=w(α)+1w(\neg\alpha) = w(\alpha) + 1 and find the rule that fails. Then explain why the definition must be strictly increasing in each argument.

Answer

With w(¬α)=w(α)+1w(\neg\alpha) = w(\alpha) + 1, De Morgan maps ¬(α∧β)\neg(\alpha \wedge \beta), of weight a+b+2a + b + 2, to ¬α∨¬β\neg\alpha \vee \neg\beta, of weight (a+1)+(b+1)+1=a+b+3(a + 1) + (b + 1) + 1 = a + b + 3: the weight increases, because the single ¬ became two. The exponential makes one ¬ above a large subformula cost more than two ¬ above its halves (2a+b+1>2a+2b+12^{a+b+1} > 2^a + 2^b + 1). Strict monotonicity is needed because rules are applied inside a context: if ww ignored, say, the left argument of ∧, a rewrite inside it would not change the total weight, and the argument would not show that the whole formula gets lighter.

3. (lower bound) Prove that every CNF equivalent to (x1∧y1)∨⋯∨(xn∧yn)(x_1 \wedge y_1) \vee \dots \vee (x_n \wedge y_n) has at least 2n2^n clauses.

Answer

For every choice cc of one variable from each pair {xi,yi}\{x_i, y_i\}, let IcI_c make the chosen variables false and the others true. Every pair then has a false member, so IcI_c falsifies the formula, hence some clause CcC_c of the CNF. We show that different choices give different clauses. Suppose one clause CC is false under both IcI_c and Ic′I_{c'}, with c≠c′c \ne c'; pick a pair ii where they differ, say xix_i is false in IcI_c and true in Ic′I_{c'} (and yiy_i the opposite). A false clause contains no true literal, so CC contains none of xi,¬xi,yi,¬yix_i, \neg x_i, y_i, \neg y_i (each is true under one of the two interpretations). Now change IcI_c by making both xix_i and yiy_i true: the result satisfies the formula (pair ii is true), but CC, which does not mention xi,yix_i, y_i, is still false — so the CNF is false there, contradicting equivalence. Hence the 2n2^n clauses CcC_c are pairwise distinct. ∎

4. (Tseitin) Give the Tseitin clauses for n⇔(a⊕b)n \Leftrightarrow (a \oplus b) and for an kk-ary n⇔(a1∧⋯∧ak)n \Leftrightarrow (a_1 \wedge \dots \wedge a_k). How many clauses does a kk-ary AND need with binary ANDs instead?

Answer

n⇔(a⊕b)n \Leftrightarrow (a \oplus b): {¬n,a,b},{¬n,¬a,¬b},{n,¬a,b},{n,a,¬b}\{\neg n, a, b\}, \{\neg n, \neg a, \neg b\}, \{n, \neg a, b\}, \{n, a, \neg b\} (the ⇔ pattern with nn negated). n⇔⋀ain \Leftrightarrow \bigwedge a_i: {¬n,ai}\{\neg n, a_i\} for each ii, plus {¬a1,…,¬ak,n}\{\neg a_1, \dots, \neg a_k, n\}: k+1k + 1 clauses, one new variable. With binary ANDs: k−1k - 1 new variables and 3(k−1)3(k-1) clauses. Solvers prefer the kk-ary form.

5. (Tseitin vs PG) Show by a concrete formula that Plaisted–Greenbaum does not preserve the model count. Why does that not hurt satisfiability?

Answer

Take φ=(p∧q)∨r\varphi = (p \wedge q) \vee r, both subformulas positive. Name mm for p∧qp \wedge q and nn for m∨rm \vee r. PG keeps only “name ⇒ definition”: {¬m,p},{¬m,q},{¬n,m,r}\{\neg m, p\}, \{\neg m, q\}, \{\neg n, m, r\} and the root {n}\{n\}. Under p=q=r=1p = q = r = 1, both m=0m = 0 and m=1m = 1 satisfy all clauses: one model of φ\varphi, two models of the clauses. (Full Tseitin adds {¬p,¬q,m}\{\neg p, \neg q, m\}, which forces m=1m = 1.) Satisfiability is not hurt: a model of φ\varphi extends by giving every name the value of its subformula; conversely, in any model of the PG clauses a true name forces its subformula true, and since the names occur only positively, the original formula is at least as true as the clauses claim.

6. (validity) A colleague checks that a 32-bit multiplier is commutative by running a SAT solver on T(mul(a,b)=mul(b,a))T(\mathit{mul}(a, b) = \mathit{mul}(b, a)) and reports “SAT, so it is correct”. What is wrong?

Answer

Satisfiability of the property only shows that some input makes the outputs equal (e.g. a=ba = b). Correctness is validity: the right query is T(mul(a,b)≠mul(b,a))T(\mathit{mul}(a, b) \ne \mathit{mul}(b, a)), and the expected answer is UNSAT; a SAT answer would come with a counterexample input.

7. (resolution) Refute {p,q,r},{¬p,q},{¬q,r},{¬r,p},{¬p,¬q,¬r}\{p, q, r\}, \{\neg p, q\}, \{\neg q, r\}, \{\neg r, p\}, \{\neg p, \neg q, \neg r\} by resolution. Check your proof with check_refutation.

Answer

From {¬q,r}\{\neg q, r\} and {¬r,p}\{\neg r, p\} on rr: {¬q,p}\{\neg q, p\}. With {¬p,q}\{\neg p, q\} the three implications form a cycle p→q→r→pp \to q \to r \to p, so all three variables are equal. From {p,q,r}\{p, q, r\} and {¬r,p}\{\neg r, p\}: {p,q}\{p, q\}; with {¬q,p}\{\neg q, p\}: {p}\{p\}. Then {p}\{p\} with {¬p,q}\{\neg p, q\}: {q}\{q\}; {q}\{q\} with {¬q,r}\{\neg q, r\}: {r}\{r\}. From {¬p,¬q,¬r}\{\neg p, \neg q, \neg r\} and {p}\{p\}: {¬q,¬r}\{\neg q, \neg r\}; with {q}\{q\}: {¬r}\{\neg r\}; with {r}\{r\}: {}\{\}. Eight resolution steps. Shorter refutations exist: saturate finds one with 5 steps — print it with format_refutation.

8. (proof) Prove the elimination lemma’s (⇐) direction for the case where all resolvents are tautologies.

Answer

Then Resx(Δ)=Δ∖(P∪N)\mathrm{Res}_x(\Delta) = \Delta \setminus (P \cup N). Let II satisfy it. If some C∈PC \in P has C∖{x}C \setminus \{x\} false under II, then for every D∈ND \in N the (tautological) resolvent contains a complementary pair l∈C∖{x}l \in C \setminus \{x\}, lˉ∈D∖{¬x}\bar l \in D \setminus \{\neg x\}, and ll is false, so lˉ\bar l is true: every D∖{¬x}D \setminus \{\neg x\} is true; set xx true. Otherwise every C∖{x}C \setminus \{x\} is true; set xx false. Either way P∪NP \cup N is satisfied.

9. (Horn) Prove that unit resolution is refutationally complete for Horn clauses.

Answer

Saturate under unit resolution without deriving {}\{\}. Let TT be the set of variables pp with a unit clause {p}\{p\}; define I(p)=1I(p) = 1 iff p∈Tp \in T. Take any clause CC. If CC contains a negative literal ¬q\neg q with q∉Tq \notin T, it is satisfied. Otherwise all its negative literals ¬q1,…,¬qk\neg q_1, \dots, \neg q_k have {qi}\{q_i\} derived; resolving CC with these units leaves either {}\{\} (impossible: we assumed it was not derived) or the single positive literal {p}\{p\} of CC (Horn: at most one), which is then a unit, so p∈Tp \in T and CC is satisfied. So II is a model, i.e. if the set is unsatisfiable, unit resolution derives {}\{\}.

10. (DP) Run DP by hand on {a,b},{¬a,c},{¬b,c},{¬c,d},{¬c,¬d}\{a, b\}, \{\neg a, c\}, \{\neg b, c\}, \{\neg c, d\}, \{\neg c, \neg d\} eliminating aa, then bb, then cc. How many clauses at each stage? Then reconstruct a model or explain why none exists.

Answer

Eliminate aa: {b,c},{¬b,c},{¬c,d},{¬c,¬d}\{b, c\}, \{\neg b, c\}, \{\neg c, d\}, \{\neg c, \neg d\} (4). Eliminate bb: {c},{¬c,d},{¬c,¬d}\{c\}, \{\neg c, d\}, \{\neg c, \neg d\} (3). Unit propagation of cc (or eliminate cc): {d},{¬d}\{d\}, \{\neg d\}, then {}\{\}: UNSAT. No model. (Indeed a∨ba \vee b forces cc, and cc forces both dd and ¬d\neg d.)

11. (encoding) Encode “exactly two of x1,…,x4x_1, \dots, x_4 are true” as clauses without new variables. How many clauses? Verify by counting models (there must be (42)=6\binom{4}{2} = 6).

Answer

“At most two”: for every 3-subset, ¬xi∨¬xj∨¬xk\neg x_i \vee \neg x_j \vee \neg x_k (4 clauses). “At least two”: for every 3-subset, xi∨xj∨xkx_i \vee x_j \vee x_k (if at most one were true, some 3-subset would be all false) — 4 clauses. Total 8 clauses, 6 models. count_models_cnf(make_cnf([...])) confirms.

12. (sequential counter) Prove that the sequential at-most-one encoding forbids li∧ljl_i \wedge l_j for i<ji < j, and allows every assignment with at most one true ll.

Answer

If lil_i is true then sis_i is true (¬li∨si\neg l_i \vee s_i), and si⇒si+1⇒⋯⇒sj−1s_i \Rightarrow s_{i+1} \Rightarrow \dots \Rightarrow s_{j-1}; the clause ¬lj∨¬sj−1\neg l_j \vee \neg s_{j-1} then forbids ljl_j. Conversely, if only lil_i is true (or none), set sks_k true exactly for k≥ik \ge i (none if no ll is true): every clause holds.

13. (programming) Add backward subsumption to saturate: when a new clause DD is kept, delete every kept clause C⊇DC \supseteq D that has not been used yet. Measure kept clauses and time on PHP4\mathrm{PHP}_4. Is the procedure still complete?

Answer

Completeness is preserved (a subsumed clause is redundant). Implementation detail: deleted clauses may already be cited by the proof, so either keep them for proof extraction but skip them in later resolution steps, or delete only clauses that have not been used yet. The kept-clause count on PHP4\mathrm{PHP}_4 should drop; measure by how much. The exponential growth itself (Haken) cannot go away.

14. (programming) davis_putnam chooses variables by min_product. Implement min_degree (the variable occurring in the fewest clauses) and compare peak clauses on the instances of script 04, Part 3.

Answer

Add a branch to choose_elimination_var computing counts[v] + counts[-v]. On sparse random instances both heuristics behave similarly; near 4.26 clauses per variable the product-based one usually keeps the peak lower, because it accounts for both sides of the elimination. Report what you measure.


12. Further reading

  • Textbooks
    • A. Bradley, Z. Manna, The Calculus of Computation, Springer 2007, §1.6 (normal forms), §1.7 (equisatisfiability, resolution, DPLL).
    • D. Kroening, O. Strichman, Decision Procedures, 2nd ed., 2016, Ch. 1 (Tseitin’s encoding in §1.3) and Ch. 2.
    • A. Biere, M. Heule, H. van Maaren, T. Walsh (eds.), Handbook of Satisfiability, 2nd ed., IOS Press 2021: Ch. 2 (CNF encodings, by S. Prestwich), Ch. 7 (proof complexity, by S. Buss and J. Nordström), Ch. 9 (preprocessing, by A. Biere, M. Järvisalo and B. Kiesl).
    • D. Knuth, The Art of Computer Programming, Vol. 4B (2022), “Satisfiability”: encodings, resolution, and the pigeonhole problem.
  • Papers mentioned
    • G. Tseitin, “On the complexity of derivation in propositional calculus”, 1968 (English translation 1983).
    • D. Plaisted, S. Greenbaum, “A structure-preserving clause form translation”, Journal of Symbolic Computation, 1986.
    • M. Davis, H. Putnam, “A computing procedure for quantification theory”, Journal of the ACM, 1960.
    • M. Davis, G. Logemann, D. Loveland, “A machine program for theorem-proving”, Communications of the ACM, 1962.
    • J. A. Robinson, “A machine-oriented logic based on the resolution principle”, Journal of the ACM, 1965.
    • A. Haken, “The intractability of resolution”, Theoretical Computer Science, 1985.
    • W. Dowling, J. Gallier, “Linear-time algorithms for testing the satisfiability of propositional Horn formulae”, Journal of Logic Programming, 1984.
    • R. Dechter, I. Rish, “Directional resolution: the Davis–Putnam procedure, revisited”, KR 1994.
    • N. Eén, A. Biere, “Effective preprocessing in SAT through variable and clause elimination”, SAT 2005.
    • C. Sinz, “Towards an optimal CNF encoding of Boolean cardinality constraints”, CP 2005.
  • Slides: C. Tinelli, Normal Forms in Propositional Logic and Decision Procedures for Satisfiability in Propositional Logic, Iowa CS:4980, Spring 2024 (adapted from Stanford CS 257 slides by Barrett, Trippel and Wu).

13. Next lecture

Lecture 3 (Proof systems, guest lecture by Clark Barrett) steps back and asks what all these procedures have in common.

  • Truth tables, semantic arguments, resolution saturation and DP are all proof systems: states, rules with premises and conclusions, derivation trees.
  • What must be proved before such a system can be trusted: soundness (rules preserve satisfiability), completeness, termination — and how a strategy turns non-deterministic rules into an algorithm (the gap between saturation and DP on the pigeonholes is a strategy effect).
  • Proof systems as certificates: the Cook–Reckhow definition, a checker for Hilbert-style proofs, and a comparison of proof sizes across systems.
  • Code: proof_systems.py implements rules as functions on states, explores all derivations of small states to check soundness, completeness and termination by machine, and replays the lecture’s examples.
← 返回课程目录