#!/usr/bin/env python3 """Job #2502 — DECLARED UNREGISTERED FOLLOW-UP (not covered by work/PREREGISTRATION.md). Job #2502's registered statistic found that the whole T23 lag-2 kill excess at p = 29 and p = 31 sits in ONE value pair, (a, b) = (60, 60): n = 14 113 against e = 7 448.115, i.e. +6 664.885 of a +6 705.5 / +6 409.1 total excess (share_3 = 1.0 at both folds, H2 survives); at p = 37 every pair deviates downwards (untestable under the frozen rule). That raises a QUESTION THE REGISTRATION DID NOT ASK, reported here as a follow-up and NOT as a registered result: is the (60,60) two-step excess a RUN effect (consecutive gaps equal to 60) or does it survive with the intermediate gap forced to differ from 60? Measurements (no new hypothesis, no threshold): 1. lag-d self-co-occurrence Q(d) = #{i : g_i = g_{i+d} = 60}, d = 1..8, against the marginal expectation c60 (c60 - 1) / D, plus a declared matched permutation control (M = 50). 2. the maximal-run decomposition of the 60-valued sites: the cyclic run-length histogram and the count of indices inside a run of length >= 3 (each such index contributes g_i = g_{i+2} = 60 without any cross-value structure). 3. the intermediate-gap composition of the (60,60) lag-2 pairs: how many have g_{i+1} = 60, and how many have g_{i+1} != 60, with the marginal expectation for the latter. The builder is imported as in the registered script; no machine-specific path is written to the log. Output: work/src2502/job2502b-mid.log (JSON) + stdout. 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 V60 = 60 LAGS = tuple(range(1, 9)) M_PERM = 50 # declared control size for this follow-up (the registered script used 100) 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) return mod def self_lags(sites, d): """#{i : B[i] and B[i+d]} for a cyclic boolean B.""" return int((sites & np.roll(sites, -d)).sum()) def run_lengths(B): """Cyclic maximal run lengths of True in B, as a histogram, plus the longest run.""" idx = np.flatnonzero(B) if idx.size == 0: return {}, 0, 0 D = int(B.size) if idx.size == D: return {str(D): 1}, D, D brk = np.flatnonzero(np.diff(idx) > 1) if brk.size == 0: return {str(int(idx.size)): 1}, int(idx.size), 1 lens = np.diff(np.append(brk, brk[0] + idx.size)) lens = np.asarray([int(x) for x in lens], dtype=np.int64) vals, cnt = np.unique(lens, return_counts=True) return {str(int(v)): int(c) for v, c in zip(vals, cnt)}, int(lens.max()), int(lens.size) 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]).astype(np.int64) D = int(gaps.size) c60 = int((gaps == V60).sum()) B = gaps == V60 checks = [] checks.append({"id": "A1_period_and_D", "pass": bool(int(gaps.sum()) == P and D == D_T23), "detail": f"sum(gaps)={int(gaps.sum())} P={P} D={D}"}) checks.append({"id": "A2_c60", "pass": c60 == 243_370, "detail": f"c60={c60}"}) marg = c60 * (c60 - 1) / D lags = {} rng = np.random.default_rng(2502) perm = {d: [] for d in LAGS} for _ in range(M_PERM): Pb = rng.permutation(B) for d in LAGS: perm[d].append(self_lags(Pb, d)) for d in LAGS: obs = self_lags(B, d) arr = np.asarray(perm[d], dtype=np.float64) pm, ps = float(arr.mean()), float(arr.std(ddof=1)) lags[str(d)] = {"observed": obs, "marginal_expectation": round(marg, 3), "excess": round(obs - marg, 3), "ratio_to_marginal": round(obs / marg, 6), "perm_mean": round(pm, 3), "perm_sd": round(ps, 3), "z": round((obs - pm) / ps, 3) if ps > 0 else None, "control_mean_rel_err": round(abs(pm - marg) / marg, 5)} hist, longest, nruns = run_lengths(B) inside3 = int(sum(int(v) * n for v, n in hist.items() if int(v) >= 3) - sum(2 * n for v, n in hist.items() if int(v) >= 3)) # indices i with g_i = g_{i+2} = 60 contributed from inside a run of length >= 3 inside_lag2 = int(sum((int(v) - 2) * n for v, n in hist.items() if int(v) >= 3)) ia = np.flatnonzero(B) ib = (ia + 2) % D keep = B[ib] ia2 = ia[keep] mid = gaps[(ia2 + 1) % D] mids = {str(int(v)): int((mid == v).sum()) for v in np.unique(mid)} q_total = int(ia2.size) q_mid60 = int((mid == V60).sum()) # marginal expectation of "a 60 followed two steps later by a 60 with the middle gap != 60" e_mid_other = (c60 * (c60 - 1) / D) * (1.0 - (c60 - 2) / (D - 2)) out = {"job": 2502, "kind": "unregistered follow-up (see docstring; the registered result is in job2502-pairs.log)", "object": "mechanism of the (60,60) two-step excess on the T23 gap word", "builder": {"file": BUILDER_REL, "sha256": builder_sha}, "V60": V60, "c60": c60, "D": D, "marginal_one_pair": round(marg, 3), "run_length_histogram": hist, "longest_run": longest, "n_runs": nruns, "indices_in_runs_ge_3": int(inside3), "lag2_pairs_inside_runs_ge_3": inside_lag2, "Q2_total": q_total, "Q2_from_runs_ge_3": inside_lag2, "Q2_from_cross_value": q_total - inside_lag2, "Q2_cross_value_excess_over_marginal_other": round((q_total - inside_lag2) - e_mid_other, 3), "marginal_expectation_cross_value": round(e_mid_other, 3), "middle_gap_composition": {"mid60": q_mid60, "mid_other": q_total - q_mid60, "all": mids, "n_values": len(mids)}, "self_lags": lags, "M_perms": M_PERM, "checks": checks, "controls_all_pass": bool(all(c["pass"] for c in checks))} with open(HERE.parent / "job2502b-mid.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"], "c60": c60, "longest_run": longest, "n_runs": nruns, "run_length_histogram": hist, "lag2_inside_runs_ge_3": inside_lag2, "lag2_total": q_total, "lag2_cross_value": q_total - inside_lag2, "marginal_cross_value": round(e_mid_other, 3), "middle_gap_composition": {"mid60": q_mid60, "mid_other": q_total - q_mid60, "n_values": len(mids)}, "self_lags": {d: {"obs": lags[str(d)]["observed"], "marg": round(marg, 1), "ratio": lags[str(d)]["ratio_to_marginal"], "z": lags[str(d)]["z"]} for d in LAGS}, "checks": checks}, indent=1, sort_keys=True)) return 0 if out["controls_all_pass"] else 1 if __name__ == "__main__": sys.exit(main())