把杨-米尔斯存在性的 Lean 证明,写成人能读懂的证明
把 OpenAI 的杨-米尔斯存在性 Lean 证明(已经过 Gross 评估组认可),写成人能读的证明文章和大众版思路。不涉及质量间隙。
| 1 | """Check atlas provenance, module partition, chapter anchors and revision-bound reviews.""" |
| 2 | import argparse |
| 3 | import hashlib |
| 4 | import os |
| 5 | import re |
| 6 | from pathlib import Path |
| 7 | from atlas import (SOURCE_COMMIT, SOURCE_URL, DECLARATION_SHA256, MODULE_SHA256, |
| 8 | USED_MODULES, HEADLINE_COUNT, DECLARATION_COUNT, USED_DECLARATIONS, |
| 9 | ROOT, need, obj, digest, extract) |
| 10 | |
| 11 | |
| 12 | def load_atlas(folder): |
| 13 | a = obj(folder / "atlas.json") |
| 14 | example = folder.resolve() == ROOT / "examples" / "atlas" |
| 15 | sources = a["sources"] |
| 16 | need(a["schema"] == 1, "unsupported atlas schema") |
| 17 | if example: |
| 18 | need(a["source_commit"] == "FICTIONAL-EXAMPLE", "example atlas must be explicitly fictional") |
| 19 | print("EXAMPLE ONLY: fictional declarations and reviews; not mathematical evidence") |
| 20 | else: |
| 21 | need(a["source_commit"] == SOURCE_COMMIT, "source commit mismatch") |
| 22 | paths = {} |
| 23 | for key, filename, expected in [("declarations", "declaration-usage.tsv", DECLARATION_SHA256), |
| 24 | ("modules", "module-usage.tsv", MODULE_SHA256)]: |
| 25 | s = sources[key] |
| 26 | paths[key] = folder / s["path"] |
| 27 | if not example: |
| 28 | need(s["sha256"] == expected and s["url"] == SOURCE_URL + filename, f"{key}: provenance mismatch") |
| 29 | need(digest(paths[key]) == s["sha256"], f"{key}: TSV sha256 mismatch") |
| 30 | names, headlines, graph = extract(paths["declarations"], paths["modules"]) |
| 31 | need(a["modules"] == graph and a["headlines"] == headlines, "atlas differs from TSV-derived module coverage/edges/headlines") |
| 32 | if not example: |
| 33 | need(len(graph) == USED_MODULES and len(headlines) == HEADLINE_COUNT, "module/headline count mismatch") |
| 34 | need(len(names) == DECLARATION_COUNT and sum(m["used"] for m in graph) == USED_DECLARATIONS, "declaration count mismatch") |
| 35 | print(f"atlas: {len(graph)} modules, {len(headlines)} headlines, sha256 ok") |
| 36 | return names, headlines, graph, example |
| 37 | |
| 38 | |
| 39 | def partition(data, graph, example): |
| 40 | chapters = data["chapters"] |
| 41 | need(isinstance(chapters, list) and chapters, "chapters must be a nonempty list") |
| 42 | need(example or 20 <= len(chapters) <= 60, "production partition needs 20 to 60 chapters") |
| 43 | by_id, owners = {}, {} |
| 44 | for c in chapters: |
| 45 | k = c["id"] |
| 46 | need(isinstance(k, str) and re.fullmatch(r"[0-9]+", k) and k not in by_id, "invalid/duplicate chapter id") |
| 47 | need(isinstance(c["writer"], str) and c["writer"].strip(), "chapter writer missing") |
| 48 | need(isinstance(c["modules"], list), "chapter modules must be a list") |
| 49 | need(k == "0" or c["modules"], "nonzero chapter needs at least one module") |
| 50 | by_id[k] = c |
| 51 | for m in c["modules"]: |
| 52 | need(isinstance(m, str) and m not in owners, "module assigned more than once") |
| 53 | owners[m] = k |
| 54 | need("0" in by_id, "chapter 0 missing") |
| 55 | need(set(owners) == {m["name"] for m in graph}, "assign every used module exactly once (no missing/extra modules)") |
| 56 | deps = {k: set() for k in by_id} |
| 57 | for m in graph: |
| 58 | k = owners[m["name"]] |
| 59 | deps[k].update(owners[d] for d in m["dependencies"] if owners[d] != k) |
| 60 | # Kahn traversal avoids recursion limits even for unusually deep input. |
| 61 | done = set() |
| 62 | while True: |
| 63 | ready = {k for k in deps if k not in done and deps[k] <= done} |
| 64 | if not ready: |
| 65 | break |
| 66 | done.update(ready) |
| 67 | need(len(done) == len(deps), "chapter dependency cycle") |
| 68 | print(f"chapters: {len(chapters)} chapters, complete partition, acyclic") |
| 69 | return by_id |
| 70 | |
| 71 | |
| 72 | def commands(text, command, tex): |
| 73 | if tex: |
| 74 | text = re.sub(r"(?<!\\)%[^\n]*", "", text) |
| 75 | starts = list(re.finditer(r"\\" + command + r"\b", text)) |
| 76 | matches = list(re.finditer(r"\\" + command + r"\s*\{([^{}]+)\}", text)) |
| 77 | need(len(starts) == len(matches), f"malformed \\{command} command") |
| 78 | values = [m[1].strip() for m in matches] |
| 79 | need(all(v and not re.search(r"[\s{}\\,;]", v) for v in values), f"invalid \\{command} argument") |
| 80 | return values |
| 81 | |
| 82 | |
| 83 | def review(path): |
| 84 | text = path.read_text(encoding="utf-8") |
| 85 | match = re.match(r"\A---\n(.*?)\n---(?:\n|$)", text, re.S) |
| 86 | need(match, f"{path.name}: review needs front matter") |
| 87 | fields = {} |
| 88 | for line in match[1].splitlines(): |
| 89 | need(":" in line, "review needs simple key: value fields") |
| 90 | k, v = [s.strip() for s in line.split(":", 1)] |
| 91 | need(k not in fields and v, "duplicate/empty review field") |
| 92 | fields[k] = v |
| 93 | need(all(fields.get(k) for k in ("reviewer", "chapter", "author", "tex_sha256", "expert")), "review identity/revision missing") |
| 94 | need(fields.get("verdict") in {"approve", "changes"} and fields["expert"] in {"yes", "no"}, "invalid review verdict/expert") |
| 95 | need(fields["reviewer"].casefold() != fields["author"].casefold(), "chapter writer cannot review own work") |
| 96 | return fields |
| 97 | |
| 98 | |
| 99 | def check_route(route, names, headlines, graph, example): |
| 100 | need(route.is_dir(), "route folder does not exist") |
| 101 | chapter_files = {p.stem for p in route.iterdir() if p.is_file() and p.suffix in {".tex", ".md"} and p.stem.isdigit()} |
| 102 | triage = route / "triage.json" |
| 103 | if triage.exists(): |
| 104 | classes = obj(triage) |
| 105 | need(set(classes) == {m["name"] for m in graph}, "triage must cover 100% of modules") |
| 106 | for m, c in classes.items(): |
| 107 | need(c["category"] in {"new", "known", "routine"}, f"{m}: invalid category") |
| 108 | need(c["category"] != "known" or isinstance(c.get("citation"), str) and c["citation"].strip(), f"{m}: known needs citation") |
| 109 | need(isinstance(c.get("routes"), list) and all(r in {f"A{i}" for i in range(1, 9)} for r in c["routes"]), "routes must be A1-A8 labels") |
| 110 | print("triage: 100% modules classified, known citations present") |
| 111 | map_file = route / "chapters.json" |
| 112 | chapters = partition(obj(map_file), graph, example) if map_file.exists() else None |
| 113 | reviews = sorted((route / "reviews").glob("**/*.md")) |
| 114 | need(triage.exists() or chapters is not None or chapter_files, "route has no submitted evidence") |
| 115 | need("0" in chapter_files or not (route / "headlines.json").exists(), "headline statements need a submitted chapter 0") |
| 116 | if not chapter_files: |
| 117 | need(not reviews, "reviews need submitted chapter files") |
| 118 | return # Phase 0: classification and partition can be accepted before prose is written. |
| 119 | need(chapters is not None, "submitted chapter files require chapters.json") |
| 120 | need(chapter_files <= set(chapters), "chapter files and partition ids differ") |
| 121 | files, anchors, labels, uses = {}, {}, set(), set() |
| 122 | for k in sorted(chapter_files, key=int): |
| 123 | candidates = [route / f"{k}{ext}" for ext in (".tex", ".md") if (route / f"{k}{ext}").exists()] |
| 124 | need(len(candidates) == 1, f"chapter {k}: needs exactly one .tex or .md file") |
| 125 | path = candidates[0] |
| 126 | text = path.read_text(encoding="utf-8") |
| 127 | files[k] = path |
| 128 | anchors[k] = set(commands(text, "lean", path.suffix == ".tex")) |
| 129 | need(all(n in names and names[n]["status"] != "outside" for n in anchors[k]), f"chapter {k}: unknown/outside Lean anchors") |
| 130 | local = commands(text, "label", path.suffix == ".tex") |
| 131 | need(len(local) == len(set(local)) and not labels.intersection(local), "duplicate node label") |
| 132 | labels.update(local) |
| 133 | uses.update(commands(text, "uses", path.suffix == ".tex")) |
| 134 | need(not uses - labels, "broken uses nodes: " + ", ".join(sorted(uses - labels))) |
| 135 | if "0" in files: |
| 136 | statements = obj(route / "headlines.json") |
| 137 | need(isinstance(statements, list) and len(statements) == len(headlines), "chapter 0: one statement per headline required") |
| 138 | need({s["declaration"] for s in statements} == set(headlines), "chapter 0: missing/duplicate headline") |
| 139 | for s in statements: |
| 140 | need(isinstance(s.get("statement"), str) and s["statement"].strip(), "chapter 0: mathematical statement missing") |
| 141 | need(s.get("jaffe_witten") in {"done", "not_done", "unclear"}, "chapter 0: invalid jaffe_witten") |
| 142 | need(set(headlines) <= anchors["0"], "chapter 0: every headline needs a Lean anchor") |
| 143 | approved, seen = {k: set() for k in files}, set() |
| 144 | for path in reviews: |
| 145 | r = review(path) |
| 146 | k, reviewer = r["chapter"], r["reviewer"].casefold() |
| 147 | need(k in files and r["author"].casefold() == chapters[k]["writer"].casefold(), "review chapter/author differs from submitted chapters") |
| 148 | need((k, reviewer) not in seen, "duplicate reviewer/chapter") |
| 149 | seen.add((k, reviewer)) |
| 150 | actual = hashlib.sha256(files[k].read_bytes().replace(b"\r\n", b"\n")).hexdigest() |
| 151 | need(r["tex_sha256"] == actual, "stale review: chapter hash differs") |
| 152 | if k == "0": |
| 153 | actual_headlines = hashlib.sha256((route / "headlines.json").read_bytes().replace(b"\r\n", b"\n")).hexdigest() |
| 154 | need(r.get("headlines_sha256") == actual_headlines, "stale review: headline statements hash differs") |
| 155 | need(r["verdict"] == "approve", f"chapter {k}: unresolved changes verdict") |
| 156 | approved[k].add(reviewer) |
| 157 | for k in files: |
| 158 | c = chapters[k] |
| 159 | assigned = {n for n, r in names.items() if r["status"] != "outside" and r["module"] in c["modules"]} |
| 160 | need(len(anchors[k] & assigned) * 100 >= 95 * len(assigned), f"chapter {k}: coverage < 95%") |
| 161 | need(len(approved[k]) >= 2, f"chapter {k}: needs two distinct non-author approving reviewers") |
| 162 | print(f"chapter {k}: not yet expert-reviewed; maintainer must confirm human sign-off") |
| 163 | print(f"chapter {k}: 0 broken anchors, coverage >= 95%") |
| 164 | |
| 165 | |
| 166 | def main(): |
| 167 | p = argparse.ArgumentParser(description=__doc__) |
| 168 | p.add_argument("route", nargs="?", type=Path) |
| 169 | p.add_argument("--atlas", type=Path) |
| 170 | a = p.parse_args() |
| 171 | if a.atlas: |
| 172 | folder = a.atlas.resolve() |
| 173 | elif a.route and a.route.resolve().parent == ROOT / "examples": |
| 174 | folder = ROOT / "examples" / "atlas" |
| 175 | else: |
| 176 | folder = Path(os.environ.get("SS_INPUT", ROOT)) |
| 177 | names, headlines, graph, example = load_atlas(folder) |
| 178 | if a.route: |
| 179 | need(not example or a.route.resolve().parent == ROOT / "examples", "fictional atlas only allowed for bundled examples") |
| 180 | check_route(a.route, names, headlines, graph, example) |
| 181 | |
| 182 | |
| 183 | if __name__ == "__main__": |
| 184 | try: |
| 185 | main() |
| 186 | except (ValueError, OSError, KeyError, TypeError, AttributeError, UnicodeError) as error: |
| 187 | print(f"Invalid blueprint: {error}") |
| 188 | raise SystemExit(1) |