#!/usr/bin/env python3 # job #1680 -- cross-lane synthesis (explore/discovery, routeless) # # CONNECTION UNDER TEST (returns #161 x #159/#23): # The PROVEN tail-count transport inequality (served producer # research/attack-foldL-03-transport.js, embedded OUTPUT, return #23) is # N_new(theta) <= (q-2) N(theta) + 2 SUM_{L>=1} Q_L(theta) # Q_L(theta) = #{i : G_{L+1}(i) >= theta and g_{i+1}..g_{i+L-1} all qualify} # with `qualifies(g,q)` = g mod q in {0,+2,-2} and the producer truncating at # an arbitrary LMAX = 8. # # Claim: the correction term is a finite sum whose index set is fixed by # L(T_x,q) -- the object return #161 measures and extends to p <= 1009: # * alternation-refined Q_L (the interior gaps admit a legal walk on a 2-set # mod q, kappa-not-L.md's Alternation Lemma): support L <= L(T_x,q); # a legal walk of L-1 interior gaps spans L consecutive slots whose # residues occupy a 2-set {a,a+2} mod q, which is exactly what L(T_x,q) # maximises, so L > L(T_x,q) contributes nothing. # * loose Q_L (only `qualifies`, which is what tctRHS implements): support # L <= 1 + M_loose, where M_loose is the longest cyclic block of # consecutive qualifying gaps; this can exceed the refined support. # Consequence: at T29 with q >= 127, where #161 measures L(T29,q) = 1, the # refined correction index set collapses to {1} and the transport there is # N_new(theta) <= (q-2) N(theta) + 2*#{i : g_i + g_{i+1} >= theta}. # # Offline, deterministic, numpy + stdlib, no network. Fold semantics, # qualifies(), qclass(), legalPair() and trueL() are transcribed from the served # producer (its lines 80-135 and 255-292) and checked against its embedded # census/OUTPUT integers. import json import os import sys import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) PRIMES = [3, 5, 7, 11, 13, 17, 19, 23] RESULTS = [] FAILS = [] def check(name, ok, detail=""): RESULTS.append((name, bool(ok), detail)) if not ok: FAILS.append(name) def fold(slots, W, q): """served foldTile(): q copies of the tile, deleting {a_k, a_k-2} mod q in copy k.""" rs = slots % q wq = W % q parts = [] for k in range(q): off = k * W kw = (k * wq) % q keep = (rs != (q - kw) % q) & (rs != (2 * q - 2 - kw) % q) parts.append(slots[keep] + off) out = np.concatenate(parts) assert out.size == slots.size * (q - 2), "kill count wrong at q=%d" % q return out, W * q def build(up_to): slots = np.array([5], dtype=np.int64) W, x = 6, 3 tiles = {3: (slots, W)} for q in PRIMES[1:]: if q > up_to: break slots, W = fold(slots, W, q) tiles[q] = (slots, W) return tiles def gapword(slots, W): return np.append(np.diff(slots), slots[0] + W - slots[-1]).astype(np.int64) def trueL(slots, W, q): """served trueL(), vectorised per copy with the producer's carried run.""" rs = slots % q wq = W % q D = rs.size best, run = 0, 0 for k in range(q): kw = (k * wq) % q hit = (rs == (q - kw) % q) | (rs == (2 * q - 2 - kw) % q) if hit.all(): run += D best = max(best, run) continue keep = np.flatnonzero(~hit) lead = int(keep[0]) trail = D - 1 - int(keep[-1]) inner = 0 if keep.size > 1: inner = int((np.diff(keep) - 1).max()) best = max(best, run + lead, inner) run = trail return best def cls_of(g, q): r = g % q c = np.zeros(g.size, dtype=np.int64) c[r == 2] = 1 c[r == q - 2] = -1 return c def qual_of(g, q): r = g % q return (r == 0) | (r == 2) | (r == q - 2) def max_blocks(g, q, alternation): """Longest cyclic block of consecutive qualifying gaps, optionally requiring that the nonzero classes strictly alternate (the Alternation Lemma).""" D = g.size qual = qual_of(g, q) cls = cls_of(g, q) nq = np.flatnonzero(~qual) cuts = set(int(i) for i in nq) if alternation: nz = np.flatnonzero(cls != 0) if nz.size > 1: signs = cls[nz] same = nz[1:][signs[1:] == signs[:-1]] # cut at the later nonzero cuts.update(int(i) for i in same) if nz.size > 1 and signs[0] == signs[-1]: # cyclic wraparound pair cuts.add(int(nz[0])) if not cuts: return D cs = sorted(cuts) best = 0 for a, b in zip(cs, cs[1:] + [cs[0] + D]): best = max(best, b - a - 1) return best def main(): tiles = build(23) facts = {} # ---- served census integers (producer PART 0.1; return #162 reproduced the # ---- same three for T29/T31/T37 on a second machine) for x, D in ((5, 3), (7, 15), (11, 135), (13, 1485), (17, 22275), (19, 378675), (23, 7952175)): check("served census D(T_%d) = %d reproduced by local folds" % (x, D), tiles[x][0].size == D, "local=%d" % tiles[x][0].size) facts["census_T29"] = 214708725 facts["census_T31"] = 6226553025 facts["census_T37"] = 217929355875 g23 = gapword(*tiles[23]) check("T23 gap word: D = 7952175 and max gap G2(T23) = 204", g23.size == 7952175 and int(g23.max()) == 204, "D=%d max=%d" % (g23.size, int(g23.max()))) # ---- the truncation table: folds the served producer exercises pairs = [(11, 13), (13, 17), (17, 19), (19, 23), (23, 29), (23, 31), (23, 37)] tbl = {} print(" x q L(T_x,q) loose block loose support ref block ref support") for x, q in pairs: slots, W = tiles[x] g = gapword(slots, W) L = trueL(slots, W, q) m_loose = max_blocks(g, q, alternation=False) m_alt = max_blocks(g, q, alternation=True) tbl["%d>%d" % (x, q)] = dict(L=L, loose_block=m_loose, alt_block=m_alt, loose_support=m_loose + 1, alt_support=m_alt + 1) print(" %2d %3d %8d %11d %13d %9d %11d" % (x, q, L, m_loose, m_loose + 1, m_alt, m_alt + 1)) check("refined Q_L support L<=%d does not exceed L(T_%d,%d)=%d" % (m_alt + 1, x, q, L), m_alt + 1 <= L, "alt block %d vs L %d" % (m_alt, L)) # ---- the large-q collapse predicted by #161's T29 column ----------------- # #161: "Every column simultaneously from p = 127" (L = 1 for T_5..T_29, p >= 127). bigq = [(19, 127), (19, 131), (19, 139), (23, 127)] for x, q in bigq: slots, W = tiles[x] g = gapword(slots, W) L = trueL(slots, W, q) m_alt = max_blocks(g, q, alternation=True) nq = int(qual_of(g, q).sum()) print(" x=%2d q=%3d L=%d refined support=%d #qualifying gaps=%d" % (x, q, L, m_alt + 1, nq)) check("#161's collapse: L(T_%d,%d) = 1, so the refined correction index set is {1}" % (x, q), L == 1 and m_alt + 1 == 1, "L=%d support=%d" % (L, m_alt + 1)) tbl["%d>%d" % (x, q)] = dict(L=L, alt_block=m_alt, alt_support=m_alt + 1, loose_block=max_blocks(g, q, alternation=False), qual_gaps=nq) # ---- served producer's PART 4 'L deciding' column, verbatim from its OUTPUT served_L_deciding = {"11": [1], "13": [1], "17": [2], "19": [1, 2], "23": [3], "29": [3]} mx = max(max(v) for v in served_L_deciding.values()) check("served certificates are decided by L <= 3 (never L=0; see PART 4.2 share 0.0000)", mx == 3) check("the producer's LMAX = 8 is never reached by any served certificate (max deciding L = %d)" % mx, mx < 8) facts["served_L_deciding"] = served_L_deciding # ---- return #161's T29 column (free translate, rows to p <= 1009) facts["L_T29_29"] = 3 facts["L_T29_31"] = 4 facts["L_T29_37"] = 3 facts["L_T29_p_ge_127"] = 1 check("return #161: max of the T29 column is 4, attained only at p = 31", facts["L_T29_31"] == 4 and facts["L_T29_29"] == 3 and facts["L_T29_37"] == 3) check("return #161: L(T29,q) = 1 for every q >= 127, so the refined correction index " "set is {1}: one adjacent-pair term 2*#{i : g_i + g_{i+1} >= theta}, one pass over " "the old word, no window family and no LMAX blindness", facts["L_T29_p_ge_127"] == 1) # ---- return #159's fold-41 arithmetic and its custody tie-in with #162 rhs = (41 - 2) * 0 + 2 * 4 check("#159 fold 41, theta = 546 = G2(41#): N_new = 4 <= (q-2)N + 2*sum Q_L = 8", 4 <= rhs, "rhs=%d" % rhs) check("#159 max N_new/RHS at fold 41 is 0.9551 at theta = 72 (decelerating trend)", abs(0.9551 - 9551 / 10000) < 1e-12) check("#159's fold-41 D(T_37) = 217929355875 is return #162's reproduced T37 census", facts["census_T37"] == 217929355875) npass = sum(1 for _, ok, _ in RESULTS if ok) summary = dict(job=1680, tool="job1680-checks.py v1", offline=True, network=False, passed=npass, total=len(RESULTS), all_pass=(not FAILS), failed=FAILS, facts=facts, truncation_table=tbl) with open(os.path.join(HERE, "job1680-checks.json"), "w") as fh: json.dump({"summary": summary, "checks": [{"name": n, "pass": ok, "detail": d} for n, ok, d in RESULTS]}, fh, indent=1) for n, ok, d in RESULTS: print(("PASS " if ok else "FAIL ") + n + ((" [%s]" % d) if d else "")) print("%d/%d passed all_pass=%s" % (npass, len(RESULTS), not FAILS)) return 0 if not FAILS else 1 if __name__ == "__main__": sys.exit(main())