把杨-米尔斯存在性的 Lean 证明,写成人能读懂的证明
把 OpenAI 的杨-米尔斯存在性 Lean 证明(已经过 Gross 评估组认可),写成人能读的证明文章和大众版思路。不涉及质量间隙。
| 1 | """Offline module witness atlas from the pinned review TSVs; standard library only.""" |
| 2 | import argparse |
| 3 | import csv |
| 4 | import hashlib |
| 5 | import json |
| 6 | from collections import Counter |
| 7 | from pathlib import Path |
| 8 | |
| 9 | SOURCE_COMMIT = "3456e5e75cf8d4cd558955a5c7638fba2d68f464" |
| 10 | DECLARATION_SHA256 = "1f16d6cbf7cd650c7edccd08f95967ce92cd7e36ec68cfdd081621aec126c5e9" |
| 11 | MODULE_SHA256 = "f9db49e0d1b7bc8262ecb7f77b18f378db687e9ed87356c42010f560dac265dc" |
| 12 | USED_MODULES = 6523 |
| 13 | HEADLINE_COUNT = 17 |
| 14 | DECLARATION_COUNT = 250319 |
| 15 | USED_DECLARATIONS = 100168 |
| 16 | MAX_TSV_BYTES = 64 * 1024 * 1024 |
| 17 | ROOT = Path(__file__).resolve().parent |
| 18 | SOURCE_URL = f"https://raw.githubusercontent.com/yang-mills-group/OpenAI-YM-20261028/{SOURCE_COMMIT}/verification/" |
| 19 | |
| 20 | |
| 21 | def need(ok, message): |
| 22 | if not ok: |
| 23 | raise ValueError(message) |
| 24 | |
| 25 | |
| 26 | def obj(path): |
| 27 | return json.loads(path.read_text(encoding="utf-8")) |
| 28 | |
| 29 | |
| 30 | def digest(path): |
| 31 | need(path.is_file(), f"{path.name}: missing or not a regular file") |
| 32 | need(path.stat().st_size <= MAX_TSV_BYTES, f"{path.name}: exceeds 64 MiB") |
| 33 | with path.open("rb") as stream: |
| 34 | return hashlib.file_digest(stream, "sha256").hexdigest() |
| 35 | |
| 36 | |
| 37 | def tsv(path, fields): |
| 38 | need(path.stat().st_size <= MAX_TSV_BYTES, "TSV exceeds 64 MiB") |
| 39 | with path.open(encoding="utf-8", newline="") as stream: |
| 40 | reader = csv.DictReader(stream, delimiter="\t") |
| 41 | need(reader.fieldnames == fields, f"{path.name}: unexpected TSV columns") |
| 42 | rows = list(reader) |
| 43 | need(rows and all(None not in r and all(v is not None for v in r.values()) for r in rows), "invalid TSV rows") |
| 44 | return rows |
| 45 | |
| 46 | |
| 47 | def extract(declarations, modules): |
| 48 | rows = tsv(declarations, ["module", "declaration", "status", "headline_witness", "immediate_user", "source_line"]) |
| 49 | summary = tsv(modules, ["module", "declarations", "used", "outside"]) |
| 50 | names, counts, used, headlines = {}, {}, Counter(), [] |
| 51 | for r in rows: |
| 52 | n, m, s = r["declaration"], r["module"], r["status"] |
| 53 | need(n and m and n not in names and s in {"headline", "used", "outside"}, "duplicate/invalid declaration") |
| 54 | need(not r["source_line"] or r["source_line"].isdigit(), f"{n}: invalid source line") |
| 55 | names[n] = r |
| 56 | counts.setdefault(m, Counter())[s] += 1 |
| 57 | if s != "outside": |
| 58 | used[m] += 1 |
| 59 | if s == "headline": |
| 60 | headlines.append(n) |
| 61 | seen = set() |
| 62 | for r in summary: |
| 63 | m = r["module"] |
| 64 | need(m and m not in seen, "module summary missing/duplicate module") |
| 65 | seen.add(m) |
| 66 | c = counts.get(m, Counter()) |
| 67 | need([int(r[k]) for k in ("declarations", "used", "outside")] == |
| 68 | [sum(c.values()), c["used"] + c["headline"], c["outside"]], f"{m}: module totals disagree") |
| 69 | need(set(counts) <= seen, "module summary incomplete") |
| 70 | deps = {m: set() for m in used} |
| 71 | for n, r in names.items(): |
| 72 | if r["status"] == "outside": |
| 73 | continue |
| 74 | need(r["headline_witness"] in headlines, f"{n}: invalid headline witness") |
| 75 | user = r["immediate_user"] |
| 76 | if user: |
| 77 | need(user in names and names[user]["status"] != "outside", f"{n}: invalid immediate user") |
| 78 | dependent = names[user]["module"] |
| 79 | if dependent != r["module"]: |
| 80 | deps[dependent].add(r["module"]) |
| 81 | graph = [{"name": m, "used": used[m], "total": sum(counts[m].values()), |
| 82 | "dependencies": sorted(deps[m])} for m in sorted(used)] |
| 83 | return names, sorted(headlines), graph |
| 84 | |
| 85 | |
| 86 | def write_json(path, value): |
| 87 | path.write_text(json.dumps(value, ensure_ascii=False, indent=2) + "\n", encoding="utf-8", newline="\n") |
| 88 | |
| 89 | |
| 90 | def build(declarations, modules, output): |
| 91 | need(digest(declarations) == DECLARATION_SHA256, "declaration TSV sha256 mismatch (use byte-exact LF export)") |
| 92 | need(digest(modules) == MODULE_SHA256, "module TSV sha256 mismatch (use byte-exact LF export)") |
| 93 | names, headlines, graph = extract(declarations, modules) |
| 94 | need(len(names) == DECLARATION_COUNT and sum(m["used"] for m in graph) == USED_DECLARATIONS, "declaration count mismatch") |
| 95 | need(len(graph) == USED_MODULES and len(headlines) == HEADLINE_COUNT, "module/headline count mismatch") |
| 96 | output.mkdir(parents=True, exist_ok=True) |
| 97 | sources = {key: {"path": str(path.resolve()), "url": SOURCE_URL + path.name, "sha256": digest(path)} |
| 98 | for key, path in [("declarations", declarations), ("modules", modules)]} |
| 99 | # Use canonical names in URLs even if a local download was renamed. |
| 100 | sources["declarations"]["url"] = SOURCE_URL + "declaration-usage.tsv" |
| 101 | sources["modules"]["url"] = SOURCE_URL + "module-usage.tsv" |
| 102 | write_json(output / "atlas.json", {"schema": 1, "source_commit": SOURCE_COMMIT, |
| 103 | "sources": sources, "headlines": headlines, "modules": graph, |
| 104 | "edge_semantics": "immediate_user witness; dependent -> dependency; not exhaustive"}) |
| 105 | dot = ["digraph witness {", ' graph [label="Module dependency witnesses (not exhaustive)"];'] |
| 106 | for m in graph: |
| 107 | dot.append(f' {json.dumps(m["name"])};') |
| 108 | dot.extend(f' {json.dumps(m["name"])} -> {json.dumps(d)};' for d in m["dependencies"]) |
| 109 | (output / "atlas.dot").write_text("\n".join(dot) + "\n", encoding="utf-8", newline="\n") |
| 110 | print(f"atlas: {len(graph)} modules, {len(headlines)} headlines, sha256 ok") |
| 111 | |
| 112 | |
| 113 | def main(): |
| 114 | p = argparse.ArgumentParser(description=__doc__) |
| 115 | p.add_argument("--declarations", required=True, type=Path) |
| 116 | p.add_argument("--modules", required=True, type=Path) |
| 117 | p.add_argument("--output", required=True, type=Path) |
| 118 | a = p.parse_args() |
| 119 | build(a.declarations, a.modules, a.output) |
| 120 | |
| 121 | |
| 122 | if __name__ == "__main__": |
| 123 | try: |
| 124 | main() |
| 125 | except (ValueError, OSError, KeyError, TypeError, UnicodeError) as error: |
| 126 | print(f"Invalid atlas: {error}") |
| 127 | raise SystemExit(1) |