47.02.02 · theoretical-cs / complexity-fundamentals

NP-Completeness and the Cook-Levin Theorem

shipped3 tiersLean: none

Anchor (Master): Sipser 2013 Introduction to the Theory of Computation 3e (Cengage) §7.4-7.5; Arora & Barak 2009 Computational Complexity: A Modern Approach (Cambridge) §2.3-2.5 (full tableau construction, circuit-SAT to SAT reduction, Ladner's theorem, structure of NP-complete problems)

Intuition Beginner

Imagine you are given a massive jigsaw puzzle. Checking whether a proposed solution is correct is quick — you just verify that every piece fits. But finding the solution yourself might take a very long time.

This is the essence of NP. A problem is in NP if every "yes" answer comes with a short proof that can be verified quickly. SAT, the Boolean satisfiability problem, is the canonical example: given a formula like "(x or y) and (not x or z)", is there an assignment of true/false values to the variables that makes the whole formula true? Checking a proposed assignment is easy. Finding one could be very hard.

NP-completeness identifies the hardest problems in NP. A problem is NP-complete if (1) it is in NP, and (2) every other problem in NP can be converted into it efficiently (in polynomial time). This means if you could solve any single NP-complete problem quickly, you could solve every NP problem quickly, and P would equal NP.

The Cook-Levin theorem (1971) proves that SAT is NP-complete. The proof works by showing that the computation of any Turing machine (as defined in 42.04.01) solving an NP problem can be encoded as a Boolean formula. The formula is satisfiable if and only if the machine accepts the input. This encoding converts the question "does this machine accept this input?" into "is this formula satisfiable?", establishing SAT as a universal hard problem.

Visual Beginner

The structure of NP-completeness: every problem in NP reduces to SAT.

   NP problems          Polynomial        SAT
  ┌───────────┐        reductions      ┌─────┐
  │  CLIQUE   │ ──────────────────────→ │     │
  │  TSP      │ ──────────────────────→ │     │
  │  3-COLOR  │ ──────────────────────→ │ SAT │
  │  SUBSET-SUM│ ──────────────────────→ │     │
  │  ...      │ ──────────────────────→ │     │
  └───────────┘                         └─────┘

A polynomial-time reduction from problem A to problem B is a function computable in polynomial time such that if and only if .

Problem In NP? NP-complete? Known poly algorithm?
SAT Yes Yes (Cook-Levin) None known
3-SAT Yes Yes (reduction from SAT) None known
Sorting Yes No (in P) Yes
Halting problem No (undecidable) No No

Worked example Beginner

We reduce SAT to 3-SAT to show 3-SAT is NP-complete.

A SAT instance: .

The second clause has 4 literals, so this is not a 3-SAT instance. We convert it using auxiliary variables.

Clause splitting. Replace with two 3-literal clauses using a new variable :

Correctness. If the original 4-literal clause is satisfiable, at least one literal is true. If or is true, set to false: both new clauses are satisfied. If or is true, set to true: both new clauses are satisfied.

Conversely, if the new clauses are both satisfied, consider . If is false, then must be true. If is true, then must be true. Either way, at least one literal in the original clause is true.

This gadget construction splits any clause of length into clauses of length 3 using new variables. The formula grows polynomially, and the conversion runs in polynomial time.

Check your understanding Beginner

Formal definition Intermediate+

Definition (NP-completeness). A language is NP-complete if:

  1. , and
  2. For every , (every language in NP is polynomial-time reducible to ).

Condition (2) is equivalent to: there exists an NP-complete language such that . This is the standard method for proving new problems NP-complete.

Definition (computation tableau). A Turing machine (as defined in 42.04.01) running on input of length within time produces a tableau — a table where row represents the configuration of at step . Each cell contains a symbol from the tape alphabet, a state, or a combination (the cell under the tape head carries both the tape symbol and the current state).

Definition (SAT). The Boolean satisfiability problem is:

A Boolean formula in CNF is a conjunction of clauses, each clause a disjunction of literals (variables or their negations).

Definition (3-SAT). The restricted problem where every clause has exactly 3 literals:

The tableau encoding

Given a language , let be a nondeterministic Turing machine (as defined in 42.04.01) that decides in time . For input of length , the computation tableau is an grid. The Cook-Levin construction builds a Boolean formula that encodes this tableau.

Variables. For each cell and each possible content (tape symbol or state-symbol pair), introduce a variable meaning "cell contains symbol ."

Clauses. The formula where:

  • : each cell contains exactly one symbol (at-least-one and at-most-one constraints),
  • : row 0 encodes the start configuration (input on the tape, head at position 0, start state),
  • : some row contains an accept state,
  • : the contents of each window of cells are consistent with the transition function of .

The size of is , polynomial in .

Counterexamples to common slips

  • "NP-complete means the problem has no polynomial algorithm." We do not know whether P = NP. NP-completeness means the problem is as hard as any NP problem, but a polynomial algorithm might exist — finding one (or proving none exists) would resolve the P vs NP question.

  • "NP means 'not polynomial'." NP stands for "nondeterministic polynomial time" — the class of problems solvable in polynomial time by a nondeterministic machine. Many NP problems (like sorting) are also in P.

  • "The Cook-Levin theorem proves P does not equal NP." The theorem proves SAT is NP-complete. It does not resolve P vs NP. It shows that resolving P vs NP can be done by studying any single NP-complete problem.

Key theorem with proof Intermediate+

Theorem (Cook-Levin). SAT is NP-complete.

Proof. We show (1) SAT is in NP and (2) every language in NP reduces to SAT.

(1) A certificate for is a satisfying assignment . The verifier evaluates on in polynomial time. So .

(2) Let . There exists a nondeterministic Turing machine (as defined in 42.04.01) deciding in time . For input of length , construct as described above. The construction runs in time.

is satisfiable iff has an accepting computation on . If accepts , the accepting tableau provides a satisfying assignment for (set to true exactly when cell contains in the accepting computation). If is satisfiable, the satisfying assignment describes a valid tableau: the cell, start, and move constraints guarantee it represents a legal computation of , and the accept constraint guarantees the computation accepts. So iff .

The function is computable in polynomial time, so .

Bridge. The Cook-Levin theorem is the foundational reason NP-completeness is a meaningful concept: there exists a single "universal" problem (SAT) to which all NP problems reduce. This builds toward the web of NP-complete problems in 47.02.03, where reductions from SAT establish hardness for combinatorial problems like CLIQUE and VERTEX-COVER. The central insight is that the tableau encoding is the bridge between computation (a machine processing symbols over time) and logic (a formula asserting the existence of a valid computation). This is exactly the connection that appears again in the PCP theorem of 47.03.06, where the tableau is probabilistically checked, and it generalises the encoding idea from the halting problem of 42.04.02. Putting these together yields the modern understanding of intractability: NP-complete problems are not just hard individually but are polynomial-time interreducible, forming a single equivalence class of difficulty.

Exercises Intermediate+

Lean formalization Intermediate+

Mathlib has Computability.TuringMachine with basic TM definitions and halting predicates, but it does not define NP, polynomial-time reductions, SAT as a complexity-theoretic problem, or NP-completeness. The foundational gap is the absence of Complexity.NP as a class of languages, Complexity.Reduction for polynomial-time many-one reductions, and the Cook-Levin construction that converts a TM computation into a Boolean formula. The tableau encoding with its cell, start, accept, and move constraints has no formalisation. This unit ships without a lean_module.

Advanced results Master

Three results extend the Cook-Levin theorem.

Theorem 1 (Cook's theorem for circuit-SAT). The circuit satisfiability problem (CIRCUIT-SAT) is NP-complete.

The proof encodes the computation tableau directly as a Boolean circuit rather than a CNF formula. Each row of the tableau is computed from the previous row by a fixed circuit that checks the windows. The overall circuit has polynomial size and is satisfiable iff the TM accepts. CIRCUIT-SAT is sometimes used as the starting point for NP-completeness proofs instead of SAT because the circuit model is closer to hardware [Arora & Barak §2.3].

Theorem 2 (Berman-Hartmanis conjecture). All known natural NP-complete problems are polynomial-time isomorphic (i.e., related by polynomial-time bijections with polynomial-time inverses).

This conjecture (1977) states that all NP-complete sets are "essentially the same" up to polynomial-time relabelling. It has been verified for all natural NP-complete problems but remains unproven in general. A consequence is that if the conjecture holds and P NP, then no sparse set (a set with only polynomially many strings of each length) is NP-complete.

Theorem 3 (NP-completeness of 3-SAT). 3-SAT is NP-complete.

The reduction from SAT to 3-SAT uses the gadget construction from the worked example. Each clause of length is split into clauses of length 3 using auxiliary variables. The reduction preserves satisfiability and runs in polynomial time. Since SAT is NP-complete and 3-SAT is in NP, transitivity gives NP-completeness of 3-SAT [Sipser §7.5].

Synthesis. The Cook-Levin theorem is the foundational reason NP-completeness is a coherent and useful concept: it provides a single universal bottleneck problem to which all NP problems reduce. The central insight is that computation can be encoded as logic — the tableau construction translates "does this machine accept?" into "is this formula satisfiable?" This builds toward the entire theory of NP-completeness reductions, where hundreds of practical problems are shown to be NP-complete by chains of reductions from SAT. The bridge is that the tableau encoding appears again in the PCP theorem, where it is made robust to probabilistic checking, and this is exactly what connects computational hardness to inapproximability results. Putting these together with the polynomial hierarchy of 47.02.04 yields the modern map of computational complexity: a landscape of difficulty levels connected by reductions.

Full proof set Master

Proposition 1 (Cook-Levin: SAT is NP-complete). is NP-complete.

Proof. Membership: because a satisfying assignment is a polynomial-length certificate verifiable in polynomial time by evaluating the formula.

Hardness: Let via NDTM running in time . Construct encoding the computation tableau. The formula has four parts:

The construction time is . If accepts , the accepting tableau satisfies . If is satisfiable, the satisfying assignment describes a valid accepting computation of on . So .

Proposition 2 (SAT reduces to 3-SAT). There exists a polynomial-time reduction from SAT to 3-SAT.

Proof. Given a CNF formula with clauses , for each clause of length :

  • If , say , replace with for new variables .
  • If , say , replace with for new variable .
  • If , keep as is.
  • If , say , replace with for new variables .

Each gadget introduces new variables and clauses. Total size is . The reduction preserves satisfiability by the gadget correctness argument.

Connections Master

  • 42.04.01 — The Turing machine model is the computational foundation for the Cook-Levin tableau encoding; every NP computation is a TM computation, and the tableau captures its full history.

  • 47.02.01 — P, NP, and polynomial-time reductions are defined in 47.02.01; the Cook-Levin theorem uses these definitions to prove the existence of NP-complete problems.

  • 47.02.03 — Classic NP-complete problems (CLIQUE, VERTEX-COVER, HAM-CYCLE) are proved NP-complete by reduction from SAT or 3-SAT, using the NP-completeness established here.

  • 47.03.02 — The Karp-Lipton theorem uses the NP-completeness of SAT to show that polynomial-size circuits for NP would collapse the polynomial hierarchy.

Historical & philosophical context Master

The Cook-Levin theorem was proved independently by Stephen Cook (1971) and Leonid Levin (1973). Cook's paper "The Complexity of Theorem-Proving Procedures" showed that SAT is NP-complete by encoding Turing machine computations as Boolean formulas. Levin's paper, published in Russian, proved the same result using a different but equivalent construction [Arora & Barak §2.3].

Richard Karp's 1972 paper "Reducibility among Combinatorial Problems" showed that 21 fundamental combinatorial problems (including CLIQUE, VERTEX-COVER, HAM-CYCLE, and SUBSET-SUM) are all NP-complete by building chains of reductions from SAT. This transformed NP-completeness from a theoretical curiosity into a practical tool: any new problem could be shown intractable (assuming P NP) by reducing a known NP-complete problem to it.

The philosophical significance of NP-completeness is that it reveals a deep unity among seemingly unrelated problems. Satisfiability of Boolean formulas, optimal tour planning, graph colouring, and scheduling are all "the same problem" in the sense that they are polynomial-time interreducible. This suggests that the boundary between tractable and intractable is a fundamental feature of computation itself, not an artifact of any particular problem formulation [Sipser §7.4].

Bibliography Master

@inproceedings{cook1971complexity,
  author    = {Cook, Stephen A.},
  title     = {The Complexity of Theorem-Proving Procedures},
  booktitle = {Proceedings of the 3rd Annual ACM Symposium on Theory of Computing},
  pages     = {151--158},
  year      = {1971},
}
@book{sipser2013,
  author    = {Sipser, Michael},
  title     = {Introduction to the Theory of Computation},
  edition   = {3rd},
  publisher = {Cengage Learning},
  year      = {2013},
}
@book{arora2009,
  author    = {Arora, Sanjeev and Barak, Boaz},
  title     = {Computational Complexity: A Modern Approach},
  publisher = {Cambridge University Press},
  year      = {2009},
}
@article{karp1972reducibility,
  author  = {Karp, Richard M.},
  title   = {Reducibility among Combinatorial Problems},
  journal = {Complexity of Computer Computations},
  pages   = {85--103},
  year    = {1972},
  publisher = {Plenum Press},
}