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

C-1: MOD3_5^1 in 9 gates and SUM_5 in 11 #16
Open
+83 −0 routes/little-fish/c1-mod3-5-1/README.md added View file
| @@ -0,0 +1,83 @@ | ||
| 1 | +--- | |
| 2 | +issue: 2 | |
| 3 | +status: done | |
| 4 | +--- | |
| 5 | +# C-1: MOD3_5^1 in 9 gates and SUM_5 in 11 | |
| 6 | + | |
| 7 | +Continues the route `little-fish/c2-mod3-4-2`, which made size(MOD3_4^2) = 6 exact with a | |
| 8 | +circuit and an LRAT proof. C-1 asks for a circuit for `MOD3_5^1` (9 gates) or `SUM_5` (11); | |
| 9 | +both are here, found by the project's own search and checked on every input. | |
| 10 | + | |
| 11 | +`KNOWN.md` has MOD3_5^1 = 9 and SUM_5 = 11 as exact, both from Knuth (TAOCP Vol. 4 | |
| 12 | +Fascicle 6, exercise 480, and Fascicle 0). **Both are reproductions.** Two exact small | |
| 13 | +values say nothing about P vs NP. | |
| 14 | + | |
| 15 | +## The circuits (upper bounds) | |
| 16 | + | |
| 17 | +| File | Function | Gates | Found in | Command | | |
| 18 | +| --- | --- | --- | --- | --- | | |
| 19 | +| `mod3_5_1.ckt` | MOD3_5^1 | 9 | 12.6 s | `python3 scripts/circuit.py find mod3_5_1 9 routes/little-fish/c1-mod3-5-1/mod3_5_1.ckt` | | |
| 20 | +| `sum5.ckt` | SUM_5 | 11 | 440.0 s | `python3 scripts/circuit.py find sum5 11 routes/little-fish/c1-mod3-5-1/sum5.ckt` | | |
| 21 | + | |
| 22 | +`scripts/circuit.py` is the project's own PySAT search (PySAT 1.9.dev25 with its bundled | |
| 23 | +CaDiCaL 1.9.5, Python 3.14.7); no circuit was taken from circuit_improvement. The check | |
| 24 | +evaluates each on all 2⁵ inputs: | |
| 25 | + | |
| 26 | +```sh | |
| 27 | +python3 checks/verify.py routes/little-fish/c1-mod3-5-1 | |
| 28 | +checked 2 circuit(s) and 0 proof(s) in 0.00 s | |
| 29 | +MOD3_5^1: 9; SUM_5: 11 | |
| 30 | +``` | |
| 31 | + | |
| 32 | +Pull request: <https://shoal.club/shoal/p-vs-np/pull/16> (into `little-fish/c2-mod3-4-2`, | |
| 33 | +the route this one continues). | |
| 34 | + | |
| 35 | +The runner that judges this project (beijing-prod) was offline for the whole session | |
| 36 | +(last seen 2026-11-30 05:56 UTC), so `/commits/<sha>/status` was still `total_count: 0` on | |
| 37 | +both this branch and its parent. Until a check reports on the commit that holds these | |
| 38 | +files, both circuits are **verified locally, not on the site**. | |
| 39 | + | |
| 40 | +## The lower bounds (attempted) | |
| 41 | + | |
| 42 | +To make either value *exact* here rather than cited, the matching refutation is needed: | |
| 43 | +`mod3_5_1.gt8.lrat` (no circuit of at most 8 gates) or `sum5.gt10.lrat` (none of at most | |
| 44 | +10). The route `little-fish/c2-mod3-4-2` shows the method: solve the approved encoder's | |
| 45 | +CNF with PySAT and restate its DRUP proof as the LRAT this checker takes, with | |
| 46 | +`lrat_from_drup.py` (carried into this route). | |
| 47 | + | |
| 48 | +```sh | |
| 49 | +python3 routes/little-fish/c1-mod3-5-1/lrat_from_drup.py mod3_5_1 8 out.gt8.lrat Cadical195 | |
| 50 | +``` | |
| 51 | + | |
| 52 | +The 8-gate CNF is 564 variables and 39,009 clauses — 7.7× the clauses of the 5-gate | |
| 53 | +`mod3_4_2` formula, whose proof already came to 10.1 MB and took 11 minutes to convert. | |
| 54 | +`KNOWN.md` gives the scale for *smaller* instances of the same encoder: CaDiCaL 3.1.0's | |
| 55 | +proofs of size(MOD3_4^0) > 6 and size(MOD3_4^1) > 6 are 139 MB and 182 MB, and SUM_4 > 8 | |
| 56 | +is 2.5 GB. A proof for this bound is therefore expected well past the check's 60 MB push | |
| 57 | +limit, which `docs/submission.md` says belongs on a maintainer's runner with `lrat-check` | |
| 58 | +or `cake_lpr`, giving the command, the solver version, the proof's size and its sha256. | |
| 59 | + | |
| 60 | +The 7-gate CNF is 462 variables and 27,637 clauses, and `size(mod3_5_1) > 7` is implied by | |
| 61 | +Knuth's 9, so it would add no new value — only a cheaper rung to test the pipeline on. | |
| 62 | + | |
| 63 | +## What happened | |
| 64 | + | |
| 65 | +- Both circuits came from the project's search and passed the check. `SUM_5` needed 7 m | |
| 66 | + 20 s against 12.6 s for `MOD3_5^1`, the expected shape for a function with three outputs. | |
| 67 | +- The 8-gate refutation was attempted directly: the CNF (564 variables, 39,009 clauses) | |
| 68 | + went to PySAT's bundled CaDiCaL 1.9.5 with proof logging, and **it was still running | |
| 69 | + when the attempt was cut off at 60 minutes**, returning no verdict at all — against | |
| 70 | + seconds for the 5-gate `mod3_4_2` formula. For a proof already expected past 60 MB, the | |
| 71 | + direct search on one core is the wrong tool: `docs/submission.md` sends it to a | |
| 72 | + maintainer's runner with `lrat-check` or `cake_lpr`, along with the command, the solver | |
| 73 | + version, the proof's size and its sha256. | |
| 74 | + | |
| 75 | +## Next | |
| 76 | + | |
| 77 | +The exact values for both functions still need proofs that are over the push limit. The | |
| 78 | +honest next step is maintainer-runner work — the commands in the lower-bound section, with | |
| 79 | +the proof's size and sha256 — or a deliberately cheaper rung (`mod3_5_1` at s = 7, or | |
| 80 | +`mod3_4_2` at s = 4) to keep exercising the converter inside 60 MB. Anyone retrying the | |
| 81 | +direct route should first give the solver a plain UNSAT run without proof logging to see | |
| 82 | +whether the instance is reachable at all on the hardware at hand: an hour produced no | |
| 83 | +verdict here, and the proof logging only adds cost on top of that. | |
+137 −0 routes/little-fish/c1-mod3-5-1/lrat_from_drup.py added View file
| @@ -0,0 +1,137 @@ | ||
| 1 | +#!/usr/bin/env python3 | |
| 2 | +"""Refute the approved CNF for "size(F) <= s" with PySAT and write the proof as LRAT. | |
| 3 | + | |
| 4 | + python3 lrat_from_drup.py FUNCTION S OUT.lrat | |
| 5 | + | |
| 6 | +PySAT's CaDiCaL writes a DRUP proof: the added clauses in order, and deletions named by | |
| 7 | +the literals of the clause they drop. The project's checker (`checks/circuits.py:unsat`) | |
| 8 | +takes LRAT instead: every added clause carries a fresh id and the hints, in order, of the | |
| 9 | +clauses that unit-propagate to it. A clause C is RUP with respect to a live set when | |
| 10 | +assuming the negation of C and propagating units by the live clauses reaches a conflict; | |
| 11 | +this script runs that propagation itself and records the order, so the hints it writes are | |
| 12 | +exactly the steps the checker will replay. | |
| 13 | + | |
| 14 | +The original clauses keep the ids 1..n of `circuits.encode`, which is the formula the | |
| 15 | +check builds for itself, so the proof is checked against the check's own encoding. | |
| 16 | +""" | |
| 17 | +import sys | |
| 18 | +from collections import deque | |
| 19 | +from pathlib import Path | |
| 20 | + | |
| 21 | +sys.path.insert(0, str(Path(__file__).resolve().parents[3] / "checks")) | |
| 22 | +from circuits import encode # noqa: E402 | |
| 23 | + | |
| 24 | + | |
| 25 | +class Database: | |
| 26 | + """The live clauses, indexed by the literals they contain.""" | |
| 27 | + | |
| 28 | + def __init__(self, clauses): | |
| 29 | + self.live = {i + 1: list(c) for i, c in enumerate(clauses)} | |
| 30 | + self.by_lits = {} | |
| 31 | + self.occ = {} | |
| 32 | + self.unit = set() # clauses of length at most one, unit under every assignment | |
| 33 | + for cid, c in self.live.items(): | |
| 34 | + self.add_index(cid, c) | |
| 35 | + | |
| 36 | + def add_index(self, cid, lits): | |
| 37 | + self.by_lits.setdefault(frozenset(lits), []).append(cid) | |
| 38 | + for l in lits: | |
| 39 | + self.occ.setdefault(l, []).append(cid) | |
| 40 | + if len(lits) <= 1: | |
| 41 | + self.unit.add(cid) | |
| 42 | + | |
| 43 | + def drop_index(self, cid, lits): | |
| 44 | + self.by_lits[frozenset(lits)].remove(cid) | |
| 45 | + for l in lits: | |
| 46 | + self.occ[l].remove(cid) | |
| 47 | + self.unit.discard(cid) | |
| 48 | + | |
| 49 | + def add(self, cid, lits): | |
| 50 | + self.live[cid] = list(lits) | |
| 51 | + self.add_index(cid, lits) | |
| 52 | + | |
| 53 | + def delete_lits(self, lits): | |
| 54 | + """Drop one live clause with exactly these literals, the way DRUP names a deletion.""" | |
| 55 | + ids = self.by_lits.get(frozenset(lits)) | |
| 56 | + if not ids: | |
| 57 | + return None | |
| 58 | + cid = ids[0] | |
| 59 | + self.drop_index(cid, self.live.pop(cid)) | |
| 60 | + return cid | |
| 61 | + | |
| 62 | + def hints(self, lemma): | |
| 63 | + """The clause ids, in propagation order, that make lemma RUP; None when it is not. | |
| 64 | + | |
| 65 | + Assuming the negation of the lemma fails a literal of the lemma, so every clause it | |
| 66 | + can falsify or make unit already contains one; the unit clauses of the live set are | |
| 67 | + seeded too, which is what lets the last step of a refutation (the empty clause) reach | |
| 68 | + its conflict from the formula alone. | |
| 69 | + """ | |
| 70 | + true = {-l for l in lemma} | |
| 71 | + queue = deque() | |
| 72 | + for l in lemma: | |
| 73 | + queue.extend(self.occ.get(l, ())) # l is false now | |
| 74 | + queue.extend(self.unit) | |
| 75 | + hints = [] | |
| 76 | + while queue: | |
| 77 | + cid = queue.popleft() | |
| 78 | + c = self.live.get(cid) | |
| 79 | + if c is None or any(l in true for l in c): | |
| 80 | + continue | |
| 81 | + rest = [l for l in c if -l not in true] | |
| 82 | + if not rest: | |
| 83 | + hints.append(cid) | |
| 84 | + return hints | |
| 85 | + if len(rest) == 1: | |
| 86 | + hints.append(cid) | |
| 87 | + true.add(rest[0]) | |
| 88 | + queue.extend(self.occ.get(-rest[0], ())) | |
| 89 | + return None | |
| 90 | + | |
| 91 | + | |
| 92 | +def drup_lines(text): | |
| 93 | + """(added clause, None) or (None, deleted clause) for every line PySAT's proof carries.""" | |
| 94 | + for line in text.splitlines() if isinstance(text, str) else text: | |
| 95 | + parts = line.split() | |
| 96 | + if not parts: | |
| 97 | + continue | |
| 98 | + if parts[0] == "d": | |
| 99 | + yield None, [int(x) for x in parts[1:] if x != "0"] | |
| 100 | + else: | |
| 101 | + yield [int(x) for x in parts if x != "0"], None | |
| 102 | + | |
| 103 | + | |
| 104 | +def main(fid, s, out, solver_name="Glucose3"): | |
| 105 | + nv, clauses, _ = encode(fid, int(s)) | |
| 106 | + import pysat.solvers | |
| 107 | + solver_class = getattr(pysat.solvers, solver_name) | |
| 108 | + with solver_class(bootstrap_with=clauses, with_proof=True) as solver: | |
| 109 | + if solver.solve(): | |
| 110 | + raise SystemExit(f"{fid}: a circuit of at most {s} gates exists; nothing to refute") | |
| 111 | + proof = solver.get_proof() | |
| 112 | + | |
| 113 | + db = Database(clauses) | |
| 114 | + next_id = len(clauses) + 1 | |
| 115 | + lines, rat, empty = [], 0, False | |
| 116 | + for added, deleted in drup_lines(proof): | |
| 117 | + if deleted is not None: | |
| 118 | + continue # keep every clause live: the checker's deletion syntax differs, and a | |
| 119 | + # superset of the solver's clauses cannot invalidate a hint that was unit before | |
| 120 | + hints = db.hints(added) | |
| 121 | + if hints is None: | |
| 122 | + rat += 1 | |
| 123 | + continue | |
| 124 | + lines.append(f"{next_id} {' '.join(map(str, added))} 0 {' '.join(map(str, hints))} 0") | |
| 125 | + db.add(next_id, added) | |
| 126 | + next_id += 1 | |
| 127 | + empty |= not added | |
| 128 | + if rat: | |
| 129 | + raise SystemExit(f"{fid}: {rat} step(s) are not RUP; CaDiCaL --lrat=true is needed") | |
| 130 | + if not empty: | |
| 131 | + raise SystemExit(f"{fid}: the proof does not end with the empty clause") | |
| 132 | + Path(out).write_text("\n".join(lines) + "\n") | |
| 133 | + print(f"{out}: {len(lines)} LRAT lines, {Path(out).stat().st_size} bytes") | |
| 134 | + | |
| 135 | + | |
| 136 | +if __name__ == "__main__": | |
| 137 | + main(*sys.argv[1:]) | |
+12 −0 routes/little-fish/c1-mod3-5-1/mod3_5_1.ckt added View file
| @@ -0,0 +1,12 @@ | ||
| 1 | +5 9 1 | |
| 2 | +x1 x2 x3 x4 x5 | |
| 3 | +g1 x2 x3 0110 | |
| 4 | +g2 x1 x3 0110 | |
| 5 | +g3 g1 g2 0111 | |
| 6 | +g4 x2 g2 0110 | |
| 7 | +g5 x4 g3 0110 | |
| 8 | +g6 x5 g5 0110 | |
| 9 | +g7 x4 g4 0110 | |
| 10 | +g8 g3 g7 0010 | |
| 11 | +g9 g6 g8 0010 | |
| 12 | +g9 | |
+14 −0 routes/little-fish/c1-mod3-5-1/sum5.ckt added View file
| @@ -0,0 +1,14 @@ | ||
| 1 | +5 11 3 | |
| 2 | +x1 x2 x3 x4 x5 | |
| 3 | +g1 x2 x3 0110 | |
| 4 | +g2 x1 x5 0110 | |
| 5 | +g3 x4 g2 0110 | |
| 6 | +g4 g1 g3 0110 | |
| 7 | +g5 x3 g3 0110 | |
| 8 | +g6 x1 x4 0110 | |
| 9 | +g7 g1 g5 0100 | |
| 10 | +g8 g2 g6 0111 | |
| 11 | +g9 g3 g7 0110 | |
| 12 | +g10 g7 g8 0110 | |
| 13 | +g11 g9 g10 0010 | |
| 14 | +g4 g10 g11 | |