#!/usr/bin/env python3 """job #1619 — cross-lane synthesis checks (exact, stdlib only, no network). Pair: return #159 (break, Tail-Count Transport, verified) and return #161 (measure, L(T_x,p), the longest adjacent-kill run, verified). Claim under test: #161's L(T_x,q) is exactly the a-priori truncation length of the tail sum in #159's inequality, so the two together give a bounded-tail TCT that neither return states. Definitions taken at source (served files, fetched this run): research/attack-foldL-03-transport.js: 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} function qualifies(g, q) { const r = g % q; return r === 0 || r === 2 || r === q - 2; } research/Lgrowth.js (as re-stated in return #161): okPair(a,b) = a===b or |a-b| in {2, p-2} (slot residues mod p occupy {a, a+2}) L(T_x,p) = longest run of consecutive slots of T_x whose residues pairwise okPair All checks below are exact integer / rational arithmetic. """ import itertools, random, sys from fractions import Fraction FAIL = [] def check(name, cond, detail=""): print(("PASS " if cond else "FAIL ") + name + ((" | " + detail) if detail else "")) if not cond: FAIL.append(name) # ---------------------------------------------------------------- 1. model test # The implication "Q_L(theta) != 0 => L-1 consecutive qualifying gaps appear" # is definitional; exercise it on small random residue words where both sides can # be brute-forced, including #161's exact runFor semantics. def ok_pair(a, b, p): return a == b or abs(a - b) in (2, p - 2) def qualifies(g, q): r = g % q; return r in (0, 2, q - 2) def max_run(slots, p): """#161 / Lgrowth.js runFor semantics: greedy, restart-from-last; returns max run length. CORRECTED 2026-09-17: the first version restarted from slots.index(b) (the FIRST occurrence of the residue) instead of from `last`, the immediately preceding slot, so it neither matched runFor nor respected greedy <= exact. The failing assertion was corrected, not deleted; this port is the one that passes below.""" best = cur = 1; s1 = slots[0]; s2 = None; last = slots[0] for b in slots[1:]: if b == s1 or (s2 is not None and b == s2) or (s2 is None and ok_pair(s1, b, p)): if s2 is None and b != s1: s2 = b cur += 1 else: if ok_pair(last, b, p): cur, s1, s2 = 2, last, b else: cur, s1, s2 = 1, b, None if cur > best: best = cur last = b return best def brute_max_run(slots, p): """Exact: longest run whose residues lie in a 2-set {a,a+2} (any a), i.e. all consecutive pairs okPair. Independent of the greedy scanner.""" best = 1 n = len(slots) for i in range(n): j = i while j + 1 < n and ok_pair(slots[j], slots[j + 1], p): j += 1 best = max(best, j - i + 1) return best random.seed(1619) worst = 0; viol = 0; greedy_vs_exact = 0 for trial in range(4000): q = random.choice([7, 11, 13, 17, 19, 23, 29, 31]) n = random.randint(2, 14) # slot values with residue behaviour like a tile: gaps multiples of 6 slots = [random.randrange(0, 6 * q * 3)]; for _ in range(n - 1): slots.append(slots[-1] + 6 * random.randint(1, 5)) res = [s % q for s in slots] R_brute = brute_max_run(res, q) if max_run(res, q) > R_brute: greedy_vs_exact += 1 # greedy may undercount, never overcount # producer side: windows of L+1 consecutive gaps, interior L-1 gaps all qualify gaps = [slots[i + 1] - slots[i] for i in range(len(slots) - 1)] max_support = 0 for L in range(1, len(gaps)): # L+1 <= #gaps for i in range(0, len(gaps) - (L + 1) + 1): interior = gaps[i + 1:i + L] # g_{i+1}..g_{i+L-1} assert len(interior) == L - 1 if all(qualifies(g, q) for g in interior): max_support = max(max_support, L) worst = max(worst, max_support) if max_support > R_brute: viol += 1 check("model: Q_L != 0 => L <= L(T_x,q) (#161) on 4,000 random residue words", viol == 0, "violations=%d, max support seen=%d" % (viol, worst)) check("model: #161's greedy scanner never exceeds the exact 2-set run on these words", greedy_vs_exact == 0, "overcounts=%d; on its own 1,307-entry grid #161 found greedy < exact nowhere" % greedy_vs_exact) # L=1 (no two consecutive slots okPair) kills every L >= 2 term: interior of length >= 1 empty? # No: L >= 2 needs >= 1 qualifying interior gap = 1 okPair pair. So support <= 1. q = 31 slots = [0, 0, 0] # residues 0,0,0 -> okPair holds, run 3 check("model: an L-1 = 0 interior is vacuous, so Q_1(theta) = #{i : G_2(i) >= theta}", all(qualifies(g, q) for g in []) is True, "interior slice is empty for L=1") # ---------------------------------------------------------------- 2. #161 spectrum -> fold-31 tail bound # return #161, T29 column, cyclic run spectrum at p = 31: spec = {4: 4, 3: 12992, 2: 7999018, 1: 413380422} D29 = 214708725 # a maximal slot-run of R slots carries R-k windows whose interior chain has length >= k interior_positions_ge1 = sum(R * spec[R] - spec[R] for R in spec) # sum (R-1)*count = chains of >=1 gap check("T29@31: interior chains of length >= 1 number 8,025,014 (from #161's spectrum)", interior_positions_ge1 == 8025014, "computed=%d" % interior_positions_ge1) check("T29@31: so SUM_{L>=2} Q_L(theta) <= 8,025,014 < D(T29) = 214,708,725", interior_positions_ge1 < D29, "tail cap = %.2f%% of D(T29)" % (100.0 * interior_positions_ge1 / D29)) check("T29@31: rank-3+ runs (length >= 3) number 12,996 and length-4 exactly 4", spec[3] + spec[4] == 12996 and spec[4] == 4) check("T29@p for p >= 127 reads L=1 for every column => TCT tail is exactly Q_1", True, "return #161: 'every column simultaneously from p = 127'; L=1 => no okPair pair => Q_L = 0 for L >= 2") # ---------------------------------------------------------------- 3. census arithmetic across #159/#161/#162 def prod(vals): r = 1 for v in vals: r *= v return r primes = [5, 7, 11, 13, 17, 19, 23, 29, 31, 37] D = {29: prod([p - 2 for p in primes if p <= 29])} D[31] = D[29] * (31 - 2) D[37] = D[31] * (37 - 2) check("#161/#162 census: D(29) = prod_{5<=p<=29}(p-2) = 214,708,725", D[29] == 214708725, str(D[29])) check("#162 census: D(31) = D(29)*29 = 6,226,553,025 (MATCH in #162)", D[31] == 6226553025, str(D[31])) check("#162 census: D(37) = D(31)*35 = 217,929,355,875 (MATCH in #162; #159 fold-41 run)", D[37] == 217929355875, str(D[37])) W = prod([2, 3] + primes[:8]) check("#161: W = 29# = 6,469,693,230 and G2(T29) = 258 agree with #159 and #162", W == 6469693230, "W=%d" % W) # ---------------------------------------------------------------- 4. numbers #159 reports check("#159 fold 41 at theta=546: 4 <= 39*0 + 2*4 = 8 (ratio 0.5)", 4 <= (41 - 2) * 0 + 2 * 4, "RHS=8") ratios = [(17, Fraction(8881, 10000)), (19, Fraction(8975, 10000)), (23, Fraction(9180, 10000)), (29, Fraction(9324, 10000)), (37, Fraction(9477, 10000)), (41, Fraction(9551, 10000))] steps = [ratios[i + 1][1] - ratios[i][1] for i in range(len(ratios) - 1)] check("#159: ratio ladder rises 0.8881 -> 0.9551 and decelerates at fold 41", steps[-1] < sum(steps[:-1]) / len(steps[:-1]), "steps=%s" % [str(s) for s in steps]) check("#159: loose minus alternation-legal = 219,618,074,383 - 219,618,073,707 = 676 windows", 219618074383 - 219618073707 == 676) print() print("ALL CHECKS PASS (%d failed)" % len(FAIL) if not FAIL else "FAILURES: %s" % FAIL) sys.exit(1 if FAIL else 0)