Navier–Stokes: the Lean blow-up proof, cleaned up together
OpenAI's 2026 Lean proofs of blowup for forced Navier–Stokes and Euler, rerun by others, not refereed, no ruling from Clay; cleaned up together: more readable, faster to build

| 1 | """One folder a pull request, from plan.json: what an agent's session needs to open it. |
| 2 | python3 -I units.py <plan.json> <site checkout> <out dir> |
| 3 | <out>/<id>/unit.json wave, family, branch, title, the declarations (name, file, first and last line on main 5baf4fe) |
| 4 | <out>/<id>/change.patch the deletions as a patch against main once the waves before it are in (absent for whole files) |
| 5 | <out>/<id>/PR.md the description's first draft |
| 6 | <out>/index.json the units by wave, in the order to open them |
| 7 | Checks itself: applying a wave's patches to the tree before it gives the tree mktree.py makes.""" |
| 8 | import collections, difflib, json, os, re, subprocess, sys, tempfile |
| 9 | plan, site, out = json.load(open(sys.argv[1])), sys.argv[2], sys.argv[3] |
| 10 | ISSUE = 10 # S-1: Delete declarations that nothing uses |
| 11 | orig = {} |
| 12 | def lines(f): |
| 13 | if f not in orig: orig[f] = open(f"{site}/{f}", encoding="utf-8").read().split("\n") |
| 14 | return orig[f] |
| 15 | def cut(f, ranges): |
| 16 | t, drop = lines(f), set() |
| 17 | for a, b in ranges: |
| 18 | drop.update(range(a, b + 1)) |
| 19 | if a >= 2 and b < len(t) and not t[a - 2].strip() and not t[b].strip(): drop.add(b + 1) |
| 20 | return drop |
| 21 | def content(f, drop): return "\n".join(l for i, l in enumerate(lines(f), 1) if i not in drop) |
| 22 | def slug(F): |
| 23 | d, _, w = F.partition("/") |
| 24 | # the folder NavierStokes/R3/ and the files NavierStokes/R3*.lean are two families |
| 25 | return ("ns" if d == "NavierStokes" else d.lower()) + "-" + re.sub(r"[^a-z0-9]+", "-", w.lower()).strip("-") + ("" if w.endswith("*") else "-folder") |
| 26 | def fam(f): |
| 27 | parts = f[:-5].split("/"); d = parts[0] |
| 28 | if f.startswith("NavierStokes/R3/"): return "NavierStokes/R3" |
| 29 | w = re.match(r"([A-Z][a-z0-9]+)", parts[-1]); return d + "/" + (w.group(1) if w else parts[-1]) + "*" |
| 30 | os.makedirs(out, exist_ok=True) |
| 31 | index = [] |
| 32 | SOURCE = ("How these were found. Treant (TitiSkywalker/NavierStokesAndEuler, the run of 2026-12-03 at upstream `f9e8bc5`) found them unreachable from the four " |
| 33 | "Comparator theorems. On this project's main (`5baf4fe`) the declaration graph, exported from the compiled tree, was read again under this " |
| 34 | "project's rule: a declaration that Treant deleted stays when one of the paper's results reaches it (the files `NavierStokes/PaperResults.lean` " |
| 35 | "imports, `NavierStokes/R3/Theorem.lean`, `NavierStokes/LocalPaperTheorem.lean`), when its docstring cites the paper, or when the text of a " |
| 36 | "declaration that stays names it. 640 of Treant's deletions stay for that; none of them is in this pull request.") |
| 37 | # wave 0: files nothing imports |
| 38 | byfam = collections.defaultdict(list) |
| 39 | for f in plan["whole_files"]: byfam[fam(f)].append(f) |
| 40 | wave0 = [] |
| 41 | for F, files in sorted(byfam.items()): |
| 42 | uid = f"s1-{slug(F)}-files"; d = f"{out}/{uid}"; os.makedirs(d, exist_ok=True) |
| 43 | n = sum(len(lines(f)) for f in files) |
| 44 | title = f"chore({F.rstrip('*')}): delete {len(files)} file{'s' if len(files) != 1 else ''} nothing imports" |
| 45 | json.dump({"id": uid, "wave": 0, "family": F, "issue": ISSUE, "branch": uid, "title": title, "kind": "files", "files": files, "lines": n}, open(f"{d}/unit.json", "w"), indent=1) |
| 46 | open(f"{d}/PR.md", "w").write(f"Part of #{ISSUE} (its first step: the files).\n\nDeletes {len(files)} file{'s' if len(files) != 1 else ''} of the family `{F}`, {n} lines:\n\n" |
| 47 | + "\n".join(f"- `{f}`" for f in files) |
| 48 | + "\n\nHow these were found. Nothing reachable from `NavierStokes/ComparatorSolution.lean`, `NavierStokes/PaperResults.lean` or `Euler/Solution.lean` imports them " |
| 49 | "(the graph of `import` lines on main `5baf4fe`): 61 files in all, the same 61 that Treant's run of 2026-12-03 deleted as dead modules " |
| 50 | "(TitiSkywalker/NavierStokesAndEuler, branch `treant/01-dead_modules`) and that are still on this main.\n\n" |
| 51 | "What it does not show: that every remaining file is needed.\n") |
| 52 | wave0.append(uid) |
| 53 | index.append(wave0) |
| 54 | # waves 1..: declarations |
| 55 | done = collections.defaultdict(set) |
| 56 | for k, w in enumerate(plan["waves"], 1): |
| 57 | ids, after_all = [], collections.defaultdict(set) |
| 58 | for F, items in sorted(w.items()): |
| 59 | uid = f"s1-{slug(F)}-{k}"; d = f"{out}/{uid}"; os.makedirs(d, exist_ok=True) |
| 60 | byfile = collections.defaultdict(list) |
| 61 | for m, a, b, name in items: byfile[m.replace(".", "/") + ".lean"].append((a, b, name)) |
| 62 | patch, removed = [], 0 |
| 63 | for f, rs in sorted(byfile.items()): |
| 64 | drop = cut(f, [(a, b) for a, b, _ in rs]) - done[f] |
| 65 | before, after = content(f, done[f]), content(f, done[f] | drop) |
| 66 | patch += difflib.unified_diff(before.splitlines(keepends=True), after.splitlines(keepends=True), f"a/{f}", f"b/{f}", n=3) |
| 67 | removed += len(drop); after_all[f] |= drop |
| 68 | open(f"{d}/change.patch", "w", encoding="utf-8").write("".join(patch)) |
| 69 | decls = [{"name": re.sub(r"^_private\..*?\.0\.", "", name), "file": f, "lines": [a, b]} for f, rs in sorted(byfile.items()) for a, b, name in sorted(rs)] |
| 70 | title = f"chore({F.rstrip('*')}): delete {len(decls)} declaration{'s' if len(decls) != 1 else ''} nothing uses" |
| 71 | json.dump({"id": uid, "wave": k, "family": F, "issue": ISSUE, "branch": uid, "title": title, "kind": "declarations", "files": sorted(byfile), "lines": removed, "declarations": decls}, |
| 72 | open(f"{d}/unit.json", "w"), indent=1, ensure_ascii=False) |
| 73 | shown = decls if len(decls) <= 60 else decls[:60] |
| 74 | open(f"{d}/PR.md", "w", encoding="utf-8").write(f"Part of #{ISSUE}.\n\nDeletes {len(decls)} declaration{'s' if len(decls) != 1 else ''} of the family `{F}` that nothing uses, {removed} lines in {len(byfile)} file{'s' if len(byfile) != 1 else ''}. " |
| 75 | "No statement and no proof that stays is changed: the diff is deletions only.\n\n" |
| 76 | + "\n".join(f"- `{x['name']}` (`{x['file']}`)" for x in shown) + (f"\n- and {len(decls) - 60} more: the diff lists them\n" if len(decls) > 60 else "\n") |
| 77 | + f"\n{SOURCE}\n\nOrder. In this wave ({k}) every declaration deleted here has no user left on main: what used them went in earlier waves or goes in this same pull request.\n\n" |
| 78 | "What it does not show: that every remaining declaration is needed.\n") |
| 79 | ids.append(uid) |
| 80 | for f, drop in after_all.items(): done[f] |= drop |
| 81 | index.append(ids) |
| 82 | flat = [u for w in index for u in w] |
| 83 | assert len(flat) == len(set(flat)), "two units share a name" |
| 84 | json.dump(index, open(f"{out}/index.json", "w")) |
| 85 | print("units by wave:", [len(x) for x in index], "=", sum(len(x) for x in index)) |
| 86 | # self-check: git apply of every wave's patches, in order, on one tree gives the tree mktree.py makes for that wave |
| 87 | with tempfile.TemporaryDirectory() as tmp: |
| 88 | subprocess.run(f"git -C {site} archive HEAD | tar -x -C {tmp}", shell=True, check=True) |
| 89 | subprocess.run(["git", "init", "-q", tmp], check=True) |
| 90 | for k in range(1, len(index)): |
| 91 | bad = 0 |
| 92 | for uid in index[k]: |
| 93 | r = subprocess.run(["git", "-C", tmp, "apply", "--whitespace=nowarn", os.path.abspath(f"{out}/{uid}/change.patch")], capture_output=True, text=True) |
| 94 | bad += r.returncode != 0 |
| 95 | if r.returncode: print(" does not apply:", uid, r.stderr.strip()[:160]) |
| 96 | diff = n = 0 |
| 97 | if os.path.isdir(f"trees/w{k}"): |
| 98 | for d, _, names in os.walk(f"trees/w{k}"): |
| 99 | for name in names: |
| 100 | if name == "REMOVED": continue |
| 101 | f = os.path.relpath(os.path.join(d, name), f"trees/w{k}"); n += 1 |
| 102 | diff += open(f"{tmp}/{f}", encoding="utf-8").read() != open(f"trees/w{k}/{f}", encoding="utf-8").read() |
| 103 | print(f"self-check, wave {k}: {bad} of {len(index[k])} patches did not apply; {diff} of {n} files differ from mktree's tree" + ("" if n else " (no tree to compare)")) |