Sub topic 10
SAT and the Cook-Levin Theorem
This chapter assumes you know polynomial-time (Karp) reductions, the definition of NP through certificate verifiers, and what NP-hard and NP-complete mean. It also assumes you can read propositional formulas in conjunctive normal form (CNF).
Why a First NP-Complete Problem Is Needed
To prove that a problem B is NP-hard, you reduce a known NP-hard problem A to B. That method only works once some first problem has been proved NP-hard. For that first problem, you must reduce every language in NP to it directly. The Cook-Levin theorem does this for SAT.
SAT is the decision problem: given a Boolean formula in CNF, is there an assignment of true/false values to its variables that makes the formula true?
SAT belongs to NP because the certificate is an assignment, and checking it takes linear time:
def satisfies(clauses, assignment):
# clauses: list of tuples of nonzero ints (DIMACS-style literals)
# assignment: dict mapping variable number -> bool
return all(any(assignment[abs(lit)] == (lit > 0) for lit in clause)
for clause in clauses)
formula = [(1, -2), (2, 3), (-1, -3)]
print(satisfies(formula, {1: True, 2: True, 3: False})) # TrueThe Idea of the Proof
Take any language L in NP. By definition, L has a verifier V that runs in time p(n) for some polynomial p. V takes an input x of length n and a certificate c, and x is in L exactly when some c makes V accept. The reduction maps x to a formula φ_x that is satisfiable exactly when such a c exists.
The construction writes down the whole computation of V as a grid called a tableau. Row t is the machine's configuration (tape contents, head position, state) at step t. Since V runs for at most p(n) steps, it can visit at most p(n) tape cells, so the grid is p(n) by p(n). There is one Boolean variable x_{t,i,s} for each cell, meaning "at step t, cell i holds symbol s."
| Clause group | What it forces |
|---|---|
| Cell | Each cell holds exactly one symbol |
| Start | Row 0 encodes x followed by free certificate cells |
| Move | Every small window of adjacent cells follows V's transition rules |
| Accept | An accepting state appears in some row |
The certificate cells in row 0 are left unconstrained, so choosing a satisfying assignment amounts to choosing a certificate. Each window rule involves a constant number of variables, and there are O(p(n)²) windows, so φ_x has polynomial size and can be built in polynomial time.
From SAT to 3-SAT
Gadget reductions are easier when every clause has at most three literals. A clause (l1 ∨ … ∨ lk) with k > 3 can be split into a chain of 3-literal clauses using new variables y. The chain is satisfiable exactly when some original literal is true.
def to_3cnf(clauses, num_vars):
out, nxt = [], num_vars + 1
for clause in clauses:
c = list(clause)
if len(c) <= 3:
out.append(tuple(c))
continue
y = nxt; nxt += 1
out.append((c[0], c[1], y))
for lit in c[2:-2]:
y2 = nxt; nxt += 1
out.append((-y, lit, y2))
y = y2
out.append((-y, c[-2], c[-1]))
return out, nxt - 1
print(to_3cnf([(1, 2, 3, 4, 5)], 5))
# ([(1, 2, 6), (-6, 3, 7), (-7, 4, 5)], 7)The output grows linearly in the input, so this is a polynomial-time reduction. 3-SAT is in NP for the same reason SAT is, so 3-SAT is NP-complete.
Exercise
In the 3-SAT conversion, suppose every original literal l1 through l5 in (l1 ∨ l2 ∨ l3 ∨ l4 ∨ l5) is false. Why can no choice of y6 and y7 satisfy (l1 ∨ l2 ∨ y6)(¬y6 ∨ l3 ∨ y7)(¬y7 ∨ l4 ∨ l5)?
Show answer
The first clause forces y6 true. The second clause then forces y7 true. That makes ¬y7 false, so the third clause has no true literal. The chain fails, as it should when the original clause is false.
Exercise
Why does the Cook-Levin construction need the verifier's running time to be polynomial?
Show answer
The tableau is p(n) by p(n), so the formula has O(p(n)²) cell-and-window constraints. If p were not polynomial, the formula could not be written down in polynomial time, and the mapping would not be a Karp reduction.