Lecture 17 · Herbrand's Theorem and Quantifier Instantiation

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

课程源码 ZIP ↓

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

本篇目录

Maps to: Stanford CS 257 Introduction to Automated Reasoning (Winter 2026), Lecture 17 · Tue 03/03/2026 · SMT: Herbrand’s theorem, quantifier instantiation (Hanna Lachnitt). Reading: Kroening and Strichman, Decision Procedures, Section 9.5 (Chapter 9 is about quantified formulas). Basis: The Stanford slides are on Canvas, and the public Iowa decks have no lecture on quantifier instantiation. This lecture is written from:

  • Kroening and Strichman, Chapter 9;
  • Herbrand’s theorem as in Enderton and in Bradley and Manna;
  • Detlefs, Nelson and Saxe (2005), the Simplify prover, where triggers and matching loops come from;
  • de Moura and Bjørner (CADE 2007), efficient E-matching in Z3;
  • Ge and de Moura (CAV 2009), model-based quantifier instantiation;
  • Reynolds, Tinelli and de Moura (FMCAD 2014), conflict-based instantiation;
  • Reynolds, Tinelli, Goel, Krstić, Deters and Barrett (CADE 2013), finite model finding in SMT;
  • Reynolds, Barbosa and Fontaine (TACAS 2018), enumerative instantiation;
  • Leino and Pit-Claudel (CAV 2016), trigger selection in Dafny.

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

  • preprocessing into quantifier atoms;
  • Herbrand instantiation;
  • an E-graph with matching modulo equalities;
  • automatic triggers;
  • conflict-based, E-matching, model-based and enumerative instantiation;
  • finite model finding;
  • certificates for every answer.

The experiments were designed for these notes and do not reflect what was said in class. Code: code/lecture17/ (3 scripts + 1 module; Python standard library only; about 1 to 5 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. Turn quantified sentences into what an SMT solver works on: negation normal form, Skolem functions, quantifier atoms, and instances added as lemmas ¬Qk∨φ[t]\neg Q_k \vee \varphi[t].
  2. State Herbrand’s theorem, explain why it turns first-order unsatisfiability into a search for finitely many ground instances, and say what it does not give (a way to prove satisfiability).
  3. Explain why the Bernays–Schönfinkel class (EPR) is decidable by instantiation, and estimate its cost.
  4. Run E-matching by hand: match a trigger against an E-graph modulo its equalities, and choose triggers, including multi-triggers.
  5. Recognize a matching loop, and stop it with a better trigger or a generation limit.
  6. Describe conflict-based, model-based and enumerative instantiation and finite model finding: what question each asks of the candidate model, and which answers each can give.
  7. Explain why every strategy must sometimes answer unknown, and what a certificate for each answer looks like.

0.2 Prerequisites and scope

AssumedIntroduced hereDeveloped later
FOL syntax, substitution (Lecture 6); NNF, Skolemization, structures (Lecture 7)quantifier atoms, inner Skolemization in NNF—
Gilmore’s method, undecidability (Lecture 8)Herbrand’s theorem modulo EUF, EPR—
congruence closure, CDCL(T), certificates (Lecture 10)E-graphs for matching, three-valued evaluationtheory combination (Lecture 18)
grind’s E-matching annotations (Lecture 15)triggers, matching loops, generationssynthesis as ∃∀ (Lecture 20)

0.3 Map

§1  why quantifiers: what verifiers ask of SMT solvers
§2  from sentences to ground formulas with quantifier atoms           ← code 01
§3  Herbrand's theorem, and instantiation by levels; EPR              ← code 01
§4  E-matching: triggers, matching modulo E, matching loops            ← code 02
§5  conflict-based and enumerative instantiation                       ← code 02, 03
§6  model-based instantiation and finite model finding                 ← code 03
§7  answers, certificates, and "unknown"                               ← code 03
§8  summary   §9 common pitfalls   §10 exercises   §11 further reading   §12 next lecture

0.4 Notation

SymbolMeaning
∀xˉ. φ\forall \bar x.\, \varphia quantifier over the variables x1…xnx_1 \ldots x_n with a quantifier-free body φ\varphi
φ[xˉ↦tˉ]\varphi[\bar x \mapsto \bar t], φ[tˉ]\varphi[\bar t]an instance: the body with ground terms tit_i for xix_i
QkQ_kthe propositional quantifier atom standing for the kk-th quantifier
HℓH_\ellthe Herbrand universe up to nesting depth ℓ\ell
[t][t]the E-graph class of term tt (all terms equal to tt in the candidate model)
{p1,…,pm}\{p_1, \ldots, p_m\}a trigger: one pattern, or several (a multi-trigger)
sky(xˉ)\mathrm{sk}_y(\bar x)the Skolem function introduced for ∃y\exists y under ∀xˉ\forall \bar x

0.5 The code of this lecture

One module, quantifiers.py:

  • preprocessing: prepare, Problem, Quant;
  • Herbrand instantiation: herbrand_universe, solve_herbrand;
  • the candidate model: EGraph with ematch, eval3 and structure; egraph_of;
  • triggers: select_triggers, syntactic_matches;
  • the instantiation loop: solve(formulas, strategy=...), with stages cbqi, ematch, mbqi, enum joined by +; solve_finite_model;
  • certificates: certify, check_instances, is_instance, check_model;
  • benchmarks: chain, transitive_chain, conflict_family, BENCHMARKS.

The ground solver of every round is Lecture 10’s CDCL(T) for EUF. Models are checked with Lecture 7’s evaluator.


1. Why quantifiers

Lectures 10–16 decided quantifier-free formulas: every name is a constant, every atom is ground. The verification tools built on SMT solvers need more. Dafny, Boogie, F*, Why3 and Viper translate a program and its specification into formulas, and those formulas contain facts like:

∀x. head(cons(x,y))=x∀i. 0≤i<n⇒a[i]≤a[i+1]∀x y z. R(x,y)∧R(y,z)⇒R(x,z)\forall x.\ \mathit{head}(\mathit{cons}(x, y)) = x \qquad \forall i.\ 0 \le i < n \Rightarrow a[i] \le a[i+1] \qquad \forall x\, y\, z.\ R(x, y) \wedge R(y, z) \Rightarrow R(x, z)

These are axioms of user-defined data types, loop invariants, and properties of functions. The solver must use them: pick the right instances and combine them with the ground facts of the program.

The obstacle. First-order validity is undecidable (Lecture 8), and so is satisfiability of quantified formulas over EUF. No procedure answers every question. Lecture 8’s resolution prover is refutationally complete but knows nothing about theories. The SMT approach is different:

  • keep the fast ground engine (CDCL(T));
  • feed it ground instances of the quantified facts, chosen by heuristics;
  • accept that the answer is sometimes unknown.

Why instances are enough, sometimes. Herbrand’s theorem (§3) says that an unsatisfiable set of universal sentences already has a finite unsatisfiable set of ground instances. The solver’s job is to find those instances. Everything in this lecture is a strategy for choosing them:

StrategyQuestion it asksCan answer
Herbrand levels (§3)all instances over terms of depth ≤ℓ\le \ellUNSAT; SAT only for EPR
E-matching (§4)which terms of the problem fit a pattern?UNSAT
conflict-based (§5)which instance is already false here?UNSAT
enumerative (§5)which small tuple of existing terms is untried?UNSAT
model-based (§6)is the candidate model already a model?UNSAT, SAT
finite model finding (§6)is there a model with at most kk elements?SAT

2. From sentences to ground formulas with quantifier atoms

2.1 The pipeline

prepare applies Lecture 7’s steps, then one new step. Script 01, Part 1, traces it:

input:          ∀x. ∃y. R(x, y)
Skolemized:     ∀x. R(x, sk_y(x))
quantifier Q1:  ∀x. R(x, sk_y(x))
ground part:    Q1

input:          ¬∃x. (P(x) ∧ ∀y. ¬R(x, y))
NNF:            ∀x. (¬P(x) ∨ ∃y. R(x, y))
Skolemized:     ∀x. (¬P(x) ∨ R(x, sk_y(x)))

input:          P(a) ∨ ∀x. (Q(x) ∧ S(x))
quantifier Q1:  ∀x. Q(x)
quantifier Q2:  ∀x. S(x)
ground part:    P(a) ∨ Q1 ∧ Q2

input:          ∀x. (P(x) ⇒ ∀y. (R(x, y) ⇒ P(y)))
quantifier Q1:  ∀x y. (¬P(x) ∨ ¬R(x, y) ∨ P(y))
  1. NNF. Eliminate ⇒\Rightarrow and ⇔\Leftrightarrow, rename bound variables apart, push negations to the atoms. Afterwards every quantifier occurs positively: ¬∃\neg\exists has become ∀\forall, and ¬∀\neg\forall has become ∃\exists.
  2. Skolemize. Replace ∃y. ψ\exists y.\, \psi by ψ[y↦sky(xˉ)]\psi[y \mapsto \mathrm{sk}_y(\bar x)], where xˉ\bar x are the universally bound variables that occur free in ∃y. ψ\exists y.\,\psi (“inner” Skolemization, which gives fewer arguments). The result is equisatisfiable, not equivalent (Lecture 7).
  3. Quantifier atoms. Each maximal ∀\forall-block is processed in four steps:
    • the ∀\foralls nested in its body are pulled to the front;
    • its body is split at ∧\wedge (miniscoping: ∀x. A∧B≡(∀x. A)∧(∀x. B)\forall x.\, A \wedge B \equiv (\forall x.\, A) \wedge (\forall x.\, B));
    • variables that a part does not use are dropped;
    • each part is replaced by a fresh propositional atom QkQ_k.

2.2 Why atoms, and why lemmas ¬Qk∨φ[t]\neg Q_k \vee \varphi[t]

The ground solver sees QkQ_k as one more Boolean atom of the skeleton (Lecture 10’s abstraction). Two facts make this sound and complete enough:

  • Instances are valid lemmas. (∀xˉ. φ)⇒φ[tˉ](\forall \bar x.\, \varphi) \Rightarrow \varphi[\bar t] is valid. With QkQ_k standing for the quantifier, the lemma ¬Qk∨φ[tˉ]\neg Q_k \vee \varphi[\bar t] is true in every model where QkQ_k means what it should. Adding it never removes a real model.
  • A false atom needs no instances. QkQ_k occurs positively, so a model of the skeleton with QkQ_k false stays a model if QkQ_k is replaced by the actual truth value of the quantifier: a positive occurrence can only gain from being true (monotonicity). Only active quantifiers, whose atom is true in the candidate model, are instantiated. Under P(a)∨…P(a) \vee \ldots the solver may choose P(a)P(a) and never instantiate at all.

One warning about the course’s parser (Lecture 6): ∀\forall binds more tightly than the connectives. So ∀x. P(x) ⇒ P(s(x)) means (∀x. P(x))⇒P(s(x))(\forall x.\, P(x)) \Rightarrow P(s(x)), with a free xx. prepare rejects free variables; write ∀x. (P(x) ⇒ P(s(x))).


3. Herbrand’s theorem

3.1 The Herbrand universe

Definition. Let SS be a set of universal sentences in Skolem form (only ∀\forall, quantifier-free bodies). Its Herbrand universe HH is the set of ground terms built from the constants and function symbols of SS. If there is no constant, a fresh one is added: domains are non-empty. Write HℓH_\ell for the terms of nesting depth ≤ℓ\le \ell.

Script 01, Part 2, counts ∣Hℓ∣|H_\ell|:

constants, functions/arityℓ=0\ell = 012345
a, b222222
a, s/1123456
a, b, s/124681012
a, g/212526677458,330
a, s/1, g/2131318333,673> 10⁶

Three behaviors:

  • No function symbols: the universe is the finite set of constants.
  • A unary symbol: linear growth.
  • A binary symbol: each level squares the previous one (doubly exponential).

A quantifier with kk variables has ∣Hℓ∣k|H_\ell|^k instances at level ℓ\ell.

3.2 The theorem

Herbrand’s theorem. A set SS of universal sentences is unsatisfiable if and only if some finite set of ground instances of its bodies, over the Herbrand universe, is unsatisfiable.

  • Ground solver. Without equality, “unsatisfiable” means propositionally unsatisfiable: Lecture 8’s Gilmore method with a SAT solver. With equality and uninterpreted functions, use an EUF solver and read “unsatisfiable” modulo EUF. That is the version this lecture uses: the equality axioms of Lecture 8 are no longer needed.
  • Validity. Dually, ∃xˉ. ψ\exists \bar x.\, \psi is valid iff a finite disjunction of instances ψ[tˉ1]∨…∨ψ[tˉm]\psi[\bar t_1] \vee \ldots \vee \psi[\bar t_m] is valid. This is how Herbrand first stated it.

Why it holds (sketch). One direction is trivial: instances are consequences, so an unsatisfiable finite set of them makes SS unsatisfiable. For the other, suppose every finite set of ground instances is satisfiable.

  1. By compactness (propositional, or modulo EUF), the set of all ground instances has a model.
  2. Build a Herbrand interpretation from it. Its domain is HH, with the classes of equal terms merged when equality is involved. Each function symbol builds terms, and each atom has the value the model gives it.
  3. Every domain element is (the class of) a ground term tt, and every instance φ[t]\varphi[t] is true. So ∀x. φ\forall x.\, \varphi is true: SS is satisfiable.

What the theorem gives.

  • A semi-decision procedure for unsatisfiability: enumerate finite sets of instances.
  • A certificate for UNSAT answers: the instances, plus a ground refutation (§7).

What it does not give.

  • Any way to establish satisfiability when HH is infinite. Every finite set of instances may be satisfiable, and the enumeration never ends.
  • Any hint about which instances to take.

3.3 Herbrand instantiation by levels

solve_herbrand adds all instances over H0H_0, then all over H1H_1, and so on, each time asking Lecture 10’s CDCL(T). Script 01, Part 3, runs it on the lecture’s benchmarks:

benchmarkexpectedresultleveluniverseinstances
chain 3UNSATUNSAT233
transitivityUNSATUNSAT05125
involutionUNSATUNSAT022
injectiveUNSATUNSAT022
listsUNSATUNSAT0432
skolemUNSATUNSAT128
orderSATSAT0468
no fixpointSATUNKNOWN41010
loopSATUNKNOWN41010
infiniteSATUNKNOWN4530

The benchmarks (quantifiers.BENCHMARKS):

  • chain 3: P(a)P(a), ∀x. P(x)⇒P(s(x))\forall x.\, P(x) \Rightarrow P(s(x)), ¬P(s3(a))\neg P(s^3(a)).
  • transitivity: a chain R(c0,c1),…,R(c3,c4)R(c_0, c_1), \ldots, R(c_3, c_4), transitivity, and ¬R(c0,c4)\neg R(c_0, c_4).
  • involution: ∀x. f(f(x))=x\forall x.\, f(f(x)) = x, f(a)=bf(a) = b, f(b)≠af(b) \ne a.
  • injective: ∀x. g(f(x))=x\forall x.\, g(f(x)) = x, f(a)=f(b)f(a) = f(b), a≠ba \ne b.
  • lists: constructor axioms for head\mathit{head} and tail\mathit{tail}, cons(a,l)=cons(b,m)\mathit{cons}(a, l) = \mathit{cons}(b, m), a≠ba \ne b.
  • skolem: ∀x∃y. R(x,y)\forall x \exists y.\, R(x, y), ∀xy. R(x,y)⇒Q(y)\forall x y.\, R(x, y) \Rightarrow Q(y), ∀x. ¬Q(x)\forall x.\, \neg Q(x).
  • order: a chain, transitivity and irreflexivity.
  • no fixpoint: ∀x. f(x)≠x\forall x.\, f(x) \ne x, f(a)=bf(a) = b.
  • loop: P(a)P(a), ¬P(b)\neg P(b), ∀x. P(x)⇒P(s(x))\forall x.\, P(x) \Rightarrow P(s(x)).
  • infinite: ∀x. s(x)≠o\forall x.\, s(x) \ne o, with ss injective.

What the table shows.

  • Every unsatisfiable benchmark is refuted at the first level whose universe holds the terms the proof needs. ‘chain 3’ needs s(s(a))s(s(a)) (level 2), and ‘skolem’ needs sky(c0)\mathrm{sk}_y(c_0) (level 1). That level is never deeper than the proof.
  • ‘involution’ is refuted without equality axioms: the instances are checked modulo EUF.
  • Satisfiable problems with a function symbol are never answered.

3.4 The price of blindness

Herbrand instantiation adds every instance at a level, including those of irrelevant axioms. Script 01, Part 4, uses P(a)P(a), ∀x. P(x)⇒P(g(x,x))\forall x.\, P(x) \Rightarrow P(g(x, x)), ¬P(td)\neg P(t_d), with tdt_d of depth dd (for d=2d = 2, t2=g(g(a,a),g(a,a))t_2 = g(g(a,a), g(a,a))), plus the irrelevant axiom ∀x y. E(x,y)⇒E(y,x)\forall x\, y.\, E(x, y) \Rightarrow E(y, x):

depth ddHerbrandleveluniverseinstancesE-matchinginstances
1UNSAT012UNSAT1
2UNSAT126UNSAT2
3UNSAT2530UNSAT3
4UNSAT326702UNSAT4
5UNKNOWN4—> 100,000UNSAT5

What the table shows.

  • The proof is tiny. It needs dd instances, x↦a,g(a,a),…x \mapsto a, g(a,a), \ldots.
  • Herbrand pays for the irrelevant axiom. At level 3, that axiom alone has 262=67626^2 = 676 of the 702 instances. At level 4 it would have about 458,000.
  • E-matching (§4) is goal-directed. It instantiates from the terms that occur in the problem and finds exactly the dd instances, in one round. The irrelevant axiom’s trigger E(x,y)E(x, y) matches nothing.

This is the central lesson: completeness is cheap to obtain and useless at scale; relevance is what matters.

3.5 EPR: when instantiation decides

The decidable case. Suppose there is no function symbol after Skolemization: only constants, which happens when every ∃\exists is outside every ∀\forall. This is the Bernays–Schönfinkel class, called EPR (“effectively propositional”) in SMT. Its universe H=H0H = H_0 is finite, and H0H_0 contains all instances. If they are satisfiable, the Herbrand interpretation is a model, so instantiation decides EPR.

Its cost. With nn constants and kk variables there are nkn^k instances per quantifier. Satisfiability of EPR is NEXPTIME-complete (Lewis 1980).

Script 01, Part 5:

EPR, satisfiable: R(c0, c1); R(c1, c2); R(c2, c3); transitivity; ∀x. ¬R(x, x)
result: SAT after 68 instances (level 0); a model with 4 elements satisfies all 5 input sentences
R: true at ([c0], [c1]), ([c0], [c2]), ([c0], [c3]), ([c1], [c2]), ([c1], [c3]), ([c2], [c3])

With a function symbol, every level is satisfiable. For ‘loop’ (P(a)P(a), ¬P(b)\neg P(b), ∀x. P(x)⇒P(s(x))\forall x.\, P(x) \Rightarrow P(s(x))), level ℓ\ell‘s ground model makes P(a),P(s(a)),…,P(sℓ+1(a))P(a), P(s(a)), \ldots, P(s^{\ell+1}(a)) true. Each is a finite piece of an infinite Herbrand model: a set of true ground atoms. No level contains the whole model, so the loop never says SAT. Yet a 2-element model exists (§6).


4. E-matching

4.1 The idea

Instantiate with terms the problem is about. A program verifier’s formula mentions cons(a,l)\mathit{cons}(a, l) and cons(b,m)\mathit{cons}(b, m), so the constructor axiom is probably needed for those terms, not for cons(cons(a,a),l)\mathit{cons}(\mathit{cons}(a, a), l).

Triggers. E-matching attaches to each quantifier a trigger (or pattern): a term with the quantifier’s variables, such as cons(x,y)\mathit{cons}(x, y). It instantiates the quantifier for every way the trigger matches a ground term of the current problem.

Origin. The method comes from the Simplify prover (Detlefs, Nelson, Saxe 2005). It is the workhorse of Z3, cvc5 and Lean’s grind (Lecture 15’s annotations are triggers).

4.2 Matching modulo equalities

Matching inside classes. The ground solver’s candidate model has an E-graph: the congruence classes of Lecture 10. E-matching matches patterns against classes, not individual terms:

  • a pattern variable matches a whole class;
  • a pattern f(p1,…,pn)f(p_1, \ldots, p_n) matches class CC if some ff-term f(t1,…,tn)f(t_1, \ldots, t_n) in CC has each [ti][t_i] matched by pip_i.

Script 02, Part 1, works on f(a)=bf(a) = b, f(b)=cf(b) = c, c≠ac \ne a, ∀x. f(f(x))=x\forall x.\, f(f(x)) = x:

E-graph:  [a] = {a}   [b] = {b, f(a)}   [c] = {c, f(b)}

pattern        syntactic matches: x ↦   matches modulo E: x ↦
f(x)           a, b                     [a], [b]
f(f(x))        none                     [a]
f(f(f(x)))     none                     none

Reading the output.

  • No term has the shape f(f(…))f(f(\ldots)). Yet f(f(x))f(f(x)) matches f(b)f(b): the matcher enters the class of the argument bb, finds f(a)f(a) there, and binds x↦[a]x \mapsto [a].
  • The instance. It uses the smallest term of the class, f(f(a))=af(f(a)) = a. Congruence then gives f(f(a))=f(b)=cf(f(a)) = f(b) = c, which contradicts c≠ac \ne a.
  • Trigger choice matters. With the trigger {f(f(x))}\{f(f(x))\} one instance suffices. The automatic trigger {f(x)}\{f(x)\} (§4.3) matches f(a)f(a) and f(b)f(b) and adds two.

What real solvers add. They compile patterns into code trees and index the E-graph so that only new matches are found after each merge (de Moura and Bjørner 2007). Here EGraph.ematch simply recomputes all matches every round; a dedupe by class tuples keeps the instances new.

4.3 Choosing triggers

What a trigger must do.

  • Bind every variable. Otherwise the instance is not ground.
  • Contain no interpreted symbol (no ==, no arithmetic), so that it can be matched.
  • Be selective, but not too selective.

select_triggers follows Simplify and Z3, simplified:

  1. Candidates: the applications in the body (function terms and predicate atoms) that contain a variable.
  2. Single triggers: the candidates that contain all variables and are minimal (no proper subterm does). Small patterns match more terms.
  3. Loop check: reject a candidate tt that matches a different application ss of the body (tσ=st\sigma = s). An instance would then create a new term that matches tt again (§4.5). Rejected candidates are kept if nothing else remains.
  4. Multi-trigger: if no single candidate covers the variables, choose a greedy cover: patterns with more variables first, ties left to right.

Script 02, Part 2:

quantifiercandidatestriggers chosenrejected (loop)
∀x. P(x)⇒P(s(x))\forall x.\, P(x) \Rightarrow P(s(x))P(x), P(s(x)), s(x){s(x)}P(x)
∀x. f(g(x))=f(x)\forall x.\, f(g(x)) = f(x)f(g(x)), g(x), f(x){g(x)}f(x)
∀x. f(f(x))=x\forall x.\, f(f(x)) = xf(f(x)), f(x){f(x)}f(x) (kept: nothing else)
∀x. g(f(x))=x\forall x.\, g(f(x)) = xg(f(x)), f(x){f(x)}—
∀xy. head(cons(x,y))=x\forall x y.\, \mathit{head}(\mathit{cons}(x, y)) = xhead(cons(x, y)), cons(x, y){cons(x, y)}—
transitivityR(x, y), R(y, z), R(x, z){R(x, y), R(y, z)}—
∀xy. f(x)=f(y)⇒x=y\forall x y.\, f(x) = f(y) \Rightarrow x = yf(x), f(y){f(x), f(y)}—
∀xy. R(x,y)⇒R(y,x)\forall x y.\, R(x, y) \Rightarrow R(y, x)R(x, y), R(y, x){R(x, y)} {R(y, x)}both (kept)
∀x. x=a\forall x.\, x = anonenone—

Multi-triggers. {R(x,y),R(y,z)}\{R(x, y), R(y, z)\} matches pairs of terms that agree on yy. That is a join, potentially quadratic in the number of RR-atoms.

No candidate. ∀x. x=a\forall x.\, x = a has no candidate at all, so E-matching never instantiates it.

Triggers in practice. In Dafny and Boogie users can write triggers themselves ({:trigger f(x)}). Dafny chooses them automatically and warns about likely matching loops (Leino and Pit-Claudel 2016). Choosing triggers is part of writing verifiable specifications.

4.4 The instantiation loop

solve(formulas, strategy="ematch") alternates the ground solver and E-matching:

repeat:
    decide ground part ∧ all lemmas ¬Qk ∨ φ[t] so far        (Lecture 10's CDCL(T))
    UNSAT  -> UNSAT
    SAT    -> build the E-graph of the candidate model
              for each active quantifier, each trigger, each match σ not instantiated yet:
                  add the lemma ¬Qk ∨ φσ
    nothing new -> UNKNOWN

Script 02, Part 3:

lists: ∀x y. head(cons(x, y)) = x;  ∀x y. tail(cons(x, y)) = y;  cons(a, l) = cons(b, m);  a ≠ b
  round 1: ground SAT, 5 classes; E-matching: Q1[x ↦ a, y ↦ l], Q1[x ↦ b, y ↦ m], Q2[x ↦ a, y ↦ l], Q2[x ↦ b, y ↦ m]
  round 2: ground UNSAT

transitivity (n = 4):
  round 1: 3 instances (neighbours joined: c0-c1-c2, c1-c2-c3, c2-c3-c4)
  round 2: 5 instances (the new atoms R(c0, c2), ... are new terms and match again)
  round 3: ground UNSAT

lists. The head instances give head(cons(a,l))=a\mathit{head}(\mathit{cons}(a, l)) = a and head(cons(b,m))=b\mathit{head}(\mathit{cons}(b, m)) = b. Congruence on cons(a,l)=cons(b,m)\mathit{cons}(a, l) = \mathit{cons}(b, m) then makes a=ba = b.

transitivity. Each round doubles the distance covered, so about log⁡2n\log_2 n rounds are needed, with more instances than the proof uses: 8, where 3 suffice (Exercise 10).

4.5 Matching loops and generations

The loop. Take ‘loop’ (P(a)P(a), ¬P(b)\neg P(b), ∀x. P(x)⇒P(s(x))\forall x.\, P(x) \Rightarrow P(s(x))) and force the trigger P(x)P(x). Each instance P(t)⇒P(s(t))P(t) \Rightarrow P(s(t)) creates the term P(s(t))P(s(t)), which matches P(x)P(x) in the next round:

round 1: E-matching: Q1[x ↦ a], Q1[x ↦ b]
round 2: E-matching: Q1[x ↦ s(a)], Q1[x ↦ s(b)]
round 3: E-matching: Q1[x ↦ s(s(a))], Q1[x ↦ s(s(b))]
...

This is a matching loop. The problem is satisfiable, so no conflict ever stops it. Script 02, Part 4:

problemtriggergeneration limitresultroundsinstancesground terms
loop (SAT)P(x)noneUNKNOWN (round budget)204040
loop (SAT)P(x)2UNKNOWN346
loop (SAT)P(x)4UNKNOWN5810
loop (SAT)P(x)8UNKNOWN91618
loop (SAT)s(x) (automatic)noneUNKNOWN102
chain 3 (UNSAT)P(x)noneUNSAT466
chain 3 (UNSAT)s(x) (automatic)noneUNSAT234
f(g(x))=f(x)f(g(x)) = f(x) (SAT)f(x)noneUNKNOWN (round budget)204081
f(g(x))=f(x)f(g(x)) = f(x) (SAT)g(x) (automatic)noneUNKNOWN105

Two remedies:

  • A better trigger. With s(x)s(x), an instance contains only s(t)s(t) for a matched tt, a term that already exists, so nothing new can match. On ‘chain 3’ it also halves the work: 3 instances against 6.
  • Generations. Input terms have generation 0, and an instance built from terms of generation ≤g\le g has generation g+1g + 1. A generation limit ignores matches above it. The loop then stops after 4, 8 or 16 instances, and the honest answer is UNKNOWN. Z3 ranks instances by a cost based on generations and delays the expensive ones.

4.6 Where E-matching gives up

When it fails. E-matching instantiates only through triggers, and only with terms already in the E-graph. Script 02, Part 5:

problemwhy E-matching is stuckE-matching+ enumerative
skolemno ground term at allUNKNOWN (0)UNSAT (5 instances, 4 rounds)
∀x. x=a\forall x.\, x = a, b≠cb \ne cno trigger can be chosenUNKNOWN (0)UNSAT (2, 3 rounds)
injective, trigger g(f(x))g(f(x))no gg-term to matchUNKNOWN (0)UNSAT (2, 3 rounds)
order (SAT)satisfiableUNKNOWN (4)UNKNOWN (68, 13 rounds)
no fixpoint (SAT)satisfiableUNKNOWN (1)UNKNOWN (30, 30 rounds)

Enumerative instantiation (Reynolds, Barbosa and Fontaine 2018) takes over when matching saturates. For each active quantifier it instantiates the smallest tuple of existing terms (by total size) that is untried and whose instance the E-graph does not already make true. It is Herbrand instantiation restricted to the problem’s terms. Like E-matching, it can only add instances, so it can never answer SAT.


5. Conflict-based instantiation

The question. Each candidate model is a partial assignment that the ground solver will revise. The most useful instance is one that makes the current model fail: a conflicting instance. Reynolds, Tinelli and de Moura (2014) made this the first stage of cvc5’s instantiation.

Three-valued evaluation. EGraph.eval3 evaluates an instance using only what the E-graph entails:

  • s=ts = t is true if [s]=[t][s] = [t], false if the two classes are kept apart by an asserted disequality, and unknown otherwise;
  • a predicate atom has the value of a known atom with the same argument classes;
  • connectives follow Kleene’s three-valued logic.

An instance that evaluates to false is entailed false: adding it causes a conflict at once.

A family where it pays. Script 03, Part 3, uses p(f(c1)),…,p(f(cn))p(f(c_1)), \ldots, p(f(c_n)), ∀x. f(x)=g(x)\forall x.\, f(x) = g(x), f(cn)≠g(cn)f(c_n) \ne g(c_n):

nE-matching instancesconflict-based instances
551
10101
20201
40401
80801

The E-graph already knows f(cn)≠g(cn)f(c_n) \ne g(c_n), so the instance x↦cnx \mapsto c_n is conflicting. E-matching instead fires on every ff-term.

On the transitivity chain with n=16n = 16:

  • E-matching adds 512 instances;
  • conflicts first, then E-matching, adds 193;
  • MBQI (§6) adds 119, one per round, in 120 ground calls;
  • Herbrand adds all 173=4,91317^3 = 4{,}913 in one round.

The proof needs n−1=15n - 1 = 15. The figure 03_instances_by_strategy.png plots these counts for n=2…16n = 2 \ldots 16.

How the search is done. Our conflict search simply enumerates class tuples, up to cbqi_limit. cvc5 finds conflicting instances by a matching procedure that treats the conflict as its goal.


6. Model-based instantiation and finite model finding

6.1 The idea

E-matching asks which terms look relevant. Model-based quantifier instantiation (MBQI; Ge and de Moura 2009, the second stage of Z3) asks: is the candidate model already a model of the quantifiers?

  1. Complete the candidate model into a finite structure (EGraph.structure).
    • The domain is the set of E-graph classes.
    • Each function is defined where the E-graph has terms, and takes a default value everywhere else (Z3’s “else”). Here the default is the value at the function’s first defined point, or element 0, or false for a predicate without points.
  2. Check each active quantifier by evaluating its body for every assignment of domain elements. The domain is finite, so this is a finite check (Lecture 7’s evaluate).
  3. A counterexample assignment becomes an instance: name each element by a term of its class. This instance is false in the current model, so the next ground model must differ.
  4. No counterexample for any quantifier: the structure is a model, and the answer is SAT.

6.2 Step by step

Script 03, Part 1, takes ∀x. f(x)≠x\forall x.\, f(x) \ne x, f(a)=bf(a) = b:

Round 1. E-graph: [a] = {a}   [b] = {b, f(a)}
Completed structure: domain {[a], [b]};  f: ([a]) ↦ [b], ([b]) ↦ [b]      (f([b]) is the default)
Check ∀x. f(x) ≠ x: false at x = [b].   Instance Q1[x ↦ b]: f(b) ≠ b
Round 2. no counterexample
Final model: domain {[a], [b], [f(b)]};  f: ([a]) ↦ [b], ([b]) ↦ [f(b)], ([f(b)]) ↦ [b]
SAT certified: a model with 3 elements satisfies all 2 input sentences

Reading the trace.

  • The default made f([b])=[b]f([b]) = [b], a fixpoint. The instance f(b)≠bf(b) \ne b forces the next ground model to give f(b)f(b) its own class.
  • In round 2, ff at the new element defaults to [b][b], and all three points satisfy f(x)≠xf(x) \ne x.

On ‘loop’, MBQI answers at once, with 0 instances and a 2-element model: ss maps both elements to [a][a], where PP holds. The default for ss happens to be a good choice. Neither Herbrand levels nor E-matching ever answer this problem.

6.3 When MBQI diverges: finite model finding

The problem. The ground solver keeps terms in separate classes unless something forces them together. Take ‘successor’: ∀x∃y. R(x,y)\forall x \exists y.\, R(x, y), ∀x. ¬R(x,x)\forall x.\, \neg R(x, x). A model needs the Skolem function to wrap around: sky(sky(c0))=c0\mathrm{sk}_y(\mathrm{sk}_y(c_0)) = c_0. MBQI never proposes this:

round 6: ground SAT, 5 classes; model-based: Q1[x ↦ sk_y(sk_y(sk_y(sk_y(c0))))]
round 7: ground SAT, 6 classes; model-based: Q1[x ↦ sk_y(sk_y(sk_y(sk_y(sk_y(c0)))))]
round 8: ground SAT, 7 classes; ...

The fix. Finite model finding (Reynolds et al. 2013, an option of cvc5) adds a cardinality bound: every ground term must equal one of kk fresh elements el1,…,elk\mathit{el}_1, \ldots, \mathit{el}_k. Then MBQI runs for k=1,2,…k = 1, 2, \ldots (solve_finite_model):

successor:      bound 1: no model with at most 1 element;  bound 2: SAT
    sk_y: ([c0]) ↦ [el1], ([el1]) ↦ [c0];   R: true at ([c0], [el1]), ([el1], [c0])
two functions (∀x. f(g(x)) = x; ∀x. g(x) ≠ x; f(a) ≠ a):  bound 2: SAT
    f: ([a]) ↦ [el1], ([el1]) ↦ [a];   g: ([a]) ↦ [el1], ([el1]) ↦ [a]

The dual of Herbrand instantiation.

  • An unsatisfiable bound says only “no model with at most kk elements”, so finite model finding never answers UNSAT.
  • It is complete for problems that have a finite model: the smallest such kk is eventually tried.

6.4 Quantifiers with arithmetic (overview)

This lecture’s engine is EUF only. With linear arithmetic (Lectures 11–12), quantifiers such as ∀i. 0≤i<n⇒a[i]≤a[i+1]\forall i.\, 0 \le i < n \Rightarrow a[i] \le a[i+1] are routine in verification.

What solvers use.

  • E-matching works the same, with triggers like a[i]a[i].
  • Quantifier elimination removes the quantifier altogether: Fourier–Motzkin (Lecture 11) for the reals, Cooper’s method (Lecture 15, §6.2) for the integers. It is complete but can blow up.
  • Counterexample-guided quantifier instantiation (CEGQI; Reynolds, King and Kuncak 2017) chooses instances from the theory solver’s model, guided by those elimination methods: a lazy quantifier elimination that computes only the disjuncts a model asks for. Z3 has a related engine based on model-based projection (Bjørner and Janota 2015).

Lecture 20 meets the same ∃∀\exists\forall structure in synthesis.


7. Answers, certificates and “unknown”

7.1 Certificates

Each answer is checked by code independent of the search (certify).

UNSAT. The certificate is Herbrand’s theorem made concrete:

  1. The instances. Each one is checked to be ground and to be an instance of its quantifier’s body: is_instance walks both trees side by side and shares no code with the substitution that built it. Each is also checked to enter as ¬Qk∨φ[tˉ]\neg Q_k \vee \varphi[\bar t].
  2. The ground refutation. It is checked as in Lecture 10: every EUF theory lemma is re-verified by a naive closure, and the DRUP proof of the propositional part is checked.

The certificate is small. Deleting instances one at a time while the ground formula stays unsatisfiable shrinks it:

  • Herbrand’s 125 transitivity instances shrink to 3;
  • E-matching’s 4 instances for ‘lists’ shrink to 2 (only the head axiom is needed).

SAT. The certificate is the finite structure. Lecture 7’s evaluate checks it on the original sentences, with their ∃\exists and ∀\forall and without Skolem functions, by enumerating the domain.

Trusted. The parser and the preprocessing (NNF, Skolemization: equisatisfiable, Lecture 7) are not checked.

7.2 Who answers what

Script 03, Part 4, runs every strategy on 14 problems: the 10 benchmarks and 4 extra ones. The extra ones are:

  • russell: ∃x∀y. R(x,y)⇔¬R(y,y)\exists x \forall y.\, R(x, y) \Leftrightarrow \neg R(y, y), the barber;
  • ∀x. x=a\forall x.\, x = a with b≠cb \ne c;
  • successor;
  • two functions.

Each cell shows the result and the number of instances; ? means UNKNOWN.

benchmarkexpectedematchcbqi+ematchematch+enummbqiematch+mbqiHerbrandfinite models
chain 3UNSATUNSAT 3UNSAT 3UNSAT 3UNSAT 3UNSAT 3UNSAT 3?
transitivityUNSATUNSAT 8UNSAT 4UNSAT 8UNSAT 6UNSAT 8UNSAT 125?
involutionUNSATUNSAT 2UNSAT 1UNSAT 2UNSAT 1UNSAT 2UNSAT 2?
injectiveUNSATUNSAT 2UNSAT 2UNSAT 2UNSAT 2UNSAT 2UNSAT 2?
listsUNSATUNSAT 4UNSAT 4UNSAT 4UNSAT 12UNSAT 4UNSAT 32?
skolemUNSAT??UNSAT 5UNSAT 7UNSAT 3UNSAT 8?
orderSAT???SAT 4SAT 9SAT 68SAT 9
no fixpointSAT???SAT 1SAT 2?SAT 2
loopSAT???SAT 0SAT 0?SAT 0
infiniteSAT???????
russellUNSAT??UNSAT 2UNSAT 2UNSAT 2UNSAT 2?
∀x. x = aUNSAT??UNSAT 2UNSAT 2UNSAT 2UNSAT 3?
successorSAT??????SAT 3
two functionsSAT??????SAT 4

Totals. The strategies answer 5, 5, 8, 11, 11, 9 and 5 problems. All 54 answers are certified, and none is wrong.

What the table shows.

  • E-matching variants answer only UNSAT, and only when the problem has ground terms to match.
  • MBQI adds SAT answers. Finite model finding adds the SAT answers that need terms to be identified.
  • MBQI is not goal-directed. It refutes every unsatisfiable benchmark here, but on ‘lists’ with 12 instances against E-matching’s 4.
  • Real solvers combine the stages in the same way. Z3 runs E-matching and MBQI. cvc5 runs conflict-based instantiation, then E-matching, with enumerative instantiation and finite model finding as options.

7.3 “Unknown” is a correct answer

‘infinite’ says that ss is injective and that oo is not in its range. Then o,s(o),s(s(o)),…o, s(o), s(s(o)), \ldots are all distinct, so every model is infinite. Script 03, Part 5, shows how each strategy fails:

  • MBQI grows its domain by one element per round, forever. Each finite candidate makes ss wrap around, and the counterexample forbids the wrap.
  • Finite model finding fails at bounds 1 to 5, correctly.
  • Herbrand instantiation sees satisfiable ground formulas at every level.
  • E-matching saturates at once.

A terminating procedure must answer UNKNOWN here. First-order logic is undecidable, so some problems will always end this way. Z3 reports unknown with the reason (incomplete quantifiers). Problems like this need induction, explicit cardinality reasoning, or an interactive proof (Lecture 15).


8. Summary

  1. Preprocessing. NNF and Skolemization put every quantifier in a positive, universal position. Each ∀\forall-block becomes an atom QkQ_k, and each instance enters as the valid lemma ¬Qk∨φ[tˉ]\neg Q_k \vee \varphi[\bar t]. Only quantifiers whose atom is true need instances.
  2. Herbrand’s theorem. Unsatisfiability equals a finite unsatisfiable set of ground instances, here modulo EUF. Herbrand instantiation by levels finds every refutation, but blindly: 702 instances where the proof needs 4. It decides EPR, whose universe is finite.
  3. E-matching instantiates with terms of the problem, through triggers matched modulo the E-graph’s equalities. Trigger choice decides efficiency and termination. Matching loops are stopped by better triggers or generation limits.
  4. Conflict-based instantiation first looks for an instance that the E-graph already makes false: 1 instance where E-matching adds 80.
  5. Enumerative instantiation recovers refutations when matching saturates.
  6. MBQI checks whether the candidate model, completed with defaults, is already a model. It is the only strategy here that answers SAT on non-EPR problems. Finite model finding adds a cardinality bound and finds models that need terms to be identified.
  7. Answers. Every answer is certified: instances plus a checked ground refutation, or a finite model evaluated on the original sentences. When all models are infinite, UNKNOWN is the correct answer.

9. Common pitfalls

  • Writing ∀x. P(x) ⇒ Q(x) and meaning ∀x. (P(x) ⇒ Q(x)). The parser of this course, and the slides’ convention, let ∀\forall bind tightly.
  • Reading UNKNOWN as SAT. E-matching saturating means “no more instances from these triggers”, not “satisfiable”.
  • Triggers that loop. A pattern that matches a bigger term of its own body creates new matches forever. Watch for P(x)P(x) next to P(s(x))P(s(x)).
  • Triggers that never fire. A pattern with no ground term to match (g(f(x))g(f(x)) without a gg-term) silently disables the axiom.
  • Expecting Skolemization to preserve models. It preserves satisfiability only; check SAT answers on the original sentences.
  • Treating a cardinality-bounded UNSAT as UNSAT. It only rules out small models.
  • Measuring in seconds. Instance counts and rounds are what grow; each instance makes every later ground call larger.

10. Exercises

1. (Skolemization) Skolemize ∀x ∃y ∀z ∃w. R(x,y,z,w)\forall x\, \exists y\, \forall z\, \exists w.\ R(x, y, z, w) with inner Skolemization. Which arguments does each Skolem function get, and why?

Answer

The result. ∀x z. R(x,sky(x),z,skw(x,z))\forall x\, z.\ R(x, \mathrm{sk}_y(x), z, \mathrm{sk}_w(x, z)). prepare produces exactly this.

Why these arguments. yy is chosen after xx only, so sky\mathrm{sk}_y depends on xx. ww is chosen after xx, yy and zz; since yy is itself a function of xx, the free universal variables of ∃w. R(…)\exists w.\, R(\ldots) are xx and zz. Inner Skolemization gives a Skolem function exactly the universal variables that occur free in its ∃\exists-subformula.

2. (Herbrand universe) For the symbols aa, f/1f/1, g/2g/2, list H1H_1 and count H2H_2.

Answer

H1H_1. {a,f(a),g(a,a)}\{a, f(a), g(a, a)\}: 3 terms.

H2H_2. Add f(t)f(t) and g(t,u)g(t, u) for t,u∈H1t, u \in H_1:

  • ff gives 3 terms, of which f(a)f(a) is already there: 2 new;
  • gg gives 9 terms, of which g(a,a)g(a, a) is already there: 8 new.

The total is 3+2+8=133 + 2 + 8 = 13, the row “a, s/1, g/2” of script 01’s table.

3. (Herbrand’s theorem by hand) Find a finite unsatisfiable set of ground instances for ‘skolem’: ∀x∃y. R(x,y)\forall x \exists y.\, R(x, y), ∀x y. R(x,y)⇒Q(y)\forall x\, y.\, R(x, y) \Rightarrow Q(y), ∀x. ¬Q(x)\forall x.\, \neg Q(x). Which Herbrand level is needed?

Answer

The Skolem form. After Skolemization, ∀x. R(x,sky(x))\forall x.\, R(x, \mathrm{sk}_y(x)). There is no constant, so add c0c_0.

The instances.

  • R(c0,sky(c0))R(c_0, \mathrm{sk}_y(c_0));
  • R(c0,sky(c0))⇒Q(sky(c0))R(c_0, \mathrm{sk}_y(c_0)) \Rightarrow Q(\mathrm{sk}_y(c_0));
  • ¬Q(sky(c0))\neg Q(\mathrm{sk}_y(c_0)).

They are unsatisfiable: three instances, using the level-1 term sky(c0)\mathrm{sk}_y(c_0). solve_herbrand refutes at level 1 with all 8 instances of that level. Strategy ematch+mbqi uses exactly these 3, and deleting any of them makes the set satisfiable.

4. (E-matching) The E-graph has classes [a]={a}[a] = \{a\}, [b]={b,f(a)}[b] = \{b, f(a)\} and [c]={c,g(b)}[c] = \{c, g(b)\}. What do the patterns g(f(x))g(f(x)), g(x)g(x) and f(g(x))f(g(x)) match, syntactically and modulo E?

Answer
  • g(f(x))g(f(x)). Syntactically nothing. Modulo E, x↦[a]x \mapsto [a]: g(b)g(b) is a gg-term, and its argument’s class [b][b] contains f(a)f(a).
  • g(x)g(x). x↦bx \mapsto b both ways.
  • f(g(x))f(g(x)). Nothing either way: the only ff-term is f(a)f(a), and the class [a][a] contains no gg-term.

egraph_of(["f(a) = b", "g(b) = c", "P(c)"]) confirms all three.

5. (triggers and loops) Which trigger does select_triggers choose for ∀x. P(f(x))⇒P(f(g(x)))\forall x.\, P(f(x)) \Rightarrow P(f(g(x)))? What happens with the trigger f(x)f(x) on P(f(a))P(f(a)), ¬P(b)\neg P(b)?

Answer

The candidates. They are P(f(x))P(f(x)), f(x)f(x), P(f(g(x)))P(f(g(x))), f(g(x))f(g(x)) and g(x)g(x). The minimal ones with xx are f(x)f(x) and g(x)g(x). The loop check rejects f(x)f(x), because it matches the body’s f(g(x))f(g(x)) with x↦g(x)x \mapsto g(x). The trigger is {g(x)}\{g(x)\}.

With f(x)f(x) on P(f(a))P(f(a)), ¬P(b)\neg P(b) (satisfiable). Round 1 instantiates x↦ax \mapsto a and creates f(g(a))f(g(a)). Round 2 matches it with x↦g(a)x \mapsto g(a) and creates f(g(g(a)))f(g(g(a))), and so on: a matching loop. solve with trigger f(x)f(x) adds one instance per round until the round budget.

With the goal ¬P(f(g(g(a))))\neg P(f(g(g(a)))) instead (unsatisfiable). The automatic trigger g(x)g(x) needs 2 instances (x↦a,g(a)x \mapsto a, g(a)) in one round. The trigger f(x)f(x) needs 4, over two rounds.

6. (MBQI) Trace MBQI on ∀x. P(x)∨P(f(x))\forall x.\, P(x) \vee P(f(x)), ¬P(a)\neg P(a).

Answer

Round 1. The E-graph has only [a][a]. Completed: f([a])=[a]f([a]) = [a] (default element 0), and PP has no defined point, so it is false everywhere. At x=[a]x = [a] the body P(a)∨P(a)P(a) \vee P(a) is false, which gives the instance P(a)∨P(f(a))P(a) \vee P(f(a)).

Round 2. The ground solver must make P(f(a))P(f(a)) true, and f(a)f(a) gets its own class. Completed:

  • f([a])=[f(a)]f([a]) = [f(a)];
  • f([f(a)])f([f(a)]) takes the default, ff‘s first defined value, [f(a)][f(a)];
  • PP is true at [f(a)][f(a)] only.

Both elements satisfy the body. The answer is SAT with a 2-element model, certified on the input.

7. (conflicting instances) The ground facts are f(a)=bf(a) = b, b≠cb \ne c, f(d)=cf(d) = c, and the quantifier is ∀x. f(x)=c\forall x.\, f(x) = c. Evaluate the instance for each class three-valued. Which instances are conflicting, and how many instances does each strategy add?

Answer

The four classes.

  • x↦ax \mapsto a: f(a)=cf(a) = c compares [b][b] with [c][c], asserted apart, so it is false: a conflicting instance.
  • x↦bx \mapsto b and x↦cx \mapsto c: f(b)f(b) and f(c)f(c) are not in the E-graph, so the value is unknown.
  • x↦dx \mapsto d: f(d)=cf(d) = c is true.

The strategies. Conflict-based instantiation adds only x↦ax \mapsto a, and the next ground call is UNSAT. E-matching with trigger f(x)f(x) adds x↦ax \mapsto a and x↦dx \mapsto d; the second is useless.

8. (no finite model) Prove that ∀x. s(x)≠o\forall x.\, s(x) \ne o and ∀x y. s(x)=s(y)⇒x=y\forall x\, y.\, s(x) = s(y) \Rightarrow x = y have no finite model. Why can finite model finding then never terminate with an answer?

Answer

No finite model. In a model with finite domain DD, ss is injective from DD to DD. On a finite set, an injective map is surjective (pigeonhole), so some xx has s(x)=os(x) = o, a contradiction.

Why there is no answer. For every bound kk, the bounded problem is unsatisfiable, and finite model finding treats that as “try k+1k + 1”. It never answers UNSAT, because a bounded refutation says nothing about larger models. The model N\mathbb{N} with s(n)=n+1s(n) = n + 1 and o=0o = 0 shows the problem is satisfiable.

9. (programming) Write a matching-loop detector for solve. Record, for every instance, the trigger and the matched term, and report a trigger whose matches create terms of ever-growing depth over three consecutive rounds. Test it on ‘loop’ with trigger P(x)P(x), and on f(g(x))=f(x)f(g(x)) = f(x) with trigger f(x)f(x).

Answer sketch

What to record. Keep, per (quantifier, trigger), the maximum term size among the instance’s terms in each round. Flag the trigger when that maximum strictly increases three rounds in a row, and print the chain of terms. This is what Z3’s axiom profiler shows graphically.

What to expect. On ‘loop’ with P(x)P(x) the sizes are 1, 2, 3, … So the detector fires at round 3, naming the trigger P(x)P(x) and the terms aa, s(a)s(a), s(s(a))s(s(a)).

10. (programming) Minimize an UNSAT certificate: delete instances one at a time, keeping a deletion when the ground formula stays unsatisfiable. Compare the minimal sizes with the instance counts of §7.2.

Answer sketch

The loop. Re-run smt.solve on the ground part plus the remaining lemmas after each tentative deletion.

The results on this course’s code.

  • transitivity: 8 instances (E-matching), 6 (MBQI) and 125 (Herbrand) all shrink to 3;
  • lists: 4 and 12 shrink to 2;
  • skolem and chain 3: already minimal (3).

Why minimal sets matter. They are what a proof checker (Lecture 15) needs to replay. The result is minimal with respect to single deletions, not necessarily of minimum size.


11. Further reading

  • D. Kroening, O. Strichman, Decision Procedures, 2nd ed., Chapter 9 (quantified formulas).
  • H. Enderton, A Mathematical Introduction to Logic, 2nd ed. (compactness, Herbrand); A. Bradley, Z. Manna, The Calculus of Computation, Chapter 3.
  • D. Detlefs, G. Nelson, J. B. Saxe, “Simplify: A Theorem Prover for Program Checking”, JACM 52(3), 2005.
  • L. de Moura, N. Bjørner, “Efficient E-matching for SMT Solvers”, CADE 2007.
  • Y. Ge, L. de Moura, “Complete Instantiation for Quantified Formulas in Satisfiability Modulo Theories”, CAV 2009.
  • A. Reynolds, C. Tinelli, L. de Moura, “Finding Conflicting Instances of Quantified Formulas in SMT”, FMCAD 2014.
  • A. Reynolds, C. Tinelli, A. Goel, S. Krstić, M. Deters, C. Barrett, “Quantifier Instantiation Techniques for Finite Model Finding in SMT”, CADE 2013.
  • A. Reynolds, H. Barbosa, P. Fontaine, “Revisiting Enumerative Instantiation”, TACAS 2018.
  • A. Reynolds, T. King, V. Kuncak, “Solving Quantified Linear Arithmetic by Counterexample-Guided Instantiation”, FMSD 2017.
  • N. Bjørner, M. Janota, “Playing with Quantified Satisfaction”, LPAR 2015.
  • K. R. M. Leino, C. Pit-Claudel, “Trigger Selection Strategies to Stabilize Program Verifiers”, CAV 2016.
  • M. Moskal, “Programming with Triggers”, SMT Workshop 2009.
  • H. R. Lewis, “Complexity Results for Classes of Quantificational Formulas”, JCSS 21, 1980 (EPR is NEXPTIME-complete).

12. Next lecture

Lecture 18: theory combination. Every lecture so far decided one theory at a time: EUF, linear arithmetic, arrays, bit-vectors. Real formulas mix them, as in f(x+1)=a[i]∧x≤if(x + 1) = a[i] \wedge x \le i. The Nelson–Oppen method combines decision procedures:

  • it purifies the formula into one part per theory;
  • the parts exchange equalities between shared variables until they agree or one finds a conflict.

It needs two conditions. Theories that are not convex require case splits, and theories that are not stably infinite (some of their satisfiable formulas have only finite models) can break the method.

See Lecture 18.

← 返回课程目录