Sub topic 10
Cook-Levin: SAT Is NP-Complete
This chapter assumes you know the definitions of NP, polynomial-time reductions, and NP-hardness from the earlier chapters. You should also be comfortable with Boolean formulas in conjunctive normal form (CNF). A CNF formula is an AND of clauses, where each clause is an OR of literals.
The Bootstrapping Problem
To prove that a problem is NP-hard, you usually reduce a known NP-hard problem to it. That method needs a first NP-hard problem, and that first proof cannot use reduction from another problem. Stephen Cook (1971) and Leonid Levin (1973) solved this independently. They showed that SAT is NP-complete. SAT is the question "does this Boolean formula have a satisfying assignment?"
The theorem has two parts:
- SAT is in NP. A certificate is an assignment of true or false to each variable, and you can check it in linear time.
- SAT is NP-hard. Every problem in NP reduces to SAT in polynomial time.
The first part is easy to check in code:
def verify_cnf(clauses, assignment):
"""clauses: list of clauses, each a list of nonzero ints (DIMACS style:
3 means x3, -3 means NOT x3). assignment: dict mapping variable number to bool."""
for clause in clauses:
if not any(assignment[abs(lit)] == (lit > 0) for lit in clause):
return False
return True
# (x1 OR NOT x2) AND (x2 OR x3)
print(verify_cnf([[1, -2], [2, 3]], {1: True, 2: False, 3: True})) # TrueThe Proof Idea
The second part has to work for every problem in NP at once, so the proof cannot use details of any particular problem. It uses the one thing all of them share. For any language L in NP, some nondeterministic Turing machine M decides L within p(n) steps, where p is a polynomial.
Fix an input w of length n. Picture M's whole computation as a tableau. A tableau is a grid where row i is the machine's configuration at step i. The grid has at most p(n) rows and p(n) columns. The reduction builds a formula φ whose variables say "cell (i, j) holds symbol s." Its clauses enforce four conditions:
| Constraint | What it forces |
|---|---|
| Cell | Each cell holds exactly one symbol |
| Start | Row 0 is M's starting configuration on w |
| Move | Each small window of adjacent cells is consistent with M's transition rules |
| Accept | Some row contains the accepting state |
The formula φ is satisfiable exactly when M has an accepting computation on w, which means exactly when w is in L. The tableau has O(p(n)²) cells, and each constraint adds a constant number of clauses per cell. So φ has polynomial size, and you can write it down in polynomial time.
Why It Matters
Once SAT is known to be NP-complete, proving another problem X NP-hard takes a single reduction from SAT (or from any problem already proven NP-complete) to X. Thousands of NP-completeness results follow this chain. Most of them start from 3-SAT, the version of SAT where every clause has exactly three literals. 3-SAT is also NP-complete and is easier to build reductions from.
Exercise
The Cook-Levin formula must have polynomial size. Which property of NP guarantees that the tableau has polynomially many cells?
Show answer
Every language in NP is decided by a nondeterministic machine running in polynomial time p(n). The machine can visit at most p(n) tape cells in p(n) steps, so the tableau is at most p(n) by p(n), which gives O(p(n)²) cells and a polynomial number of clauses.
Exercise
Why is it not enough to show only that SAT is NP-hard to conclude that SAT is NP-complete?
Show answer
NP-complete means NP-hard and also a member of NP. You must also show SAT is in NP, which the polynomial-time verifier for satisfying assignments does.