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: verify rejection from empty stacks and isolate the decoder type
Browse filesChecks
build Program · lake build, no sorry
Details
challenge Program · statement files and build config
Details
+30 −5 Problems/PVersusNP/Machines/CertificateBound.lean View file
| @@ -399,7 +399,31 @@ private def rejectRun (saved : List (tm.Γ tm.k₀)) : | ||
| 399 | 399 | Run tm sep reject k (checkpoint (.restore false) { saved := saved }) |
| 400 | 400 | (haltList (guarded tm sep reject k) [reject]) := by |
| 401 | 401 | induction saved with |
| 402 | - | nil => apply oneStep; certificate_step | |
| 402 | + | nil => | |
| 403 | + apply oneStep | |
| 404 | + let empty (j : tm.K ⊕ Aux) : List (Alphabet tm j) := [] | |
| 405 | + have blank : (checkpoint (.restore false : Phase k) ({} : Work (tm.Γ tm.k₀))).stk = empty := by | |
| 406 | + funext j | |
| 407 | + cases j with | |
| 408 | + | inl j => exact initEmpty tm j | |
| 409 | + | inr j => cases j <;> rfl | |
| 410 | + have clean : Function.update empty (.inr .saved) [] = empty := | |
| 411 | + Function.update_eq_self _ _ | |
| 412 | + have output : Function.update empty (.inl tm.k₁) [reject] = | |
| 413 | + (haltList (guarded tm sep reject k) [reject]).stk := by | |
| 414 | + funext j | |
| 415 | + by_cases eq : j = Sum.inl tm.k₁ | |
| 416 | + · subst j | |
| 417 | + exact (Function.update_self _ _ _).trans (haltList_stk_self _ _).symm | |
| 418 | + · exact (Function.update_of_ne eq _ _).trans (haltList_stk_ne _ _ eq).symm | |
| 419 | + apply congrArg some | |
| 420 | + change TM2.stepAux (guard tm sep reject k (.restore false)) (none, tm.initialState) | |
| 421 | + (checkpoint (.restore false) ({} : Work (tm.Γ tm.k₀))).stk = _ | |
| 422 | + rw [blank] | |
| 423 | + change { l := none, var := (none, tm.initialState), | |
| 424 | + stk := Function.update (Function.update empty (.inr .saved) []) (.inl tm.k₁) [reject] } = _ | |
| 425 | + rw [clean] | |
| 426 | + exact congrArg (fun st => ⟨none, (none, tm.initialState), st⟩) output | |
| 403 | 427 | | cons a xs ih => exact beginStep (by certificate_step) ih |
| 404 | 428 | |
| 405 | 429 | private theorem initial (inp : List (tm.Γ tm.k₀)) : |
| @@ -437,16 +461,17 @@ def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | ||
| 437 | 461 | inputAlphabet := h.inputAlphabet |
| 438 | 462 | outputAlphabet := h.outputAlphabet |
| 439 | 463 | outputsFun p := by |
| 440 | - let sep := h.inputAlphabet.symm (Sum.inr none) | |
| 464 | + let rawDecode : ea.Γ ⊕ Option Γ → h.tm.Γ h.tm.k₀ := h.inputAlphabet.symm | |
| 465 | + let sep := rawDecode (Sum.inr none) | |
| 441 | 466 | let reject := h.outputAlphabet.symm false |
| 442 | - let xs := (ea.encode p.1).map (fun a => h.inputAlphabet.symm (Sum.inl a)) | |
| 443 | - let ys := p.2.map (fun b => h.inputAlphabet.symm (Sum.inr (some b))) | |
| 467 | + let xs := (ea.encode p.1).map (fun a => rawDecode (Sum.inl a)) | |
| 468 | + let ys := p.2.map (fun b => rawDecode (Sum.inr (some b))) | |
| 444 | 469 | have inputEq : |
| 445 | 470 | List.map h.inputAlphabet.invFun ((pair_encoding ea (fin_encoding_string Γ)).encode p) = |
| 446 | 471 | xs ++ sep :: ys := by |
| 447 | 472 | refine (congrArg (List.map h.inputAlphabet.invFun) |
| 448 | 473 | (pair_encoding.encode_eq ea (fin_encoding_string Γ) p)).trans ?_ |
| 449 | - change List.map (fun a : ea.Γ ⊕ Option Γ => h.inputAlphabet.symm a) | |
| 474 | + change List.map rawDecode | |
| 450 | 475 | ((ea.encode p.1).map Sum.inl ++ Sum.inr none :: p.2.map (fun b => Sum.inr (some b))) = |
| 451 | 476 | xs ++ sep :: ys |
| 452 | 477 | rw [List.map_append, List.map_cons, List.map_map, List.map_map] <;> rfl |