Complexity, SAT, and SMT

Why decidable reasoning can be difficult, how conflict-driven solvers exploit structure, and how Boolean search cooperates with mathematical theories.

Modern logic · Part 20Historical questions · mathematical ideas

Why can SAT be hard in the worst case and still be useful in practice?

Trace a learned clause, distinguish SAT witnesses from UNSAT evidence, and see why an SMT domain changes the answer.

Selected landmarksSeries timeline ↗

Davis and Putnam present a clause-based procedure for quantification theory.

Source: A Computing Procedure for Quantification Theory (1960)

A decision procedure eventually answers every input in its stated domain. That guarantee says nothing by itself about whether the answer arrives within a practical amount of time.

Complexity theory studies this distinction by measuring resources as a function of input size. SAT and SMT show how worst-case difficulty can coexist with powerful practical methods.

From computability to resource bounds

Work by Hartmanis and Stearns, Cobham, Edmonds, and others in the 1960s helped establish systematic approaches to computational complexity and feasible computation.

The class P contains decision problems solvable in deterministic polynomial time. NP contains problems whose positive instances have polynomial-size certificates verifiable in polynomial time, under the standard equivalent machine formulations.

For propositional satisfiability, a certificate is a truth assignment. Given an assignment, evaluating the formula takes polynomial time in its written size.

Finding such an assignment can require a much larger search. The definition of NP does not supply an efficient deterministic method for finding a certificate.

Stephen Cook's 1971 paper proved a foundational completeness result for propositional reasoning. Leonid Levin's independent work, published in 1973, developed universal search problems in a related framework. Richard Karp's 1972 reductions showed how many important combinatorial problems fit the resulting theory.

The publication dates and formulations should be distinguished. The standard modern statement that SAT is NP-complete summarizes this development; it does not imply a single joint 1971 publication.

Stephen A. Cook at the Logic and Complexity fall school in Prague, 2008
Stephen A. Cook (b. 1939) Polynomial reductions and the complexity of propositional reasoning.
Sources and credit for Stephen A. Cook

Jiří Janíček, 24 September 2008, via Wikimedia Commons. Image source · CC BY-SA 3.0 · Biographical dates

Leonid A. Levin before a talk at Rutgers University, 2010
Leonid A. Levin (b. 1948) Universal search problems and independent work on computational complexity.
Sources and credit for Leonid A. Levin

Sergio01, 22 September 2010, via Wikimedia Commons. Image source · CC BY-SA 3.0 · Biographical dates

What NP-completeness establishes

A polynomial reduction translates instances of one problem into instances of another, preserving the answer with only polynomial growth and computational overhead.

Portrait of Richard M. Karp
Richard M. Karp (b. 1935)
Sources and credit for Richard M. Karp

Rama. Via Wikimedia Commons. Image source · CC BY-SA 2.0 fr · Biographical dates

SAT's NP-completeness says that every problem in NP has such a reduction to SAT, and SAT itself belongs to NP.

If SAT has a polynomial-time algorithm, then P equals NP. Whether P equals NP remains open. NP-completeness is proved; the conjecture that no polynomial-time SAT algorithm exists is not.

Nor does the open question imply that every imaginable complexity lower bound remains unknown. Many lower bounds are proved for specified models, proof systems, and complexity classes.

Worst-case complexity also does not predict the difficulty of every instance. A large formula with exploitable structure may be easier than a smaller adversarial one.

Complexity described by logical language

Complexity classes also admit descriptions through what a language can express. This descriptive complexity perspective connects the finite-model theory of graphs and databases with computational resource bounds. Fix a finite relational vocabulary and standard encodings of its finite structures; one sentence must describe the property uniformly at every size.

Ronald Fagin's 1974 theorem states that an isomorphism-invariant class of such structures is in NP exactly when it is definable by an existential second-order sentence. The sentence existentially chooses relations, then checks a first-order condition. A relation of fixed arity rr on nn elements needs only nrn^r membership bits, so these choices provide polynomial-size certificates. Conversely, a bounded accepting computation can be encoded by relations and checked locally.

For example, three-colorability says that there exist unary relations R,G,BR,G,B partitioning the vertices, with no edge joining two vertices in the same part. The second-order choices supply the coloring; the first-order check verifies one color per vertex and the edge constraints. Fagin's theorem covers general NP properties, not just this example. Unlike the polynomial-time result below, it does not require a supplied linear order: an auxiliary order can itself be existentially chosen and checked when needed.

Reachability as a least fixed point

For a directed graph with edge relation EE, start with R0=∅R_0=\varnothing and iterate

Ri+1(x,y)  ⟺  E(x,y)∨∃z (Ri(x,z)∧E(z,y)).R_{i+1}(x,y)\iff E(x,y)\lor \exists z\,(R_i(x,z)\land E(z,y)).

For the path a→b→c→da\to b\to c\to d, stage one contains the three edges; stage two adds (a,c)(a,c) and (b,d)(b,d); stage three adds (a,d)(a,d). The next stage changes nothing. The result describes paths of positive length; adding x=yx=y gives reflexive reachability.

The operator is monotone: enlarging RiR_i cannot remove pairs at the next stage. On an nn-vertex graph the increasing sequence adds at most n2n^2 pairs before stabilizing. Least-fixed-point logic, FO(LFP), permits this construction for relation variables occurring positively. Nested fixed points are allowed. The same iterative idea appears in Datalog, although ordinary positive Datalog is a restricted language and should not be identified with all of FO(LFP).

Polynomial time, with the ordering assumption visible

Neil Immerman and Moshe Vardi independently established in 1982 that FO(LFP) captures PTIME on finite structures equipped with a linear order. Every fixed FO(LFP) sentence can be evaluated in polynomial time; conversely every polynomial-time property of ordered structures has such a sentence. The order lets tuples serve as ordered addresses and time indices in a logical simulation of a machine. Immerman's original paper states the order hypothesis explicitly.

An arbitrary order-sensitive sentence need not describe a property of the underlying unordered structure. If the intended question concerns that structure alone, its answer must be independent of the chosen order. Nor can order simply be deleted from the theorem: ordinary LFP cannot express even the polynomial-time property “the universe has even size” on pure finite sets with equality alone. The qualification concerns expressibility, not the implementation detail of storing a graph in memory.

These are statements about data complexity: hold the query fixed and vary the input structure. Allowing both the query and the structure to vary gives combined complexity, a different measure. In particular, the polynomial exponent may depend on the fixed formula and its relation arities. The theorem supplies no single polynomial bound for evaluating arbitrary input formulas of unbounded size. Vardi's 1982 paper separates these measures explicitly.

Descriptive complexity explains which computational properties logical languages can specify. SAT encodings ask a complementary practical question: how should a particular problem be translated into constraints that a solver can handle?

What an efficient SAT encoding preserves

Cook's reduction represents a bounded nondeterministic computation by a Boolean formula: local constraints enforce a legal initial configuration, each allowed transition, and an accepting outcome. The certificate is a whole accepting computation encoded by the variables. The key is polynomial growth in the time bound, not a claim that each problem already looks like a formula.

Practical SAT encodings also avoid repeatedly distributing disjunction over conjunction, which can cause exponential expansion. A transformation associated with Grigori Tseitin introduces a variable for a subformula. For z↔(a∧b)z\leftrightarrow(a\land b), use

(¬z∨a)∧(¬z∨b)∧(z∨¬a∨¬b).(\neg z\lor a)\land(\neg z\lor b)\land(z\lor\neg a\lor\neg b).

The first two clauses say that zz implies both inputs; the third says that two true inputs imply zz. Add a unit clause asserting the variable for the complete formula. Repeating this construction for each connective gives an encoding whose size is linear in the formula representation.

The new formula is over a larger variable set. Every satisfying assignment to the old formula extends to one for the encoding, and every satisfying assignment to the encoding restricts to one for the old formula. This equisatisfiability is the relevant guarantee. It does not identify formulas of different signatures literally. The choice of encoding can strongly affect what unit propagation discovers.

Proof size and certificates

A satisfying assignment certifies SAT. An unsatisfiability claim needs different evidence.

A resolution refutation can serve as an UNSAT certificate. Each local inference is readily checked, but some formula families require very long refutations in a particular proof system.

Cook and Reckhow's 1979 framework studies propositional proof systems and polynomially bounded proofs. It clarifies a common confusion: efficient checking of each supplied proof does not guarantee that every true statement has a short proof in the system.

The precise general connection is that a polynomially bounded Cook–Reckhow proof system for all propositional tautologies exists if and only if NP = coNP. If every tautology has a short, efficiently checked proof, tautology testing has NP certificates; conversely an NP verifier for tautologies supplies such proofs. This is not the same open question as P = NP, although P = NP would imply NP = coNP. See the original paper, especially its opening definitions and propositions.

Proof complexity therefore studies both particular calculi and the general possibility of short certificates. A lower bound for resolution does not establish a lower bound for every stronger proof system.

From DP to DPLL

The Davis–Putnam procedure of 1960 used clause operations including variable elimination. The 1962 work of Martin Davis, George Logemann, and Donald Loveland developed the branching approach now called DPLL.

Portrait of Martin Davis
Martin Davis (1928–2023)
Sources and credit for Martin Davis

George Bergman. Via Wikimedia Commons. Image source · GFDL 1.2 · Biographical dates

Portrait of Hilary Putnam
Hilary Putnam (1926–2016)
Sources and credit for Hilary Putnam

Unknown photographer or artist. Via Wikimedia Commons. Image source · CC BY-SA 2.5 · Biographical dates

Unit propagation forces the remaining literal of a clause when all its other literals are false. If propagation cannot decide the problem, the solver chooses a literal and explores a branch.

A contradiction closes a branch. Backtracking explores alternatives.

This is a complete method for finite propositional formulas when implemented with exhaustive search. Its challenge is the size of the search tree.

A conflict and a learned clause

Consider three clauses:

C1=(¬a∨b),C2=(¬a∨c),C3=(¬b∨¬c).C_1=(\neg a\lor b),\qquad C_2=(\neg a\lor c),\qquad C_3=(\neg b\lor\neg c).

There are no initial unit clauses. Decide aa to be true.

Then C1C_1 forces bb true, and C2C_2 forces cc true. Clause C3C_3 becomes false. The branch conflicts.

Resolve C3C_3 with C1C_1 on bb:

¬a∨¬c.\neg a\lor\neg c.

Resolve this clause with C2C_2 on cc:

¬a.\neg a.

The learned clause records why the branch failed. It is a consequence of the original clauses, so retaining it preserves the solution set.

After backtracking, the learned unit clause forces aa false. Choosing bb and cc false now satisfies all three original clauses.

The example is intentionally small. In larger instances, conflict analysis can identify a clause involving only some recent decisions and permit nonchronological backtracking, often called backjumping.

The following lab makes these dependencies visible one step at a time. The second preset introduces an earlier decision that the learned clause does not depend on, so a backjump can skip a decision level.

Interactive lab · Conflict-driven clause learning

Follow a conflict to its explanation

Step through decisions, propagation, resolution, and backtracking. Each forced assignment records its reason; each learned clause is derived from existing clauses.

Before you step: Which clause becomes false if a is chosen true? Does that make the whole formula unsatisfiable?

Edit the clauses

Write a for a positive literal and ~a for its negation. Spaces mean “or”; separate lines mean “and”. Up to 8 variables and 24 clauses. Editing starts a new trace.

Ready for the first decision

No variable is assigned. There are no initial unit clauses.

Hint and challenge

The first example has three satisfying assignments, all with a false. Learning ¬a excludes the failed branch without excluding any model. In the backjump example, watch which earlier assignments the learned clause actually depends on. Change a clause and predict how the trace will change.

Scope and interpretation

Scope: a small, deterministic CDCL teaching engine. Decisions follow variable order and try true first. It implements unit propagation and resolution-based learning, without restarts, clause deletion, or performance heuristics. This trace is computed here; it does not expose Z3’s internal search.

Conflict-driven search as an engineering achievement

João Marques-Silva and Karem Sakallah's GRASP work and Roberto Bayardo and Robert Schrag's work in the 1990s were important contributions to modern conflict-driven solving.

Chaff, described by Moskewicz and collaborators in 2001, demonstrated major gains from carefully engineered propagation, decision heuristics, and data structures.

The GRASP report and Chaff paper make the point concrete: strong solvers depend on managing the cost of repeated operations, not merely adopting one logically powerful rule.

Modern CDCL solvers combine propagation, learning, backjumping, restarts, and clause management. These mechanisms help discover useful structure without eliminating worst-case difficulty.

An UNSAT claim can be accompanied by a checkable certificate in a specified format. Certificate generation and verification are distinct engineering tasks; a solver's unsupported answer and an independently checked derivation provide different evidence.

Why propagation became fast

A clause with several unassigned literals needs no immediate action. Chaff's two-watched-literal technique watches two candidates instead of rescanning every clause after every decision. When one watched literal becomes false, a true other watch already satisfies the clause, so no propagation is needed. Otherwise the solver tries to move the false watch to another nonfalse literal. If no replacement exists, an unassigned other watch is forced true, while a false other watch means the clause conflicts. Unit clauses are handled directly. This distinction is explicit in the Chaff paper's propagation account.

This changes the cost of maintaining the search, not the logical meaning of a clause. Restarts similarly discard a current decision trail while keeping useful learned information. Clause deletion saves memory and propagation cost, but the overall search policy must still satisfy appropriate progress conditions if a termination guarantee is claimed. The abstract DPLL(T) analysis separates inference rules from the strategies needed for soundness, completeness, and termination.

These distinctions explain how apparently modest implementation choices changed the practical reach of satisfiability. They also explain why completeness belongs to a specified algorithm, not to an unrestricted combination of learning, restarts, and forgetting.

Beyond propositional atoms

Boolean reasoning treats atoms as independently assignable truth values. Mathematical atoms often constrain one another.

Consider

x>2,y≥x,y<1x>2,\qquad y\ge x,\qquad y<1

over the real numbers. The conjunction is inconsistent, although a Boolean abstraction could initially assign all three atoms true.

An arithmetic procedure recognizes that y≥x>2y\ge x>2 contradicts y<1y<1. It can return a theory conflict corresponding to the clause saying that these three conditions cannot all hold together.

Satisfiability modulo theories, SMT, combines Boolean structure with such background reasoning. The theory may involve arithmetic, arrays, bit-vectors, uninterpreted functions, or other precisely defined objects.

To see what the background theory contributes, begin with the inconsistent real inequalities. Then change a bound, compare integers with reals, or encode a small scheduling problem.

Interactive lab · Satisfiability modulo theories

Find a model—or explain a conflict

Translate a problem into constraints, predict the answer, and ask Z3 to check it. A model gives one satisfying interpretation; an unsatisfiable core identifies constraints that cannot hold together.

Real numbers · linear arithmetic

Three individually possible inequalities cannot always hold together. Enable or edit each constraint, then inspect the result.

Before you run: Can x > 2, y ≥ x and y < 1 all hold?

Constraints
Edit SMT-LIB

The declarations specify the domain. Editing this source switches to a custom problem; Reset restores the selected example. Run performs the satisfiability check.

Supported commands: set-logic, declare-sort, declare-const, declare-fun, define-fun, and assert. Each assertion may have a distinct :named label. Models and cores are requested by the lab.

The solver downloads when you first run it. Computation stays in your browser. Edits are saved here when browser storage is available. Each check has a 10-second solver limit.

Ready to explore

Run the starting example to test whether all three inequalities can hold.

Hint

A and B imply y > 2. Compare this lower bound with C. A core identifies a conflicting subset; it need not be the smallest one.

Try a variation

Change only C to (< y 4). Run again and check every original inequality against the model.

Scope and interpretation

Scope: Z3 checks the encoded problem. A satisfying model is one witness. A core is a sufficient conflicting subset, not necessarily a minimal core or an independently checked proof. UNKNOWN, a time limit, and a stopped run do not establish either satisfiability or unsatisfiability. Z3 guide · SMT-LIB language · Solver license

These experiments also show why a solver's answer must be read together with the declared domain. The next question is which domains admit decision procedures and where their guarantees end.

Decidable theories have boundaries

Presburger's 1929 result establishes decidability for first-order arithmetic with addition in the relevant language. It does not include unrestricted multiplication of variables.

Tarski's work establishes decidability for real closed fields, with effective methods for polynomial equalities and inequalities. It does not decide every statement about arbitrary real functions or transcendental operations.

These boundaries explain why two formulas that both look like arithmetic may belong to very different computational problems.

Even inside a decidable theory, quantifiers and representations can make decision procedures expensive. Practical SMT systems therefore distinguish fragments and may return an inconclusive result outside the guarantees of a selected procedure.

Cooperation between decision procedures

Greg Nelson and Derek Oppen's 1979 work gave a principled method for combining decision procedures through shared equality information.

The standard combination setting includes disjoint nonlogical signatures and stable infiniteness, with additional distinctions governing whether equality exchange requires case splits. Stable infiniteness means that a satisfiable quantifier-free constraint has a model with an infinite domain in the relevant sorts.

These assumptions cannot simply be dropped. Fixed-width bit-vectors, for example, have finite domains and require appropriate alternative treatment.

Later DPLL(T) architectures organize the interaction between a Boolean engine and one or more theory solvers. Theory propagation and conflict explanations allow information to flow back into the Boolean search.

The result is a framework for cooperation, not a universal decision procedure for all combined mathematics.

Leonardo de Moura and Nikolaj Bjørner's 2008 paper introducing Z3 presented an SMT solver for combinations of theories including arithmetic, bit-vectors, arrays, and uninterpreted functions, with applications to software verification and analysis. The lab above uses Z3 to make this distinction practical: the Boolean structure, declared sorts, and theory operations all contribute to the problem being solved.

A theory conflict shared through equality

Consider an integer-valued uninterpreted function ff and constraints

x≤y,y≤x,f(x)≠f(y).x\le y,\qquad y\le x,\qquad f(x)\ne f(y).

Arithmetic entails x=yx=y. Congruence for functions then entails f(x)=f(y)f(x)=f(y), contradicting the last constraint. Treating the three input atoms as unrelated Boolean variables misses the conflict. The interaction works because equality communicates information between the arithmetic and function theories. It does not require knowing any special formula for ff.

A finite-width bit-vector is a different object from an unbounded integer. For an unsigned 8-bit value, adding one to 255 produces 0 modulo 256; over integers it produces 256. Choosing the domain is therefore part of specifying the problem. The Z3 authors' programming guide describes the distinct theories and their cooperating procedures.

An unsatisfiable core identifies a subset of assertions that is already inconsistent. It need not be the smallest such subset, and the subset alone is not a derivation of its inconsistency. A proof certificate explains how the conclusion follows; a model explains a satisfiable answer; unknown records that the selected procedure did not establish either answer. These outputs support different kinds of diagnosis and assurance.

From solving to programming

SAT and SMT expose logical constraints and search for satisfying interpretations or contradictions. Another tradition uses logical clauses as programs whose proofs compute answers.

Check your understanding: what does a solver's model certify?

A solver finds x=255x=255 and x+1=0x+1=0. Is its answer wrong?

The declared theory decides. The constraints are satisfiable for an 8-bit value with modular addition. They are inconsistent over mathematical integers. A satisfying assignment certifies the encoded problem only after the operators, widths, signedness, and domain have been fixed. Likewise, an UNSAT certificate cannot repair a translation that used the wrong arithmetic.

Sources and further reading