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: transport acceptance and rejection runs across encodings
Browse filesChecks
build Program · lake build, no sorry
Details
challenge Program · statement files and build config
Details
+24 −14 Problems/PVersusNP/Machines/CertificateBound.lean View file
| @@ -37,10 +37,10 @@ private inductive Phase (k : ℕ) | ||
| 37 | 37 | | restore (ok : Bool) |
| 38 | 38 | deriving Fintype |
| 39 | 39 | |
| 40 | -private abbrev Alphabet (tm : FinTM2) : tm.K ⊕ Aux → Type := | |
| 41 | - Sum.elim tm.Γ fun | |
| 42 | - | .saved => tm.Γ tm.k₀ | |
| 43 | - | _ => Unit | |
| 40 | +private abbrev Alphabet (tm : FinTM2) : tm.K ⊕ Aux → Type | |
| 41 | + | .inl j => tm.Γ j | |
| 42 | + | .inr .saved => tm.Γ tm.k₀ | |
| 43 | + | .inr _ => Unit | |
| 44 | 44 | |
| 45 | 45 | private abbrev Register (tm : FinTM2) := Option (tm.Γ tm.k₀) × tm.σ |
| 46 | 46 | |
| @@ -244,6 +244,13 @@ private def oneStep {a b : (guarded tm sep reject k).Cfg} | ||
| 244 | 244 | (step : (guarded tm sep reject k).step a = some b) : Run tm sep reject k a b := |
| 245 | 245 | (EvalsToInTime.of_step step).toEvalsTo |
| 246 | 246 | |
| 247 | +@[local simp] private theorem initEmpty (tm : FinTM2) (j : tm.K) : | |
| 248 | + (initList tm []).stk j = [] := by | |
| 249 | + by_cases hj : j = tm.k₀ | |
| 250 | + · subst j | |
| 251 | + exact initList_stk_self tm [] | |
| 252 | + · exact initList_stk_ne tm [] hj | |
| 253 | + | |
| 247 | 254 | macro "certificate_step" : tactic => do |
| 248 | 255 | let machine := Lean.mkIdent `tm |
| 249 | 256 | `(tactic| |
| @@ -464,12 +471,11 @@ def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | ||
| 464 | 471 | (EvalsTo.trans _ _ _ _ cleared compared)) |
| 465 | 472 | have lengths : (m ≤ cap) ↔ |
| 466 | 473 | p.2.length ≤ (ea.encode p.1).length ^ k := by simp [xs, ys, m, cap, n] |
| 467 | - change Run h.tm sep reject k | |
| 468 | - (initList (guarded h.tm sep reject k) | |
| 469 | - (List.map h.inputAlphabet.invFun ((pair_encoding ea (fin_encoding_string Γ)).encode p))) | |
| 470 | - (haltList (guarded h.tm sep reject k) | |
| 471 | - (List.map h.outputAlphabet.invFun (finEncodingBoolBool.encode (check ea k verifier p)))) | |
| 472 | - have started := initial (sep := sep) (reject := reject) (k := k) (xs ++ sep :: ys) | |
| 474 | + have started := (congrArg (initList (guarded h.tm sep reject k)) inputEq).trans | |
| 475 | + (initial (sep := sep) (reject := reject) (k := k) (xs ++ sep :: ys)) | |
| 476 | + let finish (b : Bool) : (guarded h.tm sep reject k).Cfg := | |
| 477 | + haltList (guarded h.tm sep reject k) | |
| 478 | + (List.map h.outputAlphabet.invFun (finEncodingBoolBool.encode b)) | |
| 473 | 479 | by_cases bound : p.2.length ≤ (ea.encode p.1).length ^ k |
| 474 | 480 | · have yes := lengths.mpr bound |
| 475 | 481 | simp only [yes, decide_true, Bool.and_self] at prefixRun |
| @@ -479,12 +485,16 @@ def checked {α Γ : Type} [Fintype Γ] {ea : FinEncoding α} | ||
| 479 | 485 | rw [List.append_nil, hs] at restored |
| 480 | 486 | have doneRun := EvalsTo.trans _ _ _ _ prefixRun |
| 481 | 487 | (EvalsTo.trans _ _ _ _ restored (liftRun original)) |
| 482 | - rw [inputEq, started, check, if_pos bound] | |
| 483 | - exact (final _ ▸ doneRun) | |
| 488 | + have ended := (final (sep := sep) (reject := reject) (k := k) | |
| 489 | + (List.map h.outputAlphabet.invFun (finEncodingBoolBool.encode (verifier p)))).trans | |
| 490 | + (congrArg finish (if_pos bound).symm) | |
| 491 | + exact started.symm ▸ ended ▸ doneRun | |
| 484 | 492 | · have no := lengths.not.mpr bound |
| 485 | 493 | simp only [no, decide_false, Bool.and_false] at prefixRun |
| 486 | - rw [inputEq, started, check, if_neg bound] | |
| 487 | - exact EvalsTo.trans _ _ _ _ prefixRun (rejectRun saved) | |
| 494 | + have doneRun := EvalsTo.trans _ _ _ _ prefixRun (rejectRun saved) | |
| 495 | + have ended : haltList (guarded h.tm sep reject k) [reject] = | |
| 496 | + finish (check ea k verifier p) := congrArg finish (if_neg bound).symm | |
| 497 | + exact started.symm ▸ ended ▸ doneRun | |
| 488 | 498 | |
| 489 | 499 | end |
| 490 | 500 | |