
This is part 6 of the Formal Methods 101 series. A Boolean-valued logic formula (predicate) is satisfiable (SAT) if there is a valid assignment of values to the predicate's variables, also known as a model, that makes the formula evaluate to TRUE.
Satisfiable and unsatisfiable predicates
Example 1: satisfiable
P = (A ∧ ¬B)
This predicate is satisfiable (SAT). Proof, by giving a model:
A = TRUE, B = FALSE
P = (TRUE ∧ ¬FALSE)
P = (TRUE ∧ TRUE)
P = TRUE
Example 2: unsatisfiable
P = (A ∧ ¬A)
This predicate is unsatisfiable (not SAT). Proof: the variable A would have to be both TRUE and FALSE at once to make this predicate evaluate to TRUE, so no model exists.
Truth tables
A common way to find all the possible states of a predicate is to build a truth table. The table lists every combination of values for the predicate's variables along with the resulting Boolean value. For the predicate (A ∧ ¬B) ∨ C it looks like this:
| A | B | C | (A ∧ ¬B) ∨ C |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 0 |
| 0 | 1 | 1 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 |
| 1 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
Predicates (Boolean-valued functions) can be specified by a truth table alone, without writing a formula. For example, here is a predicate P(a, b):
| a | b | P |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
This predicate may also be written as a formula:
P = (A ∧ ¬B)
Normal forms: CNF and DNF
Two standard shapes for a formula are used by SAT solvers.
- Conjunctive normal form (CNF) is a conjunction (ANDs) of one or more clauses, where each clause is a disjunction (ORs) of literals.
- Disjunctive normal form (DNF) is a disjunction (ORs) of one or more terms, where each term is a conjunction (ANDs) of literals.
CNF: (A ∨ B ∨ C) ∧ (D ∨ E ∨ F) ∧ (H ∨ I ∨ J)
DNF: (A ∧ B ∧ C) ∨ (D ∧ E ∧ F) ∨ (H ∧ I ∧ J)
Any propositional formula can be converted into CNF or DNF using these logical equivalences: double negation elimination, De Morgan's laws, and the distributive law. This also means CNF and DNF are interchangeable: one can be converted into the other with the same equivalences.
Solver algorithms
The next sections describe five approaches. The worked examples all use the same predicate, ¬A ∧ B ∧ C, whose only model is A = 0, B = 1, C = 1.
Depth-first search (DFS)
DFS is a search algorithm for tree or graph data structures. It starts at the root and explores as deep into a branch as possible before backtracking up the tree one level. Here each level of the tree assigns one variable, and a leaf is the value of the predicate for one full assignment.
Breadth-first search (BFS)
BFS is also a search algorithm for tree or graph data structures. It starts at the root and explores all of the neighbouring nodes before proceeding down to the next layer of the tree.
Bounded model checking (BMC)
BMC is a bounded-DFS approach: an iterative DFS to depth K, with backtracking. If no SAT is found, the search is repeated to depth K + D, or stops when necessary. The bound prevents the search from falling into the pitfall of infinite loops.
K = 2
With K = 2 the search goes only two edges deep, which is too short to evaluate the variable C:
The search terminates without a model. It has not proven that the formula is unsatisfiable; its depth was simply too short to evaluate C, so it ends without proving SAT.
K = 3
With K = 3 the leaves are within reach and the search finds the model:
Note that this example is a little deceiving, because it is not the true purpose of BMC. Usually, for BMC you search to a depth equal to the number of variables in the CNF, which is a standard DFS. The reason is that your CNF would be created by translating a state transition system into CNF up to K time steps.
Reduced ordered binary decision diagrams (ROBDDs)
ROBDDs are an approach to SAT (and to representing reachable state spaces). The procedure builds a compressed tree representation of the variable assignments and their results. It picks a variable as the root node and builds branches off it into the other variables, then merges isomorphic nodes (nodes for the same variable with the same children and results) and equivalent results (leaves).
The unreduced diagram
Before reduction, the diagram is the complete decision tree: every assignment has its own path and its own leaf.
Reducing it
Reduction uses two steps, applied from the bottom layers up:
- Merge isomorphic subgraphs. The seven 0 leaves merge into one, and then the three C nodes whose edges both lead to that 0 leaf merge into one node.
- Eliminate nodes with two isomorphic children. A node whose 0 and 1 edges lead to the same place cannot affect the result, so it is removed and the edges into it are redirected to its child. This removes the merged C node, and then the B node that had only reached it.
Note that the variable (node) ordering can affect the size of the ROBDD for larger predicates.
Davis-Putnam-Logemann-Loveland (DPLL)
DPLL (sometimes used interchangeably with CNF-SAT) is a backtracking search algorithm that works on a formula in conjunctive normal form. It looks at all the CNF clauses, picks a variable (literal) or its negation and assumes it is TRUE, and sets aside the clauses that this assumption made true. In the leftover clauses it removes the opposite literal, then looks for conflicts among the remaining literals. For example, if clause 1 = (A) and clause 2 = (¬A), then A is in conflict. If a conflict occurs, it backtracks and flips the previous assumption; if no conflict occurs, it picks a new assumption among the leftover clauses. This repeats until SAT is proven or not proven.
Steps
- Choose a variable R from the CNF predicate P and assume it is TRUE, preferably one that occurs in many of the clauses. (The negation of R could also be assumed true.)
- Identify the clauses Y that do NOT contain R. If Y is the empty set ∅, terminate as SAT.
- Remove from these clauses any references to ¬R.
- Look for conflicts among the remaining variables of the clauses. (An example conflict is one clause containing only A and another containing only ¬A.)
- If a conflict exists, go back to step 1 and pick a variable L that you did not pick before and assume it is TRUE (that is, L ≠ R). Then repeat steps 2 to 4. If no such variable exists, terminate as NOT SAT.
- Otherwise repeat step 1, but pick a variable T, with T ≠ R, from Y, and assume it is TRUE.
- Repeat steps 2 to 6 with the variable T.
Worked example
The CNF predicate:
P = (¬A ∨ C) ∧ (¬A ∨ B ∨ ¬C) ∧ (A ∨ ¬B ∨ ¬C)
- Assume A is TRUE.
- The set of clauses of P without A is Y = (¬A ∨ C) ∧ (¬A ∨ B ∨ ¬C).
- Remove ¬A from Y and get (C) ∧ (B ∨ ¬C).
- Assume B is TRUE.
- The set of clauses of Y without B is W = (C).
- Assume C is TRUE.
- The set of clauses of W without C is the empty set ∅.
- Therefore this predicate is SAT, with A = 1, B = 1, C = 1.
Other variants of the SAT problem
- MAJ-SAT: decide whether the majority of all assignments make the predicate TRUE.
- #SAT: count the number of variable assignments that make the predicate true.
- UNIQUE-SAT: decide whether a predicate has exactly one satisfying assignment.
- UNAMBIGUOUS-SAT: a SAT problem in which the formula guarantees that there is only one satisfying assignment.
- MAX-SAT: find the maximum number of clauses that can be satisfied by any one assignment.
- And others.