Cook p. 5: 3-SAT is -complete (Cook 1971)
OpenPvsNP.threeSAT_npCompleteCook (p. 5): "An important special case of Satisfiability is 3-SAT, which was also shown to be -complete in [9]. Instances of 3-SAT are restricted to formulas in conjunctive normal form with three literals per clause. For example, the formula is a YES instance to 3-SAT since the truth assignment satisfies the formula, where and ."
Theorem. , the set of codes of satisfiable CNF formulas in which every clause has exactly three literals, is -complete: it is in , and every language in is p-reducible to it.
Formalization Note "Three literals per clause" is formalized as exactly three; a clause may repeat a variable (e.g. ), as is standard. Membership in is as for with the additional syntactic check. By Cook's Proposition 1(b) it suffices to p-reduce to by splitting long clauses with fresh variables and padding short ones, again as an explicit polynomial-time multi-stack machine.
import Definitions.Def_PvsNP import Mathlib
namespace PvsNP theorem threeSAT_npComplete : NPComplete ThreeSAT := by sorry end PvsNP
Read-back
What the Lean code literally says, in plain math · claude-fable-5-1
Read-back: PvsNP.threeSAT_npComplete
The declaration is a closed proposition: it takes no arguments, has no hypotheses, no free variables and no typeclass assumptions. (Its body is the placeholder sorry, i.e. the statement is asserted, not proved.) What it asserts is, after unfolding every definition of the bundle down to Mathlib primitives, the conjunction of the two claims (A) and (B) in Section 6 below. Everything before Section 6 is the fine print needed to read those two claims literally.
0. Conventions
Throughout, a string is a finite list over the two-letter alphabet (Lean's Bool, with , ); the set of strings is and denotes the length of . A language is any subset (the type Language Bool is literally the type of sets of such lists; nothing about decidability or definability is built in). For a list and a function producing lists, is the concatenation (empty for ).
1. The language
Formulas. A literal is a pair with and (the variable index; there is no bound on ). A clause is a finite list of literals (any length, repetitions allowed, no restriction that variables be distinct). A CNF is a finite list of clauses (possibly empty; clauses may repeat).
Evaluation. For an assignment (a total function on all of ),
with the empty disjunction being and the empty conjunction being . is satisfiable iff with . In particular the empty CNF is satisfiable, and any CNF containing an empty clause is not.
Binary digits. is the list of binary digits of , least significant first, with no leading zeros, and : and for , . E.g. , .
String coding of formulas. Each literal, clause and CNF is coded as a string over as follows:
- : take the list (the sign bit followed by the digits of ), replace every entry by the two symbols , concatenate, then append the two symbols . So
of length . For instance and .
- for a clause : (the literal codes concatenated, followed by the two symbols ).
- for a CNF : (concatenation, with no terminator). In particular is the empty string.
The language.
That is, is in the language iff is the code of some CNF each of whose clauses has exactly three literals (as a list — the three literals may coincide or involve the same variable) and which is satisfiable. No injectivity of is assumed or asserted anywhere; membership is by existence of a preimage. Strings that are not codes of any CNF are not in the language. The empty string is in (witnessed by ).
2. The machine model and "outputs in time"
Machines. A bundled stack machine consists of: a finite type of stack indices with decidable equality; two designated indices (input stack) and (output stack) in , which are allowed to coincide; for each a type of stack symbols, with finite (nothing is required of the other beyond being types); a finite type of labels with a designated label ; a finite type of internal states with a designated initial state ; and a program , where statements are built inductively by
where means "a symbol of or nothing". The functions inside statements are arbitrary set-theoretic functions (no computability or finiteness condition on them beyond the finiteness of , , ).
Configurations and steps. A configuration is a triple (current label or "halted", internal state , and for each a finite list — the contents of stack , top first). One step of from a configuration with label executes the whole statement recursively: pushes on stack and continues with ; replaces by (top may be "nothing") and continues with ; does the same and additionally removes the top of stack (no-op on an empty stack); replaces by ; continues with if , else ; ends the step with label ; ends the step with the label "halted". From a halted configuration there is no step (the step function returns "none"). Time is counted as the number of steps in this sense, so one step may perform as many stack operations as the (fixed, finite) statement contains.
Initial and final configurations. For an input list over , is the configuration with label , internal state , stack containing and every other stack empty. For an output list over , is the configuration that is halted, has internal state equal to the initial state , stack containing exactly , and every other stack empty.
Outputs in time. " on input outputs within steps" means: there is a number such that applying the step function exactly times to (treating "no step available" as absorbing) yields exactly the configuration — so after steps the machine is halted, has returned to state , has cleared all stacks other than , and stack holds precisely .
3. Polynomial-time computability relative to codings
Given types , coding functions and , and a function , " is poly-time computable w.r.t. " means there exist: a bundled stack machine as above; bijections and between the input/output stack alphabets and the coding alphabets; and a polynomial (natural-number coefficients) such that for every ,
where are applied letterwise. In particular the machine must halt on every input of the form , with exactly the coded output on the output stack, in the sense of Section 2. Nothing is required of on inputs not of the form .
Three instances are used:
- Poly-time decider of : poly-time computable w.r.t. (input string used as is, so the input alphabet is in bijection with ) and (the one-letter output string , output alphabet in bijection with ). Time bound .
- Poly-time checker of : poly-time computable w.r.t. and the pair coding
over the four-letter alphabet (letters of tagged "left", letters of tagged "right", concatenated). So the input alphabet is in bijection with this four-letter alphabet and the time bound is .
- Poly-time computable string function : poly-time computable w.r.t. (both stack alphabets in bijection with ), time bound .
4. The class of the bundle
A language is in iff there exist a function and a natural number (possibly ) such that has a poly-time checker (Section 3) and, for every string ,
Here is natural-number exponentiation with ; for the witness must have length regardless of .
5. Reducibility of the bundle
is P-reducible to iff there exists that is poly-time computable (third instance of Section 3) and such that for every string ,
( is a total function on all strings; the equivalence must hold for all , including strings that code nothing.)
6. The assertion
The theorem states , i.e. the conjunction of:
(A) . Spelled out: there exist , , a bundled stack machine with input alphabet in bijection with and output alphabet in bijection with , and a polynomial , such that (i) for every pair of strings, started on the tagged concatenation halts within steps in the configuration whose output stack holds the single letter , whose internal state is and whose other stacks are empty; and (ii) for every string ,
(B) For every language with (in the sense of Section 4), is P-reducible to . Spelled out: for every such there exist , a bundled stack machine with input and output stack alphabets each in bijection with , and a polynomial , such that for every string , started on halts within steps with exactly on its output stack (state , other stacks empty), and
The quantification over ranges over all subsets of satisfying the Section 4 condition, including itself, the empty language and (if they satisfy that condition); the reduction may depend on and need not be injective.
7. Edge cases made explicit
- Clauses in a witness must have list-length exactly ; there is no requirement that the three literals be distinct or mention distinct variables, and no bound on variable indices.
- The empty CNF codes to the empty string and is satisfiable, so .
- Variable index contributes no digit bits: . Digits are least-significant-first with no leading zeros.
- Whether is injective, or whether every string is a code, plays no role in the statement; membership is existential over .
- In , is allowed (witness length , using even for ).
- The polynomials have coefficients in and are evaluated at the length of the coded input ( for checkers, for reductions).
- The time bound and correct-output requirement apply to every input of the coded form; the machine's behaviour on other stack contents is unconstrained.
- A "step" executes one entire labelled statement; the halting configuration must have internal state equal to the initial state and all non-output stacks empty; is permitted.
- The bundle's and reducibility are defined only through this specific stack-machine model and these specific codings; the theorem asserts nothing about any other machine model or coding.