#!/usr/bin/env python3 """job 2732 / return #1365's corrected next step -- verdicts for prereg-marginal.md. Reads the pre-registration, hashes it, re-runs the custody gates, cross-checks the fresh recomputation of the |R|=5 class against the rows #1365 served, and evaluates every pre-registered falsifier predicate against the measured rows. Writes a verdict JSON. python verify-prereg.py -> prints the table and job2732/verify-prereg.json """ import glob import hashlib import importlib.util import json import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.dirname(HERE) MOD = os.path.join(HERE, "killer-marginal.py") spec = importlib.util.spec_from_file_location("km", MOD) km = importlib.util.module_from_spec(spec) spec.loader.exec_module(km) out = {"tool": "job2732/verify-prereg.py", "version": "1.0.0", "checks": []} def check(name, ok, detail): out["checks"].append({"check": name, "pass": bool(ok), "detail": detail}) print("%-34s %-5s %s" % (name, "PASS" if ok else "FAIL", detail)) def load(p): with open(p, encoding="utf-8") as fh: return json.load(fh) # ---- V0 custody: the pre-registration hash and the windowed-path gates ------------------- pre = os.path.join(HERE, "prereg-marginal.md") # the server's allowlist rejects a .sha256 extension, so the hash file is served as *.sha256.txt sha = os.path.join(HERE, "prereg-marginal.sha256.txt") if not os.path.exists(sha): sha = os.path.join(HERE, "prereg-marginal.sha256") want = open(sha, encoding="utf-8").read().split()[0] got = hashlib.sha256(open(pre, "rb").read()).hexdigest() check("V0a_prereg_hash", want == got, "sha256 %s" % got[:16]) out["prereg_sha256"] = got gate_rows = [] allgate = True for (B, S, wantk) in km.GATES: L = B for q in S: L *= q b = km.blocked_kstar(B, S, L, 1 << 25) d = km.kstar(B, S) gate_rows.append({"base": B, "R": list(S), "published": wantk, "blocked": b, "direct": d}) allgate = allgate and b == wantk and d == wantk check("V0b_custody_gates_5_of_5", allgate, "windowed path == direct path == published K*") out["gates"] = gate_rows # ---- V0c: fresh |R|=5 recomputation vs the rows #1365 served ----------------------------- r5 = load(os.path.join(HERE, "margin-r5.json")) p30 = load(os.path.join(HERE, "margin-p30030.json")) fresh = r5["fresh_rows_detail"] + p30["fresh_rows_detail"] served = [] for f in km.SERVED_ROWS: p = os.path.join(HERE, f) if os.path.exists(p): for r in load(p)["rows"]: r = dict(r) r["q"] = r["p"] r["source"] = f served.append(r) fresh_key = {(r["P"], tuple(sorted(r["R"])), r["q"]): r for r in fresh} mismatch = [] for r in served: k = (r["P"], tuple(sorted(r["R"])), r["q"]) if k in fresh_key: f = fresh_key[k] if (f["A"], f["K"], f["marginal"]) != (r["A"], r["K"], r["marginal"]): mismatch.append({"served": r, "fresh": f}) check("V0c_fresh_vs_served_1365", not mismatch, "%d overlapping rows, %d mismatches" % (len(fresh_key), len(mismatch))) out["mismatches"] = mismatch # ---- the pre-registered claims ---------------------------------------------------------- allrows = served + fresh def bound(r, name): A, q = r["A"], r["q"] return {"C1": (2 * A) // q, "C2": (2 * A) // q + 1, "C3": q - 1, "C4": A, "C5": 2 * (A // q) + 1}[name] P1 = [r for r in allrows if r["marginal"] < 0] check("P1_marginal_ge_0", not P1, "%d rows, min marginal %d" % (len(allrows), min(r["marginal"] for r in allrows))) P2rows = [r for r in allrows if r.get("rise") is not None] P2 = [r for r in P2rows if r["marginal"] <= r["rise"]] P2_untested = [r for r in fresh if r["P"] == 30030 and r["nR"] == 3] check("P2_strict_chain_marg_ge_rise_plus1", not P2, "%d rows with rise known, %d violations; UNTESTED: %d rows of the P=30030 |R|=3 quadrant" % (len(P2rows), len(P2), len(P2_untested))) out["P2_untested_rows"] = [{"P": r["P"], "q": r["q"], "R": r["R"], "A": r["A"], "Mp": r["Mp"]} for r in P2_untested] r5c = [r for r in fresh if r["P"] == 30] p30c3 = [r for r in fresh if r["P"] == 30030 and r["nR"] == 3] P3a = [r for r in r5c if r["marginal"] >= r["q"]] P3b = [r for r in p30c3 if r["marginal"] >= r["q"]] check("P3_marginal_le_q_minus_1__C_A", not P3a, "|R|=5 class: %d of %d rows violate; worst marginals %s" % (len(P3a), len(r5c), sorted(r["marginal"] for r in P3a))) check("P3_marginal_le_q_minus_1__C_B", not P3b, "P=30030 |R|=3: %d of %d rows violate" % (len(P3b), len(p30c3))) P4 = [r for r in fresh if all(r["marginal"] <= bound(r, n) for n in ("C1", "C2", "C5", "C4"))] check("P4_A_over_q_bounds_false", not P4, "%d fresh rows satisfy ALL of C1,C2,C5,C4 (falsifier would need >=1)" % len(P4)) ratios = [r["marginal"] / float(bound(r, "C5")) for r in fresh] P5 = max(ratios) > 1 check("P5_A_over_q_bounds_violated_hard", P5, "max marginal/(2*floor(A/q)+1) = %.1f" % max(ratios)) # ---- exploratory (NOT pre-registered; discovered from these rows) ------------------------ fam = {} for r in allrows: fam.setdefault((r["P"], tuple(sorted(tuple(r["R"]) + (r["q"],)))), []).append(r) constK = twoA = 0 for k, rs in fam.items(): if len(rs) > 1: if len({r["K"] for r in rs}) == 1: constK += 1 if len({r["A"] for r in rs}) > 1: twoA += 1 # ---- the candidate table, computed ONCE over the combined population (served + all fresh) ---- # The per-class runs each folded their own fresh rows, so their "violations_all" differ by which # class ran; this is the single authoritative table over the same 15,769 rows for every candidate. CANDS = { "C1_floor(2A/q)": lambda r: (2 * r["A"]) // r["q"], "C2_floor(2A/q)+1": lambda r: (2 * r["A"]) // r["q"] + 1, "C3_q-1": lambda r: r["q"] - 1, "C4_A": lambda r: r["A"], "C5_2*floor(A/q)+1": lambda r: 2 * (r["A"] // r["q"]) + 1, } cand_tab = {} for name, f in CANDS.items(): vs = [r for r in served if r["marginal"] > f(r)] vf = [r for r in fresh if r["marginal"] > f(r)] cand_tab[name] = { "violations_served": len(vs), "violations_fresh": len(vf), "violations_all": len(vs) + len(vf), "rows": len(allrows), "worst_excess": max((r["marginal"] - f(r) for r in allrows), default=None), "fresh_example": ({"P": vf[0]["P"], "q": vf[0]["q"], "R": vf[0]["R"], "A": vf[0]["A"], "marginal": vf[0]["marginal"], "bound": f(vf[0])} if vf else None), } out["candidates_combined"] = cand_tab print("\nCANDIDATES over all %d rows (served %d + fresh %d):" % (len(allrows), len(served), len(fresh))) for name in CANDS: c = cand_tab[name] print(" %-20s violations: served %5d + fresh %2d = %5d worst excess %s" % (name, c["violations_served"], c["violations_fresh"], c["violations_all"], c["worst_excess"])) out["histogram_combined"] = {str(v): sum(1 for r in allrows if r["marginal"] == v) for v in sorted({r["marginal"] for r in allrows})} out["rows_combined"] = len(allrows) print(" histogram: %s" % out["histogram_combined"]) out["exploratory"] = { "union_families": len(fam), "families_with_multiple_rows": sum(1 for rs in fam.values() if len(rs) > 1), "families_with_constant_K": constK, "families_with_more_than_one_A": twoA, "max_marginal_all": max(r["marginal"] for r in allrows), "marginal_hist_all": {str(v): sum(1 for r in allrows if r["marginal"] == v) for v in sorted({r["marginal"] for r in allrows})}, } print("EXPLORATORY within each fixed union set {prime set}: K constant in %d of %d " "multi-row families, A takes >1 value in %d" % (constK, len(fam), twoA)) out["all_pass"] = all(c["pass"] for c in out["checks"][:1] + out["checks"][2:6]) with open(os.path.join(HERE, "verify-prereg.json"), "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1) print("\npre-registered claims passing: %d of %d (the two P3 halves are separate claims)" % (sum(1 for c in out["checks"] if c["pass"] and c["check"].startswith("P")), sum(1 for c in out["checks"] if c["check"].startswith("P")))) sys.exit(0)