Lecture 10 · First-Order Theories and DPLL(T)

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

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 10 · Thu 02/05/2026 · First-order theories: overview and DPLL(T) (Hanna Lachnitt). The take-home midterm covers Lectures 1–10. Reading: Bradley & Manna (CC) Chapter 3 (first-order theories); congruence closure is CC Chapter 9. Basis: The Stanford slides are on Canvas and not public. This lecture follows two public Iowa decks (CS:4980, Cesare Tinelli, Spring 2024), which say they are adapted from slides by Clark Barrett, Caroline Trippel and Andrew (Haoze) Wu (Stanford):

  • the second half of Satisfiability Modulo Theories: common theories, quantifier-free fragments;
  • Combining Theory Solvers with SAT Solvers: eager and lazy approaches, the very lazy loop, the CDCL(T) rules, theory propagation, the architecture.

The third Iowa deck on theory solvers (congruence closure) is not machine-readable, so §3 is written from CC Chapter 9 and from Nieuwenhuis and Oliveras (2005, 2007). “The slides” below means the Iowa decks.

These notes add:

  • a small SMT solver, smt.py, on top of Lecture 5’s CDCL solver: Boolean abstraction, congruence closure with explanations and backtracking, the very lazy loop, online CDCL(T) with three levels of theory propagation, and Ackermann’s eager reduction;
  • the slides’ derivations reproduced by the code;
  • families where every approach struggles (diamonds, translation validation);
  • checkable answers: models re-evaluated on the input, refutations checked by DRUP plus an independent check of every theory lemma.

The experiments and their code were designed for these notes and do not reflect what was said in class. Code: code/lecture10/ (4 scripts + 1 module; Python standard library only; 1 to 20 seconds each) Reading time: 3–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. Name the common SMT theories and say what “quantifier-free fragment” means, and why SMT focuses on it.
  2. Build the Boolean abstraction of a formula and explain why it over-approximates.
  3. Decide a conjunction of EUF literals by congruence closure, and explain an equality or a conflict.
  4. Run the very lazy SMT loop and say why blocking with explanations beats blocking with models.
  5. State the CDCL(T) rules T-CONFLICT, T-PROPAGATE and T-EXPLAIN, and trace them on an example.
  6. Say what a theory solver must provide (incremental, backtrackable, explaining, propagating).
  7. Perform Ackermann’s reduction with transitivity constraints, and compare eager and lazy SMT.
  8. Check an SMT solver’s answers: models by evaluation, refutations by DRUP plus theory-lemma checks.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
CDCL, learning, backjumping, DRUP (Lecture 5)CDCL(T), theory lemmas, theory propagation—
first-order theories, T-validity (Lecture 8)the SMT theories, quantifier-free fragmentsarithmetic (Lectures 11–12), arrays and strings (13), bit-vectors (16)
Tseitin (Lecture 2)Boolean abstraction—
equality, functions (Lectures 6–8)congruence closure, Ackermann’s reductioncombining theories (Lecture 18)

0.3 Map

§1  first-order theories for SMT                                              ← code 01
§2  from formulas to conjunctions: DNF, the Boolean abstraction, eager vs lazy  ← code 01
§3  congruence closure: deciding EUF conjunctions, with explanations           ← code 02
§4  the very lazy approach                                                     ← code 03
§5  CDCL(T)                                                                    ← code 03
§6  the eager approach: Ackermann's reduction; hard families                    ← code 01, 04
§7  applications and trust: translation validation, certificates               ← code 04
§8 summary   §9 common pitfalls   §10 exercises   §11 further reading   §12 next lecture

0.4 Notation

SymbolMeaning
TT, ⊨T\models_Ta theory and entailment in it (Lecture 8)
EUF (TEUFT_{\mathrm{EUF}})equality with uninterpreted functions: all interpretations of the signature
1,2ˉ,…1, \bar 2, \dotsthe propositional variables of the atoms (the slides’ numbering); 2ˉ=¬2\bar 2 = \neg 2
MM, Δ\Delta, CCCDCL states: trail, clause set, conflict clause (Lecture 5)
s∼ts \sim tss and tt are in the same congruence class
find(x)\mathrm{find}(x)the representative of xx‘s class

0.5 The code of this lecture

One module, smt.py:

  • parse (Lecture 6’s parser) and Abstraction: atoms, the skeleton, and its clauses. A skeleton that is already a CNF keeps its clauses, so the numbering matches the slides; anything else goes through Tseitin.
  • CongruenceClosure: union-find, signature table, use lists, proof-forest explanations, backtracking by an undo log.
  • EUF: a theory solver with three levels of disequality propagation.
  • lazy_offline: the very lazy loop, blocking whole models or explanations.
  • CDCLT: Lecture 5’s CDCLSolver, subclassed with theory hooks, plus solve(formula, ...).
  • ackermann and solve_eager: the eager approach.
  • check_model_euf, naive_euf_unsat and check_unsat: certificates.
  • the benchmark generators diamond, random_euf and hoisting.

1. First-order theories for SMT

1.1 Why theories

Lecture 8 ended with theories: a signature plus a class of intended interpretations. In practice the questions are of this kind:

  • “can i + 1 > n hold on this path while a[i] is read?”;
  • “do these two circuits, written with 64-bit adders and memories, compute the same thing?”

Bit-blasting everything into SAT is possible, as Lecture 9 did for small counters, but it loses structure:

  • a 64-bit multiplier becomes thousands of clauses;
  • an array becomes as many variables as it has cells;
  • "x<y∧y<xx < y \wedge y < x" becomes a hard SAT problem when it is a one-line contradiction for an arithmetic procedure.

Satisfiability modulo theories keeps the theory atoms as they are and decides them with specialized procedures.

1.2 The common theories

The slides list the theories SMT has traditionally focused on. These are theories whose quantifier-free fragment is decidable, often efficiently:

theorysignatureintended modelssatisfiability of the quantifier-free fragment (as the slides state)
EUF, the “empty theory”any symbols, =all interpretationsdecidable, conjunctions in polynomial time (congruence closure); with quantifiers: only semi-decidable (it is FOL)
reals, TRAT_{RA}+,−,∗,≤+, -, *, \le, numeralsthe real numbersfull theory decidable (doubly exponential); linear fragment: conjunctions in polynomial time
integers, TIAT_{IA}+,−,∗,≤+, -, *, \le, numeralsthe integersnot even semi-decidable with ∗* (Hilbert’s tenth problem); linear (Presburger) decidable, worst case triply exponential
arrays, TAT_Aread, writeread-over-write axioms (+ extensionality)full theory undecidable; several decidable fragments
bit-vectors, strings, …——Lectures 13, 16

A fragment is a syntactic restriction:

  • the quantifier-free fragment: no quantifiers; free symbols act as constants;
  • the linear fragment of arithmetic: multiplication only by numerals.

As in propositional logic, φ\varphi is TT-valid iff ¬φ\neg\varphi is TT-unsatisfiable. SMT solvers therefore speak only of satisfiability.

EUF in examples. EUF interprets = as equality and leaves every function symbol uninterpreted: ff may be any function. Script 01, Part 1:

formula φφ¬φso φ is
a=b∧f(a)=b∧g(a)≠g(f(a))a = b \wedge f(a) = b \wedge g(a) \ne g(f(a)) (the slides)UNSATSATunsatisfiable
f3(a)=a∧f5(a)=a∧f(a)≠af^3(a) = a \wedge f^5(a) = a \wedge f(a) \ne aUNSATSATunsatisfiable
p(a)∧a=b∧¬p(b)p(a) \wedge a = b \wedge \neg p(b)UNSATSATunsatisfiable
a=b⇒f(a)=f(b)a = b \Rightarrow f(a) = f(b)SATUNSATvalid
f(a)=f(b)∧a≠bf(a) = f(b) \wedge a \ne bSATSATsatisfiable: ff need not be injective

A model of an EUF formula is a partition of its terms into classes, with every function mapping classes to classes consistently. For f(a)=f(b)∧a≠bf(a) = f(b) \wedge a \ne b the model is the classes {f(a),f(b)}\{f(a), f(b)\}, {a}\{a\}, {b}\{b\}.

Why “uninterpreted” is useful. If a property holds for every ff, it holds for the real ff as well. Verification tools exploit this. They replace a complicated operation (a multiplier, a hash function, a floating-point unit) by an uninterpreted symbol, keeping only “equal inputs give equal outputs”. §7 shows an example.


2. From formulas to conjunctions

2.1 Theorem 1: DNF

Theory solvers decide conjunctions of literals. The slides’ Theorem 1 says this is enough.

Theorem 1. For every theory TT, TT-satisfiability of quantifier-free formulas is decidable iff TT-satisfiability of conjunctions of literals is decidable.

The proof: convert to DNF and check every disjunct. Correct, and exponential. Script 01, Part 3, on the diamond formulas ⋀i<n((xi=yi∧yi=xi+1)∨(xi=zi∧zi=xi+1))∧x0≠xn:\bigwedge_{i<n} \big((x_i = y_i \wedge y_i = x_{i+1}) \vee (x_i = z_i \wedge z_i = x_{i+1})\big) \wedge x_0 \ne x_n:

natomsDNF disjunctsT-consistent
417160
10411,0240

Every one of the 2n2^n disjuncts must be refuted by the theory solver. The SAT solver’s job is to avoid this enumeration.

2.2 The Boolean abstraction

Replace every atom by a propositional variable. For the slides’ running example φ=g(a)=c∧(f(g(a))≠f(c)∨g(a)=d)∧c≠d\varphi = g(a) = c \wedge (f(g(a)) \ne f(c) \vee g(a) = d) \wedge c \ne d script 01, Part 2 prints:

variableatom
1c=g(a)c = g(a)
2f(c)=f(g(a))f(c) = f(g(a))
3d=g(a)d = g(a)
4c=dc = d

The skeleton is 1∧(2ˉ∨3)∧4ˉ1 \wedge (\bar 2 \vee 3) \wedge \bar 4, with clauses {1},{2ˉ,3},{4ˉ}\{1\}, \{\bar 2, 3\}, \{\bar 4\}.

Atoms are normalized first: g(a)=cg(a) = c and c=g(a)c = g(a) must get the same variable, otherwise only the theory would know they are related.

The skeleton has 3 models, and the theory refutes all of them:

Boolean modelT-consistent?T-inconsistent core
1, ¬2, ¬3, ¬4no1, ¬2
1, ¬2, 3, ¬4no1, ¬2
1, 2, 3, ¬4no1, 3, ¬4

So the abstraction over-approximates:

  • an unsatisfiable skeleton proves the formula unsatisfiable;
  • a satisfiable skeleton proves nothing until the theory has checked the model.

2.3 Eager or lazy

The slides contrast two ways to use SAT technology:

eagerlazy
ideatranslate into an equisatisfiable propositional formula; any SAT solverSAT solver on the abstraction; a theory solver refines it
prosthe best SAT solver off the shelftheory-specific reasoning; modular (a new theory = a new theory solver); scales much better
conscare in encoding; tends not to scaledesigning theory solvers is hard; the SAT solver needs extensions for a good interplay
systems (the slides)UCLIDBitwuzla, cvc5, MathSAT, Yices, Z3

§3–§5 build the lazy approach and §6 the eager one. Experiments on both, including a case where the eager one wins, are in §6.


3. Congruence closure

3.1 The problem

Given a conjunction of equalities si=tis_i = t_i and disequalities uj≠vju_j \ne v_j over terms with uninterpreted functions, is it satisfiable? The equalities generate the smallest relation that is:

  • an equivalence (reflexive, symmetric, transitive);
  • a congruence: if s1∼t1,…,sn∼tns_1 \sim t_1, \dots, s_n \sim t_n then f(s1..sn)∼f(t1..tn)f(s_1..s_n) \sim f(t_1..t_n).

The conjunction is satisfiable iff no disequality u≠vu \ne v has u∼vu \sim v. Then the classes themselves form a model.

Only the formula’s terms matter. Congruence closure computes the relation on the subterms of the input only. If a=ba = b is asserted and f(b)f(b) does not occur, nothing is said about it, and nothing needs to be.

3.2 The algorithm

CongruenceClosure follows Nelson and Oppen (1980) and Downey, Sethi and Tarjan (1980). It has five parts:

  1. Nodes. Every subterm is a node; an application knows its children.
  2. Union-find. find(x) returns the representative of xx‘s class. Merging links the smaller class under the larger, which keeps paths short.
  3. Signatures. The signature of f(a,b)f(a, b) is (f,find(a),find(b))(f, \mathrm{find}(a), \mathrm{find}(b)). A table maps signatures to nodes, so congruent applications are found by one lookup.
  4. Use lists. When class AA is merged into BB, only the applications that use a member of AA can change signature. Only they are re-hashed, and any collision becomes a new pending merge.
  5. Disequalities are stored. After every merge they are checked.

Script 02, Part 1, on the slides’ example a=b∧f(a)=b∧g(a)≠g(f(a))a = b \wedge f(a) = b \wedge g(a) \ne g(f(a)):

assert 1: a = b         merge a, b                       classes: {a, b}
assert 2: f(a) = b      merge f(a), b
                        merge g(f(a)), g(a)  (congruence)  classes: {a, b, f(a)}, {g(a), g(f(a))}
assert 3: g(a) ≠ g(f(a))  CONFLICT -- explanation: 2, 1, 3

3.3 Explanations

CDCL(T) needs more than “inconsistent”. It needs a small set of asserted literals that causes the inconsistency, because that set becomes a learned clause.

Every merge adds an edge x−yx - y to a proof forest, labelled with its reason:

  • either an asserted equality (its tag);
  • or a congruence (the two applications).

The edges of one class form a tree, so two equal terms are joined by a unique path. To explain s=ts = t:

  • collect the tags on the path;
  • for each congruence edge f(u⃗)−f(v⃗)f(\vec u) - f(\vec v), explain ui=viu_i = v_i recursively.

Bradley and Manna’s example (script 02, Part 2): from f3(a)=af^3(a) = a (tag A), congruence gives f4(a)=f(a)f^4(a) = f(a) and f5(a)=f2(a)f^5(a) = f^2(a). Adding f5(a)=af^5(a) = a (tag B) collapses everything into one class:

equalityexplained by
f(a)=af(a) = aA, B
f3(a)=af^3(a) = aA
f5(a)=af^5(a) = aB

The disequality f(a)≠af(a) \ne a (tag C) then conflicts with explanation {A, B, C}. That is the lemma ¬A∨¬B∨¬C\neg A \vee \neg B \vee \neg C, three literals however many merges happened.

3.4 Backtracking and cost

Inside CDCL(T) the theory solver must undo assertions whenever the SAT solver backjumps. Our closure never compresses paths and logs every change (unions, signature entries, disequalities), so undoing is popping the log (script 02, Part 3). Real solvers use the same “trail” idea as CDCL itself.

Cost (script 02, Part 4, random conjunctions with equalities over a tenth of the terms):

termsmergesby congruenceunion-findnaive fixpoint
4004770.001 s0.019 s
80094140.001 s0.080 s
1,600203430.002 s(skipped)

Both compute the same classes. The naive fixpoint compares every pair of applications in each pass; Downey–Sethi–Tarjan is O(nlog⁡n)O(n \log n).

Run it: python3 02_congruence_closure.py (about 1 s), with figures/02_cc_scaling.png.

congruence closure scaling


4. The very lazy approach

The simplest combination uses the SAT solver and the theory solver as black boxes:

repeat:
    M := SAT(clauses);  UNSAT -> φ is T-unsatisfiable
    if the atom literals of M are T-consistent -> φ is T-satisfiable
    else add a blocking clause ¬(the T-inconsistent literals)

Script 03, Part 1, on the slides’ example:

blocking clause = ¬(whole model)blocking clause = ¬(theory explanation)
SAT call 11, ¬2, ¬3, ¬4 → add {¬1, 2, 3, 4}1, ¬2, ¬3, ¬4 → add {¬1, 2}
SAT call 21, ¬2, 3, ¬4 → add {¬1, 2, ¬3, 4}1, 2, 3, ¬4 → add {¬1, ¬3, 4}
SAT call 31, 2, 3, ¬4 → add {¬1, ¬2, ¬3, 4}UNSAT
SAT call 4UNSAT

With explanations the lemmas are exactly the slides’ 1ˉ∨2\bar 1 \vee 2 and 1ˉ∨3ˉ∨4\bar 1 \vee \bar 3 \vee 4.

With whole models we need 4 SAT calls, the slides 3. The slides’ SAT solver returned the partial model {1,2ˉ,4ˉ}\{1, \bar 2, \bar 4\}. Ours assigns every atom, and a longer blocking clause excludes fewer models.

The loop has two weaknesses:

  • The models. Whole-model blocking can enumerate exponentially many models.
  • Restarts. Every SAT call starts from scratch and forgets what it learned.

On the diamonds of §6, whole-model blocking needs 50 SAT calls for n=2n = 2, against 8 with explanations, and becomes impractical from n=4n = 4 on.


5. CDCL(T)

5.1 The rules

The slides extend abstract CDCL (Lecture 5) with three rules that consult the theory:

\textscT−ConflictC=nolˉ1,…,lˉn∈Mlˉ1∧⋯∧lˉn⊨T⊥C:={l1,…,ln}\textsc{T-Conflict}\quad \frac{C = \text{no} \qquad \bar l_1, \dots, \bar l_n \in M \qquad \bar l_1 \wedge \dots \wedge \bar l_n \models_T \bot}{C := \{l_1, \dots, l_n\}}

\textscT−Propagatel∈Lits(Δ)l,lˉ∉MM⊨TlM:=M l\textsc{T-Propagate}\quad \frac{l \in \mathrm{Lits}(\Delta) \qquad l, \bar l \notin M \qquad M \models_T l}{M := M\, l}

\textscT−ExplainC={l}∪Dlˉ1∧⋯∧lˉn⊨Tlˉlˉ1,…,lˉn≺MlˉC:={l1,…,ln}∪D\textsc{T-Explain}\quad \frac{C = \{l\} \cup D \qquad \bar l_1 \wedge \dots \wedge \bar l_n \models_T \bar l \qquad \bar l_1, \dots, \bar l_n \prec_M \bar l}{C := \{l_1, \dots, l_n\} \cup D}

T-Conflict turns a T-inconsistent part of MM into a conflict clause, a theory lemma: valid in TT, so adding it is sound. T-Propagate adds literals the theory entails. T-Explain resolves a conflict clause with the lemma behind a propagated literal.

The slides’ correctness theorems carry over from CDCL:

theoremstatement (the slides)
strong terminationan execution is finite if LEARN/FORGET are applied finitely often and RESTART with increasing periodicity
refutation soundnessending in UNSAT means Δ0\Delta_0 is T-unsatisfiable
refutation completenessending with CC = no means MM is T-satisfiable and M⊨Δ0M \models \Delta_0

5.2 How CDCLT implements them

CDCLT subclasses Lecture 5’s CDCLSolver and changes four things:

  1. After every unit-propagation fixpoint, the new atom literals on the trail are sent to the theory solver (eager=True; with eager=False only complete assignments are checked).
  2. T-CONFLICT: the theory’s explanation l1..lnl_1..l_n becomes the clause {lˉ1,…,lˉn}\{\bar l_1, \dots, \bar l_n\}, which is handed to the unchanged 1-UIP conflict analysis. If the conflict lies entirely below the current level (a theory checked late), the solver backjumps to the conflict’s level first.
  3. T-PROPAGATE: an entailed literal ll with explanation l1..lnl_1..l_n goes on the trail with the reason clause {l,lˉ1,…,lˉn}\{l, \bar l_1, \dots, \bar l_n\}. Conflict analysis then resolves through it exactly as through an input clause. That is T-EXPLAIN, at no extra cost.
  4. Backjumping calls theory.backtrack_to(trail length).

The slides’ warning applies: no pure-literal rule. A literal pure in the skeleton may still be forced by the theory.

5.3 The slides’ derivations, reproduced

Script 03, Part 2. Without T-PROPAGATE (the slides’ “better lazy approach”):

PROPAGATE     1  from clause {1}
PROPAGATE     ¬4  from clause {¬4}
DECIDE        •¬2  (level 1)
T-CONFLICT    {¬1, 2}
LEARN+BACKJUMP {2}, back to level 0
PROPAGATE     3  from clause {3, ¬2}
T-CONFLICT    {¬1, ¬3, 4}
CONFLICT      on {¬1, ¬3, 4} at level 0 -> FAIL: UNSAT

With T-PROPAGATE (the slides’ “theory propagation example”):

PROPAGATE     1, ¬4
T-PROPAGATE   2  because 1 ⊨_T 2          (c = g(a) ⇒ f(c) = f(g(a)), by congruence)
T-PROPAGATE   ¬3  because 1, ¬4 ⊨_T ¬3     (g(a) = c, c ≠ d ⇒ g(a) ≠ d)
CONFLICT      on {3, ¬2} at level 0 -> FAIL: UNSAT

No decision at all: “T-propagation eliminates search altogether in this case” (the slides).

5.4 Equalities are cheap, disequalities are not

The slides’ exercise, a=b∧(a=c∨c=b)∧(a≠b∨f(a)≠f(c))∧(c≠b∨g(a)=g(c))a = b \wedge (a = c \vee c = b) \wedge (a \ne b \vee f(a) \ne f(c)) \wedge (c \ne b \vee g(a) = g(c)), contrasts two levels of propagation. EUF offers three (script 03, Part 3):

disequality propagationdecisionsconflictsT-conflictsT-propagations
none (slides’ Scenario 1)1220
simple: s∼cs \sim c, t∼dt \sim d for an asserted c≠dc \ne d1220
full (slides’ Scenario 2)0102

Entailed equalities are cheap. One find per side.

Entailed disequalities may need congruence. f(a)≠f(c)f(a) \ne f(c) entails a≠ca \ne c, because a=ca = c would force f(a)=f(c)f(a) = f(c). The simple rule misses this.

The full rule tentatively asserts each unassigned equality, looks for a conflict, and undoes it. Its explanation for ¬2\neg 2 is just 4ˉ\bar 4, smaller than the slides’ “1, ¬4”. It costs one tentative merge per unassigned atom per call.

Two small observations on the slides:

  • With the “true first” decision phase, Scenario 1 reproduces the slides’ table line by line.
  • The slides annotate its second T-CONFLICT “as 1, ¬3, ¬4 ⊨ ⊥”. The lemma 1ˉ∨3ˉ∨4\bar 1 \vee \bar 3 \vee 4 refutes 1,3,4ˉ1, 3, \bar 4.

5.5 All variants on random formulas

Script 03, Part 4, 60 random EUF formulas (4 constants, 20 atoms, 80 clauses; 29 SAT, 31 UNSAT):

configurationSAT callsconflictsT-conflictsT-propagations
very lazy, block models4685,5254080
very lazy, block explanations1361,062760
CDCL(T), theory at complete assignments60668870
CDCL(T), theory at every fixpoint60656960
CDCL(T) + T-propagation (simple)6059266134
CDCL(T) + T-propagation (full)6052543240

All six agree on all 60 formulas, and every model was checked against the input. On formulas this small, “eager” theory checks change little. Propagation converts theory conflicts into propagations.

5.6 What a theory solver must provide

The slides’ architecture slide, as implemented by TheorySolver:

requirementmethodwhy
check T-satisfiability of conjunctions of literalsassert_lit, checkthe core job
be incrementalassert_lit one literal at a timethe trail grows literal by literal
be backtrackablebacktrack_to(pos)CDCL backjumps constantly
produce explanationsconflicts as lists of tagsconflicts become learned clauses
compute propagationspropagate()guide the search
produce modelsmodel(), value_offor SAT answers and their check

Lectures 11–13 provide exactly this interface for linear arithmetic (simplex), integers and arrays.


6. The eager approach

6.1 Ackermann’s reduction

The slides’ eager example, f(b)=a∨f(a)≠af(b) = a \vee f(a) \ne a (script 01, Part 4):

  1. Eliminate functions (Ackermann 1954). Replace each application by a fresh constant, f(b)↦f#1f(b) \mapsto f\#1 and f(a)↦f#2f(a) \mapsto f\#2, and add functional consistency: b=a⇒f#1=f#2b = a \Rightarrow f\#1 = f\#2.
  2. Eliminate equalities. Introduce a propositional variable eije_{ij} for each pair of constants (eii=⊤e_{ii} = \top, and eij=ejie_{ij} = e_{ji} by naming), plus transitivity eij∧ejk⇒eike_{ij} \wedge e_{jk} \Rightarrow e_{ik} for every triple.
translated input:        e1_2 ∨ ¬e2_3            (f#1 = a  ∨  ¬(a = f#2))
functional consistency:  e0_2 ⇒ e1_3             (b = a  ⇒  f#1 = f#2)
transitivity (12 over 4 constants): e0_1 ∧ e1_2 ⇒ e0_2  ...
CDCL: SAT

The result is equisatisfiable with the input. With mm constants there are 3(m3)3\binom{m}{3} transitivity clauses: cubic. (The slides note “not all transitivity cases are needed”; sparse encodings exist.)

6.2 Diamonds: where eager wins

Script 04, Part 1:

nvery lazy (explanations)CDCL(T) conflictseager clauseseager conflicts
428 calls217,7474
8283 calls28162,1498
10–1,069121,42610
14–16,787333,29214

The lazy methods grow like 2n2^n; the eager one needs exactly nn conflicts.

Why. CDCL(T)‘s proofs are resolution proofs over the input atoms plus theory lemmas over those atoms. Every lemma speaks about one way through the diamonds, and refuting all 2n2^n ways with such lemmas is exponential.

The eager encoding has a variable for every pair of constants, including xi=xi+1x_i = x_{i+1}. Its transitivity clauses derive that fact from either side of diamond ii, after which the proof is linear. The price is the cubic encoding: half a million clauses at n=16n = 16.

Plan vs reality. The plan was to show that adding the atoms xi=xi+1x_i = x_{i+1} (as tautologies xi=xi+1∨xi≠xi+1x_i = x_{i+1} \vee x_i \ne x_{i+1}) rescues CDCL(T). It does not: the conflicts are identical (281 at n=8n = 8). The theory solver’s explanations still mention only the original equalities, so no learned clause ever uses the new atoms. A short proof exists, but our solver never produces the lemmas it needs. Real solvers create new atoms inside the search, together with lemmas that mention them: splitting on demand (Barrett, Nieuwenhuis, Oliveras and Tinelli 2006), and the interface equalities of theory combination (Lecture 18).

6.3 When eager loses

On random formulas the roles flip. Every function application becomes a constant (27 to 38 per formula), and the transitivity constraints dominate. Script 04 runs the first 10 random formulas of script 03:

  • CDCL(T) needs 0.03 s and 80 conflicts in all;
  • the eager procedure needs 6.0 s and 100 conflicts, with 80,539 to 230,830 clauses per formula.

The hoisting family of §7 shows the same blow-up: 634,775 clauses for 6 stages. Neither approach dominates, which is why both survive. Solvers apply Ackermann’s reduction selectively; Z3, for example, has tactics that do it for bit-vector formulas.


7. Applications and trust

7.1 Translation validation

Did an optimizer preserve the meaning of a program? Pnueli, Siegel and Singerman (1998) check each compilation instead of the compiler. Script 04, Part 2 validates hoisting a common call out of a conditional:

original:   x_{i+1} = if q(x_i) then f(g(x_i)) else f(h(x_i))
optimized:  y_{i+1} = f(if q(y_i) then g(y_i) else h(y_i))        x_0 = y_0 = a;  is x_n = y_n?

f,g,h,qf, g, h, q are uninterpreted. An UNSAT answer for …∧xn≠yn\ldots \wedge x_n \ne y_n therefore proves the optimization correct for every implementation of them:

stagesCDCL(T)decisionsconflictscertificateeager clauses
2UNSAT64ok18,565
4UNSAT3930ok177,670
6UNSAT160131ok634,775
8UNSAT787624ok–

The growth is exponential again, for the diamonds’ reason: the intermediate facts xi=yix_i = y_i are not atoms. With the branches swapped in stage 1 the answer is SAT. The counter-model, a partition of the terms in which qq is false everywhere, is checked against the input.

7.2 Can we trust the answers?

SAT answers. Evaluate the input formula in the theory model. Re-evaluating the whole formula, not the clauses, also catches bugs in the abstraction and in Tseitin.

UNSAT answers. These split into two independent claims:

  1. Every theory lemma is TT-valid: its negation, a conjunction of literals, is unsatisfiable. naive_euf_unsat re-checks each lemma with a deliberately simple fixpoint closure that shares no code with CongruenceClosure.
  2. The propositional part. Lecture 5’s DRUP checker verifies that the proof derives the empty clause from the input clauses plus the lemmas.

Script 04, Part 3:

  • 48 formulas: 19 SAT answers, all models checked;
  • 29 UNSAT answers with 182 distinct theory lemmas, all re-checked, and every DRUP proof verified.

On the slides’ example the certificate is two lemmas, {1ˉ,2}\{\bar 1, 2\} and {1ˉ,3ˉ,4}\{\bar 1, \bar 3, 4\}, and the DRUP proof (2),()(2), (). Tampering with a lemma is caught: lemma (1, 2) is not T-valid.

Production solvers emit such proofs (cvc5 in the Alethe and LFSC formats, Z3 as proof objects). Checking the theory steps is the hard part.


8. Summary

  1. SMT decides quantifier-free formulas over theories: EUF, arithmetic, arrays, bit-vectors, strings. Theory solvers decide conjunctions of literals, and Theorem 1 (DNF) shows that suffices in principle, at exponential cost.
  2. The Boolean abstraction replaces atoms by variables. It over-approximates: the theory must check every candidate model.
  3. Congruence closure decides EUF conjunctions with union-find, signatures and use lists. Its proof forest yields small explanations, and an undo log makes it backtrackable.
  4. The very lazy loop blocks inconsistent models. Blocking explanations instead of models cut SAT calls from 468 to 136 on our random set.
  5. CDCL(T) adds T-CONFLICT, T-PROPAGATE and T-EXPLAIN to CDCL. Lemmas enter as conflict and reason clauses, so 1-UIP learning and backjumping work unchanged. On the slides’ example, theory propagation removes all decisions.
  6. Equality propagation is cheap; disequality propagation may need congruence (complete but costly).
  7. Eager SMT (Ackermann + transitivity) uses a plain SAT solver. It wins on diamonds (nn conflicts against 2n2^n) and loses badly when there are many function instances (cubic encodings).
  8. SMT answers can be certified: models by evaluation, refutations by DRUP plus independent theory-lemma checks.

9. Common pitfalls

  • Forgetting to normalize atoms. a=ba = b and b=ab = a must get the same variable. Otherwise the SAT solver may set them differently, and only a theory check can repair it.
  • Treating a SAT skeleton as SAT. The abstraction over-approximates; only a T-consistent model counts.
  • Using the pure-literal rule in CDCL(T). A literal pure in the skeleton may still be forced by the theory.
  • Blocking clauses that are too long. Whole models exclude almost nothing; explanations exclude every model that contains the inconsistent core.
  • Explanations that are not subsets of the trail. Every literal of a theory lemma must be currently true, or the “conflict clause” is not conflicting. Axioms (such as $true≠$false\text{\textdollar true} \ne \text{\textdollar false}) must not appear in explanations.
  • Theory conflicts found late. If the theory runs only at complete assignments, a conflict may lie entirely below the current decision level. Backjump to its level before analysing it.
  • Ackermann without transitivity. The equality variables must form an equivalence relation, or UNSAT answers become wrong.
  • Assuming a short proof means a fast solver. Diamonds have short proofs over the right atoms, and our CDCL(T) still needs 2n2^n conflicts.

10. Exercises

1. (congruence closure) Run congruence closure by hand on f(a,b)=a∧f(f(a,b),b)≠af(a, b) = a \wedge f(f(a, b), b) \ne a. Which merges happen, and what is the explanation of the conflict?

Answer

Nodes. aa, bb, f(a,b)f(a,b), f(f(a,b),b)f(f(a,b), b).

The merges.

  • Asserting f(a,b)=af(a,b) = a merges f(a,b)f(a,b) and aa.
  • The signature of f(f(a,b),b)f(f(a,b), b) becomes (f,find(a),find(b))(f, \mathrm{find}(a), \mathrm{find}(b)), the same as that of f(a,b)f(a,b). Congruence merges f(f(a,b),b)f(f(a,b), b) with f(a,b)f(a,b), hence with aa.

The conflict. The disequality f(f(a,b),b)≠af(f(a,b),b) \ne a now conflicts. Its explanation is {f(a,b)=af(a,b) = a, the disequality}: the congruence edge’s argument pairs are (f(a,b),a)(f(a,b), a), explained by the asserted equality, and (b,b)(b, b), which is trivial.

2. (abstraction) Why must p(a)∧a=b∧¬p(b)p(a) \wedge a = b \wedge \neg p(b) be refuted by the theory and not by the SAT solver? Give its abstraction and its theory lemma.

Answer

The abstraction. Atoms 1: p(a)p(a), 2: a=ba = b, 3: p(b)p(b). The skeleton 1∧2∧3ˉ1 \wedge 2 \wedge \bar 3 is satisfiable.

The theory step. EUF encodes p(⋅)p(\cdot) as p(⋅)=$truep(\cdot) = \text{\textdollar true} / $false\text{\textdollar false}. From a=ba = b, congruence merges p(a)p(a) and p(b)p(b), so $true=$false\text{\textdollar true} = \text{\textdollar false}, a conflict.

The lemma. 1ˉ∨2ˉ∨3\bar 1 \vee \bar 2 \vee 3.

3. (very lazy) Prove that the very lazy loop with explanation blocking terminates. Bound the number of SAT calls.

Answer

Each call removes a model. Every blocking clause excludes the current model: it falsifies the model’s own literals.

The bound. There are at most 2∣atoms∣2^{|\text{atoms}|} assignments to the atoms, so the loop ends after at most that many calls. Explanations make each clause exclude many models at once, but the worst case stays exponential, as the diamonds show.

4. (CDCL(T)) In the slides’ example without propagation, why does conflict analysis learn the unit clause {2}\{2\}, and why is the backjump to level 0?

Answer

The conflict clause. The T-conflict clause is {1ˉ,2}\{\bar 1, 2\}. Literal 1 is at level 0, and 2ˉ\bar 2 is the decision at level 1.

Learning. The clause has exactly one literal of the current level, so it is already asserting: 1-UIP learns it unchanged.

Learning a unit. Level-0 literals are left out of learned clauses, so the clause learned is {2}\{2\}.

The backjump. A unit learned clause backjumps to level 0, where 2 is propagated.

5. (propagation) Give an EUF conjunction where the “simple” disequality rule propagates something and an example where only the “full” rule does.

Answer

Simple. Assert a=ca = c and c≠dc \ne d. The atom a=da = d is then entailed false by the simple rule: a∼ca \sim c, d∼dd \sim d, and c≠dc \ne d is asserted.

Full only. Assert f(a)≠f(c)f(a) \ne f(c) with a=ca = c unassigned. Only a congruence argument shows that a=ca = c is entailed false, which is the slides’ exercise.

6. (Ackermann) Apply Ackermann’s reduction to f(f(a))≠f(a)∧f(a)=af(f(a)) \ne f(a) \wedge f(a) = a. List the fresh constants, the functional-consistency constraints, and explain why the result is unsatisfiable.

Answer

Fresh constants. f(a)↦F1f(a) \mapsto F_1 and f(f(a))=f(F1)↦F2f(f(a)) = f(F_1) \mapsto F_2.

Functional consistency. a=F1⇒F1=F2a = F_1 \Rightarrow F_1 = F_2.

The translated input. F2≠F1∧F1=aF_2 \ne F_1 \wedge F_1 = a.

Why it is unsatisfiable. From F1=aF_1 = a (symmetric), consistency gives F1=F2F_1 = F_2, which contradicts F2≠F1F_2 \ne F_1.

7. (eager size) How many transitivity clauses does the eager encoding of diamond(nn) contain? Check against script 01’s table for n=4n = 4.

Answer

Counting the constants. x0..xn,y0..yn−1,z0..zn−1x_0..x_n, y_0..y_{n-1}, z_0..z_{n-1}: m=3n+1m = 3n + 1 constants.

Counting the clauses. 3(m3)3\binom{m}{3}. For n=4n = 4: m=13m = 13 and 3⋅286=8583 \cdot 286 = 858, as in the table.

8. (certificates) Why is it not enough to check the DRUP proof against the input clauses alone? What exactly does the lemma check guarantee?

Answer

Why the input alone is not enough. The input clauses are only the abstraction. They are usually propositionally satisfiable, and the refutation needs the theory lemmas as extra axioms.

What the lemma check adds. It proves each lemma TT-valid. So input ∧ lemmas is TT-equivalent to the input, and its propositional unsatisfiability implies the input’s TT-unsatisfiability.

9. (programming) Make the new atoms useful. When EUF.propagate finds an unassigned atom s=ts = t with s∼ts \sim t, the reason clause already mentions it. Change explain so that, when an equality atom u=vu = v between two terms on the path is currently asserted, its tag is used for that segment instead of the original edges. Measure diamonds with the extra atoms xi=xi+1x_i = x_{i+1}.

Answer sketch

The change. Keep, for each asserted equality atom, its nodes. In _path (or in a post-pass), replace the sub-path between two nodes u,vu, v by the asserted tag whenever u=vu = v is asserted.

What to expect. Explanations then mention xi=xi+1x_i = x_{i+1}, and learned clauses can be about them. Measure whether the conflicts on diamonds drop from 2n2^n towards O(n)O(n). This is related to the “explanation quality” problem studied by Nieuwenhuis and Oliveras.

10. (programming) Implement sparse transitivity for ackermann: build the graph whose edges are the equalities that occur, make it chordal (Bryant and Velev 2002), and add transitivity constraints only for its triangles. Compare clause counts on diamonds and random formulas.

Answer sketch

The graph. The vertices are the constants, and the edges are the pairs eije_{ij} that occur after function elimination (input equalities and functional-consistency equalities).

Chordal completion. Eliminate vertices in some order (e.g. minimum degree), adding fill-in edges between the neighbours of each eliminated vertex.

The constraints. Add the three transitivity clauses for every triangle of the chordal graph.

What to expect. Correctness: an assignment that is transitive on a chordal graph extends to an equivalence relation. On diamonds the graph is nearly a path, and the count drops from cubic to linear.


11. Further reading

  • G. Nelson, D. C. Oppen, “Fast Decision Procedures Based on Congruence Closure”, JACM 1980; P. Downey, R. Sethi, R. Tarjan, “Variations on the Common Subexpression Problem”, JACM 1980.
  • R. Nieuwenhuis, A. Oliveras, “Proof-Producing Congruence Closure”, RTA 2005; and “Fast Congruence Closure and Extensions”, Information and Computation 2007.
  • R. Nieuwenhuis, A. Oliveras, C. Tinelli, “Solving SAT and SAT Modulo Theories: From an Abstract Davis–Putnam–Logemann–Loveland Procedure to DPLL(T)”, JACM 2006: the abstract framework of the slides.
  • C. Barrett, R. Nieuwenhuis, A. Oliveras, C. Tinelli, “Splitting on Demand in SAT Modulo Theories”, LPAR 2006.
  • W. Ackermann, Solvable Cases of the Decision Problem, North-Holland 1954; R. E. Bryant, M. N. Velev, “Boolean Satisfiability with Transitivity Constraints”, ACM TOCL 2002.
  • A. Pnueli, M. Siegel, E. Singerman, “Translation Validation”, TACAS 1998.
  • C. Barrett, R. Sebastiani, S. Seshia, C. Tinelli, “Satisfiability Modulo Theories”, Chapter 33 of the Handbook of Satisfiability (2nd ed. 2021).
  • D. Kroening, O. Strichman, Decision Procedures, Chapters 3 (equality and EUF) and 11 (DPLL(T)).

12. Next lecture

Lecture 11: linear real arithmetic and the simplex method. EUF needed union-find; arithmetic needs linear algebra.

  • We build the general simplex method in the form SMT solvers use (Dutertre and de Moura 2006): bounds on variables, a tableau that never changes its constraints, Bland’s rule for termination, and Farkas explanations for conflicts.
  • Strict inequalities need an infinitesimal δ.
  • We plug it into smt.py as a theory solver, with the same interface as EUF.
← 返回课程目录