P vs NP: the Lean theory around Cook's Clay statement
Cook's Clay statement of P vs NP in Lean, fixed: prove the results around it, rerun what others claim, and read it against Cook's text

A reader’s guide to the P versus NP statement
Read this guide beside Millennium.lean and Stephen Cook’s
The P versus NP Problem.
The line numbers refer to declarations in Millennium.lean. The page numbers
refer to Cook’s printed pages. Cook describes a one-tape machine in his appendix.
Lean uses Mathlib’s TM2ComputableInPolyTime. The links below locate the
corresponding definitions for a side-by-side reading.
From languages to the two targets
| Lean declaration | Cook’s text and how to read the declaration |
|---|---|
Language, L77 |
§1, p. 1, “a language over Σ is a subset L of Σ∗.” Lean represents a subset by a predicate α → Prop. For strings, α is List alphabet. fin_encoding_string, L217 uses the list itself as its encoding. |
InPolynomialTime, L92 |
§1, pp. 1–2, the definition of P uses a machine that “runs in polynomial time.” Lean asks for a Boolean decider with polynomial-time machine evidence and requires its output to be true exactly on members of the language. |
pair_encoding, L158 |
§1, p. 2, Cook writes “Lᵣ = {w#y | R(w, y)}.” The Lean encoding tags the left and right symbols and places a distinct separator between them. pair_encoding.encode_eq, L180 shows the resulting word. |
PolynomialTimeCheckingRelation, L269 |
§1, p. 2, “We say that R is polynomial-time iff Lᵣ ∈ P.” Lean applies InPolynomialTime to the predicate R p.1 p.2 on pairs under pair_encoding. |
InNondeterministicPolynomialTime, L286 |
§1, p. 2, Cook gives “w ∈ L ⟺ ∃y(|y| ≤ |w|ᵏ and R(w, y)).” Lean quantifies over a finite certificate alphabet, a checking relation and an exponent. Certificates are lists over that alphabet, and the input length is the length of its encoding. |
PolynomialTimeReducible, L297 |
§2, p. 4, Definition 3 asks for a “polynomial-time computable function” with “x ∈ L₁ ⟺ f(x) ∈ L₂.” Lean supplies machine evidence for f between the two encodings and states that membership equivalence for every source input. |
NondeterministicPolynomialTimeComplete, L331 |
§2, p. 4, Definition 4 says “L is in NP, and L′ ≤ₚ L for every language L′ in NP.” The two conjuncts in Lean express membership in NP and reducibility from every NP language, with its own encoded input type. |
Millennium.ClayPVersusNP, L1547 |
§1, p. 2, “Does P = NP?” The positive proposition unfolds to ClayPVersusNP.Formulations.ClassEquality, L1535. For every language over a finite alphabet with at least two symbols, being in P is equivalent to being in NP. |
Millennium.ClayPVersusNP.Formulations.NegativeBranch, L1860 |
§3, p. 7, “Suppose, on the other hand, that P ≠ NP, and consider how one might prove it.” The negative proposition is the negation of the positive proposition above. |
Cook poses the equality in §1 and then supplies the definitions of reduction and
NP-completeness in §2. His opening sentence in §1 points to the inclusion
NP ⊆ P, expressed at
ClayPVersusNP.Formulations.HardDirection, L1379.
In Lean, the equivalence between that inclusion and literal class equality uses
the composition hypothesis described below.
One verified machine for the left projection
Lines 495–1370 build the finite machine that
returns w on a canonical input w#y whose two strings use the same finite
alphabet. Its transition table copies the left symbols onto a work stack until
it sees the separator, discards the right block, and drains the work stack to
the output stack. The two stack transfers restore the original order. The
one-step proofs are assembled into an evaluation bounded by
4 * w.length + y.length + 4 at
string_projection_evals_canonical, L1127.
The length of the tagged input is w.length + 1 + y.length, so
LeftProjection.linear_time_correctness, L1349
supplies the bound 4n + 4 in the encoded input length n.
Cook’s §1 proof of P ⊆ NP uses the relation R(w, y) ⟺ w ∈ L.
The projection supplies the first machine in that construction. A decider
for L supplies the second.
The 23 theorems that take polynomial-time composition
ClayPVersusNP.Support.PolynomialTimeComputableComposition, L308
asks for machine evidence for g ∘ f from polynomial-time machine evidence
for f and g with a common intermediate encoding. Each of the following
theorem signatures explicitly takes that proposition.
What the file proves without the composition hypothesis
- The encoding equations give the canonical pair word at
L180 and its length at L188.
The projection proof has its own machine transitions and runtime bound
at L495–1370.
LeftProjection.polynomial_time_computable.of_linear_time, L1455 turns the linear-time evidence supplied at L1349 into a polynomial-time machine witness. ClayVerifiableLanguage.iff_in_nondeterministic_polynomial_time, L422 repackages the same bounded-certificate data in both directions.ClayFiniteAlphabet.VerifiableLanguage.iff_in_nondeterministic_polynomial_time, L468 specializes that statement to a bundled alphabet. The equivalence of checking with the hard direction is proved at L1405, and the equivalence of checking with deterministic simulation at L1422.ClayPVersusNP.Formulations.ClassEquality.iff_subsets, L1576 expresses equality as the conjunction of the two inclusions. A proof of the positive target gives the hard direction at L1592 and the easy direction at L1616. The standalone easy inclusion at L1522 uses composition. Its earlier helperPolynomialTimeContainedInNondeterministicPolynomialTime.certificate_verifier, L1503 takes the verifier lift as a premise and chooses the empty certificate.NondeterministicPolynomialTimeComplete.in_nondeterministic_polynomial_time, L1840 andNondeterministicPolynomialTimeComplete.reduces, L1849 extract the two parts of a supplied NP-completeness proof.