#!/usr/bin/env python3 """Job #2502 (explore/discovery, routeless, lane formalize) — WHERE in the gap-value alphabet does the lag-2 kill excess live? Statistic, controls and falsifier are frozen in `work/PREREGISTRATION.md` (written before this file was first run; read it first). ONE QUESTION. On the T23 gap word with the kill indicator k_i = [g_i mod p in {0, 2, p-2}] (cyclic), return #1200 measured S(2) - rho^2 D at z = +81.7 / +79.9 / -19.8 for p = 29 / 31 / 37 against a matched permutation control, i.e. the lag-2 structure is real and its SIGN FLIPS with the fold. The kill class is a condition on a FINITE SET of gap values V_p, so the excess decomposes exactly over ordered value pairs E(2) = sum_{(a,b)} ( n(a,b) - e(a,b) ), n(a,b) = #{i : g_i = a, g_{i+2} = b}, e(a,b) = c_a c_b / D (a != b) else c_a (c_a - 1) / D. Is that excess carried by a value-specific subset of V_p x V_p, or is it alphabet-wide? H2 (value-specific) is REFUTED at a fold when share_3 < 0.50, where share_k is the fraction of the total positive deviation carried by the k largest deviations; UNTESTABLE when there is no positive deviation. Frozen before the run. The word builder is IMPORTED from the sibling evidence file `runs/run_20260919_110445_qlJxww/work/src2499/job2499-checks.py` (`t23_word`); its sha256 is recorded in the log instead of any local tree layout, and no machine-specific path is written to the log (the platform refuses to publish those, README gotcha 67). Output: work/src2502/job2502-pairs.log (JSON) + a stdout summary. No timing in the log. """ import hashlib import importlib.util import json import pathlib import sys import time import numpy as np HERE = pathlib.Path(__file__).resolve() BUILDER_REL = "runs/run_20260919_110445_qlJxww/work/src2499/job2499-checks.py" BUILDER = HERE.parents[3] / "run_20260919_110445_qlJxww" / "work" / "src2499" / "job2499-checks.py" D_T23 = 7_952_175 T23_FOLDS = (29, 31, 37) SERVED_K2 = {29: 288, 31: 564, 37: 64} SERVED_LETTERS_31 = {60: 243_370, 126: 4_668, 186: 20} SHARE_CUT = 0.50 # frozen falsifier threshold (H2 refuted below this) TOP_KS = (1, 3, 5) def load_builder(): spec = importlib.util.spec_from_file_location("job2499_checks", BUILDER) mod = importlib.util.module_from_spec(spec) spec.loader.exec_module(mod) # defs only: the module's main() is guarded return mod def kill_indicator(gaps, p): m = gaps % p return (m == 0) | (m == 2) | (m == p - 2) def fold(gaps, p): K = kill_indicator(gaps, p) D = int(K.size) kills = int(K.sum()) rho = kills / D S1 = int((K & np.roll(K, -1)).sum()) S2 = int((K & np.roll(K, -2)).sum()) K2 = int((K[:-1] & K[1:]).sum()) K3 = int((K[:-2] & K[1:-1] & K[2:]).sum()) # the finite kill-value alphabet at this fold, read off the word itself kill_pos = np.flatnonzero(K) vpos = np.flatnonzero(np.isin(np.arange(D), kill_pos)) # placeholder, replaced below del vpos kill_vals = np.unique(gaps[K]) codes = {int(v): i for i, v in enumerate(kill_vals)} c = np.array([int((gaps == v).sum()) for v in kill_vals], dtype=np.int64) # ordered lag-2 pairs (a, b) among kill sites only ia = kill_pos ib = (ia + 2) % D keep = K[ib] ia, ib = ia[keep], ib[keep] ca = np.array([codes[int(v)] for v in gaps[ia]], dtype=np.int64) cb = np.array([codes[int(v)] for v in gaps[ib]], dtype=np.int64) n = np.zeros((kill_vals.size, kill_vals.size), dtype=np.int64) np.add.at(n, (ca, cb), 1) idx = np.arange(kill_vals.size) e = np.outer(c, c).astype(np.float64) / D for i in range(kill_vals.size): # a = b is without replacement e[i, i] = c[i] * (c[i] - 1) / D dev = n - e pos = float(dev[dev > 0].sum()) order = np.argsort(dev, axis=None)[::-1] shares = {} for k in TOP_KS: top = float(dev.flat[order[:k]].sum()) shares[str(k)] = round(top / pos, 6) if pos > 0 else None # conditional kill rate after two steps, per kill value a h = {} for a, i in codes.items(): sel = ca == i h[str(a)] = {"c_a": int(c[i]), "pairs": int(sel.sum()), "h": round(float(n[i].sum()) / c[i], 9) if c[i] else None, "e_h": round(float(e[i].sum()) / c[i], 9) if c[i] else None} pairs = [{"a": int(kill_vals[i // kill_vals.size]), "b": int(kill_vals[i % kill_vals.size]), "n": int(n.flat[i]), "e": round(float(e.flat[i]), 3), "dev": round(float(dev.flat[i]), 3)} for i in order[:8]] return {"p": int(p), "D": D, "kills": kills, "rho": rho, "S1": S1, "S2": S2, "K2": K2, "K3": K3, "V_p": [int(v) for v in kill_vals], "c_a": {str(int(kill_vals[i])): int(c[i]) for i in range(c.size)}, "partition_sum_n": int(n.sum()), "marginal_null_sum_e": round(float(e.sum()), 3), "rho2D": round(rho * rho * D, 3), "E2": round(S2 - rho * rho * D, 3), "pos_deviation": round(pos, 3), "share_topk": shares, "share_topk_of_E2": {str(k): (round(float(dev.flat[order[:k]].sum()) / abs(S2 - rho * rho * D), 6) if S2 - rho * rho * D != 0 else None) for k in TOP_KS}, "top_pairs": pairs, "conditional_h": h, "letter_counts": {str(int(v)): int((gaps == v).sum()) for v in kill_vals}} def main(): t0 = time.time() mod = load_builder() builder_sha = hashlib.sha256(BUILDER.read_bytes()).hexdigest() res, P = mod.t23_word() gaps = np.append(np.diff(res), res[0] + P - res[-1]) gaps = gaps.astype(np.int64) checks = [] checks.append({"id": "A1_period_and_D", "pass": bool(int(gaps.sum()) == P and int(gaps.size) == D_T23), "detail": f"sum(gaps)={int(gaps.sum())} P={P} D={int(gaps.size)} expected={D_T23}"}) folds = {p: fold(gaps, p) for p in T23_FOLDS} checks.append({"id": "A2_K2_K3_reproduce_1195", "pass": all(folds[p]["K2"] == SERVED_K2[p] and folds[p]["K3"] == 0 for p in T23_FOLDS), "detail": f"K2={ {p: folds[p]['K2'] for p in T23_FOLDS} } K3={ {p: folds[p]['K3'] for p in T23_FOLDS} }"}) checks.append({"id": "A3_letter_counts_p31", "pass": folds[31]["letter_counts"] == {str(k): v for k, v in SERVED_LETTERS_31.items()}, "detail": f"{folds[31]['letter_counts']}"}) checks.append({"id": "B1_S1_is_K2", "pass": all(folds[p]["S1"] == folds[p]["K2"] for p in T23_FOLDS), "detail": "the lag-1 term is exactly the retained census K2"}) checks.append({"id": "B2_pair_partition_exact", "pass": all(folds[p]["partition_sum_n"] == folds[p]["S2"] for p in T23_FOLDS), "detail": "sum over ordered value pairs of n(a,b) equals S(2) at every fold"}) checks.append({"id": "B3_marginal_null_matches_rho2D", "pass": all(abs(folds[p]["marginal_null_sum_e"] - folds[p]["rho2D"]) / folds[p]["rho2D"] < 0.01 for p in T23_FOLDS), "detail": "sum of the analytic pair means is within 1% of rho^2 D at every fold"}) verdict = {} for p in T23_FOLDS: f = folds[p] if f["pos_deviation"] <= 0: verdict[str(p)] = "untestable (no positive deviation)" elif f["share_topk"]["3"] >= SHARE_CUT: verdict[str(p)] = f"H2 survives: share_3={f['share_topk']['3']}" else: verdict[str(p)] = f"H2 REFUTED: share_3={f['share_topk']['3']} < {SHARE_CUT}" out = {"job": 2502, "object": "value-pair decomposition of the T23 lag-2 kill excess E(2)", "builder": {"file": BUILDER_REL, "sha256": builder_sha}, "preregistration": "work/PREREGISTRATION.md", "share_cut": SHARE_CUT, "top_ks": list(TOP_KS), "folds": {str(p): folds[p] for p in T23_FOLDS}, "H2_verdict": verdict, "checks": checks, "controls_all_pass": bool(all(c["pass"] for c in checks))} with open(HERE.parent / "job2502-pairs.log", "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) fh.write("\n") # timing goes to STDERR: stdout is the artifact and must reproduce byte for byte elsewhere print("wall_s=%.3f" % (time.time() - t0), file=sys.stderr) print(json.dumps({"controls_all_pass": out["controls_all_pass"], "H2_verdict": verdict, "table": {p: {"V_p": folds[p]["V_p"], "kills": folds[p]["kills"], "S2": folds[p]["S2"], "E2": folds[p]["E2"], "c_a": folds[p]["c_a"], "share": folds[p]["share_topk"], "top_pairs": folds[p]["top_pairs"][:4]} for p in T23_FOLDS}, "checks": checks}, indent=1, sort_keys=True)) return 0 if out["controls_all_pass"] else 1 if __name__ == "__main__": sys.exit(main())