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 | # AGENTS.md |
| 2 | |
| 3 | Read [README.md](README.md) first, then `KNOWN.md`. **P vs NP is open, and this project does not claim to move it.** |
| 4 | `main` holds Cook's Clay statement in Lean and the results proved about it; what we want is more of those results, |
| 5 | proved in this model with no `sorry`, and a statement a reader can follow. Never describe a change here as progress on |
| 6 | P vs NP itself: the statement is fixed, and a result about it is not a step towards either answer. |
| 7 | |
| 8 | ## First session |
| 9 | |
| 10 | In your clone of this project, with Python 3 and no Lean: |
| 11 | |
| 12 | ```bash |
| 13 | python3 checks/challenge.py . # last line: ok: 2 challenge files and the build configuration as approved; … |
| 14 | git fetch origin issues && git show origin/issues:BOARD.md # the pieces, and who works on what |
| 15 | sed -n 77,100p Problems/PVersusNP/Millennium.lean # languages and P (InPolynomialTime) |
| 16 | sed -n 269,340p Problems/PVersusNP/Millennium.lean # NP, ≤ₚ, the composition hypothesis, NP-complete |
| 17 | ``` |
| 18 | |
| 19 | Then pick one piece nobody holds. Each issue says what to do, what it needs (reading only, compiling one file, or a full |
| 20 | build on a large machine), when it closes and what it does not show. By what you have: |
| 21 | |
| 22 | - **No Lean, reading only**: V-11 or V-13 (the statement against Cook's text, a few rows each), V-8 (the SAT of the |
| 23 | claimed Cook–Levin), V-17 (two false "P = NP" repositories), P-1 (a reader's guide), L-1 (one row of the table). |
| 24 | - **A laptop with elan** (the project compiles in seconds once Mathlib's cache is there): V-6 (rebuild, and record it), |
| 25 | then S-9 (parity is in P: a first machine of your own), P-2, S-2. |
| 26 | - **A large machine, or days**: V-7 (rerun Tan's 11,600 lines), S-1 and S-5 (bring them in), S-13 to S-20. |
| 27 | |
| 28 | ## Reruns and readings |
| 29 | |
| 30 | A rerun of anything (this project, a claim made elsewhere) is a dated record in `routes/<your-branch>/RERUN.md`, one |
| 31 | section per run, never replaced: a later run is a new section. The one template: |
| 32 | |
| 33 | ```markdown |
| 34 | ## 2026-12-02: <what was rerun>, by <who> (<which agent, if one ran it>) |
| 35 | |
| 36 | - Machine: <CPU model, cores, RAM, OS>; <your own machine, or the site's job number> |
| 37 | - Image: <the image tag and id, or `lean --version` and the Mathlib commit> |
| 38 | - Commit: <repository URL and the full commit that was rerun> |
| 39 | - Command: <each command as typed, with its exit code and wall time> |
| 40 | - What it printed: <the lines that carry the verdict, copied, not paraphrased> |
| 41 | - What was not checked: <every part of the claim this run does not cover; "none" is almost never true> |
| 42 | ``` |
| 43 | |
| 44 | A reading (a statement against Cook's text, a claim's SAT, a paper) is a note in the path its piece names, each verdict |
| 45 | with the page and line it rests on. Both close when a second party (someone else's agent, or the house's maintainer |
| 46 | agent) has checked them and said so in a review. A rerun says what ran; it never says a claim is true beyond what ran. |
| 47 | |
| 48 | ## Claim an issue |
| 49 | |
| 50 | Work on a branch of your own, and say what you take in its notes: |
| 51 | |
| 52 | ```bash |
| 53 | git switch -c my-change origin/main |
| 54 | mkdir -p routes/my-change |
| 55 | cat > routes/my-change/README.md <<'EOF' |
| 56 | --- |
| 57 | issue: 3 |
| 58 | status: working |
| 59 | --- |
| 60 | # my-change |
| 61 | |
| 62 | Which files, and what I prove or change in them. |
| 63 | |
| 64 | ## Next |
| 65 | |
| 66 | The first concrete step. |
| 67 | EOF |
| 68 | ``` |
| 69 | |
| 70 | A push keeps the claim alive. If you stop, leave `## Next` so whoever continues knows where you stopped. Your change |
| 71 | itself is in the Lean files; the notes say what it is. |
| 72 | |
| 73 | ## Changes we want |
| 74 | |
| 75 | - A result about the statement's definitions, proved in a new file under `Problems/PVersusNP/` that imports |
| 76 | `Problems.PVersusNP.Millennium`: P ⊆ NP without hypotheses, closure of P and NP under complement, union and |
| 77 | intersection, facts about reductions and NP-completeness, the polynomial hierarchy, and in time Cook–Levin. |
| 78 | - A proof of `ClayPVersusNP.Support.PolynomialTimeComputableComposition`, or of another hypothesis the statement's |
| 79 | theorems take, followed by unconditional versions of the theorems that took it, in a new file. |
| 80 | - Explicit two-stack machines with their time bounds, written once as reusable lemmas, as `Sanity.lean`'s |
| 81 | `constFalseDecider` and the statement's `left_projection_machine` are. |
| 82 | - Improving `PolynomialHierarchy.lean`: docstrings that say what is defined, and lemmas about its levels. |
| 83 | - Moving a general fact about Mathlib's Turing machines (not about P vs NP) to a file that could go to Mathlib, and |
| 84 | offering it there. |
| 85 | - A sanity test in a new file under `Tests/PVersusNP/` that shows a definition is not degenerate. |
| 86 | |
| 87 | ## Changes we don't want |
| 88 | |
| 89 | - Any change to `Problems/PVersusNP/Millennium.lean` or `Tests/PVersusNP/Sanity.lean`, even a docstring or a typo: |
| 90 | they are the problem, and `challenge` fails a commit that changes them. Make a reader's aid a separate file. If you |
| 91 | think the statement is wrong, open an issue titled "Ruling: …" and say why. |
| 92 | - A proof of `Millennium.ClayPVersusNP` or `NegativeBranch` as an ordinary pull request. Say it in an issue with the |
| 93 | whole argument; a person decides how it is judged (README, "A solution"). |
| 94 | - New definitions of P or NP that compete with the statement's. A different model goes in a file of its own, with a |
| 95 | theorem relating it to the statement's. |
| 96 | - A result that takes a new unproved hypothesis without saying so in its name or docstring. |
| 97 | - `sorry`, `admit`, `axiom`, `native_decide`, `implemented_by` or `extern` anywhere: `challenge` fails them. |
| 98 | - Any change to `checks/`, `docker/`, or to `lakefile.toml` beyond a `require`'s `rev`, `leanOptions`, |
| 99 | `defaultTargets`, `lean_exe` or `[cache]`; a dependency outside leanprover and leanprover-community, a |
| 100 | `lakefile.lean`, or files under `.lake/`. |
| 101 | |
| 102 | ## Pull requests |
| 103 | |
| 104 | Keep each pull request to one result or one change. Compile it if you can (`lake exe cache get`, then `lake build`); |
| 105 | if Lean is not installed, don't install it for this: push and let the `build` check say. Either way, open the pull request, and don't write in it that it |
| 106 | builds: `build` says that. Titles follow |
| 107 | [Mathlib's convention](https://leanprover-community.github.io/contribute/commit.html). In the description, name the |
| 108 | issue it answers (`Closes #3`), state the main theorem in one line, and name every hypothesis it takes. Keep the title |
| 109 | and description in step with the diff when you push more commits. |
| 110 | |
| 111 | If you want to make the same kind of change in many places, open one pull request first and wait for the maintainer to |
| 112 | say we want it before you open the others. |
| 113 | |
| 114 | ## CI |
| 115 | |
| 116 | Two checks run on every push, and both gate the merge. Their code is `checks/` at the approved version, so editing it |
| 117 | on your branch changes nothing about your verdict. They differ from a project with a proved theorem: P vs NP is open, |
| 118 | so there is no theorem to check and no Comparator run. |
| 119 | |
| 120 | - **`challenge`**, seconds: the statement (`Millennium.lean`) and its sanity tests (`Sanity.lean`) are as approved, the |
| 121 | build configuration is too, and the source has no `sorry`, `admit`, `axiom`, `native_decide`, `implemented_by` or |
| 122 | `extern`. Run it yourself: `python3 checks/challenge.py .` |
| 123 | - **`build`**, minutes: in the project's Lean image with no network, `lake build` of `Problems` and `Tests` ends |
| 124 | without error, and no module reports a declaration that uses `sorry`. Its last line is |
| 125 | `ok: lake build passes with no sorry`, or what failed. If you can build, the same before you push: |
| 126 | `lake exe cache get && lake build`; if you cannot, push and let `build` say. |
| 127 | |
| 128 | A toolchain or Mathlib bump passes `challenge`, but `build` needs a new image first (`docker/README.md`): open an issue |
| 129 | for a person who maintains the project rather than a pull request that cannot pass. |
| 130 | |
| 131 | ## For the maintainer |
| 132 | |
| 133 | The house's maintainer agent (`pnp-maintainer`) comes about every two hours while people work here, at least twice a |
| 134 | day, and within minutes when written to. It reviews (first line ``**Review of `<commit>`: <verdict>**``), does not |
| 135 | merge, logs each round on the issue "Maintainer log", and opens `Ruling: …` issues (`needs-person`) for what only a |
| 136 | person decides. Here, as an `open` problem: |
| 137 | |
| 138 | - **Claims rerun** (skill `verify-claim`): what a pull request claims is rebuilt in the project's Lean image with the |
| 139 | approved checks, `#print axioms` of each new theorem is read, and the result is a dated `RERUN.md` on a route of |
| 140 | the agent's own, in the template above. |
| 141 | - **The ledger of claims** (skill `ledger`) in "Where it stands": each claim about P vs NP made here or elsewhere, with |
| 142 | one of the README's four statuses and who reproduced it. A claim of P = NP or P ≠ NP stays "written argument, |
| 143 | unread" and goes to a person. |
| 144 | - **Sources watched**: `lean-dojo/LeanMillenniumPrizeProblems` (the upstream) and new arXiv preprints in cs.CC that |
| 145 | state a result about the fixed statement; one this workspace can rerun becomes a "Reproduce …" issue. |
| 146 | |
| 147 | P vs NP is open. Judge every pull request against the two lists above: is it a sound result about the fixed statement, |
| 148 | stated honestly and readable. |
| 149 | |
| 150 | - **Merge** a change we want once `challenge` and `build` have passed on its head, the description states the main |
| 151 | theorem and every hypothesis it takes, and the code says the same. |
| 152 | - **Request changes** when the description and the diff disagree, when it is two changes in one, when it is on the |
| 153 | second list (say which item), or when a hypothesis is hidden. |
| 154 | - **Request changes** when `challenge` or `build` failed: quote the check's last line. |
| 155 | - **Escalate**, never merge, a pull request or issue that claims to prove `Millennium.ClayPVersusNP` or |
| 156 | `Millennium.ClayPVersusNP.Formulations.NegativeBranch`, or P = NP or P ≠ NP in any form: the checks cannot judge |
| 157 | it, and a person adds a Comparator challenge first. Escalate also a change to the statement files, to `checks/` or |
| 158 | `docker/`, to `lakefile.toml`'s libraries or dependencies, a "Ruling:" issue, or two reviews that disagree: say in |
| 159 | one sentence what a person must decide. |
| 160 | - **Close** a repeat of a change already merged or open, pointing to it, and a mass change opened before the first of |
| 161 | its kind was wanted. |
| 162 | |
| 163 | Never merge on the author's word that it builds: only `build` on its head says so. Never describe a merged result as |
| 164 | progress on P vs NP. After a merge, add to `KNOWN.md` the theorem proved and the hypotheses it takes. |