Formal Methods 101: Satisfiability Modulo Theories (SMT)

This is part 7 of the Formal Methods 101 series. The Satisfiability Modulo Theories (SMT) problem extends SAT to predicates whose variables take on values beyond just Boolean values. An SMT solver can be thought of as deciding whether a predicate is satisfiable by combining SAT techniques with a domain theory.

From SAT to SMT

A Boolean-valued logic formula (predicate) does not have to contain only Boolean-valued variables. Its variables may be of any type, for example the set of all real numbers, ℝ. If a predicate contains just Boolean-valued variables, asking whether it is satisfiable is the SAT problem. If it contains variables of other kinds (such as ℝ), the problem is usually called an SMT problem.

Examples

Example 1: satisfiable

P = (Z ≥ X + Y), where Z, X, Y ∈ ℝ

This predicate is satisfiable (SAT). Proof, by giving a satisfying assignment:

Z = 5.14, X = 2.15, Y = 0.54
P = (5.14 ≥ 2.15 + 0.54)
P = (5.14 ≥ 2.69)
P = TRUE

Example 2: an assignment that fails

The same predicate under a different assignment:

Z = 0.00, X = 4.62, Y = −1.51
P = (0.00 ≥ 4.62 + (−1.51))
P = (0.00 ≥ 3.11)
P = FALSE

This assignment is not a model of P, but one failing assignment says nothing about satisfiability: P is still satisfiable, by the assignment in Example 1. To show that a predicate is unsatisfiable we must show that every assignment fails. For instance, (Z ≥ X + Y) ∧ (Z < X + Y) is unsatisfiable, because no values of Z, X and Y can make both parts true at once.

Solver algorithms

Three approaches to solving SMT problems are covered here:

  1. Bit vectoring
  2. DPLL(T)
  3. Symbolic execution

Bit vectoring

Bit vectoring solves an SMT problem by converting the numerical predicate types (int, float, and so on) into a fixed-width (for example 32-bit) binary representation and then running the result through a SAT solver.

For the predicate P = (Z ≥ X + Y), each number becomes a vector of symbolic bits:

Z = Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9 Z10 ...   (symbolic binary)
X = X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 ...   (symbolic binary)
Y = Y1 Y2 Y3 Y4 Y5 Y6 Y7 Y8 Y9 Y10 ...   (symbolic binary)

The predicate is then rewritten over these Boolean bit variables. As a sketch of the idea, the first bits contribute terms like these:

P = (((X1 ∨ Y1) ∧ ¬Z1) ∨ ((X2 ∨ Y2) ∧ ¬Z2) ∨ ((X3 ∨ Y3) ∧ ¬Z3) ∨ …)

A real encoding builds the addition and the comparison out of Boolean gates over all the bits, but the principle is the same: the numeric question becomes a purely Boolean formula. A SAT solution to it, such as X1 = 1, Y1 = 1, Z1 = 0, reads back as numbers. An illustrative binary solution looks like this:

Z = 01010101010101...  (binary)
X = 11010100101010...  (binary)
Y = 11010101010101...  (binary)

DPLL(T)

DPLL(T) combines a DPLL SAT solver with a domain theory T to decide whether the problem is satisfiable. It first abstracts the SMT problem into a SAT problem, replacing the non-Boolean-valued parts with Boolean-valued variables. It then runs this expression through a classical DPLL SAT solver and checks the solution for consistency with the domain theory T. That is, after a SAT solution is found, it checks whether the non-Boolean versions of the variables can agree that the solution is satisfiable.

A flow of five boxes. The SMT formula (X + 1 at least 0) and (X + Y at least 3) and not (X - Y at least 10) is abstracted to a Boolean formula P = A and B and not C. A DPLL SAT solver finds the candidate A true, B true, C false. The theory solver for linear integer arithmetic checks the candidate. If it is consistent, X = 5 and Y = 4 satisfy it and P is satisfiable. If not, the assignment is blocked and the solver backtracks to DPLL.
The DPLL(T) loop for the worked example below. The SAT solver proposes a Boolean assignment; the theory solver either accepts it with real numbers or rejects it, sending the SAT solver back to look for another.

DPLL(T) with T = Linear Integer Arithmetic (LIA)

Take this predicate:

P = ((X + 1 ≥ 0) ∧ (X + Y ≥ 3) ∧ ¬(X − Y ≥ 10))

Step 1: convert expressions to Boolean variables.

A = (X + 1 ≥ 0)
B = (X + Y ≥ 3)
C = (X − Y ≥ 10)
P = (A ∧ B ∧ ¬C)

Step 2: run DPLL on P to find a possible SAT.

  1. A = TRUE
  2. T = P \ A = (B ∧ ¬C)
  3. B = TRUE
  4. T \ B = (¬C)
  5. ¬C = TRUE
  6. SAT at A = TRUE, B = TRUE, C = FALSE

Step 3: use LIA to verify the possible SAT.

  1. (X + 1 ≥ 0) → (X ≥ −1)
  2. (X + Y ≥ 3) → (X ≥ 3 − Y)
  3. ¬(X − Y ≥ 10) → (X − Y < 10) → (X < 10 + Y)
  4. Assume Y = 4. Then (2) gives X ≥ −1, which agrees with (1), and (3) gives X < 14. Any X from −1 up to 13 works; assume X = 5.
  5. Solution: X = 5, Y = 4. Check: 5 + 1 ≥ 0, 5 + 4 ≥ 3, and 5 − 4 < 10, all true. Therefore P is satisfiable.

Note: if step 3 did not produce a solution, you would backtrack just as in the traditional DPLL algorithm, until either SAT or UNSAT is proven.

Symbolic execution

Symbolic execution is the third approach on the list. This part does not go further into it.

Domain theories T

Examples of domain theories T, with algorithms that decide them where the original notes name one:

TheoryExample algorithm or note
Linear Integer Arithmetic (LIA)Simplex algorithm, criss-cross algorithm
Equality and Uninterpreted Functions (EUF)Congruence closure algorithm
Linear Integer/Real ArithmeticSimplex algorithm
Arrays
Bit vectors
Inductive datatypes (ID)
Non-linear integer arithmeticIncomplete procedure
Strings with length constraintsIncomplete procedure
Quantified formulasIncomplete procedure

You can also combine domain theories in one solver, for example DPLL(LIA + ID), and generalize this to N combinations:

DPLL(T₁ + T₂ + T₃ + … + Tₙ)

Classifying procedures for a theory

Procedures for a domain theory T are classified by what they guarantee.

  • Sound. An algorithm is sound if, anytime it returns an answer, that answer is true. Soundness is a weak guarantee: it does not promise that the algorithm will terminate.
  • Complete. An algorithm is complete if it guarantees to return a correct answer for any arbitrary input (or, if no answer exists, it guarantees to return failure).
  • Complete decision procedures or incomplete procedures. This relates to the decidability of problems. A decidable problem can have a complete decision procedure; for an undecidable problem we can only have incomplete procedures. An undecidable problem is one for which it is provable that no algorithm can be constructed that always gives a correct yes or no answer to the whole class of problems. The halting problem is the standard example of an undecidable problem.