Lecture 18 · Theory Combination

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

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 18 · Thu 03/05/2026 · SMT: theory combination (Caroline Trippel). Reading: Kroening and Strichman, Decision Procedures, Sections 10.1–10.5. Basis: The Stanford slides are on Canvas. The public Iowa deck Combining Theories and Their Solvers (Tinelli, Spring 2024) credits Barrett, Trippel and Wu at Stanford, and it is the outline of this lecture: its examples, definitions and theorems appear here. Further sources:

  • Nelson and Oppen (1979), the method;
  • Oppen (1980), convexity;
  • Tinelli and Harandi (1996), the non-deterministic version;
  • Bozzano et al. (2005), delayed theory combination;
  • de Moura and Bjørner (2008), model-based theory combination;
  • Ranise, Ringeissen and Zarba (2005) and Jovanović and Barrett (2010), polite combination.

These notes add one module, combine.py, with:

  • purification;
  • Nelson–Oppen with an independently checked trace;
  • model-based case splits;
  • arrangements;
  • a finite-sort counterexample;
  • CDCL(T1, T2) by interface clauses;
  • certificates;
  • an Ackermann cross-check.

The experiments were designed for these notes and do not reflect what was said in class. Code: code/lecture18/ (3 scripts + 1 module; Python standard library only; about 2 to 13 seconds of CPU time each) Reading time: 2.5 hours including running the code


0. How to read this lecture

0.1 Learning goals

After this lecture you should be able to:

  1. Define the combination T1⊕T2T_1 \oplus T_2 of two theories, and purify a mixed formula into two pure parts that share only variables.
  2. Run the Nelson–Oppen method by hand: check each part, propagate entailed equalities between shared variables, and decide.
  3. Define convexity, show that the integers are not convex, and explain why non-convex theories need case splits.
  4. State the non-deterministic method with arrangements and its correctness theorems, and say where stable infiniteness is needed. Build a counterexample when it fails.
  5. Explain how CDCL(T1, …, Tn) lifts the combination into the SAT search: interface equalities as atoms, local propagation and conflicts.
  6. Certify a combined answer, and compare the modular method with the eager alternative, Ackermann’s reduction.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
theories, CDCL(T), EUF and congruence closure, Ackermann (Lecture 10)T1⊕T2T_1 \oplus T_2, purification, shared variables—
LRA and the simplex method (Lecture 11); LIA, branch and bound (Lecture 12)convexity; equality propagation; case splits—
arrays and their reduction to EUF (Lecture 13); bit-vectors (Lecture 16)stable infiniteness, finite sortstext-to-SQL with mixed theories (Lecture 19)
E-graphs (Lecture 17)interface literals, delayed and model-based combination—

0.3 Map

§1  why formulas mix theories
§2  combined theories and purification                         ← code 01
§3  Nelson–Oppen for convex theories                            ← code 01
§4  convexity, and case splits for the integers                 ← code 02
§5  arrangements, correctness, and stable infiniteness          ← code 02
§6  CDCL(T1, ..., Tn)                                           ← code 03
§7  certificates, and the eager alternative                     ← code 01, 03
§8  summary   §9 common pitfalls   §10 exercises   §11 further reading   §12 next lecture

0.4 Notation

SymbolMeaning
T1⊕T2T_1 \oplus T_2the combined theory: interpretations whose restriction to each signature is a model of that theory
L1L_1, L2L_2the pure T1T_1- and T2T_2-literals after purification
VVthe shared variables, occurring in both L1L_1 and L2L_2
L⊨TφL \models_T \varphiLL entails φ\varphi in theory TT
arrangement AAfor every pair u,v∈Vu, v \in V, either u=vu = v or u≠vu \ne v
Bell(n)\mathrm{Bell}(n)the number of arrangements (set partitions) of nn variables

0.5 The code of this lecture

One module, combine.py:

  • purification: purify, Purifier, owner, literal_owner;
  • component solvers on conjunctions: EUFOracle, LRAOracle, LIAOracle, FiniteOracle, each with sat, entails and core;
  • Nelson–Oppen: nelson_oppen (with split and propagate options), Step, check_trace;
  • arrangements: set_partitions, bell, combine_by_arrangements, share_terms;
  • CDCL(T1, T2): Pair, prepare_combined, solve_combined;
  • certificates: combined_model, evaluate_combined, certify_combined;
  • the eager alternative: ackermann_arith, solve_ackermann;
  • benchmarks: SLIDES_CONVEX, SLIDES_NONCONVEX, MOTIVATING, MOTIVATING_UNSAT, FINITE_SORT_EXAMPLE, ping_pong, random_mixed.

The component solvers are the earlier lectures’ own: congruence closure (Lecture 10), the simplex method (Lecture 11), and branch and bound (Lecture 12). The combination never looks inside them.


1. Why formulas mix theories

The slides open with a formula of the kind program verifiers produce:

a=b+2  ∧  A=write(B,a,4)  ∧  (read(A,b+3)=b−2  ∨  f(a−b)≠f(b+1))a = b + 2 \;\wedge\; A = \mathit{write}(B, a, 4) \;\wedge\; \big(\mathit{read}(A, b + 3) = b - 2 \;\vee\; f(a - b) \ne f(b + 1)\big)

It needs integer arithmetic, arrays and an uninterpreted function at once. Every solver of Lectures 10–16 handles one theory. A smaller example shows the problem (script 01, Part 1):

f(f(x)−f(y))=a  ∧  f(0)>a+2  ∧  x=yf(f(x) - f(y)) = a \;\wedge\; f(0) > a + 2 \;\wedge\; x = y
methodanswer
EUF alone: −-, 00, ++ uninterpreted, >> a free BooleanSAT
arithmetic alone: every ff-term an unrelated numberSAT
Nelson–Oppen: EUF and LRA exchanging equalitiesUNSAT
Ackermann’s reduction: ff eliminated, consistency constraints addedUNSAT

Why it is unsatisfiable.

  1. x=yx = y gives f(x)=f(y)f(x) = f(y) by congruence.
  2. So f(x)−f(y)=0f(x) - f(y) = 0 by arithmetic.
  3. So f(f(x)−f(y))=f(0)f(f(x) - f(y)) = f(0) by congruence, that is, a=f(0)a = f(0).
  4. And f(0)>a+2f(0) > a + 2 by arithmetic: a contradiction.

The argument alternates between the theories. Each solver alone treats the other’s symbols as uninterpreted, so it over-approximates and answers SAT.

Two ways out.

  • Eagerly, translate one theory away. Ackermann’s reduction (Lecture 10) removes ff in exchange for consistency constraints.
  • Modularly, keep both solvers and let them exchange facts. Nelson and Oppen (1979) showed that, under conditions on the theories, the facts that need to be exchanged are only equalities between shared variables. This is how all SMT solvers combine theories today.

2. Combined theories and purification

2.1 The combined theory

Theories. Recall from the slides that a theory T=(Σ,I)T = (\Sigma, \mathcal{I}) is a signature with a class of interpretations, the models.

The combination. For two theories with compatible signatures, the combination is

T1⊕T2=(Σ1∪Σ2, {I∣IΣ1∈I1 and IΣ2∈I2})T_1 \oplus T_2 = (\Sigma_1 \cup \Sigma_2,\ \{\mathcal{I} \mid \mathcal{I}^{\Sigma_1} \in \mathcal{I}_1 \text{ and } \mathcal{I}^{\Sigma_2} \in \mathcal{I}_2\})

Its models are interpretations of both signatures whose reduct to each signature is a model of that theory. EUF ⊕ LRA has rational numbers with their arithmetic, plus arbitrary functions ff on them.

The standing assumption. The function symbols are disjoint: Σ1F∩Σ2F=∅\Sigma_1^F \cap \Sigma_2^F = \emptyset. The theories share only sorts, equality and the free constants (our “variables”).

2.2 Purification

A literal is pure if all its symbols come from one signature. Purification names every alien subterm, a term of one theory inside a literal or term of the other, by a fresh variable:

repeat:
    find an i-term t (non-variable, top symbol in Σi) that is a subterm of a non-Σi literal or term
    replace t by a fresh variable v; add the definition v = t (a Σi-literal)
until every literal is pure; split into L1 (Σ1-literals) and L2 (Σ2-literals)

Script 01, Part 2 (purify works innermost first; the slides number the fresh variables differently):

input:        f(f(x) - f(y)) = a ∧ f(0) > a + 2 ∧ x = y
definitions:  v1 = f(x) (EUF),  v2 = f(y) (EUF),  v3 = v1 - v2 (arith),  v4 = 0 (arith),  v5 = f(v4) (EUF)
L1 (EUF):     f(v3) = a,  x = y,  v1 = f(x),  v2 = f(y),  v5 = f(v4)
L2 (arith):   a + 2 < v5,  v3 = v1 - v2,  v4 = 0
shared:       a, v1, v2, v3, v4, v5

Three remarks.

  • Numerals are arithmetic terms. So f(0)f(0) needs two definitions: v4=0v_4 = 0 for arithmetic, and v5=f(v4)v_5 = f(v_4) for EUF.
  • Equalities between variables. x=yx = y belongs to both signatures, and is put in EUF, as on the slides. The other theory learns about it only through shared variables, and here x,yx, y are not shared at all.
  • Purification preserves satisfiability. A model of the input extends to the fresh variables by their definitions, and a model of L1∪L2L_1 \cup L_2 satisfies the input because each vv equals its term.

After purification the halves share only variables. Everything the combination does is about the shared variables VV: which are equal and which are different.


3. Nelson–Oppen for convex theories

3.1 The method

The deterministic method (the slides’ steps 2 and 4):

purify into L1, L2;  E := {}
repeat:
    if L1 ∪ E is T1-unsatisfiable or L2 ∪ E is T2-unsatisfiable:  return UNSAT
    for every pair u, v of shared variables with u = v not in E:
        if L1 ∪ E ⊨T1 u = v or L2 ∪ E ⊨T2 u = v:  add u = v to E        (propagation)
    if nothing was added:  return SAT

Script 01, Part 3, on the slides’ example (EUF + LRA):

steptheoryderivesbecause
1EUFv1=v2v_1 = v_2x=yx = y, v1=f(x)v_1 = f(x), v2=f(y)v_2 = f(y)
2LRAv3=v4v_3 = v_4v3=v1−v2v_3 = v_1 - v_2, v4=0v_4 = 0, v1=v2v_1 = v_2
3EUFa=v5a = v_5f(v3)=af(v_3) = a, v5=f(v4)v_5 = f(v_4), v3=v4v_3 = v_4
4LRA⊥a+2<v5a + 2 < v_5, a=v5a = v_5

These are the slides’ four steps: congruence, arithmetic, congruence, arithmetic. The answer is UNSAT after 4 rounds and 112 calls to the component solvers.

3.2 Both directions, and the dialogue

Script 01, Part 4, restricts which theory may send equalities:

propagationanswersteps
both directionsUNSATEUF ⊨ v1 = v2, LRA ⊨ v3 = v4, EUF ⊨ a = v5, LRA ⊨ ⊥
EUF → arithmetic onlySAT (wrong)EUF ⊨ v1 = v2
arithmetic → EUF onlySAT (wrong)—
no exchangeSAT (wrong)—

Each half is satisfiable alone. The contradiction exists only in the dialogue, which must go back and forth until a fixpoint.

3.3 Why it is correct (for convex, stably infinite theories)

UNSAT is always right. Every propagated equality is entailed by one half, hence by the whole. A refutation of Li∪EL_i \cup E is therefore a refutation of the input. The slides call this refutation soundness.

Termination. With nn shared variables there are at most n−1n - 1 useful equalities: each one merges two classes.

SAT needs an argument. When propagation stops, consider the arrangement

A={u=v∣u=v follows from E}∪{u≠v∣otherwise}A = \{u = v \mid u = v \text{ follows from } E\} \cup \{u \ne v \mid \text{otherwise}\}

Each half is consistent with AA:

  • Take Li∪EL_i \cup E and the disequalities of AA.
  • If this set were unsatisfiable, Li∪EL_i \cup E would entail the disjunction of the equalities that AA denies.
  • For a convex theory (§4), it would then entail one of them, and that one would have been propagated.

So both L1∪AL_1 \cup A and L2∪AL_2 \cup A are satisfiable.

Gluing the two models. Take a model of each half with domains of the same cardinality (infinite, for stably infinite theories, §5). Identify the elements named by shared variables according to AA. Rename the rest bijectively. The result is a model of T1⊕T2T_1 \oplus T_2 satisfying the input.

3.4 What it costs

The cost of pairwise tests. Propagation as written tests every pair of shared variables in every round. Script 01, Part 5, uses a family ping_pong(n) whose proof alternates nn times:

x1=y1,xi+1=f(xi)+1,yi+1=f(yi)+1,f(xn)≠f(yn)x_1 = y_1,\quad x_{i+1} = f(x_i) + 1,\quad y_{i+1} = f(y_i) + 1,\quad f(x_n) \ne f(y_n)

nnshared variablesstepsroundssolver calls
10111
243326
3855219
41277772
516991,877

The proof has 2n−12n - 1 steps, but the tests cost roughly n3n^3 calls.

How real solvers avoid it. Solvers obtain entailed equalities as a by-product:

  • a congruence closure knows its classes;
  • the simplex method detects equalities among tight bounds.

They also explain them as theory propagations (Lecture 10’s T-EXPLAIN). Here the explanations are small premise sets found by deletion.


4. Convexity, and case splits for the integers

4.1 Convex theories

A theory TT is convex if, for every set Γ\Gamma of literals and every finite disjunction of equalities, Γ⊨Tx1=y1∨⋯∨xn=yn\Gamma \models_T x_1 = y_1 \vee \cdots \vee x_n = y_n implies Γ⊨Txk=yk\Gamma \models_T x_k = y_k for some kk.

Script 02, Part 1, tests the slides’ example x=1,y=2,1≤z,z≤2x = 1, y = 2, 1 \le z, z \le 2:

theoryentails z=xz = xentails z=yz = yentails z=x∨z=yz = x \vee z = y
LRAnonono
LIAnonoyes

Which theories are convex.

  • LRA is convex. The solutions of a set of literals form a convex polyhedron. A convex set covered by finitely many hyperplanes lies inside one of them. (Here z=3/2z = 3/2 even refutes the disjunction.)
  • EUF is convex too.
  • LIA is not. Over the integers z∈{1,2}z \in \{1, 2\}, so the disjunction holds but neither equality does.
  • Many SMT theories are not convex: arrays, bit-vectors, finite datatypes.

4.2 What goes wrong, and the case split

Script 02, Part 2, uses the slides’ non-convex example:

1≤x≤2  ∧  f(1)=a  ∧  f(x)=b  ∧  a=b+2  ∧  f(2)=f(1)+31 \le x \le 2 \;\wedge\; f(1) = a \;\wedge\; f(x) = b \;\wedge\; a = b + 2 \;\wedge\; f(2) = f(1) + 3

Over the reals. It is SAT. A certified model is x=3/2x = 3/2, f(1)=9/2f(1) = 9/2, f(3/2)=5/2f(3/2) = 5/2, f(2)=15/2f(2) = 15/2, with a=9/2a = 9/2 and b=5/2b = 5/2.

Over the integers. It is UNSAT:

  • x=1x = 1 gives b=f(1)=a=b+2b = f(1) = a = b + 2;
  • x=2x = 2 gives b=f(2)=a+3=b+5b = f(2) = a + 3 = b + 5.

Propagation alone answers SAT, which is wrong. LIA entails x=v1∨x=v2x = v_1 \vee x = v_2 (with v1=1v_1 = 1, v2=2v_2 = 2), but neither disjunct. The two candidate models disagree: arithmetic has x=v1=1x = v_1 = 1, while EUF puts xx and v1v_1 in different classes.

The fix: case splits. When propagation stalls, the combination must split on an equality between shared variables (the slides’ step 3, “Decision”). Which pair to split on is a design choice:

  • The slides guess any non-entailed equality.
  • Model-based combination (de Moura and Bjørner 2008) splits only on a pair where the two candidate models disagree, first the way the arithmetic model suggests. When the models agree on every shared pair, they induce the same arrangement and can be glued: SAT.

With model-based splitting, the example needs one split and 259 solver calls:

EUF ⊨ a = v4          because f(v1) = a, v4 = f(v1)
split: v1 = x
    EUF ⊨ a = b       because f(x) = b, v4 = f(v1), a = v4, v1 = x
    EUF ⊨ b = v4      because f(x) = b, v4 = f(v1), v1 = x
    LIA ⊨ ⊥           because a = b + 2, a = b
split: v1 ≠ x
    LIA ⊨ v2 = x      because 1 ≤ x, x ≤ 2, v1 = 1, v2 = 2, v1 ≠ x
    EUF ⊨ b = v3      because f(x) = b, v3 = f(v2), v2 = x
    LIA ⊨ ⊥           because a = b + 2, v3 = v4 + 3, a = v4, b = v3

These are the two branches of the slides’ CDCL(T1, T2) trace (§6).


5. Arrangements, correctness, and stable infiniteness

5.1 The non-deterministic method

The slides’ bare-bones version:

guess an arrangement A of the shared variables V (for all u, v ∈ V: u = v ∈ A or u ≠ v ∈ A)
if Li ∪ A is Ti-unsatisfiable for i = 1 or 2:  this guess fails
SAT if some guess succeeds; UNSAT if every guess fails

The slides state four theorems for it:

  1. Refutation soundness: if every arrangement fails, the input is unsatisfiable in T1⊕T2T_1 \oplus T_2.
  2. Solution soundness: if the signatures share no function symbols and both theories are stably infinite, a successful arrangement means the input is satisfiable.
  3. Termination: there are finitely many arrangements.
  4. Decidability: under the conditions of theorem 2, if quantifier-free satisfiability is decidable in each TiT_i, it is decidable in T1⊕T2T_1 \oplus T_2.

The cost is the number of arrangements, the Bell numbers (script 02, Part 3):

nn12345678910
Bell(nn)12515522038774,14021,147115,975

The non-convex example has 7 shared variables. Over LIA all 877 arrangements fail (986 solver calls). Over LRA the 333rd works: {a,v1,v4}\{a, v_1, v_4\} together, everything else apart, meaning f(1)=af(1) = a.

Searching the arrangements cleverly. Propagation is a way of searching the arrangements without listing them. Convexity guarantees that propagation alone finds the right one. Case splits and CDCL search the rest.

5.2 Stable infiniteness

TT is stably infinite (for a sort σ\sigma) if every quantifier-free formula satisfiable in TT is satisfiable in a model where σ\sigma is infinite.

Which theories are stably infinite.

  • EUF, LRA and LIA are: an EUF model can be padded with extra elements, and the numbers are infinite anyway.
  • Theories with only finite models are not: bit-vectors of a fixed width, arithmetic modulo nn, finite datatypes, strings of bounded length.

Why the gluing needs it. The halves’ models must have domains of the same size.

The slides’ counterexample. Arrays whose indices and elements are 1-bit vectors, and five arrays that are pairwise different. The array solver accepts the five disequalities, and the bit-vector solver receives nothing. But only 22=42^2 = 4 such arrays exist.

Script 02, Part 4, has the same phenomenon with EUF. gg maps into a sort BB with exactly 2 elements, and the literals are g(a)≠g(b)g(a) \ne g(b), g(b)≠g(c)g(b) \ne g(c), g(a)≠g(c)g(a) \ne g(c):

  • Brute force: of the 8 functions from {a,b,c}\{a, b, c\} to BB, none has three different values.
combinationanswerarrangements tried
share only variables common to both halves (none)SAT (wrong)1
share every term of sort BB (w1=g(a)w_1 = g(a), w2=g(b)w_2 = g(b), w3=g(c)w_3 = g(c))UNSAT5

What goes wrong. No variable is shared, so the theory of BB never hears about the three values.

The repair. Share every term of the finite sort, so that the finite theory must accept the arrangement. EUF accepts only “all different”, and BB rejects it.

In real solvers. Refinements of this idea are used for bit-vectors and datatypes:

  • polite combination (Ranise, Ringeissen and Zarba 2005; Jovanović and Barrett 2010) requires one theory to be “polite” and shares a computed set of terms;
  • cvc5 also reasons explicitly about cardinalities.

6. CDCL(T1, …, Tn)

6.1 The rules

Why move the combination into CDCL. Formulas have Boolean structure, and Lecture 10’s CDCL(T) takes one theory solver. The slides lift the combination into the SAT search. Let CC be the shared constants, M∣iM|_i the Σi\Sigma_i-literals of the trail, and I(M)I(M) the interface literals: c=dc = d and c≠dc \ne d for shared c,dc, d.

rulechange from CDCL(T)
DECIDEmay decide interface literals too
T-PROPAGATEpropagates literals, interface literals included, entailed by M∣iM\vert_i in one TiT_i
T-CONFLICT, T-EXPLAINreason locally in one TiT_i
I-LEARN (new)adds l1∨⋯∨lnl_1 \vee \cdots \vee l_n over interface literals when it is TiT_i-valid (the non-convex disjunctions, such as x=v1∨x=v2x = v_1 \vee x = v_2)

Theory reasoning stays local, and the SAT solver searches the arrangements.

6.2 Delayed theory combination, as implemented

solve_combined takes a simple route (Bozzano et al.’s delayed theory combination), with no change to Lecture 10’s CDCL(T):

  1. Purify the whole formula (any Boolean structure). Conjoin the definitions, and turn arithmetic equalities into two ≤\le (Lecture 11).
  2. Add interface clauses. For every pair of shared variables u,vu, v, add the interface clause (u=v)⇔(u≤v∧v≤u)(u = v) \Leftrightarrow (u \le v \wedge v \le u). It states the same fact in each theory’s language: the EUF atom on the left, LRA/LIA atoms on the right.
  3. Combine the solvers. A Pair theory solver dispatches each atom to EUF or to arithmetic. The two solvers never talk to each other.

Script 03, Part 1, runs this on the slides’ example. It has 6 shared variables, hence 15 interface clauses:

T-PROP      v1 = v2      because f(x) = v1, f(y) = v2, x = y        (EUF)
PROP        v1 ≤ v2                                                  (interface clause)
PROP        v2 ≤ v1
T-PROP      ¬(v5 ≤ a)    because a + 2 < v5                         (LRA)
PROP        ¬(a = v5)                                                (interface clause)
...
UNSAT: 53 decisions, 5 conflicts, 44 theory propagations; certified

Nelson–Oppen as unit propagation. The exchange of equalities is just unit propagation on the interface clauses. Undecided interface atoms are decided like any other atom: those are the case splits.

The non-convex example needs no special code (script 03, Part 2):

arithmeticanswerdecisionsconflictstheory propagationscertificate
LIAUNSAT1291479ok
LRASAT126975ok

The price. One interface atom per pair of shared variables, which is quadratic. The SAT solver also decides many of them.

What Z3 does instead. Its model-based theory combination creates interface equalities only when the theories’ candidate models disagree. That is the splitting rule of §4.2, inside the SAT search.

6.3 Without interface clauses

Script 03, Part 3, drops the interface clauses:

formulaarithmeticinterface clausesanswercertificate
slides’ convex exampleLRAyesUNSATok
slides’ convex exampleLRAnoSATREJECTED: the model falsifies the formula
non-convex exampleLIAyesUNSATok
non-convex exampleLIAnoSATREJECTED

The wrong SAT is caught by the certificate (§7). An unchecked solver would have reported it.

6.4 Three theories

The motivating formula of §1 has arrays, ff and integers. Script 03, Part 4, decides it in two stages:

  1. Lecture 13’s eager reduction removes the arrays: read\mathit{read} becomes a function, and the write becomes a fresh array with read-over-write instances. Here: 1 write, index set {b+3,a,k1}\{b + 3, a, k_1\}, 4 instances.
  2. CDCL(EUF, LIA) decides the result.

The results.

  • The motivating formula is SAT, with 6 shared variables and 15 interface clauses. The certified model has a=7a = 7, b=5b = 5, f(2)=10f(2) = 10, f(6)=11f(6) = 11, so f(a−b)≠f(b+1)f(a - b) \ne f(b + 1).
  • The variant a=b+2∧A=write(B,a,4)∧read(A,b+2)≠4a = b + 2 \wedge A = \mathit{write}(B, a, 4) \wedge \mathit{read}(A, b + 2) \ne 4 is UNSAT, certified.

Combining by reduction (arrays into EUF) and by combination (EUF with LIA) is how real solvers stack theories.


7. Certificates, and the eager alternative

7.1 Certifying combined answers

A Nelson–Oppen trace is a proof. Each step is a local entailment in one theory, from input literals and earlier steps. check_trace re-checks each step with code that shares nothing with the solvers:

  • EUF steps by a naive congruence closure;
  • LRA steps by Fourier–Motzkin, showing that u<vu < v and u>vu > v are both impossible.

On the slides’ example all 4 steps check. A combination proof is a chain of local proofs glued by shared equalities.

CDCL(T1, T2) answers (certify_combined):

  • UNSAT. Every theory lemma is re-checked in its own theory: naive closure, Fourier–Motzkin, or integer box enumeration. A lemma mixing theories would be rejected, and none occurs. The DRUP proof is checked with the interface clauses as input clauses. That is sound because each interface clause is valid in T1⊕T2T_1 \oplus T_2.

  • SAT. A combined model is built:

    • each arithmetic variable gets the arithmetic solver’s value;
    • each EUF class gets the value of a variable in it, or a fresh number;
    • each function symbol gets a table.

    The original formula is then evaluated. Different classes receive different values, so the tables are well defined.

7.2 The eager alternative: Ackermann’s reduction

ackermann_arith replaces each application f(tˉ)f(\bar t) by a fresh variable. For every two applications of the same ff it adds (tˉ1=tˉ2)⇒F1=F2(\bar t_1 = \bar t_2) \Rightarrow F_1 = F_2. What remains is pure arithmetic, for Lecture 11’s or 12’s solver.

A cross-check. It uses no EUF solver and no combination code. Script 03, Part 5:

formulas × theoriesSATUNSATsame answer as Ackermanncertified
20096104200/200200/200

Scaling on ping-pong(n), the family of §3.4:

nnNelson–Oppen solver callsCDCL(T1, T2) interface clausesconflictsAckermann constraints
226656
3219281415
4772662828
51,8771204745

All three methods answer UNSAT. The figure 03_combination_cost.png plots their CPU time.

Ackermann wins here because ff has only 2n2n applications. With many applications the eager method’s quadratic constraints dominate, as in Lecture 10’s eager-versus-lazy comparison.

Why modular combination wins in general. It keeps every theory solver’s own strengths (congruence closure, simplex, bit-blasting), and it never blows the formula up.


8. Summary

  1. Mixed formulas. Formulas mix theories, and each solver alone over-approximates. The combined theory T1⊕T2T_1 \oplus T_2 has as models the interpretations whose reducts are models of each theory. Its signatures share no function symbols.
  2. Purification names alien subterms by fresh variables, so the two halves share only variables.
  3. Nelson–Oppen checks each half and propagates entailed equalities between shared variables, in both directions, until a contradiction or a fixpoint. On the slides’ example: 4 steps, each independently checkable.
  4. Convexity makes propagation complete. The integers are not convex, so combination needs case splits. Model-based splitting needed one split on the slides’ example.
  5. The non-deterministic method tries Bell(nn) arrangements: 877 for 7 shared variables. It is correct when both theories are stably infinite. A finite sort breaks it, and sharing every term of that sort repairs it.
  6. CDCL(T1, …, Tn) decides interface equalities in the SAT search and keeps theory reasoning local. With interface clauses (u=v)⇔(u≤v∧v≤u)(u = v) \Leftrightarrow (u \le v \wedge v \le u), Nelson–Oppen’s exchange becomes unit propagation.
  7. Every answer is certified: per-theory lemma checks plus DRUP, or a combined model evaluated on the original formula. Ackermann’s reduction agrees on all 200 random cases.

9. Common pitfalls

  • Checking the halves separately. Two satisfiable halves say nothing; the shared equalities are the whole point.
  • Propagating in one direction only. The dialogue must reach a fixpoint on both sides.
  • Forgetting non-convexity. Over the integers, bit-vectors or arrays, propagation alone answers SAT wrongly. Split, or let the SAT solver decide interface atoms.
  • Combining a finite theory as if it were stably infinite. Cardinality must be shared too: share every term of the finite sort.
  • Shared function symbols. The method assumes disjoint signatures. A symbol interpreted by both theories breaks the gluing argument.
  • Counting only conflicts. The cost of combination is in the interface: pairs of shared variables, entailment tests, interface atoms.

10. Exercises

1. (purification) Purify f(x+1)≤y∧g(f(x+1))=y−1f(x + 1) \le y \wedge g(f(x + 1)) = y - 1. Which variables are shared?

Answer

The definitions. x+1x + 1 is arithmetic inside ff: v1=x+1v_1 = x + 1. Then f(v1)f(v_1) sits inside the arithmetic literal ≤\le: v2=f(v1)v_2 = f(v_1). In the second literal, the equality is arithmetic (its right side y−1y - 1 is), and g(f(v1))g(f(v_1)) is alien there: v3=g(f(v1))v_3 = g(f(v_1)). Inside it, f(v1)f(v_1) is pure EUF and stays.

The halves.

  • L1={v2=f(v1), v3=g(f(v1))}L_1 = \{v_2 = f(v_1),\ v_3 = g(f(v_1))\};
  • L2={v2≤y, v3=y−1, v1=x+1}L_2 = \{v_2 \le y,\ v_3 = y - 1,\ v_1 = x + 1\}.

Shared. v1,v2,v3v_1, v_2, v_3; xx and yy occur only in L2L_2. purify gives exactly this.

2. (Nelson–Oppen by hand) Decide x≤y∧y≤x∧f(x)≠f(y)x \le y \wedge y \le x \wedge f(x) \ne f(y) with EUF + LRA. Write the trace.

Answer

The halves. Already pure: L1={f(x)≠f(y)}L_1 = \{f(x) \ne f(y)\}, L2={x≤y,y≤x}L_2 = \{x \le y, y \le x\}, shared x,yx, y.

The trace.

  1. LRA ⊨ x=yx = y (because x≤yx \le y, y≤xy \le x).
  2. EUF ⊨ ⊥ (because f(x)≠f(y)f(x) \ne f(y), x=yx = y).

UNSAT, and check_trace verifies both steps.

3. (convexity) Show that LIA is not convex with x+y=1x + y = 1, 0≤x≤10 \le x \le 1, 0≤y≤10 \le y \le 1, u=0u = 0, w=1w = 1. What does LRA entail?

Answer

Over the integers. x∈{0,1}x \in \{0, 1\}, so x=u∨x=wx = u \vee x = w is entailed, but neither x=ux = u nor x=wx = w is.

Over the reals. x=1/2x = 1/2 is possible, so even the disjunction is not entailed.

The oracles report: LRA entails none of the three; LIA entails only the disjunction.

4. (arrangements) For f(a)=b∧f(b)=c∧a+c=2⋅b∧a<bf(a) = b \wedge f(b) = c \wedge a + c = 2 \cdot b \wedge a < b, list the arrangements of the shared variables. Which ones does each theory accept?

Answer

The arrangements. The shared variables are a,b,ca, b, c, so there are Bell(3) = 5 arrangements: all equal, {a,b}{c}\{a, b\}\{c\}, {a,c}{b}\{a, c\}\{b\}, {b,c}{a}\{b, c\}\{a\}, all different.

EUF accepts 4. It rejects only {a,b}{c}\{a, b\}\{c\}: a=ba = b gives f(a)=f(b)f(a) = f(b), that is, b=cb = c.

LRA accepts 1. a<ba < b and c=2b−a>bc = 2b - a > b force all three to be different.

Together. Only “all different” works for both: SAT. Nelson–Oppen needs no step at all (nothing is entailed). The certified combined model is a=−2a = -2, b=−1b = -1, c=0c = 0, f(−2)=−1f(-2) = -1, f(−1)=0f(-1) = 0.

5. (stable infiniteness) Is the theory with the single axiom ∀x y. x=y\forall x\, y.\ x = y stably infinite? Give literals on which Nelson–Oppen combines it wrongly with EUF.

Answer

Not stably infinite. Every model has exactly one element.

A failure. The EUF literal f(a)≠f(b)f(a) \ne f(b) is satisfiable in EUF. The one-element theory receives no literal and no shared variable, so the combination says SAT. In the combination every two terms are equal, so it is UNSAT.

The repair. Share the terms f(a)f(a) and f(b)f(b). The one-element theory then rejects the only arrangement EUF accepts.

6. (interface size) How many interface clauses does prepare_combined add for kk shared variables? Check the numbers 15 (slides’ example) and 120 (ping-pong(5)).

Answer

The count. One clause per unordered pair: k(k−1)/2k(k-1)/2.

The check. The slides’ example has 6 shared variables: 1515. Ping-pong(5) has 16: 120120.

7. (eager vs lazy) How many consistency constraints does Ackermann’s reduction add for one function symbol applied to mm distinct argument tuples? Check ping-pong(5).

Answer

The count. One constraint per pair of applications: m(m−1)/2m(m-1)/2.

The check. Ping-pong(5) applies ff to x1..x5x_1..x_5 and y1..y5y_1..y_5, so m=10m = 10, giving 45 constraints, the number printed by script 03.

8. (I-LEARN) In the slides’ non-convex example, which disjunction of interface equalities does I-LEARN add, and why is it valid in LIA? Why is it not valid in LRA?

Answer

The disjunction. ¬(1≤x)∨¬(x≤2)∨x=v1∨x=v2\neg(1 \le x) \vee \neg(x \le 2) \vee x = v_1 \vee x = v_2, where v1=1v_1 = 1 and v2=2v_2 = 2. On the slides it is the I-LEARN clause over the atoms numbered 4 (1≤x1 \le x), 5 (x≤2x \le 2), 11 (x=v1x = v_1) and 12 (x=v2x = v_2), with 4 and 5 negated.

Why it holds in LIA. The only integers between 1 and 2 are 1 and 2.

Why not in LRA. x=3/2x = 3/2 falsifies it. The clause is exactly what makes the LIA branch of the trace work.

9. (programming) Replace the pairwise entailment tests of nelson_oppen for EUF by reading the classes of a congruence closure (smt.CongruenceClosure): every two shared variables in one class are entailed equal, with explain as premises. Compare the number of solver calls on ping_pong(n).

Answer sketch

The change. Assert L1∪EL_1 \cup E into one CongruenceClosure. For each class, chain its shared variables (u1=u2u_1 = u_2, u2=u3u_2 = u_3, …). explain(u, v) gives the premises.

What to expect. EUF then costs one call per round instead of one per pair. LRA still tests pairs, unless equalities are read off tight bounds of the simplex tableau, so expect the total to shrink but keep growing with the number of pairs.

10. (programming) Make Pair model-based: drop the interface clauses. In check(final=True), compare the EUF classes with the arithmetic values of shared variables. If they disagree on a pair u,vu, v, return a conflict that forces a decision on u=vu = v.

Answer sketch

The difficulty. Lecture 10’s CDCL(T) cannot add new atoms during search, so the simplest version pre-registers the atoms u=vu = v without the clauses linking them. At the final check:

  • if EUF and arithmetic disagree on a pair, return the clause (u=v)⇔(u≤v∧v≤u)(u = v) \Leftrightarrow (u \le v \wedge v \le u) for that pair only, as a lemma (it is valid);
  • otherwise the models glue, and the answer is SAT.

What to expect. Only the pairs on which the models actually disagree get a clause, instead of all k(k−1)/2k(k-1)/2; measure how many on the slides’ examples and on ping_pong(n). This is z3’s model-based theory combination.


11. Further reading

  • D. Kroening, O. Strichman, Decision Procedures, 2nd ed., Sections 10.1–10.5 (theory combination).
  • C. Tinelli, Combining Theories and Their Solvers, CS:4980 slides, University of Iowa, Spring 2024 (with Barrett, Trippel and Wu).
  • G. Nelson, D. C. Oppen, “Simplification by Cooperating Decision Procedures”, ACM TOPLAS 1(2), 1979.
  • D. C. Oppen, “Complexity, Convexity and Combinations of Theories”, Theoretical Computer Science 12, 1980.
  • C. Tinelli, M. Harandi, “A New Correctness Proof of the Nelson–Oppen Combination Procedure”, FroCoS 1996.
  • M. Bozzano, R. Bruttomesso, A. Cimatti, T. Junttila, S. Ranise, P. van Rossum, R. Sebastiani, “Efficient Satisfiability Modulo Theories via Delayed Theory Combination”, CAV 2005.
  • L. de Moura, N. Bjørner, “Model-based Theory Combination”, ENTCS 198(2), 2008 (SMT 2007).
  • S. Ranise, C. Ringeissen, C. G. Zarba, “Combining Data Structures with Nonstably Infinite Theories Using Many-Sorted Logic”, FroCoS 2005.
  • D. Jovanović, C. Barrett, “Polite Theories Revisited”, LPAR 2010.
  • C. Barrett, C. Tinelli, “Satisfiability Modulo Theories”, in Handbook of Model Checking, Springer 2018 (Section on combination).

12. Next lecture

Lecture 19: using formal verification for text-to-SQL. A guest lecture applies the course’s tools to queries written by language models.

  • The question. When is a generated SQL query correct? Its semantics has bags (duplicates), NULLs and aggregation.
  • The method. Encode small symbolic tables into a solver. Then ask whether two queries can differ on some database, and produce a tiny counterexample database when they can.
  • The theories. The encoding mixes EUF, integers and Booleans, so today’s combination is what decides it.

See Lecture 19.

← 返回课程目录