把黎曼猜想的 Lean 证明,写成人能读懂的证明
把黎曼猜想的 Lean 证明写成数学家能读的证明文章,以及人人能看懂的证明思路
| 1 | """Bounded, offline declaration atlas and chapter-map checks (Python stdlib).""" |
| 2 | import gzip |
| 3 | import hashlib |
| 4 | import json |
| 5 | import re |
| 6 | from pathlib import Path |
| 7 | |
| 8 | MAX_BYTES = 32 * 1024 * 1024 |
| 9 | MAX_EXPANDED = 256 * 1024 * 1024 |
| 10 | NAME = re.compile(r"[^\s{}\\,;]+") |
| 11 | CATEGORIES = {"standard-in-literature", "mechanical", "new", "unclassified"} |
| 12 | TARGETS = ["riemannHypothesis", "riemannZeta_eq_zero_re", "LFunction_ne_zero_of_half_lt_re", |
| 13 | "LFunction_eq_zero_re", "LFunction_eq_zero_re_of_isPrimitive"] |
| 14 | |
| 15 | |
| 16 | def need(ok, message): |
| 17 | if not ok: |
| 18 | raise ValueError(message) |
| 19 | |
| 20 | |
| 21 | def read(path, limit=MAX_BYTES): |
| 22 | need(path.is_file() and path.stat().st_size <= limit, f"{path.name}: missing or exceeds byte limit") |
| 23 | return path.read_bytes() |
| 24 | |
| 25 | |
| 26 | def obj(path): |
| 27 | return json.loads(read(path, 1_000_000)) |
| 28 | |
| 29 | |
| 30 | def atlas(folder): |
| 31 | manifest = folder / "atlas-manifest.json" |
| 32 | if not manifest.exists(): |
| 33 | return None |
| 34 | m = obj(manifest) |
| 35 | name = m.get("file", "") |
| 36 | need(isinstance(name, str) and name in {"atlas.jsonl", "atlas.jsonl.gz"}, "manifest.file must be atlas.jsonl[.gz]") |
| 37 | raw = read(folder / name) |
| 38 | need(hashlib.sha256(raw).hexdigest() == m.get("sha256"), "atlas sha256 mismatch") |
| 39 | rows = {} |
| 40 | # Bounded streaming decompression; never download a route-supplied URL. |
| 41 | import io |
| 42 | stream = gzip.GzipFile(fileobj=io.BytesIO(raw)) if name.endswith('.gz') else io.BytesIO(raw) |
| 43 | total = 0 |
| 44 | with stream: |
| 45 | while True: |
| 46 | line = stream.readline(1_000_001) |
| 47 | if not line: |
| 48 | break |
| 49 | total += len(line) |
| 50 | need(len(line) <= 1_000_000 and total <= MAX_EXPANDED, "atlas exceeds expanded/line limit") |
| 51 | d = json.loads(line) |
| 52 | n = d.get("name") |
| 53 | need(isinstance(n, str) and NAME.fullmatch(n) and n not in rows, "invalid/duplicate atlas declaration") |
| 54 | for k in ("module", "kind", "type"): |
| 55 | need(isinstance(d.get(k), str) and bool(d[k].strip()), f"{n}: missing {k}") |
| 56 | deps = d.get("dependencies") |
| 57 | need(isinstance(deps, list) and all(isinstance(v, str) and NAME.fullmatch(v) for v in deps), f"{n}: invalid dependencies") |
| 58 | need(len(deps) == len(set(deps)), f"{n}: duplicate dependencies") |
| 59 | need(type(d.get("source_lines")) is int and d['source_lines'] >= 0, f"{n}: invalid source_lines") |
| 60 | rows[n] = d |
| 61 | need(bool(rows), "empty atlas") |
| 62 | need(type(m.get('declarations')) is int and m['declarations'] == len(rows), "manifest declaration count mismatch") |
| 63 | return rows |
| 64 | |
| 65 | |
| 66 | def cone(rows, targets): |
| 67 | need(isinstance(targets, list) and bool(targets) and all(isinstance(n, str) and n in rows for n in targets), "unknown cone target") |
| 68 | seen = set() |
| 69 | todo = list(targets) |
| 70 | while todo: |
| 71 | n = todo.pop() |
| 72 | if n in seen: |
| 73 | continue |
| 74 | seen.add(n) |
| 75 | todo.extend(d for d in rows[n]['dependencies'] if d in rows and d not in seen) |
| 76 | return seen |
| 77 | |
| 78 | |
| 79 | def triage(rows, data, example=False): |
| 80 | targets = data.get('targets') |
| 81 | need(example or targets == TARGETS, "cone must target exactly the five headline theorems in SOURCE order") |
| 82 | names = cone(rows, targets) |
| 83 | classes = data.get('classifications') |
| 84 | need(isinstance(classes, dict) and set(classes) == names, "classify every cone declaration exactly once") |
| 85 | need(all(isinstance(c, str) and c in CATEGORIES for c in classes.values()), "unknown triage category") |
| 86 | counts = {c: sum(v == c for v in classes.values()) for c in CATEGORIES} |
| 87 | total = len(names) |
| 88 | need(counts['unclassified'] * 100 < total * 5, "unclassified must be < 5%") |
| 89 | # Conservative rounding: never display 5.0% as < 5%. |
| 90 | pc = lambda c: f"{100 * counts[c] / total:.1f}" |
| 91 | line = (f"cone: {total} decls, {sum(rows[n]['source_lines'] for n in names)} lines; " |
| 92 | f"standard {pc('standard-in-literature')}%, mechanical {pc('mechanical')}%, " |
| 93 | f"new {pc('new')}%, unclassified < 5%") |
| 94 | return names, line |
| 95 | |
| 96 | |
| 97 | def chapters(rows, data, cone_names): |
| 98 | cs = data.get('chapters') |
| 99 | need(isinstance(cs, list) and bool(cs), "chapters must be a nonempty list") |
| 100 | by_id, owner = {}, {} |
| 101 | for c in cs: |
| 102 | ident = c.get('id') |
| 103 | need(isinstance(ident, str) and re.fullmatch(r'[A-Za-z0-9_-]+', ident) and ident not in by_id, "invalid/duplicate chapter id") |
| 104 | need(isinstance(c.get('writer'), str) and bool(c['writer'].strip()), "chapter writer required") |
| 105 | decls, interface = c.get('declarations'), c.get('interface') |
| 106 | need(isinstance(decls, list) and bool(decls) and all(isinstance(n, str) and n in cone_names and n not in owner for n in decls), "chapter has unknown/duplicate declarations") |
| 107 | need(len(decls) == len(set(decls)), "duplicate declaration in chapter") |
| 108 | need(isinstance(interface, list) and bool(interface) and all(isinstance(n, str) and n in decls for n in interface) and len(interface) == len(set(interface)), "invalid chapter interface") |
| 109 | by_id[ident] = c |
| 110 | owner.update({n: ident for n in decls}) |
| 111 | need(set(owner) == cone_names, "chapters must partition the full cone") |
| 112 | edges = {k: set() for k in by_id} |
| 113 | for n, chapter in owner.items(): |
| 114 | for dep in rows[n]['dependencies']: |
| 115 | other = owner.get(dep) |
| 116 | if other and other != chapter: |
| 117 | need(dep in by_id[other]['interface'], f"cross-chapter dependency {dep} missing from interface") |
| 118 | edges[chapter].add(other) |
| 119 | # Iterative topological elimination avoids recursion-depth dependence. |
| 120 | pending = {k: set(v) for k, v in edges.items()} |
| 121 | while pending: |
| 122 | ready = {k for k, v in pending.items() if not v} |
| 123 | need(bool(ready), "chapter dependency graph is cyclic") |
| 124 | pending = {k: v - ready for k, v in pending.items() if k not in ready} |
| 125 | return by_id |