# A reader’s guide to the P versus NP statement Read this guide beside [`Millennium.lean`](Millennium.lean) and Stephen Cook’s [*The P versus NP Problem*](https://www.claymath.org/wp-content/uploads/2022/06/pvsnp.pdf). 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](Millennium.lean#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](Millennium.lean#L217) uses the list itself as its encoding. | | [`InPolynomialTime`, L92](Millennium.lean#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](Millennium.lean#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](Millennium.lean#L180) shows the resulting word. | | [`PolynomialTimeCheckingRelation`, L269](Millennium.lean#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](Millennium.lean#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](Millennium.lean#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](Millennium.lean#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](Millennium.lean#L1547) | §1, p. 2, “Does P = NP?” The positive proposition unfolds to [`ClayPVersusNP.Formulations.ClassEquality`, L1535](Millennium.lean#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](Millennium.lean#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](Millennium.lean#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](Millennium.lean#L495-L1370) 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](Millennium.lean#L1127). The length of the tagged input is `w.length + 1 + y.length`, so [`LeftProjection.linear_time_correctness`, L1349](Millennium.lean#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](Millennium.lean#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. | Declaration within `Millennium` | What it gives | | --- | --- | | [`PolynomialTimeReducible.source_in_p`, L339](Millennium.lean#L339) | Pulls a P decider back along a reduction (Cook, Proposition 1(a)). | | [`PolynomialTimeReducible.trans`, L358](Millennium.lean#L358) | Composes two polynomial-time many-one reductions. | | [`NondeterministicPolynomialTimeComplete.transfer`, L375](Millennium.lean#L375) | Transfers NP-completeness along a reduction to an NP language (Proposition 1(b)). | | [`ClayPVersusNP.Support.DeciderAsVerifier.of_projection`, L1471](Millennium.lean#L1471) | Lifts a P decider to a verifier given a polynomial-time left projection. | | [`ClayPVersusNP.Support.DeciderAsVerifier.of_left_projection_machine`, L1491](Millennium.lean#L1491) | Lifts a P decider using the verified left-projection machine. | | [`PolynomialTimeContainedInNondeterministicPolynomialTime.of_turing_machine_composition`, L1522](Millennium.lean#L1522) | Derives P ⊆ NP via the certificate-ignoring verifier. | | [`ClayPVersusNP.Formulations.ClassEquality.of_hard_direction_and_projection`, L1635](Millennium.lean#L1635) | Gets class equality from the hard direction and a supplied polynomial-time projection. | | [`ClayPVersusNP.Formulations.ClassEquality.of_hard_direction_and_turing_machine_composition`, L1646](Millennium.lean#L1646) | Gets class equality from the hard direction using the verified projection. | | [`ClayPVersusNP.Formulations.ClassEquality.iff_hard_direction`, L1655](Millennium.lean#L1655) | Equates class equality with the hard direction. | | [`ClayPVersusNP.iff_hard_direction`, L1663](Millennium.lean#L1663) | Equates the positive target with the hard direction. | | [`ClayPVersusNP.Formulations.HardDirection.polynomial_time_equals_nondeterministic_polynomial_time`, L1672](Millennium.lean#L1672) | Derives the positive target from the hard direction. | | [`ClayPVersusNP.iff_nondeterministic_polynomial_time_simulation`, L1678](Millennium.lean#L1678) | Equates the positive target with deterministic simulation. | | [`ClayPVersusNP.Formulations.DeterministicSimulation.polynomial_time_equals_nondeterministic_polynomial_time`, L1688](Millennium.lean#L1688) | Derives the positive target from deterministic simulation. | | [`ClayPVersusNP.iff_checkable`, L1699](Millennium.lean#L1699) | Equates the positive target with checkability implying solvability. | | [`ClayPVersusNP.Formulations.CheckableImpliesSolvable.polynomial_time_equals_nondeterministic_polynomial_time`, L1709](Millennium.lean#L1709) | Derives the positive target from checkability implying solvability. | | [`CookNondeterministicPolynomialTimeCompleteInPolynomialTime.nondeterministic_polynomial_time_contained_in_polynomial_time`, L1720](Millennium.lean#L1720) | Derives the hard direction from an NP-complete language in P (Proposition 1(c), inclusion form). | | [`CookNondeterministicPolynomialTimeCompleteInPolynomialTime.polynomial_time_equals_nondeterministic_polynomial_time`, L1734](Millennium.lean#L1734) | Derives class equality from an NP-complete language in P and a supplied decider-as-verifier principle. | | [`CookNondeterministicPolynomialTimeCompleteInPolynomialTime.of_projection`, L1746](Millennium.lean#L1746) | Derives class equality from an NP-complete language in P and a supplied polynomial-time projection. | | [`CookNondeterministicPolynomialTimeCompleteInPolynomialTime.of_turing_machine_composition`, L1760](Millennium.lean#L1760) | Derives class equality from an NP-complete language in P using the verified projection. | | [`ClayPVersusNP.Consequences.NondeterministicPolynomialTimeCompleteInPolynomialTime.of_turing_machine_composition`, L1783](Millennium.lean#L1783) | Proves the global implication from any NP-complete language in P to class equality. | | [`ClayPVersusNP.nondeterministic_polynomial_time_complete_in_polynomial_time`, L1790](Millennium.lean#L1790) | Derives the positive target given an NP-complete language in P. | | [`ClayFiniteAlphabet.NondeterministicPolynomialTimeCompleteInPolynomialTime.of_turing_machine_composition`, L1822](Millennium.lean#L1822) | Proves the implication from an NP-complete language in P to class equality over a fixed alphabet. | | [`ClayFiniteAlphabet.PolynomialTimeEqualsNondeterministicPolynomialTime.nondeterministic_polynomial_time_complete_in_polynomial_time`, L1829](Millennium.lean#L1829) | Derives class equality over a fixed alphabet given an NP-complete language in P. | ## What the file proves without the composition hypothesis - The encoding equations give the canonical pair word at [L180](Millennium.lean#L180) and its length at [L188](Millennium.lean#L188). The projection proof has its own machine transitions and runtime bound at [L495–1370](Millennium.lean#L495-L1370). [`LeftProjection.polynomial_time_computable.of_linear_time`, L1455](Millennium.lean#L1455) turns the linear-time evidence supplied at L1349 into a polynomial-time machine witness. - [`ClayVerifiableLanguage.iff_in_nondeterministic_polynomial_time`, L422](Millennium.lean#L422) repackages the same bounded-certificate data in both directions. [`ClayFiniteAlphabet.VerifiableLanguage.iff_in_nondeterministic_polynomial_time`, L468](Millennium.lean#L468) specializes that statement to a bundled alphabet. The equivalence of checking with the hard direction is proved at [L1405](Millennium.lean#L1405), and the equivalence of checking with deterministic simulation at [L1422](Millennium.lean#L1422). - [`ClayPVersusNP.Formulations.ClassEquality.iff_subsets`, L1576](Millennium.lean#L1576) expresses equality as the conjunction of the two inclusions. A proof of the positive target gives the hard direction at [L1592](Millennium.lean#L1592) and the easy direction at [L1616](Millennium.lean#L1616). The standalone easy inclusion at L1522 uses composition. Its earlier helper [`PolynomialTimeContainedInNondeterministicPolynomialTime.certificate_verifier`, L1503](Millennium.lean#L1503) takes the verifier lift as a premise and chooses the empty certificate. - [`NondeterministicPolynomialTimeComplete.in_nondeterministic_polynomial_time`, L1840](Millennium.lean#L1840) and [`NondeterministicPolynomialTimeComplete.reduces`, L1849](Millennium.lean#L1849) extract the two parts of a supplied NP-completeness proof.