Skip to main content
  (Week 3)

Lecture 3: Solvers: Theories and Equality

Week 3 | Apr 13 – Apr 19

Last week you saw solvers encode and optimize real engineering problems. But everything fit into boolean variables and CNF. This week you find out that Z3 has been doing more than that all along. Theory solvers extend SAT with richer primitives: integers, bitvectors, arrays, equality. Your reductions can speak the language of your actual problem instead of decomposing everything into booleans. We open with two concrete payoffs (shorter encodings, better abstraction), then look inside one theory solver to see how it decides equality without knowing what the functions actually do.

What We Cover

Practice reveals that theories have been there all along, then builds out the two payoffs. Z3's .sexpr() method exposes the SMT-LIB representation underneath our first-week xkcd demo. A side-by-side sudoku encoding shows how theories make the reduction shorter and easier to get right. A program-equivalence demo on bitvector multiplication shows how uninterpreted functions plus one well-chosen axiom turn a slow bit-level proof into a fast term-level one. We close with a sketch of the SMT architecture and a puzzle that motivates the Theory phase.

Theory opens up the equality solver. We work through the axioms of equality (reflexivity, symmetry, transitivity, and function congruence) and then walk the congruence closure algorithm by hand on the same formula you saw Z3 decide in milliseconds. Two worked examples land the main ideas: why f3(a)=af5(a)=af(a)a is unsat, and why f(x)=f(y)xy is sat even though the surface shape suggests otherwise.

Studio is your first session writing Z3 code yourself. Three files build one skill: ask the solver a question, read the answer, refine the question based on what you saw. You count sudoku solutions with a blocking-clause loop and use it to rebuild uniqueness on under-determined puzzles. You predict and check six short EUF formulas. Stretch material walks you through iterative refinement of an EUF witness.

Practice: Beyond booleans, theories in action

From SAT to SMT: richer primitives for encoding, and the right abstraction for performance.

Theory: EUF and congruence closure

How does a solver reason about equality without knowing what the functions actually do?

Studio: Equality and theories in Z3

Your first session writing Z3 code yourself. The exercises build one skill: asking the solver a question, reading the answer, and refining the question based on what you saw.