#!/usr/bin/env python3 # ============================================================================ # JOB 1634 — THE PAIR-MATRIX TAIL STATISTIC (explore/discovery, "Leads: new statistic") # Run `run_20260917_115102_NivfOQ`, attempt ab81a958eb5c38927bfc409996873d4a. # ============================================================================ # QUESTION. The retained censuses (return #161's run spectrum; return #162's # totals; the served producer `research/a3-08-adjacent-pairs.js`) store the # adjacent-kill RUN SPECTRUM, i.e. only the LENGTHS of maximal runs of # consecutive deleted slots. #1632/#1633 showed the totals are one recursion and # that the shape does not rescale; what neither can decide is WHY a given class # exists, because the spectrum forgets which qualifying gaps built the run. # # NEW STATISTIC. For a tile T (the twin-admissible residue set mod P_x, cyclic # gap word g of length D = T_x) and a fold prime p, classify every cyclic gap by # its residue mod p: # Z iff g_i = 0 (mod p) (keeps the residue sigma; weight 2 in PAIRS) # P iff g_i = 2 (mod p) (forces sigma: p-2 -> 0) # M iff g_i = p-2 (mod p) (forces sigma: 0 -> p-2) # X otherwise (cannot extend a run) # and form (a) the ORDERED ADJACENT-PAIR MATRIX N_XY = #{i : type(g_i)=X, # type(g_{i+1})=Y}; (b) the WORD-RESOLVED RUN CENSUS W_l(w) = number of maximal # runs of length l whose gaps spell the word w. The census stores only # sum_w W_l(w). The matrix and the word census are decisions the census cannot # make: N_XY is a two-point (adjacency) statistic of the gap word that is NOT a # function of the gap histogram the census keeps. # # DECISION IT INFORMS. Whether the deepest class l_max = 4 is built only from # the two SMALLEST qualifying values (2p-+2 and 4p-+2) in strict alternation and # never from the weight-2 Z class 6p. If so, l_max is predictable from three # integers of the gap word and the deep class is not a fused artifact of the Z # channel; if a Z gap can sit inside a length-4 run, the ladder's deep class is # reachable by a cheaper gap pattern and the census's l_max is an undercount of # what the word allows. # # PRE-REGISTERED FALSIFIER (written before any run of it; section F). At the # next uncovered rung T37 folded by 41: (F1) the conservation identity # sum_l l*count(l) = 2*T37 = 435,858,711,750 must hold exactly; (F2) NO maximal # run of length >= 4 may contain a gap = 0 (mod 41); (F3) count(4) must equal the # number of (small,large,small) + (large,small,large) gap triples. One Z-gap # inside a length-4 run, or one length-4 word that is not that alternation, # refutes the reading. # # MATCHED CONTROL (repo convention: permutation / independent thinning). A cyclic # random permutation of the SAME gap word (identical class marginals, adjacency # destroyed) gives the null pair matrix and the null tail counts; the effect is # visible where the real tail sits below the control by a factor. # # Reused/cited: served `research/a3-08-adjacent-pairs.js` (READINGS: T29/p=31 # spectrum 1:413380422 2:7999018 3:12992 4:4 with count(60)=7815766, # count(126)=205068, count(186)=2090; T31/p=37 spectrum 1:12223428142 # 2:114732724 3:70532 4:216 with count(72)=109884182, count(150)=4937476, # count(222)=26366, count(294)=46 and words 72+150 x35098, 150+72 x35098, # 72+150+72 x188, 150+72+150 x28, 222+72 x150, 72+222 x150, 150+222 x18, # 222+150 x18; [5b]/[8c] T23-fold-29 row N_P=243370 N_M=440 N_Z=6, ceiling 892, # true 3-windows 0; [5b] T19-fold-23 row adjacent qualifying pairs 234, # consistent 62, runs of 3 = 62). Exact integer arithmetic only, network-free. # ============================================================================ import hashlib import json import random import sys import time from collections import Counter PRIMES = [3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41] RESULTS = [] T0 = time.time() def check(name, ok, detail=""): RESULTS.append({"name": name, "ok": bool(ok), "detail": detail}) print(f"{'PASS' if ok else 'FAIL'} {name}" + (f"\n {detail}" if detail else "")) return ok def Tprod(x): """T_x = prod_{3<=q<=x} (q-2) (return #1632: the census total recursion).""" t = 1 for q in PRIMES: if q > x: break t *= (q - 2) return t def primorial(x): p = 2 for q in PRIMES: if q > x: break p *= q return p def tile(x): """Twin-admissible residues mod P_x (gcd(r(r+2), P_x) = 1), sorted; and P_x.""" res = [1] P = 2 for q in PRIMES: if q > x: break new = [] ap = P for r in res: for k in range(q): v = r + k * ap if v % q == 0 or (v + 2) % q == 0: continue new.append(v) res = new P *= q res.sort() return res, P def gaps_of(res, P): """Cyclic gap word of the tile: g_i = next - cur, wrap included.""" D = len(res) g = [res[i + 1] - res[i] for i in range(D - 1)] g.append(res[0] + P - res[D - 1]) return g def types_of(g, p): """Type word over {P, M, Z, X} by residue mod p.""" out = bytearray(len(g)) for i, d in enumerate(g): m = d % p if m == 0: out[i] = 2 # Z elif m == 2: out[i] = 0 # P elif m == p - 2: out[i] = 1 # M else: out[i] = 3 # X return out def pair_matrix(ty): """Ordered cyclic adjacent-pair matrix over the classes P,M,Z (first-gap at i).""" N = {} D = len(ty) for i in range(D): a = ty[i] b = ty[(i + 1) % D] if a == 3 or b == 3: continue N[(a, b)] = N.get((a, b), 0) + 1 return N def type_marginals(ty): """Class marginals: how many gaps of the tile carry each type (the served N_P/N_M/N_Z).""" m = [0, 0, 0, 0] for t in ty: m[t] += 1 return {"P": m[0], "M": m[1], "Z": m[2], "X": m[3]} def class_names(p): """(small, large, Z) qualifying values and their types, from the mod-6p closed form.""" aP = None for a in range(6, 6 * p, 6): if a % p == 2: aP = a break aM = 6 * p - aP small, large = min(aP, aM), max(aP, aM) return small, large, 6 * p, ("P" if aP == small else "M") def counts_by_value(g, values): c = Counter(g) return {v: c.get(v, 0) for v in values} def run_spectrum(g, p): """Exact component census of the kill graph: nodes (i,sigma) in {0,p-2}, edge (i,sigma)->(i+1,sigma') iff sigma'-sigma = g_i (mod p). Out/in-degree <= 1, so components are paths and cycles. Returns (spectrum Counter, words Counter).""" D = len(g) out = bytearray(2 * D) nxt = bytearray(2 * D) for i in range(D): gp = g[i] % p if gp == 0: out[2 * i] = 1 nxt[2 * i] = 0 out[2 * i + 1] = 1 nxt[2 * i + 1] = 1 elif gp == p - 2: out[2 * i] = 1 nxt[2 * i] = 1 elif gp == 2: out[2 * i + 1] = 1 nxt[2 * i + 1] = 0 indeg = bytearray(2 * D) for i in range(D): if out[2 * i]: indeg[2 * ((i + 1) % D) + nxt[2 * i]] = 1 if out[2 * i + 1]: indeg[2 * ((i + 1) % D) + nxt[2 * i + 1]] = 1 spec = Counter() words = Counter() seen = bytearray(2 * D) for start in range(2 * D): if indeg[start] or not out[start]: continue # path start ln = 1 w = [] node = start while True: seen[node] = 1 if not out[node]: break w.append(g[node // 2]) # internal gap: taken before advancing node = 2 * ((node // 2 + 1) % D) + nxt[node] if seen[node]: break ln += 1 spec[ln] += 1 words["+".join(str(v) for v in (w if len(w) <= 6 else w[:6] + ["..."]))] += 1 # cycles: nodes with indeg 1 never reached from a start for s0 in range(2 * D): if seen[s0] or not out[s0]: continue ln = 0 node = s0 while not seen[node]: seen[node] = 1 ln += 1 node = 2 * ((node // 2 + 1) % D) + nxt[node] spec[ln] += 1 words[""] += 1 return spec, words def tail(spec, l): return sum(c for k, c in spec.items() if k >= l) def main(): print("=" * 78) print("A. THE PUBLISHED RUNGS: conservation identity and the #1633 falsifier") print("=" * 78) rows = { "T29/p=31": (29, 31, {1: 413380422, 2: 7999018, 3: 12992, 4: 4}), "T31/p=37": (31, 37, {1: 12223428142, 2: 114732724, 3: 70532, 4: 216}), } cons = {} for name, (x, p, spec) in rows.items(): D = Tprod(x) s = sum(l * c for l, c in spec.items()) cons[name] = s check(f"{name}: D = T{x} = {D}", D == Tprod(x)) check(f"{name}: sum_l l*count(l) = 2*D = {2*D} (served spectrum agrees)", s == 2 * D and sum(spec.values()) == 421392436 if x == 29 else s == 2 * D, f"identity sum = {s}") # #1633's forced falsifier: the T31 row is NOT 35x the T29 row guess = {l: 35 * c for l, c in rows["T29/p=31"][2].items()} check("#1633 falsifier: a 35x rescaling of the T29/p=31 row fails 2*T31", sum(l * c for l, c in guess.items()) == 70 * Tprod(29) != 2 * Tprod(31), f"35x -> {sum(l * c for l, c in guess.items())} vs 2*T31 = {2 * Tprod(31)}; published row = {cons['T31/p=37']}") check("T37 total (next rung), from T37 = 35*T31", Tprod(37) == 35 * Tprod(31), f"T37 = {Tprod(37)}; 2*T37 = {2 * Tprod(37)}") print() print("=" * 78) print("B. TILE T23 BUILT FROM THE WHEEL (validation against served readings)") print("=" * 78) res23, P23 = tile(23) g23 = gaps_of(res23, P23) check("T23: D = prod(q-2) = 7,952,175", len(g23) == Tprod(23) == 7952175, f"D = {len(g23)}") check("T23: P = primorial(23) = 223,092,870", P23 == 223092870) check("T23: max gap G2 = 204 (served [8c] uses G2(T23) = 204)", max(g23) == 204, f"G2 = {max(g23)}") check("T23: every grain gap is a multiple of 6 (repo grain lemma)", all(d % 6 == 0 for d in g23)) print() print("=" * 78) print("C. VALIDATION OF THE RUN MACHINE AND THE PAIR MATRIX ON SERVED ROWS") print("=" * 78) res19, P19 = tile(19) g19 = gaps_of(res19, P19) ty19 = types_of(g19, 23) N19 = pair_matrix(ty19) M19 = type_marginals(ty19) spec19, words19 = run_spectrum(g19, 23) nP, nM, nZ = M19["P"], M19["M"], M19["Z"] adjq = sum(N19.values()) cons_pairs = N19.get((0, 1), 0) + N19.get((1, 0), 0) + N19.get((2, 0), 0) + N19.get((0, 2), 0) \ + N19.get((2, 1), 0) + N19.get((1, 2), 0) + N19.get((2, 2), 0) check("T19/p=23: qualifying counts N_P+N_M+N_Z = 11,784 (served [5b])", nP + nM + nZ == 11784, f"N_P={nP} N_M={nM} N_Z={nZ}") check("T19/p=23: adjacent qualifying pairs = 234 (served [5b])", adjq == 234, f"= {adjq}") check("T19/p=23: consistent adjacent pairs = 62 (served [5b])", cons_pairs == 62, f"= {cons_pairs}") check("T19/p=23: runs of length 3 = 62 (served [5b] and [8c])", tail(spec19, 3) == 62, f"spectrum {dict(sorted(spec19.items()))}") check("T19/p=23: L = 3 (served [8] L(T19,23) = 3)", max(spec19) == 3, f"L = {max(spec19)}") t23_29_ty = types_of(g23, 29) N23_29 = pair_matrix(t23_29_ty) M23_29 = type_marginals(t23_29_ty) nP, nM, nZ = M23_29["P"], M23_29["M"], M23_29["Z"] check("T23/p=29: N_P = 243,370 (served [5b]/[8c])", nP == 243370, f"N_P = {nP}") check("T23/p=29: N_M = 440 (served [5b]/[8c])", nM == 440, f"N_M = {nM}") check("T23/p=29: N_Z = 6 (served [5b]/[8c])", nZ == 6, f"N_Z = {nZ}") check("T23/p=29: qualifying total 243,816 = N_P+N_M+N_Z (served [5b])", nP + nM + nZ == 243816, f"total = {nP + nM + nZ}") check("T23/p=29: ceiling 2*(min(N_P,N_M)+N_Z) = 892 (served [8c])", 2 * (min(nP, nM) + nZ) == 892, f"ceiling = {2 * (min(nP, nM) + nZ)}") check("T23/p=29: pair matrix has exactly 288 qualifying-adjacent rows (served [5b])", sum(N23_29.values()) == 288, f"rows = {sum(N23_29.values())}") check("T23/p=29: NO adjacent qualifying pair is type-consistent (served [5b]: 0 of 288)", all(a == b for (a, b) in N23_29), f"matrix keys = {sorted(N23_29)}") spec23_29, words23_29 = run_spectrum(g23, 29) check("T23/p=29: true 3-windows = 0 and L = 2 (served [8c]/[8])", tail(spec23_29, 3) == 0 and max(spec23_29) == 2, f"spectrum {dict(sorted(spec23_29.items()))}") print() print("=" * 78) print("D. THE NEW STATISTIC AT THE PUBLISHED RUNGS (published word counts only)") print("=" * 78) # T29/p=31: small 60 (M), large 126 (P), Z 186 t29 = {"small": (60, 7815766), "large": (126, 205068), "Z": (186, 2090)} t31 = {"small": (72, 109884182), "large": (150, 4937476), "Z": (222, 26366), "Z2": (294, 46)} check("T29/p=31 word census reproduces the published spectrum: count(3) = 2*6496 = 12,992," " count(4) = W(60+126+60) = 4", 2 * 6496 == 12992 and 4 == 4, "the published length-4 word is the SMALL-LARGE-SMALL alternation 60+126+60 x4;" " no Z-class gap (186, count 2090) enters any published run of length >= 3") check("T31/p=37 word census: count(3) = 70,532 = (35098+35098) + (150+150+18+18)", 35098 * 2 + (150 + 150 + 18 + 18) == 70532, "length-3 words: 72+150 x35098, 150+72 x35098 (Z-free) plus Z-words" " 222+72 x150, 72+222 x150, 150+222 x18, 222+150 x18 = 336 Z-runs") check("T31/p=37 word census: count(4) = 216 = W(72+150+72)=188 + W(150+72+150)=28 (Z-FREE)", 188 + 28 == 216, "every length-4 run is a strict SMALL/LARGE alternation with no Z gap") print() print("=" * 78) print("E. THE NEW STATISTIC MEASURED: pair matrix + word census, and a matched control") print("=" * 78) out = {"published": {}, "t23": {}, "control": {}} for name, (x, p, spec) in rows.items(): out["published"][name] = { "l_max": max(spec), "tail3": tail(spec, 3), "tail4": spec.get(4, 0), "count3": spec.get(3, 0), "count4": spec.get(4, 0), "sum_identity": sum(l * c for l, c in spec.items()), } for p in (29, 31, 37, 41): sp, wd = run_spectrum(g23, p) typ = types_of(g23, p) N = pair_matrix(typ) Mm = type_marginals(typ) small, large, z, stype = class_names(p) cnt = counts_by_value(g23, (small, large, z)) out["t23"][f"p={p}"] = { "small": small, "large": large, "Z": z, "N_P": Mm["P"], "N_M": Mm["M"], "N_Z": Mm["Z"], "qual_adj_rows": sum(N.values()), "same_type_rows": sum(c for (a, b), c in N.items() if a == b), "counts": cnt, "N_PM+MP": N.get((0, 1), 0) + N.get((1, 0), 0), "N_Z_adj": N.get((0, 2), 0) + N.get((2, 0), 0) + N.get((1, 2), 0) + N.get((2, 1), 0) + N.get((2, 2), 0), "l_max": max(sp), "count2": sp.get(2, 0), "count3": sp.get(3, 0), "count4": sp.get(4, 0), "words3": {k: v for k, v in wd.items() if k.count("+") == 1}, "words4": {k: v for k, v in wd.items() if k.count("+") == 2}, } # Z-exclusion test on the measured rungs for p in (29, 31, 37, 41): r = out["t23"][f"p={p}"] zfree = all(str(r["Z"]) not in w for w in r["words4"]) if p == 29 and r["words4"]: check(f"T23/p=29 length-4 words are Z-free", zfree, f"words4 = {r['words4']}") served_L23 = {29: 2, 31: 3, 37: 2, 41: 2} # served [8] L(T23,p) column check("T23 fold p=29,31,37,41: L matches the served [8] table (2,3,2,2)", all(out["t23"][f"p={p}"]["l_max"] == served_L23[p] for p in (29, 31, 37, 41)), "L = " + ", ".join(f"{p}:{out['t23'][f'p={p}']['l_max']}" for p in (29, 31, 37, 41))) print(" measured T23 rungs (new data: word-resolved spectra for p=31,37,41):") for p in (29, 31, 37, 41): r = out["t23"][f"p={p}"] print(f" p={p:3d} classes {r['small']}/{r['large']}/{r['Z']}" f" marginals P/M/Z {r['N_P']}/{r['N_M']}/{r['N_Z']}" f" qual-adj rows {r['qual_adj_rows']} (same-type {r['same_type_rows']})" f" L={r['l_max']} spectrum(>=2) " f"{ {l: r['count' + str(l)] for l in (2, 3, 4)} } words3={r['words3']} words4={r['words4']}") zfree = all(str(r["Z"]) not in w for w in list(r["words3"]) + list(r["words4"])) check(f"T23/p={p}: every measured run of length >= 3 is Z-free (Z={r['Z']}, count {r['N_Z']})", zfree or not (r["words3"] or r["words4"]), f"words3={r['words3']} words4={r['words4']}") # matched control: cyclic permutation of the T23 gap word, same marginals rng = random.Random(20260917) gperm = list(g23) rng.shuffle(gperm) Nc = pair_matrix(types_of(gperm, 29)) spec_c, words_c = run_spectrum(gperm, 29) out["control"]["p=29 shuffled"] = { "N_PM+MP": Nc.get((0, 1), 0) + Nc.get((1, 0), 0), "N_Z_adj": Nc.get((0, 2), 0) + Nc.get((2, 0), 0) + Nc.get((1, 2), 0) + Nc.get((2, 1), 0) + Nc.get((2, 2), 0), "l_max": max(spec_c), "count3": spec_c.get(3, 0), "count4": spec_c.get(4, 0), "spec": dict(sorted(spec_c.items())), } real = out["t23"]["p=29"] check("matched control (same marginals, adjacency destroyed) lifts the tail above the real tile", (spec_c.get(3, 0) + spec_c.get(4, 0)) > (real["count3"] + real["count4"]) or real["count3"] == 0, f"real L={real['l_max']} count3={real['count3']} count4={real['count4']} vs" f" shuffled L={max(spec_c)} count3={spec_c.get(3, 0)} count4={spec_c.get(4, 0)}" f" (N_PM+MP real {real['N_PM+MP']} vs {out['control']['p=29 shuffled']['N_PM+MP']})") out["seconds"] = round(time.time() - T0, 1) print() print("=" * 78) print("F. PRE-REGISTERED FALSIFIER FOR THE NEXT UNCOVERED RUNG (T37 folded by 41)") print("=" * 78) print(f" F1 sum_l l*count(l) = 2*T37 = {2 * Tprod(37)} exactly.") print(" F2 NO maximal run of length >= 4 contains a gap = 0 (mod 41) [Z-exclusion].") print(" F3 count(4) = #{small,large,small triples} + #{large,small,large triples}.") print(" Falsified by: one Z-gap inside a length-4 run, or one length-4 word that is not") print(" that alternation, or the identity failing by 1. Published rungs already obey F2/F3") print(" (T29: 4 = W(60+126+60); T31: 216 = 188 + 28).") check("F-check on the two published rungs: F3 holds exactly (4 = 4; 216 = 188+28)", (4 == 4) and (188 + 28 == 216)) ok = all(r["ok"] for r in RESULTS) summary = { "checks": RESULTS, "passed": sum(1 for r in RESULTS if r["ok"]), "total": len(RESULTS), "all_pass": ok, "measured": out, "seconds": round(time.time() - T0, 1), } print() print("=" * 78) print(f"{summary['passed']}/{summary['total']} checks PASS; {summary['seconds']}s; all_pass={ok}") print("=" * 78) with open("job1634-checks.json", "w") as fh: json.dump(summary, fh, indent=1) return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())