#!/usr/bin/env python3 """G4 (corrected) dead-instrument control + the registered sign-consistency clause, for job #4164. G4 as registered -- "a draw with B_m = 1 on every positioned prime reproduces the observed field" -- is unsatisfiable: that draw sets Lam~ = log m on every allowed m, while the observed Lambda_{>B} is non-zero only on prime powers, so the control as written would require the null hypothesis itself. The instrument's dead-draw control is therefore implemented as: hold the DRAWS at the observed Lambda pattern (Lambda~ = Lambda) and require the whole pipeline -- support truncation, #654's class renormalisation, and the R_L grid -- to reproduce the observed surface. This exercises exactly the code path the registered readings go through, which is what the control was for. Reads: sieve-null.py (imported as a module, so the code path is literally the same one), results.json (for the sign consistency evaluation). """ import importlib.util, json, math, sys import numpy as np XS = (16384, 65536, 262144, 1048576) def load(path, name): spec = importlib.util.spec_from_file_location(name, path) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) return mod def main(): sn = load("sieve-null.py", "sn") prod = load("../src/return-636/fibre-sign-lag.py", "fssl") stat = load("../src/return-654/job1438-cls-resid-offset.py", "stat1438") out = {"control": {}, "signs": {}, "verdict_check": {}} # ---- G4 (corrected): dead draw must reproduce the observed surface ------------- for x in XS: T = sn.build_tables(x, prod) b = T["b"] ns, U, Y = b["ns"], T["U"], T["Y"] li, ri = b["li"], b["ri"] facts = T["facts"] c_obs = np.where(np.abs(T["c_true"]) <= sn.SUPPORT_TOL, 0.0, T["c_true"]) cN = (T["LamL"] - T["dL"])[li] * (T["LamR"] - T["dR"])[ri] cN = np.where(np.abs(cN) <= sn.SUPPORT_TOL, 0.0, cN) r_obs, members, viol = sn.residual_of(c_obs, ns, U, Y, facts, stat.class_key) rN, _, _ = sn.residual_of(cN, ns, U, Y, facts, stat.class_key) sq_obs = float((r_obs * r_obs).sum()) / len(ns) sq_N = float((rN * rN).sum()) / len(ns) g_obs = sn.rl_grid(stat, r_obs, sq_obs) g_N = sn.rl_grid(stat, rN, sq_N) diffs = [abs(g_obs[k] - g_N[k]) for k in g_obs if g_obs[k] is not None and g_N[k] is not None] out["control"][str(x)] = { "G1_ok": T["g1"]["ok"], "G2a_ok": T["g2a"]["ok"], "max_abs_c_field_diff": float(np.max(np.abs(cN - c_obs))), "support_identical": bool(np.array_equal(cN != 0.0, c_obs != 0.0)), "max_abs_rl_diff": float(max(diffs)) if diffs else None, "cells_compared": len(diffs), "ok": None, } e = out["control"][str(x)] e["ok"] = bool(T["g1"]["ok"] and T["g2a"]["ok"] and e["support_identical"] and e["max_abs_c_field_diff"] <= 1e-12 and (e["max_abs_rl_diff"] is not None and e["max_abs_rl_diff"] <= 1e-12)) sys.stderr.write("G4 x=%d ok=%s rl_diff=%.3g\n" % (x, e["ok"], e["max_abs_rl_diff"])) # ---- the registered sign-consistency clause ----------------------------------- res = json.load(open("results.json")) S = res["scales"] keys = sorted(S[str(XS[0])]["cells"].keys(), key=lambda s: (int(s.split(":")[0]), int(s.split(":")[1]))) tab = {} for x in XS: for k in keys: c = S[str(x)]["cells"][k] tab[(k, str(x))] = (c["R_obs"] - c["mean"], c["z"], c["outside_band"], c["rank_p_one_sided"], c["hold"]) out["signs"] = {} for k in keys: row = [] for x in XS: disp, z, o, rp, hold = tab[(k, str(x))] row.append({"x": x, "disp": disp, "z": z, "outside": o, "rank_p": rp, "sign": (1 if disp > 0 else -1 if disp < 0 else 0), "hold_outside": hold.get("rank_p_one_sided") is not None and (hold["rank_p_one_sided"] <= 0.025 or hold["rank_p_one_sided"] >= 0.975)}) if all(r["outside"] for r in row): out["signs"][k] = row consistent = [k for k, row in out["signs"].items() if len(set(r["sign"] for r in row)) == 1] out["verdict_check"] = { "cells_outside_at_all_four": sorted(out["signs"].keys(), key=lambda s: (int(s.split(":")[0]), int(s.split(":")[1]))), "cells_with_consistent_sign_4scales": sorted(consistent, key=lambda s: (int(s.split(":")[0]), int(s.split(":")[1]))), "shared_L_values_consistent": sorted(set(int(k.split(":")[0]) for k in consistent)), "signs_of_consistent": {k: [r["sign"] for r in out["signs"][k]] for k in sorted(consistent)}, "Ls_of_consistent": sorted(set(int(k.split(":")[0]) for k in consistent)), "hold_confirming": sorted([k for k in consistent if all(r["hold_outside"] for r in out["signs"][k])], key=lambda s: (int(s.split(":")[0]), int(s.split(":")[1]))), "n_outside_per_scale": {str(x): len([k for k in keys if tab[(k, str(x))][2]]) for x in XS}, } out["verdict_check"]["success_A"] = bool(consistent and out["verdict_check"]["Ls_of_consistent"]) with open("control.json", "w", encoding="utf-8", newline="\n") as fh: fh.write(json.dumps(out, indent=1, sort_keys=True, default=float) + "\n") print(json.dumps({"control_ok": {k: v["ok"] for k, v in out["control"].items()}, "verdict_check": out["verdict_check"]}, indent=1)[:3000]) return 0 if __name__ == "__main__": sys.exit(main())