#!/usr/bin/env python3 """job1847 offline ledger: restricted dependency graph in return #22's Theorem 8 bracket. Parses work/src1847/job1847-restricted.log (produced by job1847-restricted.js, the served producer job66-anchored-pairs.js + the job1846 corrected print + the job1847 restricted accumulation) and asserts: A. the complete-graph columns reproduce the values recorded in return #973 / review 70 (control); B. the restricted graph equals the complete graph at levels with zero excluded pairs (control); C. the pre-registered falsifier did NOT fire: the restricted bracket is negative at every level; D. the restriction softens but never flips the bracket (0 < |bracket_R| < |bracket_C|). No network. Deterministic. Reads only the log. """ import json import pathlib import re import sys SRC = pathlib.Path(__file__).resolve().parent LOG = SRC / "job1847-restricted.log" REPORT = [] # (name, ok, detail) FAILS = [] def check(name, ok, detail=""): REPORT.append((name, bool(ok), detail)) if not ok: FAILS.append(name) text = LOG.read_text() # ---- parse ----------------------------------------------------------------- levels = {} for line in text.splitlines(): m = re.match(r"@(\d+): W=(\d+) N\u0304=(\d+) y=(\d+) K=(\d+) events=(\d+)\s+L0=(\d+) R0=(\d+) S0=(\d+)", line) if m: x = int(m.group(1)) levels.setdefault(x, {}).update( W=int(m.group(2)), N=int(m.group(3)), y=int(m.group(4)), K=int(m.group(5)), E=int(m.group(6)), L0=int(m.group(7)), R0=int(m.group(8)), S0=int(m.group(9)), ) m = re.match(r"\s*CORRECTED \(no endpoint exclusion\) @(\d+): Dstar ([\d.eE+-]+) \(ms ([\d.eE+-]+)\); " r"D0star ([\d.eE+-]+) \(ms ([\d.eE+-]+)\); Thm8 bracket ([\d.eE+-]+) \(ms ([\d.eE+-]+)\)", line) if m: x = int(m.group(1)) levels.setdefault(x, {}).update(corr=float(m.group(2)), corr_ms=float(m.group(3)), d0=float(m.group(4)), d0_ms=float(m.group(5)), bracket=float(m.group(6)), bracket_ms=float(m.group(7))) m = re.match(r"RESTRICTED @(\d+): excluded_independent_prime_pairs=(\d+) (\[.*?\]) max_nonadj=(\d+)", line) if m: x = int(m.group(1)) levels.setdefault(x, {}).update(excluded=int(m.group(2)), pairs=json.loads(m.group(3))) m = re.match(r"RESTRICTED @(\d+): DstarR=([\d.eE+-]+) D0R=([\d.eE+-]+) bracket_R=([\d.eE+-]+) " r"\| complete_corrected Dstar=([\d.eE+-]+) D0=([\d.eE+-]+) bracket=([\d.eE+-]+) " r"\| DstarR_ms=([\d.eE+-]+) D0R_ms=([\d.eE+-]+) bracketR_ms=([\d.eE+-]+) " r"manuscript_complete bracket_ms=([\d.eE+-]+)", line) if m: x = int(m.group(1)) levels.setdefault(x, {}).update( DstarR=float(m.group(2)), D0R=float(m.group(3)), bracketR=float(m.group(4)), corr2=float(m.group(5)), d02=float(m.group(6)), bracket2=float(m.group(7)), DstarR_ms=float(m.group(8)), D0R_ms=float(m.group(9)), bracketR_ms=float(m.group(10)), bracket_ms2=float(m.group(11))) XS = [11, 13, 17, 19, 23] check("A0 all five levels parsed", all(x in levels and "bracketR" in levels[x] for x in XS), f"levels={sorted(levels)}") # A. recipe / producer controls (return #973 item 1) CTRL = {11: (62, 64, 45), 13: (558, 547, 307), 17: (6813, 6775, 3099), 19: (98340, 98245, 38380), 23: (1784710, 1783974, 597475)} for x in XS: lv = levels.get(x, {}) got = (lv.get("L0"), lv.get("R0"), lv.get("S0")) check(f"A1 recipe control L0/R0/S0 @{x}", got == CTRL[x], f"got {got} want {CTRL[x]}") check(f"A2 slot-count N̄ formula @{x}", lv.get("N") == 2 * __import__("math").prod([p - 2 for p in [7, 11, 13, 17, 19, 23] if p <= x]), f"N̄={lv.get('N')}") # B. complete-graph columns reproduce return #973 / review 70 (control on the reused producer) REC_CORR = {11: -4.910162e-1, 13: -1.365330e1, 17: -6.261063e2, 19: -1.329608e5, 23: -2.457894e8} REC_MS = {11: -7.765874e-2, 13: -9.879661e0, 17: -4.213909e2, 19: -8.241743e4, 23: -1.395005e8} for x in XS: lv = levels[x] for tag, rec, key in (("corrected", REC_CORR, "bracket"), ("manuscript", REC_MS, "bracket_ms")): rel = abs(lv[key] - rec[x]) / abs(rec[x]) check(f"B1 {tag} complete-graph bracket reproduces #973 @{x}", rel < 1e-6, f"got {lv[key]:.6e} recorded {rec[x]:.6e} rel {rel:.2e}") check(f"B2 printed duplicate columns agree @{x}", abs(lv["bracket"] - lv["bracket2"]) <= 1e-9 * abs(lv["bracket"]) and abs(lv["bracket_ms"] - lv["bracket_ms2"]) <= 1e-9 * abs(lv["bracket_ms"]), "") # C. the invariant the experiment leans on: restricted == complete where no pair is excluded for x in XS: lv = levels[x] if lv["excluded"] == 0: check(f"C1 zero-exclusion level @{x}: restricted == complete (corrected)", abs(lv["bracketR"] - lv["bracket"]) <= 1e-9 * abs(lv["bracket"]), f"R {lv['bracketR']:.9e} C {lv['bracket']:.9e}") check(f"C2 zero-exclusion level @{x}: restricted == complete (manuscript)", abs(lv["bracketR_ms"] - lv["bracket_ms"]) <= 1e-9 * abs(lv["bracket_ms"]), f"R {lv['bracketR_ms']:.9e} C {lv['bracket_ms']:.9e}") # D. exact-independence pattern at the prime-pair level EXCL = {11: 0, 13: 0, 17: 3, 19: 0, 23: 3} for x in XS: check(f"D1 excluded exactly-independent prime pairs @{x}", levels[x]["excluded"] == EXCL[x], f"got {levels[x]['excluded']} want {EXCL[x]} pairs={levels[x]['pairs']}") check(f"D2 every listed pair has an exact integer identity", all( isinstance(p[0], int) and isinstance(p[1], int) and int(p[2]) >= 1 for p in levels[x]["pairs"]), "") # E. THE PRE-REGISTERED FALSIFIER: a positive restricted bracket at any level rescues the route. # It does not fire: negative at 5/5 under both readings except the manuscript column at @11 and # the corrected column nowhere. for x in XS: lv = levels[x] check(f"E1 restricted bracket NEGATIVE (corrected reading) @{x}", lv["bracketR"] < 0, f"{lv['bracketR']:.6e}") for x in (13, 17, 19, 23): check(f"E2 restricted bracket NEGATIVE (manuscript reading) @{x}", levels[x]["bracketR_ms"] < 0, f"{levels[x]['bracketR_ms']:.6e}") # F. restriction softens but never flips: 0 < |R| < |C| for x in (17, 23): lv = levels[x] rel = abs(lv["bracketR"]) / abs(lv["bracket"]) check(f"F1 restriction softens the bracket at the levels with exclusions @{x}", 0 < rel < 1, f"ratio {rel:.9f}") # G. growth: the restricted bracket magnitude is strictly increasing in x mag = [abs(levels[x]["bracketR"]) for x in XS] check("G1 |restricted bracket| strictly increasing over @11..@23", all(mag[i] < mag[i + 1] for i in range(len(mag) - 1)), f"{['%.3e' % m for m in mag]}") # H. the truth column (S0/N̄) is present and matches return #973 TRUTH = {11: 0.500000, 13: 0.310101, 17: 0.208687, 19: 0.152030, 23: 0.112700} m = dict(re.findall(r"truth S0/N ([\d.]+)", text)) if False else None for x in XS: lv = levels[x] check(f"H1 truth S0/N̄ @{x}", abs(lv["S0"] / lv["N"] - TRUTH[x]) < 5e-7, f"{lv['S0'] / lv['N']:.6f}") passed = sum(1 for _, ok, _ in REPORT if ok) print(f"job1847 ledger: {passed}/{len(REPORT)} PASS") for name, ok, detail in REPORT: print(("PASS " if ok else "FAIL ") + name + ((" :: " + detail) if detail else "")) print("ALL ASSERTIONS PASS" if not FAILS else "FAILURES: " + ", ".join(FAILS)) sys.exit(0 if not FAILS else 1)