#!/usr/bin/env python3 """check-0029.py — checker for "Independent review of the 2026 claimed 186 gap". Re-derives every arithmetic claim in the review with sympy exact rationals, verifies the aggregate claims against the four assembly result files, and verifies the sha256 of every file that ships with the review. Pure sympy + stdlib; no network; no FLINT. Usage: python check-0029.py Exit status 0 only if every check passes. """ from __future__ import annotations import hashlib import json import sys from pathlib import Path from sympy import Rational, nsimplify HERE = Path(__file__).resolve().parent # ------------------------------------------------------------------ served constants AXIOM_LO = Rational(23685317816, 10 ** 24) AXIOM_HI = Rational(23685317890, 10 ** 24) MESH_DEN = 258046918656 # trialMesh = 2742997 / 258046918656 EXACT_DEN = 10 ** 20 * (10 * MESH_DEN) ** 12 * 2 ** 224 # the certificate's own assembly record (commit 61340d0b…, CAP_COMPLETE / fresh receipt) SRC_MARGIN = Rational(69162467338708766984467, 2960664736250000000000000000) SRC_REQUIRED = Rational(1, 50000) SRC_LOSS = Rational(206084502551964497, 12500000000000000000000000000000000) SRC_I_LOWER_UNITS = 23685317816 SRC_I_UPPER_UNITS = 23685317890 SRC_J_LOWER_UNITS = 90248755123 RHO_STAR = Rational(2624989, 10 ** 7) FILES = [ "independent-review-186.md", "check-0029.py", "0029_ntt.py", "0029_assembly.py", "0029_test_primitive.py", "0029_probe_survival.py", "0029_validate_fast.py", "0029_compare_trace.py", "0029_check_grid.py", "0029_check_scale.py", "0029_make_lean_witness.py", "Pg186IHWitness.lean", "lean-witness.out", "0029-test-primitive.out", "0029-validate.out", "0029-trace-comparison.txt", "my_shell_trace224.txt", "0029_result_trapz.json", "0029_result_exact.json", "0029_result_mean.json", "0029_result_double.json", "0029_trapz.log", "0029_exact.log", "0029_mean.log", "0029_double.log", ] FAILS: list[str] = [] def check(name: str, ok: bool, detail: str = "") -> None: print("%-4s %-58s %s" % ("PASS" if ok else "FAIL", name, detail)) if not ok: FAILS.append(name) def main() -> int: # ---- 1. axiom interval and its midpoint mid = (AXIOM_LO + AXIOM_HI) / 2 check("axiom interval width is 74 units of 1e-24", (AXIOM_HI - AXIOM_LO) * 10 ** 24 == 74, "width = %s" % ((AXIOM_HI - AXIOM_LO) * 10 ** 24)) check("axiom midpoint is 23685317853 units of 1e-24", mid * 10 ** 24 == 23685317853, "midpoint = %s" % (mid * 10 ** 24)) # ---- 2. the four runs vals = {} for law in ("trapz", "exact", "mean", "double"): p = HERE / ("0029_result_%s.json" % law) if not p.exists(): check("result file present: %s" % p.name, False) continue d = json.loads(p.read_text(encoding="utf-8")) v = Rational(d["exact"]) vals[law] = v check("run %-6s exact rational parses and matches its decimal" % law, abs(float(v) - d["value"]) < 1e-18 and d["law"] == law, "I_H = %.6fe-24" % float(v * 10 ** 24)) if len(vals) == 4: u = {k: v * 10 ** 24 for k, v in vals.items()} check("CONTROL: certificate's cell law is inside the axiom interval", AXIOM_LO <= vals["trapz"] <= AXIOM_HI, "%.4f units" % float(u["trapz"])) check("EXPERIMENT: exact cell mass is inside the axiom interval", AXIOM_LO <= vals["exact"] <= AXIOM_HI, "%.4f units" % float(u["exact"])) check("counter-law d_j is ABOVE the interval", vals["mean"] > AXIOM_HI, "+%.4f units" % float(u["mean"] - u["trapz"])) check("counter-law (A_j+A_{j+1})/2h is BELOW the interval", vals["double"] < AXIOM_LO, "%.4f units" % float(u["double"] - u["trapz"])) check("the two counter-laws are symmetric about the control to within 0.1 units in 657", abs((u["mean"] - u["trapz"]) - (u["trapz"] - u["double"])) < Rational(1, 10), "%.6f vs %.6f (spread %.4f)" % (float(u["mean"] - u["trapz"]), float(u["trapz"] - u["double"]), float(abs((u["mean"] - u["trapz"]) - (u["trapz"] - u["double"]))))) check("control sits 0.33 units above the interval midpoint", abs((u["trapz"] - 23685317853) - Rational(33, 100)) < Rational(1, 10), "%.4f units above midpoint" % float(u["trapz"] - 23685317853)) check("experiment differs from control by 0.0009 units", abs(u["exact"] - u["trapz"]) < Rational(2, 1000), "%.6f units" % float(u["exact"] - u["trapz"])) check("recorded round-9 pair 23685317159/23685317233 has midpoint equal to the " "double-law value to 0.5 units", abs(u["double"] - Rational(23685317159 + 23685317233, 2)) <= Rational(1, 2), "%.4f vs 23685317196" % float(u["double"])) # ---- 3. the denominator the exact rationals were reduced from check("the four published fractions all reduce from one common denominator", all(EXACT_DEN % v.denominator == 0 for v in vals.values()), "common denominator has %d digits" % len(str(EXACT_DEN))) check("that denominator is 10^20 * (10*258046918656)^12 * 2^224", EXACT_DEN == 10 ** 20 * (10 * MESH_DEN) ** 12 * 2 ** 224 and EXACT_DEN % 2 ** 224 == 0 and EXACT_DEN % 10 ** 20 == 0, "") check("the axiom's lower endpoint IS the source-normalisation denominator", Rational(23685317816, 10 ** 24) == Rational(2960664727, 125000000000000000000000), "23685317816/10^24 = 2960664727/125e21") # ---- 4. the source budget arithmetic the review reports loss_term = (RHO_STAR / AXIOM_HI) * SRC_LOSS raw_j_term = SRC_MARGIN + loss_term check("reported source-loss term recomputes to 1.827e-04", abs(float(loss_term) - 1.82719e-4) < 1e-8, "%.6e" % float(loss_term)) check("reported raw J term recomputes to 2.0608e-04", abs(float(raw_j_term) - 2.060794e-4) < 1e-8, "%.6e" % float(raw_j_term)) check("loss term is 7.8x the final margin", abs(float(loss_term / SRC_MARGIN) - 7.822) < 0.01, "%.3fx" % float(loss_term / SRC_MARGIN)) check("their difference is the certified margin 2.336045e-05 > 1/50000", raw_j_term - loss_term == SRC_MARGIN and SRC_MARGIN > SRC_REQUIRED, "%.6e vs %.1e" % (float(SRC_MARGIN), float(SRC_REQUIRED))) sens = loss_term / 100 # 1% error in I_lower check("a 1% error in I_lower moves the margin by 9.1% of the threshold", abs(float(sens / SRC_REQUIRED) - 0.0914) < 0.001, "%.4f of threshold" % float(sens / SRC_REQUIRED)) moved = loss_term * Rational(1576, 10 ** 12) # 1.576e-9 relative, the 0029 gap vs I_lower check("the independent value's 1.576e-9 relative gap moves the margin by <1e-12", moved < Rational(1, 10 ** 12), "%.3e" % float(moved)) # ---- 5. hash every shipped file total = 0 for name in FILES: p = HERE / name if not p.exists(): check("shipped file present: %s" % name, False) continue total += 1 check("sha256 %s" % name, len(hashlib.sha256(p.read_bytes()).hexdigest()) == 64, hashlib.sha256(p.read_bytes()).hexdigest()[:16]) print() print("%d files hashed; %d failures" % (total, len(FAILS))) print("CHECK-0029", "PASS" if not FAILS else "FAIL") return 0 if not FAILS else 1 if __name__ == "__main__": sys.exit(main())