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

fix: elaborate guarded runs and canonical input in Lean
Browse filesChecks
build Program · lake build, no sorry
Details
challenge Program · statement files and build config
Details
+12 −6 Problems/PVersusNP/Machines/CertificateBound.lean View file
| @@ -18,6 +18,8 @@ namespace Millennium.Machines.CertificateBound | ||
| 18 | 18 | |
| 19 | 19 | open Computability Turing StateTransition |
| 20 | 20 | |
| 21 | +noncomputable section | |
| 22 | + | |
| 21 | 23 | private inductive Aux |
| 22 | 24 | | saved | base | temp | count | next | cert |
| 23 | 25 | deriving DecidableEq, Fintype |
| @@ -65,7 +67,7 @@ private def mark {tm : FinTM2} (sep : tm.Γ tm.k₀) (_ : Register tm) (x : Opti | ||
| 65 | 67 | |
| 66 | 68 | private def prev {k : ℕ} (i : Fin (k + 1)) : Fin (k + 1) := ⟨i.val - 1, by omega⟩ |
| 67 | 69 | |
| 68 | -private noncomputable def guard (tm : FinTM2) (sep : tm.Γ tm.k₀) (reject : tm.Γ tm.k₁) | |
| 70 | +private def guard (tm : FinTM2) (sep : tm.Γ tm.k₀) (reject : tm.Γ tm.k₁) | |
| 69 | 71 | (k : ℕ) : Phase k → Stmt tm k := by |
| 70 | 72 | classical |
| 71 | 73 | exact fun |
| @@ -124,7 +126,7 @@ private noncomputable def guard (tm : FinTM2) (sep : tm.Γ tm.k₀) (reject : tm | ||
| 124 | 126 | else .push (.inl tm.k₁) (fun _ => reject) |
| 125 | 127 | (.load (fun _ => (none, tm.initialState)) .halt))) |
| 126 | 128 | |
| 127 | -private noncomputable def guarded (tm : FinTM2) (sep : tm.Γ tm.k₀) (reject : tm.Γ tm.k₁) | |
| 129 | +private def guarded (tm : FinTM2) (sep : tm.Γ tm.k₀) (reject : tm.Γ tm.k₁) | |
| 128 | 130 | (k : ℕ) : FinTM2 where |
| 129 | 131 | K := tm.K ⊕ Aux |
| 130 | 132 | kFin := by letI := tm.kFin; infer_instance |
| @@ -272,8 +274,8 @@ private def scanLeft (xs ys saved : List (tm.Γ tm.k₀)) (base : ℕ) | ||
| 272 | 274 | (noSep : ∀ x ∈ xs, x ≠ sep) : |
| 273 | 275 | Run tm sep reject k |
| 274 | 276 | (checkpoint (.scan false) { input := xs ++ sep :: ys, saved := saved, base := base }) |
| 275 | - (checkpoint (.scan true) { input := ys, saved := sep :: (xs.reverse ++ saved), | |
| 276 | - base := base + xs.length, count := 1 }) := by | |
| 277 | + (checkpoint (.scan true) | |
| 278 | + { input := ys, saved := sep :: (xs.reverse ++ saved), base := base + xs.length, count := 1 }) := by | |
| 277 | 279 | induction xs generalizing saved base with |
| 278 | 280 | | nil => apply oneStep; certificate_step |
| 279 | 281 | | cons x xs ih => |
| @@ -411,7 +413,7 @@ def check {α Γ : Type} (ea : FinEncoding α) (k : ℕ) (verifier : α × List | ||
| 411 | 413 | if p.2.length ≤ (ea.encode p.1).length ^ k then verifier p else false |
| 412 | 414 | |
| 413 | 415 | /-- Adding Cook's certificate length bound preserves computable checking. -/ |
| 414 | -noncomputable def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | |
| 416 | +def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | |
| 415 | 417 | {verifier : α × List Γ → Bool} |
| 416 | 418 | (h : TM2Computable (pair_encoding ea (fin_encoding_string Γ)).encode |
| 417 | 419 | finEncodingBoolBool.encode verifier) (k : ℕ) : |
| @@ -428,7 +430,9 @@ noncomputable def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | ||
| 428 | 430 | have inputEq : |
| 429 | 431 | List.map h.inputAlphabet.invFun ((pair_encoding ea (fin_encoding_string Γ)).encode p) = |
| 430 | 432 | xs ++ sep :: ys := by |
| 431 | - simp [pair_encoding.encode_eq, xs, ys, sep] <;> rfl | |
| 433 | + simp only [pair_encoding.encode_eq, fin_encoding_string_encode, List.map_append, | |
| 434 | + List.map_cons, List.map_map] | |
| 435 | + rfl | |
| 432 | 436 | have noSep : ∀ x ∈ xs, x ≠ sep := by |
| 433 | 437 | intro x hx eq |
| 434 | 438 | obtain ⟨a, _, rfl⟩ := List.mem_map.mp hx |
| @@ -468,4 +472,6 @@ noncomputable def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | ||
| 468 | 472 | rw [check, if_neg bound] |
| 469 | 473 | exact EvalsTo.trans _ _ _ _ prefixRun (rejectRun saved) |
| 470 | 474 | |
| 475 | +end | |
| 476 | + | |
| 471 | 477 | end Millennium.Machines.CertificateBound |