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 | --- |
| 2 | issue: 30 |
| 3 | status: done |
| 4 | --- |
| 5 | # Even parity by an explicit linear-time machine |
| 6 | |
| 7 | For S-9, `Problems/PVersusNP/Examples/Parity.lean` proves |
| 8 | `Millennium.Examples.Parity.evenTrueCount_in_P`: |
| 9 | `InPolynomialTime (fin_encoding_string Bool) evenTrueCount`, where |
| 10 | `evenTrueCount inp` is `inp.count true % 2 = 0`. There is no composition |
| 11 | hypothesis or other unproved hypothesis. This is an elementary example in the |
| 12 | fixed model, and says nothing about which answer to P vs NP holds. |
| 13 | |
| 14 | ## What changed and why |
| 15 | |
| 16 | The explicit two-stack machine keeps an even-parity flag and whether its last |
| 17 | pop found an input symbol. It consumes one Boolean per step, toggles its flag |
| 18 | exactly on `true`, then writes that flag, resets its state and halts. `run` |
| 19 | proves an `EvalsToInTime` bound of `inp.length + 1`, for any initial flag and |
| 20 | existing output stack. `parityAfter_eq` relates the flag invariant to the |
| 21 | recursive answer; `evenParity_eq_true_iff` relates that answer to the count |
| 22 | predicate. `parityDecider` packages the run with polynomial `X + 1`. |
| 23 | |
| 24 | The model is the constant-false machine in the fixed `Sanity.lean`; neither |
| 25 | fixed file, the checker, dependencies, nor build configuration was edited. |
| 26 | The existing `Problems.+` glob includes the new module. |
| 27 | |
| 28 | ## What happened |
| 29 | |
| 30 | The first push (`715fa0d`) claimed #30 before implementation. No Lean or Lake |
| 31 | was installed locally, and none was installed for this work. The default |
| 32 | Python challenge attempt failed before inspection because it lacked tomllib; |
| 33 | the already installed Python 3.12 runs it successfully. |
| 34 | |
| 35 | The first Lean build, [job 1484](https://shoal.club/shoal/p-vs-np/jobs/1484), |
| 36 | failed on Boolean-negation precedence and decider elaboration. Parenthesizing |
| 37 | the Boolean argument fixed the first. Direct `simpa` still failed at |
| 38 | `11e1faa`; temporary diagnostic commits `becf2af` and `42cd9a5` exposed the |
| 39 | remaining mismatch (the former also misplaced a declaration option). The final |
| 40 | proof rewrites the output of a separately named run before weakening its time |
| 41 | bound. This removes the final decider elaboration error. |
| 42 | Diagnostic options were removed. All failures remain in branch history. |
| 43 | |
| 44 | ## Verification and reproduction |
| 45 | |
| 46 | The proof-bearing commit is |
| 47 | [`4c9d27d9df2a5fbe5c21f90ab5ec90166c2a410c`](https://shoal.club/shoal/p-vs-np/commit/4c9d27d9df2a5fbe5c21f90ab5ec90166c2a410c). |
| 48 | [Challenge job 1492](https://shoal.club/shoal/p-vs-np/jobs/1492) passed on it, |
| 49 | checking 4 Lean files / 2,436 lines. [Build job 1493](https://shoal.club/shoal/p-vs-np/jobs/1493) |
| 50 | passed on this same commit, explicitly compiling `Problems.PVersusNP.Examples.Parity` |
| 51 | and reporting `ok: lake build passes with no sorry`. Its `#print axioms` |
| 52 | reports `[propext, Classical.choice, Quot.sound]` for `evenTrueCount_in_P`. |
| 53 | These checks judged the new module, not merely the claim commit. See |
| 54 | [RERUN.md](RERUN.md) for the dated build record. |
| 55 | |
| 56 | On a machine with the pinned Lean and Mathlib, run `lake build Problems Tests`. |
| 57 | For the file-only challenge here: |
| 58 | |
| 59 | ```sh |
| 60 | /Users/wang-thumac/.cache/codex-runtimes/codex-primary-runtime/dependencies/python/bin/python3.12 checks/challenge.py . |
| 61 | ``` |
| 62 | |
| 63 | Documentation-only commits after the proof-bearing commit carry its check |
| 64 | verdicts; they do not rerun Lean. No Comparator configuration judges P vs NP |
| 65 | in this project, and this example makes no claim about its answer. |
| 66 | |
| 67 | ## Next |
| 68 | |
| 69 | The maintainer should review the new example and decide whether to merge |
| 70 | [PR #80](https://shoal.club/shoal/p-vs-np/pull/80) for #30. The source contribution is complete and the site's two |
| 71 | gating checks pass on the proof-bearing commit. |