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

| 1 | import Problems.PVersusNP.Millennium |
| 2 | import Problems.PVersusNP.Machines.CertificateBound |
| 3 | |
| 4 | /-! |
| 5 | # Polynomial time and computable enumerability |
| 6 | |
| 7 | Cook's polynomial-time reductions and checking relations can be used as computable |
| 8 | ones. For NP, the computable checker also enforces the original certificate bound. |
| 9 | -/ |
| 10 | |
| 11 | namespace Millennium |
| 12 | |
| 13 | open Computability Turing |
| 14 | |
| 15 | /-- A polynomial-time many-one reduction is a computable many-one reduction. -/ |
| 16 | theorem PolynomialTimeReducible.toManyOneReducible {α β : Type} |
| 17 | {ea : FinEncoding α} {eb : FinEncoding β} {L₁ : Language α} {L₂ : Language β} |
| 18 | (h : PolynomialTimeReducible ea eb L₁ L₂) : ManyOneReducible ea eb L₁ L₂ := by |
| 19 | obtain ⟨f, machine, correct⟩ := h |
| 20 | exact ⟨f, machine.toTM2ComputableInTime.toTM2Computable, correct⟩ |
| 21 | |
| 22 | /-- A polynomial-time checking relation is a computable checking relation. -/ |
| 23 | theorem PolynomialTimeCheckingRelation.toComputableCheckingRelation {α β : Type} |
| 24 | {ea : FinEncoding α} {eb : FinEncoding β} {R : α → β → Prop} |
| 25 | (h : PolynomialTimeCheckingRelation ea eb R) : ComputableCheckingRelation ea eb R := by |
| 26 | obtain ⟨verifier, machine, correct⟩ := h |
| 27 | exact ⟨verifier, machine.toTM2ComputableInTime.toTM2Computable, fun a b => correct (a, b)⟩ |
| 28 | |
| 29 | /-- Every NP language is computably enumerable, using a computable checker that also |
| 30 | rejects certificates longer than the original NP bound. -/ |
| 31 | theorem InNondeterministicPolynomialTime.toComputablyEnumerable {α : Type} |
| 32 | {ea : FinEncoding α} {L : Language α} |
| 33 | (h : InNondeterministicPolynomialTime ea L) : ComputablyEnumerable ea L := by |
| 34 | obtain ⟨Γ, hΓ, R, k, hR, correct⟩ := h |
| 35 | letI : Fintype Γ := hΓ |
| 36 | obtain ⟨verifier, machine, verifies⟩ := hR.toComputableCheckingRelation |
| 37 | refine ⟨Γ, hΓ, fun a y => y.length ≤ (ea.encode a).length ^ k ∧ R a y, ?_, correct⟩ |
| 38 | exact ⟨_, Machines.CertificateBound.checked machine k, fun a y => by |
| 39 | by_cases bound : y.length ≤ (ea.encode a).length ^ k |
| 40 | · simpa [bound, Machines.CertificateBound.check] using verifies a y |
| 41 | · simp [bound, Machines.CertificateBound.check]⟩ |
| 42 | |
| 43 | end Millennium |