#!/usr/bin/env python3 # Job #1629 (explore/discovery, lane formalize, no route) -- NEW STATISTIC checks. # # QUESTION (house format): using ONLY the columns the retained census # `research/centered-discrepancy-measurement.json` already stores, does the # companion-removed parity residual # R(j) = D_y(2^j)/2^j + (T1(2^j)/2^j - C2) # stay noise-sized against the census's own four seeded random-sign draws (H0 of # work/job1629/job1629-preregistration.md, sha256 49d95955...), or does the # pre-registered falsifier F* fire (rho(j) > 3 at some j >= 30 AND fitted # slope of log|R| over j >= 30 > 0.544 + 0.15)? # # Inputs : retained census JSON (read-only), pre-registration file (hashed). # Output : job1629-checks.json + a plain table on stdout. No network, no new # arithmetic beyond the stored columns; 0 CPU-hours by design. import json, math, hashlib, sys, os, statistics HERE = os.path.dirname(os.path.abspath(__file__)) CENSUS = sys.argv[1] if len(sys.argv) > 1 else os.path.join( HERE, "..", "..", "replies", "cdm.json.raw") PREREG = os.path.join(HERE, "..", "job1629-preregistration.md") OUT = os.path.join(HERE, "job1629-checks.json") SLOPE_BAND = 0.15 # pre-registered: |lam - 0.544| must not exceed this RHO_T = 3.0 # pre-registered: rho threshold for F* CTRL_SLOPE = 0.544 # census §3 item 3, control slope over j >= 26 RAW_SLOPE = 0.863 # census §3 item 3, log|D_y| slope over j >= 26 JMIN_STAT = 30 # pre-registered: statistic evaluated for j >= 30 def slope(xs, ys): """least-squares slope of ys against xs""" mx, my = sum(xs) / len(xs), sum(ys) / len(ys) num = sum((a - mx) * (b - my) for a, b in zip(xs, ys)) den = sum((a - mx) ** 2 for a in xs) return num / den def main(): d = json.load(open(CENSUS)) C2 = d["config"]["C2"] rows = sorted(d["rows"], key=lambda r: r["j"]) checks, table, other = [], [], [] for r in rows: if r.get("shift", 2) != 2: # The companion removal is defined for the assigned shift 2 only; the stored T1 column # of a shifted row is not that row's companion. Keep it as a diagnostic, not a statistic. sd = [s["D"] for s in r["seeds"]] cr = math.sqrt(sum(v * v for v in sd) / len(sd)) / r["x"] other.append(dict(j=r["j"], shift=r.get("shift"), raw_ratio=abs(r["D"] / r["x"]) / cr)) continue x = r["x"] cD = r["D"] / x # census's raw quantity cT1 = r["T1"] / x - C2 # classical companion's finite-size error Rc = cD + cT1 # NEW statistic (companion-removed) seedD = [s["D"] for s in r["seeds"]] ctrl_rms = math.sqrt(sum(v * v for v in seedD) / len(seedD)) / x rho_R = abs(Rc) / ctrl_rms if ctrl_rms else float("nan") rho_D = abs(cD) / ctrl_rms if ctrl_rms else float("nan") # F**: transcription/algebra check of the retained identity columns ident = (r["S"] - C2 * x) / x - cT1 - r["P"] / x - r["Epp"] / x - r["Eeven"] / x table.append(dict(j=r["j"], x=x, cD=cD, cT1=cT1, rho_R=rho_R, rho_D=rho_D, R=Rc, ctrl_rms=ctrl_rms, ident_res=abs(cD - ident))) checks.append(dict(name="F**: retained identity D/x == (S-C2)/x - cT1 - P/x - Epp/x - Eeven/x", ok=all(t["ident_res"] < 1e-9 for t in table), worst=("%.3e" % max(t["ident_res"] for t in table)))) checks.append(dict(name="pre-registration file present and hashed", ok=os.path.exists(PREREG), sha256=hashlib.sha256(open(PREREG, "rb").read()).hexdigest()[:16])) hi = [t for t in table if t["j"] >= JMIN_STAT] xs = [t["j"] * math.log(2.0) for t in hi] lam = -slope(xs, [math.log(abs(t["R"])) for t in hi]) # log|R| vs log x lam_D = -slope(xs, [math.log(abs(t["cD"])) for t in hi]) # raw statistic, same rows lam_ctrl = -slope(xs, [math.log(t["ctrl_rms"]) for t in hi]) worst_rho = max(hi, key=lambda t: t["rho_R"]) fires_rho = worst_rho["rho_R"] > RHO_T fires_slope = lam > CTRL_SLOPE + SLOPE_BAND checks.append(dict(name="F* part 1: max rho_R over j>=30 > 3.0", ok=not fires_rho, value=round(worst_rho["rho_R"], 4), at_j=worst_rho["j"])) checks.append(dict(name="F* part 2: fitted lam <= 0.544 + 0.15", ok=not fires_slope, value=round(lam, 4), bound=CTRL_SLOPE + SLOPE_BAND)) checks.append(dict(name="H0 confirmed (census §3 item 3/7 stands at retained scales)", ok=not (fires_rho and fires_slope))) # Pre-registered direction: the RAW ratio is the census's own excess reading; the DETRENDED ratio # must be O(1). (First run asserted lam_D > lam_ctrl instead; that expectation was wrong over # j >= 30 and the failing run is kept as job1629-checks.fail1.log.) checks.append(dict(name="raw |D|/ctrl_rms reproduces the census's excess reading (max > 5 over j>=30)", ok=max(t["rho_D"] for t in hi) > 5, value=round(max(t["rho_D"] for t in hi), 3))) checks.append(dict(name="companion-removed rho_R is O(1) (max < 2 over j>=30)", ok=max(t["rho_R"] for t in hi) < 2, value=round(max(t["rho_R"] for t in hi), 3))) checks.append(dict(name="detrended slope matches the control slope within 0.25 (random-sign model)", ok=abs(lam - lam_ctrl) < 0.25, lam_detrended=round(lam, 4), lam_ctrl=round(lam_ctrl, 4))) print("j x D/x T1/x-C2 R=D/x+(T1/x-C2) rho_R |D|/ctrl") for t in table: if t["j"] >= 26: print("%-6d %-13.6g %-13.6e %-14.6e %-16.6e %-8.4f %-8.4f" % (t["j"], t["x"], t["cD"], t["cT1"], t["R"], t["rho_R"], t["rho_D"])) print() print("fitted over j>=%d: lam(R)=%.4f lam(|D|)=%.4f lam(ctrl)=%.4f (band %.2f..%.2f)" % (JMIN_STAT, lam, lam_D, lam_ctrl, CTRL_SLOPE - SLOPE_BAND, CTRL_SLOPE + SLOPE_BAND)) print("F* fires:", bool(fires_rho and fires_slope), " rho trigger:", fires_rho, " slope trigger:", fires_slope) for o in other: print("non-shift-2 diagnostic row: j=%s shift=%s raw|D|/ctrl=%.4f (companion removal not valid here)" % (o["j"], o["shift"], o["raw_ratio"])) for c in checks: print(("PASS " if c["ok"] else "FAIL "), c["name"], {k: v for k, v in c.items() if k not in ("name", "ok")}) json.dump(dict(checks=checks, table=table, other_shift_rows=other, JMIN_STAT=JMIN_STAT, lam=lam, lam_D=lam_D, lam_ctrl=lam_ctrl, F_star=bool(fires_rho and fires_slope), census_note="research/centered-discrepancy-measurement.md", prereg_sha256=hashlib.sha256(open(PREREG, "rb").read()).hexdigest()), open(OUT, "w"), indent=1) print("wrote", OUT) print("PASSED %d/%d" % (sum(1 for c in checks if c["ok"]), len(checks))) if __name__ == "__main__": main()