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:
- Turn quantified sentences into what an SMT solver works on: negation normal form, Skolem functions, quantifier atoms, and instances added as lemmas .
- 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).
- Explain why the Bernays–Schönfinkel class (EPR) is decidable by instantiation, and estimate its cost.
- Run E-matching by hand: match a trigger against an E-graph modulo its equalities, and choose triggers, including multi-triggers.
- Recognize a matching loop, and stop it with a better trigger or a generation limit.
- 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.
- Explain why every strategy must sometimes answer unknown, and what a certificate for each answer looks like.
0.2 Prerequisites and scope
| Assumed | Introduced here | Developed 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 evaluation | theory combination (Lecture 18) |
| grind’s E-matching annotations (Lecture 15) | triggers, matching loops, generations | synthesis 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
| Symbol | Meaning |
|---|---|
| a quantifier over the variables with a quantifier-free body | |
| , | an instance: the body with ground terms for |
| the propositional quantifier atom standing for the -th quantifier | |
| the Herbrand universe up to nesting depth | |
| the E-graph class of term (all terms equal to in the candidate model) | |
| a trigger: one pattern, or several (a multi-trigger) | |
| the Skolem function introduced for under |
0.5 The code of this lecture
One module, quantifiers.py:
- preprocessing:
prepare,Problem,Quant; - Herbrand instantiation:
herbrand_universe,solve_herbrand; - the candidate model:
EGraphwithematch,eval3andstructure;egraph_of; - triggers:
select_triggers,syntactic_matches; - the instantiation loop:
solve(formulas, strategy=...), with stagescbqi,ematch,mbqi,enumjoined 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:
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:
| Strategy | Question it asks | Can answer |
|---|---|---|
| Herbrand levels (§3) | all instances over terms of depth | UNSAT; 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 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))
- NNF. Eliminate and , rename bound variables apart, push negations to the atoms. Afterwards every quantifier occurs positively: has become , and has become .
- Skolemize. Replace by , where are the universally bound variables that occur free in (“inner” Skolemization, which gives fewer arguments). The result is equisatisfiable, not equivalent (Lecture 7).
- Quantifier atoms. Each maximal -block is processed in four steps:
- the s nested in its body are pulled to the front;
- its body is split at (miniscoping: );
- variables that a part does not use are dropped;
- each part is replaced by a fresh propositional atom .
2.2 Why atoms, and why lemmas
The ground solver sees as one more Boolean atom of the skeleton (Lecture 10’s abstraction). Two facts make this sound and complete enough:
- Instances are valid lemmas. is valid. With standing for the quantifier, the lemma is true in every model where means what it should. Adding it never removes a real model.
- A false atom needs no instances. occurs positively, so a model of the skeleton with false stays a model if 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 the solver may choose and never instantiate at all.
One warning about the course’s parser (Lecture 6): binds more tightly than the connectives. So ∀x. P(x) ⇒ P(s(x)) means , with a free . prepare rejects free variables; write ∀x. (P(x) ⇒ P(s(x))).
3. Herbrand’s theorem
3.1 The Herbrand universe
Definition. Let be a set of universal sentences in Skolem form (only , quantifier-free bodies). Its Herbrand universe is the set of ground terms built from the constants and function symbols of . If there is no constant, a fresh one is added: domains are non-empty. Write for the terms of nesting depth .
Script 01, Part 2, counts :
| constants, functions/arity | 1 | 2 | 3 | 4 | 5 | |
|---|---|---|---|---|---|---|
| a, b | 2 | 2 | 2 | 2 | 2 | 2 |
| a, s/1 | 1 | 2 | 3 | 4 | 5 | 6 |
| a, b, s/1 | 2 | 4 | 6 | 8 | 10 | 12 |
| a, g/2 | 1 | 2 | 5 | 26 | 677 | 458,330 |
| a, s/1, g/2 | 1 | 3 | 13 | 183 | 33,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 variables has instances at level .
3.2 The theorem
Herbrand’s theorem. A set 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, is valid iff a finite disjunction of instances 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 unsatisfiable. For the other, suppose every finite set of ground instances is satisfiable.
- By compactness (propositional, or modulo EUF), the set of all ground instances has a model.
- Build a Herbrand interpretation from it. Its domain is , 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.
- Every domain element is (the class of) a ground term , and every instance is true. So is true: 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 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 , then all over , and so on, each time asking Lecture 10’s CDCL(T). Script 01, Part 3, runs it on the lecture’s benchmarks:
| benchmark | expected | result | level | universe | instances |
|---|---|---|---|---|---|
| chain 3 | UNSAT | UNSAT | 2 | 3 | 3 |
| transitivity | UNSAT | UNSAT | 0 | 5 | 125 |
| involution | UNSAT | UNSAT | 0 | 2 | 2 |
| injective | UNSAT | UNSAT | 0 | 2 | 2 |
| lists | UNSAT | UNSAT | 0 | 4 | 32 |
| skolem | UNSAT | UNSAT | 1 | 2 | 8 |
| order | SAT | SAT | 0 | 4 | 68 |
| no fixpoint | SAT | UNKNOWN | 4 | 10 | 10 |
| loop | SAT | UNKNOWN | 4 | 10 | 10 |
| infinite | SAT | UNKNOWN | 4 | 5 | 30 |
The benchmarks (quantifiers.BENCHMARKS):
- chain 3: , , .
- transitivity: a chain , transitivity, and .
- involution: , , .
- injective: , , .
- lists: constructor axioms for and , , .
- skolem: , , .
- order: a chain, transitivity and irreflexivity.
- no fixpoint: , .
- loop: , , .
- infinite: , with 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 (level 2), and ‘skolem’ needs (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 , , , with of depth (for , ), plus the irrelevant axiom :
| depth | Herbrand | level | universe | instances | E-matching | instances |
|---|---|---|---|---|---|---|
| 1 | UNSAT | 0 | 1 | 2 | UNSAT | 1 |
| 2 | UNSAT | 1 | 2 | 6 | UNSAT | 2 |
| 3 | UNSAT | 2 | 5 | 30 | UNSAT | 3 |
| 4 | UNSAT | 3 | 26 | 702 | UNSAT | 4 |
| 5 | UNKNOWN | 4 | — | > 100,000 | UNSAT | 5 |
What the table shows.
- The proof is tiny. It needs instances, .
- Herbrand pays for the irrelevant axiom. At level 3, that axiom alone has 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 instances, in one round. The irrelevant axiom’s trigger 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 is outside every . This is the Bernays–Schönfinkel class, called EPR (“effectively propositional”) in SMT. Its universe is finite, and contains all instances. If they are satisfiable, the Herbrand interpretation is a model, so instantiation decides EPR.
Its cost. With constants and variables there are 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’ (, , ), level ‘s ground model makes 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 and , so the constructor axiom is probably needed for those terms, not for .
Triggers. E-matching attaches to each quantifier a trigger (or pattern): a term with the quantifier’s variables, such as . 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 matches class if some -term in has each matched by .
Script 02, Part 1, works on , , , :
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 . Yet matches : the matcher enters the class of the argument , finds there, and binds .
- The instance. It uses the smallest term of the class, . Congruence then gives , which contradicts .
- Trigger choice matters. With the trigger one instance suffices. The automatic trigger (§4.3) matches and 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:
- Candidates: the applications in the body (function terms and predicate atoms) that contain a variable.
- Single triggers: the candidates that contain all variables and are minimal (no proper subterm does). Small patterns match more terms.
- Loop check: reject a candidate that matches a different application of the body (). An instance would then create a new term that matches again (§4.5). Rejected candidates are kept if nothing else remains.
- 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:
| quantifier | candidates | triggers chosen | rejected (loop) |
|---|---|---|---|
| P(x), P(s(x)), s(x) | {s(x)} | P(x) | |
| f(g(x)), g(x), f(x) | {g(x)} | f(x) | |
| f(f(x)), f(x) | {f(x)} | f(x) (kept: nothing else) | |
| g(f(x)), f(x) | {f(x)} | — | |
| head(cons(x, y)), cons(x, y) | {cons(x, y)} | — | |
| transitivity | R(x, y), R(y, z), R(x, z) | {R(x, y), R(y, z)} | — |
| f(x), f(y) | {f(x), f(y)} | — | |
| R(x, y), R(y, x) | {R(x, y)} {R(y, x)} | both (kept) | |
| none | none | — |
Multi-triggers. matches pairs of terms that agree on . That is a join, potentially quadratic in the number of -atoms.
No candidate. 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 and . Congruence on then makes .
transitivity. Each round doubles the distance covered, so about 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’ (, , ) and force the trigger . Each instance creates the term , which matches 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:
| problem | trigger | generation limit | result | rounds | instances | ground terms |
|---|---|---|---|---|---|---|
| loop (SAT) | P(x) | none | UNKNOWN (round budget) | 20 | 40 | 40 |
| loop (SAT) | P(x) | 2 | UNKNOWN | 3 | 4 | 6 |
| loop (SAT) | P(x) | 4 | UNKNOWN | 5 | 8 | 10 |
| loop (SAT) | P(x) | 8 | UNKNOWN | 9 | 16 | 18 |
| loop (SAT) | s(x) (automatic) | none | UNKNOWN | 1 | 0 | 2 |
| chain 3 (UNSAT) | P(x) | none | UNSAT | 4 | 6 | 6 |
| chain 3 (UNSAT) | s(x) (automatic) | none | UNSAT | 2 | 3 | 4 |
| (SAT) | f(x) | none | UNKNOWN (round budget) | 20 | 40 | 81 |
| (SAT) | g(x) (automatic) | none | UNKNOWN | 1 | 0 | 5 |
Two remedies:
- A better trigger. With , an instance contains only for a matched , 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 has generation . 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:
| problem | why E-matching is stuck | E-matching | + enumerative |
|---|---|---|---|
| skolem | no ground term at all | UNKNOWN (0) | UNSAT (5 instances, 4 rounds) |
| , | no trigger can be chosen | UNKNOWN (0) | UNSAT (2, 3 rounds) |
| injective, trigger | no -term to match | UNKNOWN (0) | UNSAT (2, 3 rounds) |
| order (SAT) | satisfiable | UNKNOWN (4) | UNKNOWN (68, 13 rounds) |
| no fixpoint (SAT) | satisfiable | UNKNOWN (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:
- is true if , 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 , , :
| n | E-matching instances | conflict-based instances |
|---|---|---|
| 5 | 5 | 1 |
| 10 | 10 | 1 |
| 20 | 20 | 1 |
| 40 | 40 | 1 |
| 80 | 80 | 1 |
The E-graph already knows , so the instance is conflicting. E-matching instead fires on every -term.
On the transitivity chain with :
- 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 in one round.
The proof needs . The figure 03_instances_by_strategy.png plots these counts for .
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?
- 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.
- 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). - 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.
- 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 , :
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 , a fixpoint. The instance forces the next ground model to give its own class.
- In round 2, at the new element defaults to , and all three points satisfy .
On ‘loop’, MBQI answers at once, with 0 instances and a 2-element model: maps both elements to , where holds. The default for 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’: , . A model needs the Skolem function to wrap around: . 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 fresh elements . Then MBQI runs for (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 elements”, so finite model finding never answers UNSAT.
- It is complete for problems that have a finite model: the smallest such 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 are routine in verification.
What solvers use.
- E-matching works the same, with triggers like .
- 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 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:
- The instances. Each one is checked to be ground and to be an instance of its quantifier’s body:
is_instancewalks both trees side by side and shares no code with the substitution that built it. Each is also checked to enter as . - 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 and 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: , the barber;
- with ;
- successor;
- two functions.
Each cell shows the result and the number of instances; ? means UNKNOWN.
| benchmark | expected | ematch | cbqi+ematch | ematch+enum | mbqi | ematch+mbqi | Herbrand | finite models |
|---|---|---|---|---|---|---|---|---|
| chain 3 | UNSAT | UNSAT 3 | UNSAT 3 | UNSAT 3 | UNSAT 3 | UNSAT 3 | UNSAT 3 | ? |
| transitivity | UNSAT | UNSAT 8 | UNSAT 4 | UNSAT 8 | UNSAT 6 | UNSAT 8 | UNSAT 125 | ? |
| involution | UNSAT | UNSAT 2 | UNSAT 1 | UNSAT 2 | UNSAT 1 | UNSAT 2 | UNSAT 2 | ? |
| injective | UNSAT | UNSAT 2 | UNSAT 2 | UNSAT 2 | UNSAT 2 | UNSAT 2 | UNSAT 2 | ? |
| lists | UNSAT | UNSAT 4 | UNSAT 4 | UNSAT 4 | UNSAT 12 | UNSAT 4 | UNSAT 32 | ? |
| skolem | UNSAT | ? | ? | UNSAT 5 | UNSAT 7 | UNSAT 3 | UNSAT 8 | ? |
| order | SAT | ? | ? | ? | SAT 4 | SAT 9 | SAT 68 | SAT 9 |
| no fixpoint | SAT | ? | ? | ? | SAT 1 | SAT 2 | ? | SAT 2 |
| loop | SAT | ? | ? | ? | SAT 0 | SAT 0 | ? | SAT 0 |
| infinite | SAT | ? | ? | ? | ? | ? | ? | ? |
| russell | UNSAT | ? | ? | UNSAT 2 | UNSAT 2 | UNSAT 2 | UNSAT 2 | ? |
| ∀x. x = a | UNSAT | ? | ? | UNSAT 2 | UNSAT 2 | UNSAT 2 | UNSAT 3 | ? |
| successor | SAT | ? | ? | ? | ? | ? | ? | SAT 3 |
| two functions | SAT | ? | ? | ? | ? | ? | ? | 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 is injective and that is not in its range. Then 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 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
- Preprocessing. NNF and Skolemization put every quantifier in a positive, universal position. Each -block becomes an atom , and each instance enters as the valid lemma . Only quantifiers whose atom is true need instances.
- 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.
- 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.
- Conflict-based instantiation first looks for an instance that the E-graph already makes false: 1 instance where E-matching adds 80.
- Enumerative instantiation recovers refutations when matching saturates.
- 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.
- 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 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 next to .
- Triggers that never fire. A pattern with no ground term to match ( without a -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 with inner Skolemization. Which arguments does each Skolem function get, and why?
Answer
The result. . prepare produces exactly this.
Why these arguments. is chosen after only, so depends on . is chosen after , and ; since is itself a function of , the free universal variables of are and . Inner Skolemization gives a Skolem function exactly the universal variables that occur free in its -subformula.
2. (Herbrand universe) For the symbols , , , list and count .
Answer
. : 3 terms.
. Add and for :
- gives 3 terms, of which is already there: 2 new;
- gives 9 terms, of which is already there: 8 new.
The total is , 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’: , , . Which Herbrand level is needed?
Answer
The Skolem form. After Skolemization, . There is no constant, so add .
The instances.
- ;
- ;
- .
They are unsatisfiable: three instances, using the level-1 term . 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 , and . What do the patterns , and match, syntactically and modulo E?
Answer
- . Syntactically nothing. Modulo E, : is a -term, and its argument’s class contains .
- . both ways.
- . Nothing either way: the only -term is , and the class contains no -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 ? What happens with the trigger on , ?
Answer
The candidates. They are , , , and . The minimal ones with are and . The loop check rejects , because it matches the body’s with . The trigger is .
With on , (satisfiable). Round 1 instantiates and creates . Round 2 matches it with and creates , and so on: a matching loop. solve with trigger adds one instance per round until the round budget.
With the goal instead (unsatisfiable). The automatic trigger needs 2 instances () in one round. The trigger needs 4, over two rounds.
6. (MBQI) Trace MBQI on , .
Answer
Round 1. The E-graph has only . Completed: (default element 0), and has no defined point, so it is false everywhere. At the body is false, which gives the instance .
Round 2. The ground solver must make true, and gets its own class. Completed:
- ;
- takes the default, ‘s first defined value, ;
- is true at 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 , , , and the quantifier is . Evaluate the instance for each class three-valued. Which instances are conflicting, and how many instances does each strategy add?
Answer
The four classes.
- : compares with , asserted apart, so it is false: a conflicting instance.
- and : and are not in the E-graph, so the value is unknown.
- : is true.
The strategies. Conflict-based instantiation adds only , and the next ground call is UNSAT. E-matching with trigger adds and ; the second is useless.
8. (no finite model) Prove that and 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 , is injective from to . On a finite set, an injective map is surjective (pigeonhole), so some has , a contradiction.
Why there is no answer. For every bound , the bounded problem is unsatisfiable, and finite model finding treats that as “try ”. It never answers UNSAT, because a bounded refutation says nothing about larger models. The model with and 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 , and on with trigger .
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 the sizes are 1, 2, 3, … So the detector fires at round 3, naming the trigger and the terms , , .
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 . 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.