CNF
Conjunctive normal form: a conjunction of clauses, each a disjunction of literals, where a literal is a variable or its negation, . It is the input format of SAT solvers. Every formula has an equivalent CNF, but it can be exponentially larger; the Tseitin transformation gives an equisatisfiable one of linear size instead.
A clause is satisfied when one of its literals is true, and the formula when every clause is. Solvers are built around that shape: a clause whose literals are all false but one forces the last one, which is unit propagation, and a clause whose literals are all false is a conflict.
An equivalent CNF comes from pushing negations down to the variables with De Morgan's laws and then distributing disjunction over conjunction:
Distribution is where the size goes. For each clause of the result picks one of from every term, which gives clauses, and no equivalent CNF has fewer.
Negation normal form, then distribution. Clauses are lists of nonzero ints, as in DIMACS: -3 is the negation of variable 3.
type f = Var of int | Not of f | And of f * f | Or of f * flet rec nnf = function| Var v -> Var v| Not (Var v) -> Not (Var v)| Not (Not a) -> nnf a| Not (And (a, b)) -> Or (nnf (Not a), nnf (Not b))| Not (Or (a, b)) -> And (nnf (Not a), nnf (Not b))| And (a, b) -> And (nnf a, nnf b)| Or (a, b) -> Or (nnf a, nnf b)let rec distribute = function| Var v -> [ [ v ] ]| Not (Var v) -> [ [ -v ] ]| And (a, b) -> distribute a @ distribute b| Or (a, b) ->let ca = distribute a and cb = distribute b inList.concat_map (fun c -> List.map (fun d -> c @ d) cb) ca| Not _ -> assert false
Clause counts for the formula above, by distribution and by the Tseitin transformation.
n distributed tseitin (clauses, variables)1 2 4, 32 4 10, 75 32 28, 1910 1024 58, 3915 32768 88, 59
Two restricted forms are decidable in polynomial time. In 2-CNF every clause has at most two literals; each clause gives the implications and , and the formula is unsatisfiable exactly when some variable and its negation lie in the same strongly connected component of the resulting graph, which is a linear-time check. In Horn CNF every clause has at most one positive literal, and unit propagation alone decides it. With three literals per clause the problem is already NP-complete.
see also
- Tseitin transformationA translation of a propositional formula into CNF that introduces a fresh variable for each subformula and adds clauses saying the variable equals it. The result is equisatisfiable with the input rather than equivalent, and its size is linear in the input's.
- SATThe Boolean satisfiability problem: given a propositional formula, decide whether some assignment of true and false to its variables makes it true. It is the canonical NP-complete problem, and also one that modern solvers routinely settle for instances with millions of variables.
- DIMACS CNFThe plain-text interchange format for CNF instances: a header giving the variable and clause counts, then one clause per line as space-separated nonzero integers terminated by a zero, with a negative integer meaning a negated variable. Every SAT solver reads it, which is what makes solvers comparable at all.
- Unit propagationThe inference rule that does most of the work in a SAT solver: if every literal of a clause is false except one unassigned literal, that literal must be true. Applying it to fixpoint after each decision is where solvers spend the bulk of their time, which is why the data structure that finds unit clauses is the thing worth optimizing.
- ResolutionThe inference rule that combines two clauses containing a complementary pair of literals into one clause without them. It is refutation complete for propositional logic: a set of clauses is unsatisfiable exactly when the empty clause can be derived. DPLL runs correspond to tree-like resolution proofs, and CDCL runs to general ones.
further reading
- [1]S. A. Cook, “The complexity of theorem-proving procedures”, STOC (1971).
- [2]B. Aspvall, M. F. Plass, R. E. Tarjan, “A linear-time algorithm for testing the truth of certain quantified Boolean formulas”, Information Processing Letters 8 (1979).