SAT solvers explained
The question is simple: can a list of conditions all be true at once? With 20 variables a truth table of 1,048,576 rows settles it. With 200 it would need more rows than there are atoms in the observable universe, and yet a laptop answers such questions in a second. This is how.
Clauses, and what satisfying them means
Solvers work on formulas in conjunctive normal form: a list of clauses, each an OR of literals, where a literal is a variable or a negated variable, and every clause has to hold. In (a ∨ ¬b) ∧ (¬a ∨ c) ∧ (b ∨ ¬c) a solution is a = true, b = true, c = true. The form is restrictive on purpose. A clause is satisfied the moment one of its literals is true, and it is violated only when every one of its literals is false, so a partial assignment already says something useful about every clause: satisfied, still open, down to one literal, or broken. That is the whole basis of the search, and the app shows exactly these four states.
Why the problem matters
Stephen Cook proved in 1971 that SAT is NP-complete, with Leonid Levin reaching the same conclusion independently in the Soviet Union; it was the first problem shown to have that property, so every problem in NP can be rewritten as a satisfiability question. For a long time that was read as bad news. Since the late 1990s it has been read the other way round: because so many problems translate into clauses, it is worth building one very good solver and translating everything into its input. Hardware verification, program analysis, planning, scheduling, package managers resolving dependencies and the solvers behind puzzle generators all run this way, on formulas with millions of variables.
Unit propagation and pure literals
Two rules do most of the work before any guessing. A unit clause has all its literals false except one, so that one must be true; setting it can make other clauses unit, and the chain continues until nothing is forced. This is where a solver spends most of its time, and fast implementations watch only two literals per clause so that they notice a clause becoming unit without visiting it. The second rule is the pure literal rule: if a variable occurs only unnegated in the clauses that are still open, making it true satisfies some of them and harms none, so no branching is needed. Davis and Putnam already used both in 1960. The pure literal rule is cheap to show but expensive to keep up to date, so CDCL solvers normally drop it; in the app it is a checkbox, and the counter says how often it fired.
DPLL: decide, propagate, backtrack
When nothing is forced, the solver picks an unassigned variable, assigns a value and propagates. That is a decision, and it opens a new level; everything propagated afterwards belongs to that level. If some clause ends with every literal false, the current level has failed: the solver undoes everything back to the last decision it has not yet flipped and tries the other value there. If both values of a decision fail, the level above has failed too, and if that happens with no decision left the formula is unsatisfiable. This procedure is from Martin Davis, George Logemann and Donald Loveland, 1962, who replaced the memory-hungry clause elimination of the 1960 Davis–Putnam method by this search; it is still the backbone of every complete solver. The search tree in the app has one node per decision, with a cross under each branch a conflict closed.
CDCL: learning from the conflict
Plain backtracking forgets why a branch failed. Suppose the solver decided a = true twenty levels ago, and the conflict only depends on a and on one later decision; it will rediscover the same clash for every combination of the variables in between. Conflict-driven clause learning, introduced by the GRASP solver of João Marques-Silva and Karem Sakallah in 1996 and made fast by Chaff in 2001, analyses the conflict instead. Each forced literal remembers the clause that forced it, so the conflict can be resolved with those reasons, newest assignment first, until only one literal of the current level is left. That point is the first unique implication point, and the clause built from it is a new clause that follows from the formula and that forbids the combination which failed. The solver adds it and jumps back to the second highest level in it — often over many levels at once — where the clause immediately forces the opposite value. The app draws the implication graph of each conflict, marks the UIP and the cut, and prints the learned clause.
Which variable to try next
The order of the decisions changes the size of the search by orders of magnitude. Taking the first unassigned variable is simple and usually poor. The DLIS rule takes the literal that occurs most often in the open clauses; the Jeroslow–Wang rule (1990) weights a literal by 2⁻ᵏ for every clause of length k it occurs in, so short clauses count much more. VSIDS, from Chaff, keeps a score per variable, raises it whenever the variable takes part in a conflict and lets all scores decay, so the solver stays in the region it has recently been fighting over; it is the default in modern solvers. On a random 3-SAT formula with 150 variables at the hard ratio the difference is stark: the first-variable rule can need hundreds of thousands of conflicts where VSIDS needs about 1,500. All five rules are in the app, and the counters make the comparison.
Getting a formula into clauses
Few problems arrive as clauses. An arbitrary formula can be brought into CNF by pushing negations inward with De Morgan's laws and then distributing OR over AND, which keeps it equivalent but can make it exponentially larger: a chain of sixteen exclusive ORs already becomes unmanageable. The standard answer is the transformation Grigori Tseitin published in 1968. Every sub-formula gets a fresh variable t, together with clauses saying that t is true exactly when the sub-formula is, and the whole formula becomes the single clause t for the top. The result is only linear in the size of the formula; it is not equivalent, because it speaks about new variables, but it is satisfiable precisely when the original is, and every model of it restricts to a model of the original. The app offers both methods, says which it used and lists the new variables with their definitions.
Puzzles as clauses
Writing a problem as clauses is a skill of its own, and the library shows the standard patterns. For n queens there is one variable per square: each row and each column gets a clause saying at least one queen is there, and every pair of squares on a row, column or diagonal gets a two-literal clause saying not both. The 4 × 4 sudoku uses four variables per cell, one per digit, with at-least-one and at-most-one clauses for every cell, row, column and box, and the givens as unit clauses. Map colouring gives each region one variable per colour and each border a clause per colour. The pigeonhole problem puts n + 1 pigeons into n holes. All of them are unsatisfiable or satisfiable for a reason you can see, which is why the app decodes the model back into a board, a grid or a coloured map.
What stays hard
Some small formulas defeat both algorithms. The pigeonhole problem is the classic: n + 1 pigeons do not fit into n holes, which a human sees by counting, but Armin Haken proved in 1985 that every resolution proof of it is exponentially large in n. Both DPLL and CDCL searches can be turned into resolution proofs, so both must take exponentially many conflicts; in the app the conflict counter grows from about 5,000 at seven holes to about 40,000 at eight. Random 3-SAT is hard for another reason. With about 4.27 clauses per variable a random formula is right at the edge between almost surely satisfiable and almost surely unsatisfiable, and the instances there are the hardest to decide either way; move the ratio slider away from the threshold in either direction and the same solver finishes in a fraction of the steps. Jian Ding, Allan Sly and Nike Sun proved in 2015 that such a sharp threshold exists for large clause lengths; for 3-SAT the value 4.267 is known only from experiments and from bounds.
Try it
Open the solver and start with four queens: 16 variables, 84 clauses, and a search short enough to follow every step. Watch unit propagation close most of the board after the first decision, then switch the problem to the pigeonhole principle with four holes and see the conflict counter climb. Turn on CDCL to see the implication graph of each conflict and the clause the solver keeps, and compare the decision counter with the number of rows a truth table would need. The teaching examples isolate one rule each: one where every value is forced, one with a single conflict, one solved by pure literals alone, and one where clause learning jumps over three levels at once.
Frequently asked questions
Does a SAT solver try every assignment in the end?
No, and that is the point. Every forced assignment settles a whole block of the truth table at once, and a learned clause rules out many blocks that were never visited. The 4 × 4 sudoku in the library is filled by unit propagation alone, in 65 steps, where a truth table would have 2⁶⁴ rows. The worst case is still exponential — nobody knows a polynomial method, which is the P versus NP question — but the typical case is nothing like it.
What does a model with a star in it mean?
That the search never needed that variable: every clause was already satisfied without it, so either value completes the assignment. The app marks such variables with ∗ and says how many there are. Variables added by the Tseitin transformation are marked too, because they belong to the conversion and not to your formula.
How is the answer checked?
A satisfying assignment is checked against every clause of the formula, not only the ones the search looked at, and the app says how many clauses were verified. Up to 14 variables it also counts the satisfying rows of the full truth table and prints that number, so the solver's verdict and the brute-force count can be compared directly. For an unsatisfiable formula the proof is the search itself: every branch ended in a conflict.
What is the DIMACS format?
The plain-text format solvers and competitions use. A line "p cnf 3 2" announces three variables and two clauses, then each clause is a list of non-zero integers ending in 0, where 3 means the third variable and −3 its negation; lines starting with c are comments. Paste such a file into the app and it is recognised automatically, and Copy DIMACS gives your formula back in that form, with the variables numbered in the order they first appear.
Are there solvers that are not based on DPLL?
Yes. Local search solvers such as WalkSAT start from a random assignment and keep flipping variables in violated clauses; they often find solutions to large satisfiable formulas very quickly, but they can never prove that none exists. Other lines of work replace resolution by stronger reasoning — cutting planes or counting arguments — which settles the pigeonhole problem immediately. The app implements the complete, proof-producing kind, because that is the kind whose steps are worth watching.
Ready to try it?
Open PictorX in your browser — no install, no credit card required to start.
Open the SAT solver