#!/usr/bin/env python3 """check.py — independent re-check of job #4139's finite claims (route 97 pursuit). Stdlib only. Re-derives the model from first principles at n = 7 (brute force over the full CRT period), re-runs the shipped engine on published rows (sequential AND the parallel decomposition), re-computes every cut/rate in ladder4139.json, re-checks the falsifier verdicts and the n = 25 re-pricing in evidence4139.json, and screens the report for the numbers it must carry. Usage: python check.py [--out check.out] Exit 0 only if every check passes; each line is PASS or FAIL. """ import argparse import hashlib import json import os import subprocess import sys HERE = os.path.dirname(os.path.abspath(__file__)) EXPECT_SHA = { "dfs97.py": "13ada477c2baa6318287ff37f504147366048e1fdf4e5aa2c49d826997644bd0", "route97-prune-ladder.json": "ee21b5a4258abb5cf00665862323262ae1e8682111c0c2c5ad56ae3d50c14121", } PUBLISHED = {7: 107, 8: 149, 9: 203, 10: 257, 11: 347, 12: 527, 13: 545, 14: 617, 15: 707} VAL_NODES = {(7, "cap"): 512, (7, "hunter"): 300, (8, "cap"): 1944, (8, "hunter"): 928, (9, "cap"): 5235, (9, "hunter"): 2568, (10, "cap"): 30873, (10, "hunter"): 14755, (11, "cap"): 111527, (11, "hunter"): 52854, (12, "cap"): 230923, (12, "hunter"): 90439, (13, "cap"): 1285505, (13, "hunter"): 427609, (14, "cap"): 9115262} N = 0 B = 0 LINES = [] def check(name, ok, detail=""): global N, B N += 1 if ok: B += 1 line = "%s %s%s" % ("PASS" if ok else "FAIL", name, (" -- " + detail) if detail else "") print(line) LINES.append(line) return ok def sha(path): with open(path, "rb") as fh: return hashlib.sha256(fh.read()).hexdigest() def load(name): with open(os.path.join(HERE, name), encoding="utf-8") as fh: return json.load(fh) def brute_R(n): """independent model check: longest all-killed prefix of block indices over the period. Hard-wired to the n = 7 case (primes 5..17, P = 85085) on purpose: it is an independent route to a(7) = 107 that shares no code with inc97.py. """ assert n == 7 primes = [5, 7, 11, 13, 17] P = 1 for p in primes: P *= p invs = [pow(6, -1, p) for p in primes] best = 0 for s in range(P): # longest prefix of killed positions 0,1,2,... t = 0 while True: killed = any((t + s) % p in (a, p - a) for p, a in zip(primes, invs)) if not killed: break t += 1 if t > best: best = t if s % 5000 == 0 and best >= 17: pass return best, P def run_engine(args): p = subprocess.run([sys.executable, os.path.join(HERE, "inc97.py")] + args, cwd=HERE, capture_output=True, encoding="utf-8", errors="replace", timeout=900) if p.returncode != 0: raise RuntimeError("inc97.py %s failed: %s" % (args, (p.stdout + p.stderr)[-400:])) return json.loads(p.stdout) def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default="check.out") a = ap.parse_args() # 1. pinned inputs for name, want in EXPECT_SHA.items(): p = os.path.join(HERE, name) check("input %s sha256" % name, os.path.isfile(p) and sha(p) == want) for name in ("inc97.py", "PREREG-4139.md", "ladder4139.json", "evidence4139.json", "validate-inc97.json", "route-97.json"): check("present %s" % name, os.path.isfile(os.path.join(HERE, name))) # 2. PREREG carries its falsifiers (written before any run) prereg = open(os.path.join(HERE, "PREREG-4139.md"), encoding="utf-8").read() for needle in ("F1", "F2", "F3", "F4", "Voiding condition", "PREREG-4139"): check("PREREG-4139.md records %r" % needle, needle in prereg) # 3. independent model derivation at n = 7 (brute force over P = 85085) R7, P7 = brute_R(7) check("brute force n=7: P=85085, R=17, a=107", P7 == 85085 and R7 == 17, "P=%d R=%d a=%d" % (P7, R7, 6 * R7 + 5)) # 4. served baseline ladder still says what it said base = load("route97-prune-ladder.json") brow = {r["n"]: r for r in base["rows"]} check("baseline ladder n=13 row", brow[13]["cap_nodes"] == 1285505 and brow[13]["hunter_nodes"] == 427609 and brow[13]["R"] == 90) check("baseline ladder n=14 cap row", brow[14]["cap_nodes"] == 9115262 and brow[14]["R"] == 102) # 5. engine reproduces published rows (sequential path), small n for n, prune, want in ((9, "cap", 5235), (9, "hunter", 2568), (11, "cap", 111527), (11, "hunter", 52854)): got = run_engine(["--single", str(n), prune]) check("sequential n=%d %s nodes=%d" % (n, prune, want), got["nodes"] == want and got["a"] == PUBLISHED[n], "engine=%d a=%d" % (got["nodes"], got["a"])) # 6. parallel decomposition equals the sequential/published count (n = 10, both prunes) for prune, want in (("cap", 30873), ("hunter", 14755)): got = run_engine(["--row", "10", prune, "--jobs", "4"]) check("parallel n=10 %s nodes=%d" % (prune, want), got["nodes"] == want, "engine=%d" % got["nodes"]) # 7. the shipped ladder: published rows, monotonic R, cut arithmetic lad = load("ladder4139.json") rows = {(r["n"], k): r[k] for r in lad["rows"] for k in ("cap", "hunter") if r[k] and not r[k].get("missing")} for (n, prune), rec in sorted(rows.items()): if (n, prune) in VAL_NODES: check("ladder n=%d %s matches the served value" % (n, prune), rec["nodes"] == VAL_NODES[(n, prune)] and rec["a"] == PUBLISHED[n], "%d/%d" % (rec["nodes"], VAL_NODES[(n, prune)])) elif n == 14 and prune == "hunter": check("ladder n=14 hunter reproduces the published term a(14)=617", rec["a"] == 617 and rec["R"] == 102, "a=%s R=%s" % (rec["a"], rec["R"])) elif n == 15 and prune == "cap": check("ladder n=15 capacity reproduces the published term a(15)=707", rec["a"] == 707 and rec["R"] == 117, "a=%s R=%s" % (rec["a"], rec["R"])) rs = {n: r["cap"]["R"] for n, r in ((r["n"], r) for r in lad["rows"]) if r["cap"] and not r["cap"].get("missing")} check("R is non-decreasing in n on the shipped ladder", all(rs[a] <= rs[b] for a, b in zip(sorted(rs), sorted(rs)[1:]))) for r in lad["rows"]: cap, hun = r.get("cap"), r.get("hunter") if cap and hun and not cap.get("missing") and not hun.get("missing"): cut = 1.0 - hun["nodes"] / cap["nodes"] check("cut n=%d recomputes (%.4f)" % (r["n"], cut), r.get("cut") is not None and abs(r["cut"] - cut) < 1e-12) # 8. evidence: falsifiers and the n = 25 re-pricing, recomputed from the ladder ev = load("evidence4139.json") n14 = rows.get((14, "cap")) n14h = rows.get((14, "hunter")) n15h = rows.get((15, "hunter")) n15c = rows.get((15, "cap")) f1 = ev.get("falsifiers", {}).get("F1", {}) if n15h and n15c: cut15 = 1.0 - n15h["nodes"] / n15c["nodes"] check("F1 verdict matches the n=15 cut", bool(f1.get("fired")) == (cut15 < 0.20), "cut15=%.4f fired=%s" % (cut15, f1.get("fired"))) else: check("F1 verdict recorded as not fired on unmeasured rows", f1.get("fired") is False and "n = 15" in str(f1.get("detail", ""))) pricing = ev.get("n25_pricing", {}) if n15c and n14: g = n15c["nodes"] / n14["nodes"] per_level = pricing.get("growth_cap_nodes") check("n=25 pricing growth factor recomputes", per_level and abs(per_level - g) / g < 0.05, "recomputed %.3f vs recorded %s" % (g, per_level)) rate = pricing.get("cap_nodes_per_s") if rate: projected = n15c["nodes"] * g ** 10 secs = projected / rate check("n=25 projected wall recomputes", abs(pricing.get("projected_cpu_seconds", 0) / secs - 1) < 0.5, "recomputed %.3g s vs recorded %.3g s" % (secs, pricing.get("projected_cpu_seconds", 0))) # 9. the report carries its own numbers rep = open(os.path.join(HERE, "report.md"), encoding="utf-8").read() for needle in ("PREREG-4139.md", "inc97.py", "check.py", "13ada477", "route97-prune-ladder.json"): check("report.md carries %r" % needle, needle in rep) if n15h and n15c: check("report.md states the n=15 cut", ("%.1f" % (100 * (1 - n15h["nodes"] / n15c["nodes"]))) in rep) if n14h: check("report.md states the n=14 Hunter node count", str(n14h["nodes"]) in rep) summary = "%d checks, %d FAIL" % (N, N - B) print(summary) LINES.append(summary) if a.out: with open(os.path.join(HERE, a.out), "w", encoding="utf-8", newline="\n") as fh: fh.write("\n".join(LINES) + "\n") return 0 if B == N else 1 if __name__ == "__main__": sys.exit(main())