Key idea of this section
Resolution: from clauses C ∪ {p} and D ∪ {¬p}, infer C ∪ D.
A CNF is unsatisfiable iff the empty clause □ is derivable by resolution.
Horn-SAT and 2-SAT are solvable in linear time; 3-SAT is NP-complete.Clauses as sets
A literal is an atom p or its negation ¬p; the complement of a literal ℓ is written ℓ̄. A clause is a finite set of literals, read as their disjunction; the empty clause □ is unsatisfiable. A CNF formula is a finite set of clauses, read as their conjunction. The satisfiability problem SAT asks, given a CNF, whether some valuation satisfies it. By the Tseitin transformation of Lesson 2 this is no less general than satisfiability of arbitrary formulas.
The resolution rule
Given clauses C₁ containing a literal ℓ and C₂ containing ℓ̄, their resolvent on ℓ is (C₁ − {ℓ}) ∪ (C₂ − {ℓ̄}). A resolution refutation of a clause set S is a finite sequence of clauses, each in S or a resolvent of two earlier ones, ending in □. Resolution was introduced by Davis and Putnam (1960) and, for first-order logic, by J. A. Robinson (1965), and it underlies modern automated theorem proving.
Theorem 5.1 (Soundness and refutation completeness of resolution). A finite clause set S is unsatisfiable if and only if □ can be derived from S by resolution.
Proof. Soundness: if v satisfies C₁ and C₂, then either v ⊨ ℓ, in which case v must satisfy some literal of C₂ other than ℓ̄, or v ⊨ ℓ̄, in which case v satisfies some literal of C₁ other than ℓ. Either way v satisfies the resolvent, so □ is never derived from a satisfiable set.
Completeness, by induction on the number n of atoms occurring in S. If n = 0, S is either empty (satisfiable) or {□}. Suppose S is unsatisfiable and p occurs in S. Let Sp be obtained by deleting every clause containing p and deleting ¬p from the remaining clauses; this is S simplified under p = 1. Similarly S_¬p is S simplified under p = 0. Both are unsatisfiable and mention fewer atoms, so each has a resolution refutation. Restore ¬p to the clauses of Sp from which it was deleted, and replay the refutation: every step remains a valid resolution step, and it now ends either in □ or in {¬p}. Similarly the refutation of S_¬p becomes a derivation of □ or of {p}. If either ends in □ we are done; otherwise one more resolution of {p} with {¬p} gives □. ∎
Example. S = {{p, q}, {¬p, q}, {p, ¬q}, {¬p, ¬q}}. Resolving the first two on p gives {q}; the last two give {¬q}; resolving these gives □. So S is unsatisfiable, as is obvious from its four clauses excluding all four assignments of p, q.
Resolution is complete but can be very slow: Haken proved in 1985 that the pigeonhole principle PHPⁿ⁺¹ₙ, which says that n + 1 pigeons cannot sit in n holes injectively, has only resolution refutations of exponential size, 2Ω(n). Proof complexity studies such lower bounds for stronger systems; a superpolynomial lower bound for every proof system would imply NP ≠ coNP and hence P ≠ NP (Cook and Reckhow, 1979).
Horn formulas
A Horn clause has at most one positive literal. Horn clauses are definite clauses {¬q₁, …, ¬qₖ, p}, read as rules q₁ ∧ … ∧ qₖ → p (with k = 0 a fact p), and goal clauses {¬q₁, …, ¬qₖ}.
Theorem 5.2. Satisfiability of a set of Horn clauses is decidable in polynomial time (indeed in linear time, by Dowling and Gallier 1984). Moreover a satisfiable Horn set has a least model.
Proof. Marking algorithm: start with nothing marked. Repeatedly, if some definite clause q₁ ∧ … ∧ qₖ → p has all qᵢ marked and p unmarked, mark p. When no rule applies, let v make exactly the marked atoms true. Every definite clause is then satisfied. Every atom that gets marked is true in every model, by induction on the stage at which it is marked. If some goal clause has all its atoms marked, the set is unsatisfiable, because those atoms are true in every model; otherwise v satisfies all goal clauses too, and v is the least model. Each step adds a mark, so there are at most n rounds. ∎
The least-model property is the semantic foundation of logic programming (Prolog) and of Datalog.
The 2-SAT problem
Theorem 5.3 (Aspvall, Plass and Tarjan 1979). Satisfiability of CNFs with at most two literals per clause is decidable in linear time.
Proof sketch. Form the implication graph with a vertex for each literal and, for each clause {ℓ₁, ℓ₂}, the edges ℓ̄₁ → ℓ₂ and ℓ̄₂ → ℓ₁. A valuation satisfies the CNF iff no edge goes from a true literal to a false one. The CNF is unsatisfiable iff some atom p and ¬p lie in the same strongly connected component: in that case p forces ¬p and ¬p forces p. Conversely, if no such component exists, process the components in reverse topological order, and whenever a component whose literals are still unassigned is reached, make all of its literals true and their complements false; one checks that no edge then leads from a true literal to a false one. Strongly connected components can be found in linear time by Tarjan's algorithm. ∎
By contrast, 3-SAT is NP-complete (Lesson 12). The dividing line between 2 and 3 literals per clause is the first and most famous instance of the phenomenon that tiny changes in a problem can move it from easy to apparently intractable. Schaefer's dichotomy theorem (1978) shows that every Boolean constraint satisfaction problem is either in P (it falls into one of six tractable classes, which include Horn, dual-Horn, 2-SAT and affine) or is NP-complete.
Exercise
- (a)Refute by resolution: {{p, q, r}, {¬p, q}, {¬q, r}, {¬r}}.
- (b)Run the marking algorithm on: facts a, b; rules a ∧ b → c, c → d, d ∧ e → f; goal ¬d ∨ ¬f. Is the set satisfiable?
- (c)Is (p ∨ q) ∧ (¬p ∨ q) ∧ (¬q ∨ r) ∧ (¬r ∨ ¬q) satisfiable?
Show solution
Answers: (a) {¬q, r} with {¬r} gives {¬q}. {¬p, q} with {¬q} gives {¬p}. {p, q, r} with {¬p} gives {q, r}; with {¬r} gives {q}; with {¬q} gives □. (b) Mark a, b, then c, then d. The rule d ∧ e → f cannot fire since e is never marked. The goal ¬d ∨ ¬f has d marked but f unmarked, so the set is satisfiable, with least model a = b = c = d = 1, e = f = 0. (c) No. From p ∨ q and ¬p ∨ q we get q; then ¬q ∨ r gives r and ¬r ∨ ¬q gives ¬r, a contradiction.