Home › Logic › Lesson 12

SAT, NP and the Cook–Levin Theorem

Lesson 12 of 13

Key idea of this section

P: decidable in polynomial time. NP: membership has polynomial-size certificates checkable in polynomial time.
Cook–Levin: SAT is NP-complete; every NP problem reduces to SAT in polynomial time.
Fagin: NP is exactly the class of properties definable in existential second-order logic.

Time complexity

Computability asks what can be computed at all; complexity theory asks what can be computed efficiently. A deterministic Turing machine runs in time t(n) if it halts within t(n) steps on every input of length n. The class P consists of languages (sets of binary strings) decided in time O(nᵏ) for some k. The class NP consists of languages L for which there is a polynomial p and a polynomial-time relation V with x ∈ L iff ∃y (|y| ≤ p(|x|) ∧ V(x, y)); equivalently, languages decided by nondeterministic machines in polynomial time. The certificate y is a "witness": a satisfying assignment for SAT, a Hamiltonian cycle for HAM, a factor for COMPOSITE. Clearly P ⊆ NP. Whether P = NP is the central open problem of theoretical computer science and one of the seven Clay Millennium Prize problems.

Reductions and completeness

A polynomial-time reduction from A to B is a polynomial-time computable f with x ∈ A iff f(x) ∈ B; write A ≤ₚ B. B is NP-hard if every A ∈ NP satisfies A ≤ₚ B, and NP-complete if moreover B ∈ NP. If any NP-complete problem is in P, then P = NP.

Theorem 12.1 (Cook 1971, Levin 1973). SAT is NP-complete.

Proof sketch. SAT ∈ NP, with the satisfying assignment as certificate. Let L ∈ NP be decided by a nondeterministic machine M in time p(n). For an input x of length n, the computation is a tableau of (p(n) + 1) rows (time steps) and p(n) + 1 columns (tape cells), each cell holding a tape symbol and possibly the state of the head. Introduce Boolean variables X(i, j, s), true iff cell j at time i holds symbol s (s ranges over the finite set Γ ∪ (Q × Γ)). Write clauses expressing: (1) each cell holds exactly one symbol; (2) row 0 is the start configuration on x; (3) every 2 × 3 window of consecutive cells in consecutive rows is consistent with a transition of M — a local condition, because a Turing machine changes the tape only next to the head; (4) some cell at some time holds the accepting state. The number of variables and clauses is O(p(n)²), with constants depending only on M, and the formula can be produced in polynomial time. It is satisfiable iff some computation of M accepts x. ∎

Theorem 12.2. 3-SAT, the restriction of SAT to clauses with exactly three literals, is NP-complete.

Proof. Reduce SAT (in CNF) to 3-SAT. Replace a clause (ℓ₁ ∨ … ∨ ℓₖ) with k > 3 by (ℓ₁ ∨ ℓ₂ ∨ y₁) ∧ (¬y₁ ∨ ℓ₃ ∨ y₂) ∧ … ∧ (¬y(k−3) ∨ ℓ(k−1) ∨ ℓₖ), with k − 3 new variables and k − 2 clauses; short clauses are padded using new variables (for example (ℓ) becomes four clauses (ℓ ∨ a ∨ b), (ℓ ∨ a ∨ ¬b), (ℓ ∨ ¬a ∨ b), (ℓ ∨ ¬a ∨ ¬b)). Each replacement is satisfiable together with the rest exactly when the original clause is. ∎

From 3-SAT, Karp (1972) derived NP-completeness of 21 problems, including CLIQUE, VERTEX COVER, HAMILTONIAN CYCLE, SUBSET SUM, and CHROMATIC NUMBER. For CLIQUE: given a 3-CNF with m clauses, build a graph with a vertex for each occurrence of a literal (3m vertices) and join two vertices when they lie in different clauses and are not complementary; the graph has an m-clique iff the formula is satisfiable.

Beyond NP

coNP is the class of complements of NP languages; TAUT, the set of propositional tautologies, is coNP-complete, since φ is a tautology iff ¬φ is unsatisfiable. NP = coNP would mean that every tautology has a short proof in some proof system. PSPACE, the class of languages decidable in polynomial space, contains NP and coNP; its canonical complete problem is TQBF, the truth of fully quantified Boolean formulas ∀x₁ ∃x₂ … φ (Stockmeyer and Meyer 1973). The time hierarchy theorem gives P ≠ EXP, but none of the inclusions P ⊆ NP ⊆ PSPACE ⊆ EXP is known to be strict individually.

Descriptive complexity

Theorem 12.3 (Fagin 1974). A class of finite structures is in NP iff it is definable by an existential second-order sentence ∃R₁ … ∃Rₖ φ, with φ first-order.

For example 3-colourability of graphs is defined by ∃R ∃G ∃B (∀x (R(x) ∨ G(x) ∨ B(x)) ∧ ∀x ∀y (E(x, y) → ¬(R(x) ∧ R(y)) ∧ ¬(G(x) ∧ G(y)) ∧ ¬(B(x) ∧ B(y)))). Immerman and Vardi (1982) showed that on ordered finite structures P is captured by first-order logic with a least fixed-point operator. Thus P = NP becomes a question about the expressive power of logics on finite structures.

Exercise

  • (a)
    Convert the clause (a ∨ b ∨ c ∨ d ∨ e) into an equisatisfiable 3-CNF. How many new variables and clauses?
  • (b)
    In the CLIQUE reduction, how many vertices does the graph have for a 3-CNF with 7 clauses, and what clique size is sought?
  • (c)
    Explain why 2-SAT ∈ P does not contradict the NP-completeness of 3-SAT.
Show solution

Answers: (a) (a ∨ b ∨ y₁) ∧ (¬y₁ ∨ c ∨ y₂) ∧ (¬y₂ ∨ d ∨ e): 2 new variables and 3 clauses, matching k − 3 = 2 and k − 2 = 3 for k = 5. (b) 21 vertices, clique of size 7. (c) No polynomial reduction from 3-SAT to 2-SAT is known; the splitting trick that reduces long clauses to length 3 does not reduce them to length 2, since a clause of length 3 is split into pieces that still need three literals each. If such a reduction existed, P = NP would follow.

V.3.1