#!/usr/bin/env python3 """job2545-posres.py -- does the KILL MASK see the FOLD's deletion positions? (job #2545, run run_20260919_140312_jWDB1A; general-mode discovery, routeless, lane formalize) QUESTION Every recorded kill statistic is a function of the gap MULTISET (S_1, summed k-decks S_k) or of a LAG between two kills (S_2/adjQ, R, NN, C(h), S(d), the bigram spectrum). None keys on the ABSOLUTE POSITION of a qualifying gap in the period. The Holt-Rudd fold is, however, a POSITIONAL operator: going from the T29 period down to T23 it deletes the slots at position residue 0 and -2 (mod 29). N-2540-01 concluded the remaining open direction is exactly positional. So the one decidable positional question is: Does Q(p) = { i : g_i mod p in {0,2,p-2} } see the fold's deletion residues? STATISTIC (new) Cyclic T_x gap word g_0..g_{D-1}, Q(p), K = |Q|. For a modulus m: P(r) = #{ i in Q(p) : i mod m = r }, r = 0..m-1 chi2(m)= sum_r (P(r) - K/m)^2 / (K/m) Fold-overlap (primary), m = q = the fold prime, S = {0, (m-2) mod m} the deletion residues: F(m) = sum_{r in S} P(r), E = K*|S|/m z_F(m) = (F - E)/sqrt(K * (|S|/m) * (1 - |S|/m)) MATCHED CONTROL Qualifying depends only on the gap VALUE, so a uniform random permutation of the gap multiset maps Q(p) to a uniform random K-subset of Z_D, preserving D and K exactly. Sampled exactly as Multinomial(K, (1/m,...,1/m)), B = 2000, seed 2545. Identity must reproduce P(r). PRE-REGISTERED FALSIFIER (fixed before the run; see ../PREREGISTRATION.md) H_fold (primary p=29, m=q=29): |z_F(29)| < 4. FALSIFIER: |z_F(29)| >= 4. H_pos (scan m in SCAN): every chi2(m) inside the central 99.9% permutation band. FALSIFIER: any chi2(m) outside its band. SCALE T23 (D = 7 952 175), folds p = 29,31,37. Bounded exec; timing to stderr only so stdout is byte-reproducible. """ import sys, time import numpy as np PRIMES = [3, 5, 7, 11, 13, 17, 19, 23, 29] CHUNK = 1 << 24 FOLDS = (29, 31, 37) SCAN = (2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37) B = 2000 SEED = 2545 def gap_word(ps): """Exact T_x gap word over one period W = 2*prod(ps), cyclic (wrap gap included). Reused verbatim from runs/run_20260919_081234_1sLl5w/work/src2461/job2461-cluster.py (also in runs/run_20260919_091355_1qD6eQ/work/src2477/job2477-corr.py).""" W = 2 for q in ps: W *= q expect_D = 1 for q in ps: expect_D *= (q - 2) gaps = []; first_pos = None; prev_last = None; D = 0; G = 0 for start in range(0, W, CHUNK): end = min(start + CHUNK, W); n = end - start ok = np.ones(n, dtype=bool) ok[0::2] = False for q in ps: f = (0 - start) % q if f < n: ok[f::q] = False f = ((q - 2) - start) % q if f < n: ok[f::q] = False pos = start + np.flatnonzero(ok) if pos.size == 0: continue if first_pos is None: first_pos = int(pos[0]) if prev_last is None: g = np.diff(pos) else: g = np.empty(pos.size, dtype=np.int64) g[0] = pos[0] - prev_last g[1:] = np.diff(pos) prev_last = int(pos[-1]); D += g.size gaps.append(g) G = max(G, int(g.max())) wrap = first_pos + W - prev_last gaps.append(np.array([wrap], dtype=np.int64)) G = max(G, wrap); D += 1 word = np.concatenate(gaps) assert word.size == D == expect_D, (word.size, D, expect_D) return word, W, G def mask_of(word, p): m = word % p return (m == 0) | (m == 2) | (m == (p - 2)) def chi2_of(counts, K, m): e = K / m return float((((counts - e) ** 2) / e).sum()) def main(): ps = [q for q in PRIMES if q <= 23] t0 = time.time() word, W, G2 = gap_word(ps) D = word.size print("T23 word: W=%d D=%d G2=%d (published D=7952175 G2=204)" % (W, D, G2)) print("build=%.2fs" % (time.time() - t0), file=sys.stderr) assert D == 7952175 and G2 == 204, (D, G2) m29 = mask_of(word, 29) A1_29 = int((m29 & np.roll(m29, 1)).sum()) print("CONTROL D=%d G2=%d A(1;p=29)=%d (served [5b]=288)" % (D, G2, A1_29)) sys.stdout.flush() rng = np.random.default_rng(SEED) idx = np.arange(D) for p in FOLDS: mask = mask_of(word, p) K = int(mask.sum()) q = min(x for x in (29, 31, 37, 41) if x > 23) # fold prime below: T23 sits under 29 print("\n== fold p=%d K=%d (fold prime q=%d, scan moduli B=%d seed=%d) ==" % (p, K, q, B, SEED)) print(" m chi2_obs null_mean null_q999 null_q001 verdict P(r) max|z_r|") for m in SCAN: r = idx % m P = np.bincount(r[mask], minlength=m).astype(np.int64) assert int(P.sum()) == K c_obs = chi2_of(P, K, m) null_counts = rng.multinomial(K, np.full(m, 1.0 / m), size=B) e = K / m null_chi2 = (((null_counts - e) ** 2) / e).sum(axis=1) q001, q999 = np.percentile(null_chi2, [0.1, 99.9]) verdict = "INSIDE" if q001 <= c_obs <= q999 else ("ABOVE" if c_obs > q999 else "BELOW") sd_r = np.sqrt(e * (1 - 1.0 / m)) maxz = float(np.max(np.abs(P - e))) / sd_r print(" %-4d %-10.3f %-10.1f %-10.1f %-10.1f %-12s %.2f" % (m, c_obs, float(null_chi2.mean()), float(q999), float(q001), verdict, maxz)) if m == q: S = sorted({0, (m - 2) % m}) F = int(sum(P[r] for r in S)) pr = len(S) / m z = (F - K * pr) / np.sqrt(K * pr * (1 - pr)) print(" FOLD-OVERLAP m=q=%d S=%s F=%d E=%.3f z_F=%+.3f (primary; |z_F|>=4 refutes H_fold)" % (m, S, F, K * pr, z)) sys.stdout.flush() t1 = time.time() print("\nwall=%.2fs" % (t1 - t0), file=sys.stderr) if __name__ == "__main__": main()