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 | #!/usr/bin/env python3 |
| 2 | """What each module of a built tree costs to elaborate, in instructions: the measure Treant's reports use |
| 3 | (TitiSkywalker/NavierStokesAndEuler, experiments/treant-perf/det_cost.py, whose method this follows without its package). |
| 4 | Every module of the libraries NavierStokes and Euler is elaborated once more, alone, on one thread and synchronously |
| 5 | (`lean -j1 -DElab.async=false`, with its library's leanOptions) against the tree's own compiled files, under |
| 6 | `perf stat -e instructions:u`. It builds nothing and writes nothing in the tree. A count does not depend on how busy the |
| 7 | machine is, so the runs go side by side. |
| 8 | |
| 9 | python3 meter.py <built tree> <out.tsv> [workers] |
| 10 | |
| 11 | Writes module, file, instructions, seconds, exit code, a row a module; prints the total over the modules that elaborate.""" |
| 12 | import concurrent.futures, os, subprocess, sys, tempfile, time, tomllib |
| 13 | tree, out = sys.argv[1], sys.argv[2] |
| 14 | workers = int(sys.argv[3]) if len(sys.argv) > 3 else os.cpu_count() or 8 |
| 15 | lake = tomllib.load(open(f"{tree}/lakefile.toml", "rb")) |
| 16 | flag = lambda k, v: f"-D{k}={str(v).lower() if isinstance(v, bool) else v}" |
| 17 | common = [flag(k, v) for k, v in (lake.get("leanOptions") or {}).items()] |
| 18 | opts = {l["name"]: common + [flag(k, v) for k, v in (l.get("leanOptions") or {}).items()] for l in lake["lean_lib"]} |
| 19 | env = dict(os.environ, LEAN_PATH=subprocess.run(["lake", "env", "printenv", "LEAN_PATH"], cwd=tree, capture_output=True, text=True, check=True).stdout.strip()) |
| 20 | lean = subprocess.run(["elan", "which", "lean"], cwd=tree, capture_output=True, text=True, check=True).stdout.strip() |
| 21 | files = [] |
| 22 | for lib in ("NavierStokes", "Euler"): |
| 23 | if os.path.exists(f"{tree}/{lib}.lean"): files.append((lib, f"{lib}.lean")) |
| 24 | for d, _, names in os.walk(f"{tree}/{lib}"): |
| 25 | files += [(lib, os.path.relpath(os.path.join(d, n), tree)) for n in names if n.endswith(".lean")] |
| 26 | files.sort(key=lambda x: x[1]) |
| 27 | |
| 28 | |
| 29 | def one(item): |
| 30 | lib, f = item |
| 31 | with tempfile.NamedTemporaryFile(suffix=".perf") as tmp: |
| 32 | t = time.time() |
| 33 | r = subprocess.run(["perf-bin", "stat", "-e", "instructions:u", "-x", ",", "-o", tmp.name, "--", lean, "-j1", "-DElab.async=false", *opts[lib], f], |
| 34 | cwd=tree, env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL) |
| 35 | n = next((int(l.split(",")[0]) for l in open(tmp.name) if "instructions" in l and l.split(",")[0].isdigit()), 0) |
| 36 | return f[:-5].replace("/", "."), f, n, round(time.time() - t, 1), r.returncode |
| 37 | |
| 38 | |
| 39 | start = time.time() |
| 40 | with concurrent.futures.ThreadPoolExecutor(workers) as ex: |
| 41 | rows = list(ex.map(one, files)) |
| 42 | with open(out, "w") as f: |
| 43 | for row in rows: f.write("\t".join(map(str, row)) + "\n") |
| 44 | ok = [r for r in rows if r[4] == 0 and r[2]] |
| 45 | print(f"{len(rows)} modules, total {sum(r[2] for r in ok):.4e} instructions:u over {len(ok)}; {len(rows) - len(ok)} did not elaborate alone: {[r[0] for r in rows if r not in ok][:6]}; {time.time() - start:.0f} s on {workers} workers") |