Riemann hypothesis: the Lean proof, cleaned up together
The 2026 Lean proof of the Riemann hypothesis and GRH, machine-checked by others, not refereed, no word from Clay; cleaned up together: more readable, faster to build, the theorems unchanged

| 1 | #!/usr/bin/env python3 |
| 2 | """Fetch the oleans of the Tau Ceti modules that this project imports. |
| 3 | |
| 4 | Tau Ceti (https://github.com/TauCetiProject/TauCeti) publishes its build outputs in its own |
| 5 | public Lake artifact cache, the service `tauceti-public` of `lakefile.toml`. Neither Mathlib's |
| 6 | cache tool nor this project's cache covers it. This script, run by `lake exe cache get` after |
| 7 | Mathlib's cache and before the project's, does four things: |
| 8 | |
| 9 | 0. checks that `src/Statements.lean`, `src/Main.lean` and `Challenge.lean` import no Tau Ceti |
| 10 | module, so that the five statements keep depending on Mathlib alone; |
| 11 | 1. checks that the Tau Ceti revision pinned in `lake-manifest.json` was built against the Mathlib |
| 12 | commit pinned there, since otherwise none of Tau Ceti's cached oleans match and Lake would |
| 13 | compile every imported Tau Ceti module from source; |
| 14 | 2. downloads Tau Ceti's input-to-output mappings for the pinned revision |
| 15 | (`lake cache get --mappings-only`; about 135 MB the first time); |
| 16 | 3. runs `lake build` on the Tau Ceti modules that `src` needs: those imported anywhere under |
| 17 | `src`, together with every Tau Ceti module they import in turn, publicly or not. Lake restores |
| 18 | a cached module without the modules it imports only privately, but a later |
| 19 | `lake build --no-build` checks those too, so they are fetched explicitly. This downloads and |
| 20 | unpacks exactly the oleans needed, without compiling. |
| 21 | |
| 22 | It only reads from Tau Ceti's cache; it never uploads. It verifies nothing about proofs. |
| 23 | """ |
| 24 | import json |
| 25 | import os |
| 26 | from pathlib import Path |
| 27 | import re |
| 28 | import subprocess |
| 29 | import sys |
| 30 | |
| 31 | ROOT = Path(__file__).resolve().parent.parent |
| 32 | # An import line may end in a comment, such as `-- shake: keep`. |
| 33 | IMPORT = re.compile(r"^\s*(?:(?:public|private|meta)\s+)*import\s+(?:all\s+)?(TauCeti(?:\.[\w']+)+)\s*(?:--.*)?$") |
| 34 | |
| 35 | |
| 36 | def say(message): |
| 37 | print(f"[Tau Ceti cache] {message}", flush=True) |
| 38 | |
| 39 | |
| 40 | def package(manifest, name): |
| 41 | for entry in manifest["packages"]: |
| 42 | if entry["name"] == name: |
| 43 | return entry |
| 44 | raise ValueError(f"{name} is not in {manifest.get('name', 'the')} manifest") |
| 45 | |
| 46 | |
| 47 | def check_mathlib_pin(): |
| 48 | ours = json.loads((ROOT / "lake-manifest.json").read_text()) |
| 49 | tauceti = package(ours, "TauCeti") |
| 50 | theirs_path = ROOT / ".lake" / "packages" / "TauCeti" / "lake-manifest.json" |
| 51 | if not theirs_path.is_file(): |
| 52 | raise ValueError(f"{theirs_path} is missing; run `lake update TauCeti` or `lake build` first") |
| 53 | theirs = json.loads(theirs_path.read_text()) |
| 54 | ours_mathlib, theirs_mathlib = package(ours, "mathlib")["rev"], package(theirs, "mathlib")["rev"] |
| 55 | if ours_mathlib != theirs_mathlib: |
| 56 | raise ValueError( |
| 57 | f"Tau Ceti {tauceti['inputRev']} ({tauceti['rev'][:12]}) was built against Mathlib " |
| 58 | f"{theirs_mathlib[:12]}, but this project pins Mathlib {ours_mathlib[:12]}. Its cached " |
| 59 | "oleans cannot be used; move the two pins together (see CACHE.md).") |
| 60 | say(f"Tau Ceti {tauceti['inputRev']} ({tauceti['rev'][:12]}) uses this project's Mathlib " |
| 61 | f"{ours_mathlib[:12]}") |
| 62 | |
| 63 | |
| 64 | TRUSTED_FILES = ("src/Statements.lean", "src/Main.lean", "Challenge.lean") |
| 65 | |
| 66 | |
| 67 | def check_trusted_files(): |
| 68 | for name in TRUSTED_FILES: |
| 69 | for line in (ROOT / name).read_text(encoding="utf-8").splitlines(): |
| 70 | if IMPORT.match(line): |
| 71 | raise ValueError(f"{name} imports a Tau Ceti module: {line.strip()}") |
| 72 | |
| 73 | |
| 74 | def tauceti_imports(path): |
| 75 | imports = set() |
| 76 | for line in path.read_text(encoding="utf-8").splitlines(): |
| 77 | match = IMPORT.match(line) |
| 78 | if match: |
| 79 | imports.add(match.group(1)) |
| 80 | return imports |
| 81 | |
| 82 | |
| 83 | def imported_modules(): |
| 84 | """The Tau Ceti modules imported under `src`, closed under Tau Ceti's own imports (public, |
| 85 | private and `meta` alike).""" |
| 86 | pending = set() |
| 87 | for path in (ROOT / "src").rglob("*.lean"): |
| 88 | pending |= tauceti_imports(path) |
| 89 | direct = len(pending) |
| 90 | source = ROOT / ".lake" / "packages" / "TauCeti" |
| 91 | modules = set() |
| 92 | while pending: |
| 93 | module = pending.pop() |
| 94 | if module in modules: |
| 95 | continue |
| 96 | modules.add(module) |
| 97 | path = source.joinpath(*module.split(".")).with_suffix(".lean") |
| 98 | if not path.is_file(): |
| 99 | raise ValueError(f"{module} is imported but {path} is missing") |
| 100 | pending |= tauceti_imports(path) - modules |
| 101 | say(f"{direct} Tau Ceti module(s) imported under src, {len(modules)} with their imports") |
| 102 | return sorted(modules) |
| 103 | |
| 104 | |
| 105 | def run_lake(args, env): |
| 106 | return subprocess.run(["lake", *args], cwd=ROOT, env=env).returncode |
| 107 | |
| 108 | |
| 109 | def main(): |
| 110 | check_trusted_files() |
| 111 | check_mathlib_pin() |
| 112 | env = os.environ.copy() |
| 113 | for key in list(env): |
| 114 | # Read-only use of a public cache: never pass upload credentials to Lake. |
| 115 | if key.startswith(("AWS_", "CLOUDFLARE_", "CF_")) or key in ( |
| 116 | "LAKE_CACHE_KEY", "LAKE_CACHE_ARTIFACT_ENDPOINT", "LAKE_CACHE_REVISION_ENDPOINT", |
| 117 | "LAKE_CACHE_SERVICE", "LAKE_ARTIFACT_CACHE"): |
| 118 | env.pop(key) |
| 119 | env["LAKE_CONFIG"] = str(ROOT / "lakefile.toml") |
| 120 | say("fetching Tau Ceti's cache mappings") |
| 121 | code = run_lake(["cache", "get", "--package", "TauCeti", "--service", "tauceti-public", |
| 122 | "--repo", "TauCetiProject/TauCeti", "--mappings-only"], env) |
| 123 | if code: |
| 124 | say("fetching the mappings failed; Lake would compile Tau Ceti modules from source") |
| 125 | return code |
| 126 | modules = imported_modules() |
| 127 | if not modules: |
| 128 | say("no Tau Ceti module is imported under src; nothing more to fetch") |
| 129 | return 0 |
| 130 | say(f"fetching oleans for those {len(modules)} Tau Ceti module(s)") |
| 131 | code = run_lake(["-q", "build", *modules], env) |
| 132 | if code: |
| 133 | say("fetching Tau Ceti oleans failed") |
| 134 | return code |
| 135 | |
| 136 | |
| 137 | if __name__ == "__main__": |
| 138 | try: |
| 139 | sys.exit(main()) |
| 140 | except (ValueError, OSError, KeyError) as error: |
| 141 | sys.exit(f"[Tau Ceti cache] stopped: {error}") |