#!/usr/bin/env python3 """Job #2495 (explore/discovery, lane formalize, routeless) — new-route pilot. ROUTE UNDER TEST. Route 82 (origin return #1025) reports the two-step kill-run count K2(T_x,p) = #{ i : g_i, g_{i+1} both in K }, K = {g : g = +-2 (mod p)}, against a UNIFORM permutation null E[K2] = m(m-1)/(D-1), m = |K|, and finds the ratio Lambda = K2/E strongly below 1 at T23 (0.0385 / 0.0729 / 0.0553 at p = 29/31/37). Its stated uncertainty is the MECHANISM ("the +2/-2 lane alternation plausibly makes long kill runs expensive ... not established"). Job #2493 (return #1190, N-2493-01) then measured an EXCESS of P/M label changes at p = 31 (equal-label pairs Y deficit, z = -56.97), which is the direction that suppresses K2. THE POINT OF THIS PILOT (the route's load-bearing observation). K2 is a LAG-1 statistic. Fit the first-order Markov chain on the label alphabet X/Z/P/M from the observed word itself (transition matrix Q, stationary pi = empirical state frequencies). Then the fitted chain's predicted adjacent-in-K count is M2 = D * sum_a pi(a) * sum_{b in K} Q(a,b) = sum_{a} sum_{b in K} N(a,b) = K2 (EXACT identity), so K2 CANNOT distinguish "first-order residue memory" from "genuine longer-range order" — every first-order model reproduces K2 by construction. The discriminating statistic is therefore the LAG-2 count K3 = #{ i : g_i, g_{i+1}, g_{i+2} all in K }, whose first-order prediction is M3 = D * sum_a pi(a) * (sum_{b in K} Q(a,b)) * (sum_{c in K} Q(b,c)), NOT an identity. This pilot reports K3 and M3 and their ratio. PRE-REGISTERED READING (written before any run, 2026-09-19T09:00Z, this file written first): * If K3/M3 ~ 1, the anti-clustering is a FIRST-ORDER effect: the uniform null is simply the wrong null, route 82's "order argument" is a one-step residue-memory statement, and the cheap repair is to replace E by M2/M3 rather than to seek long-range structure. (This is the interesting and falsifying direction for route 82's framing.) * If K3/M3 is far from 1 (the ratio is the effect size; at D ~ 8e6 a Poisson band is ~1e-6 and statistical significance is trivial, so we judge by ratio, NOT by a sigma), the kill word carries memory beyond one step and route 82's order argument is required, now with a quantitative target (the size of K3/M3 - 1). * Control: the census machine L(T23,p) must reproduce the served 2/3/2 (return #1188, C1), else the word is wrong and nothing is read. Reuses the validated T23 builder of job #2492 / job #2493 (unchanged). Cheap: one pass, no allocation, wall seconds. """ import json import sys import time import numpy as np ODD = [3, 5, 7, 11, 13, 17, 19, 23] CH = 1 << 24 SERVED_T23 = {29: 2, 31: 3, 37: 2} # states: 0 = X, 1 = Z (g = 0), 2 = P (g = +2), 3 = M (g = -2) IN_K = np.array([0, 0, 1, 1]) # K = {P, M}; Z and X are out def t23_word(): P = 2 for q in ODD: P *= q parts = [] for start in range(0, P, CH): end = min(start + CH, P) ok = np.ones(end - start, dtype=bool) ok[(-start) % 2::2] = False for q in ODD: ok[(-start) % q::q] = False ok[(q - 2 - start) % q::q] = False parts.append(np.flatnonzero(ok).astype(np.int64) + start) return np.concatenate(parts), P def gap_word(res, P): g = np.diff(res) return np.append(g, res[0] + P - res[-1]) def machine_L(gaps, p): """Served census L only (return #1188, C1).""" m = gaps % p q = (m == 0) | (m == 2) | (m == p - 2) if bool(q[0]) or not bool(q[-1]): j0 = int(np.flatnonzero(~q)[0]) gaps = np.roll(gaps, -j0) runs = {} l0 = l1 = 1 for gi in gaps.tolist(): r = gi % p if r == 0: l0 += 1 l1 += 1 elif r == 2: runs[l0] = runs.get(l0, 0) + 1 l0, l1 = l1 + 1, 1 elif r == p - 2: runs[l1] = runs.get(l1, 0) + 1 l1, l0 = l0 + 1, 1 else: runs[l0] = runs.get(l0, 0) + 1 runs[l1] = runs.get(l1, 0) + 1 l0 = l1 = 1 return int(max(runs)) def analyse(gaps, p): D = int(gaps.size) m = gaps % p lab = np.zeros(D, dtype=np.int64) lab[m == 0] = 1 lab[m == 2] = 2 lab[m == p - 2] = 3 K = IN_K[lab].astype(bool) mK = int(K.sum()) K2 = int((K[:-1] & K[1:]).sum()) K3 = int((K[:-2] & K[1:-1] & K[2:]).sum()) E2 = mK * (mK - 1) / (D - 1) E3 = mK * (mK - 1) * (mK - 2) / ((D - 1) * (D - 2)) T = np.bincount((lab[:-1] * 4 + lab[1:]), minlength=16).reshape(4, 4).astype(float) rows = T.sum(axis=1, keepdims=True) Q = np.divide(T, rows, out=np.zeros_like(T), where=rows > 0) pi = np.bincount(lab, minlength=4).astype(float) / D # M2 (identity check), M3 (the discriminator); first label restricted to K in both M2 = D * sum(pi[a] * IN_K[a] * float((Q[a] * IN_K).sum()) for a in range(4)) M3 = 0.0 for a in range(4): if not IN_K[a]: continue for b in range(4): if IN_K[b]: M3 += D * pi[a] * Q[a, b] * float((Q[b] * IN_K).sum()) # observed vs first-order conditional follow-through given a K-K pair obs_follow = K3 / K2 if K2 else 0.0 m1_follow = 0.0 if K2: num = 0.0 for a in range(4): for b in range(4): if IN_K[a] and IN_K[b]: num += T[a, b] * float((Q[b] * IN_K).sum()) m1_follow = num / K2 return { "p": int(p), "D": D, "mK": mK, "fracK": mK / D, "K2": K2, "K3": K3, "E2_uniform": E2, "Lambda2": K2 / E2 if E2 else None, "E3_uniform": E3, "Lambda3": K3 / E3 if E3 else None, "M2_first_order": M2, "M3_first_order": M3, "M2_over_K2": (M2 / K2) if K2 else None, "K3_over_M3": (K3 / M3) if M3 else None, "obs_follow_K_given_KK": obs_follow, "m1_follow_given_KK": m1_follow, "follow_ratio": (obs_follow / m1_follow) if m1_follow else None, "state_counts": {s: int(v) for s, v in zip(("X", "Z", "P", "M"), np.bincount(lab, minlength=4))}, } def main(): t0 = time.time() res, P = t23_word() gaps = gap_word(res, P) checks, stats = [], {} checks.append({"id": "A1_gap_sum_is_period", "pass": int(gaps.sum()) == P, "detail": f"sum(gaps)={int(gaps.sum())} period={P}"}) for p in (29, 31, 37): L = machine_L(gaps, p) stats[str(p)] = analyse(gaps, p) checks.append({"id": f"A2_served_L_T23_{p}", "pass": L == SERVED_T23[p], "detail": f"machine L={L} served={SERVED_T23[p]}"}) # A3 the exact identity M2 == K2 (the route's load-bearing observation), all folds ok3 = all(abs(stats[str(p)]["M2_first_order"] - stats[str(p)]["K2"]) < 1e-6 for p in (29, 31, 37)) checks.append({"id": "A3_M2_equals_K2_identity", "pass": bool(ok3), "detail": "first-order fitted chain reproduces K2 at p=29,31,37"}) # A4 the discriminator is reported and finite ok4 = all(stats[str(p)]["M3_first_order"] > 0 and stats[str(p)]["K3_over_M3"] is not None for p in (29, 31, 37)) checks.append({"id": "A4_K3_discriminator_finite", "pass": bool(ok4), "detail": "K3 and M3 present at all three folds"}) # A5 the two independent readings of the follow-through agree in sign of the effect ok5 = all(stats[str(p)]["follow_ratio"] is not None for p in (29, 31, 37)) checks.append({"id": "A5_follow_through_reported", "pass": bool(ok5), "detail": "obs/m1 conditional follow-through present"}) out = {"word": {"period": int(P), "gaps": int(gaps.size), "gap_sum": int(gaps.sum())}, "stats": stats, "checks": checks, "all_pass": all(c["pass"] for c in checks), "wall_s": round(time.time() - t0, 3)} print(json.dumps(out, indent=1, sort_keys=True)) return 0 if out["all_pass"] else 1 if __name__ == "__main__": sys.exit(main())