#!/usr/bin/env python3 """T29 gap-value set (and the T5..T23 controls) for the twin-admissible word. Question (pre-registered successor of N-2478-01): the free-translate layer of #161's L(T_x,p) is decided by the tile's gap-VALUE set -- L(T_x,p) >= 2 <=> some gap g of the word satisfies g mod p in {0,2,p-2} (#159's qualify(g,p)) -- so the column is computable from the multiset of differences between consecutive admissible residues. Measure that set at T29 with the constant-memory segmented sieve (gotcha 47), one full period P29 = 2*3*5*...*29, and read off maxgap(T29) and the predicted column for every odd prime. Controls (same code path, same chunking): x = 5,7,11,13,17,19,23 must give D(T_x) = prod_{q<=x, q odd} (q-2) and maxgap = 12,30,42,66,108,150,204 (corrected constructor, P = 2, odd primes only; note N-2478-01). """ import json import sys import numpy as np ODD = [3, 5, 7, 11, 13, 17, 19, 23, 29] CH = 1 << 24 COLUMN_PRIMES = [p for p in range(3, 504, 2) if all(p % d for d in range(3, int(p ** 0.5) + 1, 2))] def word_stats(x): primes = [q for q in ODD if q <= x] P = 2 for q in primes: P *= q d_expected = 1 for q in primes: d_expected *= (q - 2) gapcounts = np.zeros(8192, dtype=np.int64) total = 0 first = None prev = None maxgap = 0 for start in range(0, P, CH): end = min(start + CH, P) ok = np.ones(end - start, dtype=bool) ok[(-start) % 2::2] = False # r odd (the q=2 pair condition, 1 class mod 2) for q in primes: ok[(-start) % q::q] = False # r = 0 (mod q) ok[(q - 2 - start) % q::q] = False # r = -2 (mod q) idx = np.flatnonzero(ok) if idx.size == 0: continue g = idx + start if first is None: first = int(g[0]) d = np.diff(g) else: d = np.diff(np.concatenate((np.array([prev], dtype=np.int64), g))) prev = int(g[-1]) total += int(g.size) if d.size: m = int(d[-1]) if d.size == 1 else int(d.max()) if m > maxgap: maxgap = m bc = np.bincount(d, minlength=1) if bc.size > gapcounts.size: gapcounts = np.concatenate((gapcounts, np.zeros(bc.size - gapcounts.size, dtype=np.int64))) gapcounts[:bc.size] += bc wrap = first + P - prev if wrap > maxgap: maxgap = wrap if gapcounts.size <= wrap: gapcounts = np.concatenate((gapcounts, np.zeros(wrap + 1 - gapcounts.size, dtype=np.int64))) gapcounts[wrap] += 1 gaps = [int(v) for v in np.flatnonzero(gapcounts)] column = {} for p in COLUMN_PRIMES: mods = np.array(gaps) % p column[str(p)] = 2 if bool(np.any((mods == 0) | (mods == 2) | (mods == p - 2))) else 1 return { "x": x, "P": P, "D": total, "D_expected": d_expected, "D_exact": total == d_expected, "maxgap": maxgap, "distinct_gap_values": len(gaps), "gaps": gaps, "gap_counts": {str(v): int(gapcounts[v]) for v in gaps}, "wrap_gap": int(wrap), "column_L2_witness": column, } def main(): out = {"controls": {}, "T29": None} for x, d_exp, mg_exp in [(5, 3, 12), (7, 15, 30), (11, 135, 42), (13, 1485, 66), (17, 22275, 108), (19, 378675, 150), (23, 7952175, 204)]: s = word_stats(x) out["controls"][str(x)] = { "D": s["D"], "D_exact": s["D_exact"], "maxgap": s["maxgap"], "maxgap_expected": mg_exp, "maxgap_ok": s["maxgap"] == mg_exp, "distinct_gap_values": s["distinct_gap_values"], } t29 = word_stats(29) out["T29"] = t29 out["controls_all_ok"] = all(c["D_exact"] and c["maxgap_ok"] for c in out["controls"].values()) with open("job2479-t29gaps.json", "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) fh.write("\n") # stdout: the artifact verbatim (no timings), so the log hash is reproducible print(json.dumps(out, indent=1, sort_keys=True)) if __name__ == "__main__": sys.exit(main())