A Million Clauses, or Sixty-One
Converting one short formula to conjunctive normal form by distributing gives 1,048,576 clauses and 20,971,520 literals; naming the subformulas gives 61 clauses and 160 literals, a factor of 131,072 in literals, and loses nothing at all - the two have the same number of models, checked exhaustively. The encoding is where a satisfiability problem is won or lost, not the solver.
Prerequisites: Logic and Knowledge Representation
Resolution has one inference rule and it needs its input in conjunctive normal form: a conjunction of disjunctions of literals. Every propositional formula has a CNF equivalent, which is usually stated as though it settled the matter.
Here is a formula that makes the difference between "has one" and "you can afford it".
Twenty conjunctions, forty variables, one line.
A. Distributing
The textbook conversion distributes over . Each of the twenty disjuncts contributes either its or its to each clause, independently, so the result has one clause per choice:
each twenty literals long: 20,971,520 literals in total. For thirty disjuncts it is 1,073,741,824 clauses. The conversion is correct, terminating, and useless.
B. Naming the subformulas
The alternative is to give each conjunction a name. Introduce and assert , which is three clauses:
and then say that at least one of them holds: .
That is clauses and 160 literals, against 20,971,520. A factor of 131,072 in literals, from a rewriting rule rather than from a better solver. This is the Tseitin transformation, and it is what every SAT solver's front end does.
C. What it costs
The usual summary is that the result is equisatisfiable rather than equivalent, which sounds like a concession. It is worth being precise about how small the concession is.
The new formula has twenty extra variables, so it is a formula about a different vocabulary and cannot be equivalent to in the strict sense. But each is forced: the three clauses pin it to the truth value of , with no freedom left. Every model of therefore extends to exactly one model of the encoding, and counting them confirms it:
| models of | models of the encoding | |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 7 | 7 |
| 3 | 37 | 37 |
| 4 | 175 | 175 |
Checked by enumerating every assignment, of them for and for the encoding. Satisfiability is preserved, the solutions are preserved, and even the model count is preserved. What is not preserved is the variable list, and the price of that is a projection step at the end.
Interactive: a million clauses, or sixty-one
Log axis. Both encodings are drawn; the toggle picks the one described.
- Clauses in this encoding
- 1,048,576
- Literals in this encoding
- 20,971,520
- Models, either encoding
- 1,096,024,843,375
- Distributed over Tseitin, literals
- 131,072x
- Distributed over Tseitin, clauses
- 17,190x
Distributing picks x or y from each of the 20 disjuncts independently, so it writes 1,048,576 clauses of 20 literals each. The literal ratio is 2 to the power n - 3, so every extra disjunct doubles the gap. Both have 1,096,024,843,375 models, 4 to the n minus 3 to the n, because each new variable is forced to the value of the conjunction it names.
D. The rule itself
Resolution takes two clauses containing a complementary pair and produces their resolvent:
It is not complete for deriving arbitrary consequences - from it will never derive , which is entailed - but it is refutation-complete: if a set of clauses is unsatisfiable, repeated resolution derives the empty clause. That is enough, because exactly when is unsatisfiable.
On the clauses a four-step refutation exists:
- with gives
- with gives
- with gives
- with gives the empty clause.
Saturating blindly instead - resolving every pair until nothing new appears - derives 8 new clauses and reaches a closure of 12 before it gets there. On four clauses the difference is nothing. It is the same difference that separates a modern conflict-driven solver from the algorithm as written in a textbook, and at scale it is everything.
The figure runs the same rule on a different knowledge base, the Wumpus breeze rule with : four clauses plus the negated query, and every answer is checked against the eight possible worlds.
Interactive: a refutation, clause by clause
Answered twice: by resolution, and by enumerating the eight worlds.
Knowledge base in CNF, with the negated query last
- !B11 v P12 v P21
- !P12 v B11
- !P21 v B11
- !B11
- P12
- Clauses to start
- 5
- New clauses derived
- 5
- Empty clause
- yes
- Model checking agrees
- yes
Resolvents, in the order the prover found them
- !P12 v B11 + !B11 -> !P12
- !P21 v B11 + !B11 -> !P21
- !P12 v B11 + P12 -> B11
- !B11 v P12 v P21 + !P12 -> !B11 v P21
- P12 + !P12 -> []
The empty clause appeared after 5 new clauses, and an empty disjunction is false in every model. So the knowledge base together with the negated query cannot be satisfied, which is precisely what it means for the knowledge base to entail the query. Model checking, enumerating all eight worlds and sharing no code with any of this, agrees.
E. What to take from it
- The translation is part of the algorithm. A problem that is impossible after distributing and routine after Tseitin was never a hard problem; it was a badly encoded one.
- Count literals, not clauses. The distributed form above is bad in both, but encodings that look comparable by clause count often differ by an order of magnitude in literals, which is what propagation actually walks.
- "There exists a CNF equivalent" is a statement about existence. So is "every problem in NP reduces to SAT". Both are true, and neither says anything about the size of what you get.
References & further reading
- Stuart Russell, Peter Norvig, Artificial Intelligence: A Modern Approach, Pearson (3rd edition), 2010· Kudos AI reference library
Copyrighted works are cited for reference only and are not hosted here; please consult the publisher for access.