"""Job #2588 (pursue route 67). QUESTION (return #1244's next step). Is the refined longest-run statistic L(T29, q) <= 4 at every prime q <= 260, i.e. does the four-term bound on the walk-refined Tail-Count Transport correction hold over the whole fold range where a component of length >= 2 can exist (G2(T29) = 258, so q > 260 forces L = 1)? OBJECTS (definitions read at source: #161's runFor, #159's nu_q / K = {0, q-2}, #971's identity, #1244's controls). T29 = the twin-slot tile of level 29: slots r in [0, P), P = 29# = 6,469,693,230, with r and r+2 coprime to every prime 3..29 (hence r = 11, 17, 29 mod 30), D = 214,708,725 slots, cyclic gap word g_i = r_{i+1} - r_i summing to P, max gap G2 = 258. For a prime q, rho_i = r_i mod q. REFINED: L(T29, q) = the longest run of consecutive slots whose residues all lie in one 2-set {a, a+2} (mod q), any a; equivalently the longest component of #159's kill graph over anchors. A component with anchor set A = {a, a+2} STARTS at slot i iff rho_i in A and rho_{i-1} not in A; every slot has exactly two anchor sets, {rho_i, rho_i + 2} and {rho_i - 2, rho_i}, so the spectrum (components by length) satisfies sum L * count = 2D (#1244). LOOSE: R_loose(q) = the longest cyclic run of consecutive qualifying gaps (g mod q in {0, 2, q-2}). ONE-LINE INEQUALITY (this job's first observation): a refined run of L slots has L-1 consecutive gaps each = 0 or +-2 mod q, so L(T29, q) - 1 <= R_loose(q); with #1244's sweep (max R_loose = 3, at q = 29, 31; <= 2 elsewhere) that already gives L <= 4 everywhere and L <= 3 off {29, 31}. This run measures L directly anyway, as the route asked. PRE-REGISTERED (before the run). F1 (the route's success clause): L(T29, q) <= 4 for every prime 29 <= q <= 257 (49 primes). F2 (frozen controls): the anchor-component spectra at q = 29 and q = 31 equal #1244's {1: 413669820, 2: 7871964, 3: 1234} and {1: 413380422, 2: 7999018, 3: 12992, 4: 4}, with sum L*count = 2D at every q. F3 (the inequality and the loose sweep): L(q) <= R_loose(q) + 1 at every q, and R_loose reproduces #1244's table (3 at 29, 31; 2 at 37, 53, 59, 61; 1 at 41, 43, 47, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113; 0 otherwise). Gates: G1 D = 214,708,725 = prod_{3<=q<=29}(q-2); G2 the cyclic word sums to P and max gap = 258. Stdout: ledger + JSON; stderr: progress. RUN: python refined2588.py --out refined2588.json """ import argparse, json, math, sys, time import numpy as np from importlib.machinery import SourceFileLoader bg = SourceFileLoader('bg', '../job1936/job1936-blockgrain.py').load_module() X = 29; QS_TILE = [3, 5, 7, 11, 13, 17, 19, 23, 29]; P = 6469693230; D_T = 214708725; G2 = 258 CONTROL = {29: {1: 413669820, 2: 7871964, 3: 1234}, 31: {1: 413380422, 2: 7999018, 3: 12992, 4: 4}} RLOOSE_1244 = {29: 3, 31: 3, 37: 2, 53: 2, 59: 2, 61: 2} for q in (41, 43, 47, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113): RLOOSE_1244[q] = 1 log = sys.stderr def block_bool(lo, hi, qs): n = hi - lo; ok = np.ones(n, dtype=bool); ok[(-lo) % 2:: 2] = False for q in qs: for kill in (0, (q - 2) % q): ok[(kill - lo) % q:: q] = False return ok def tile_slots(): BL = 30030 * 64; out = [] for lo in range(0, P, BL): hi = min(P, lo + BL); out.append(np.flatnonzero(block_bool(lo, hi, QS_TILE)).astype(np.int64) + lo) return np.concatenate(out) def runs_max_and_hist(ok, cyclic=True, maxlen=64): """longest run of True in a boolean array (cyclic) and histogram of run lengths (non-cyclic runs of the doubled array clipped).""" n = len(ok); d = np.concatenate([ok, ok[:maxlen]]) if cyclic else ok x = d.astype(np.int8); idx = np.flatnonzero(np.diff(np.concatenate([[0], x, [0]]))) if len(idx) == 0: return 0 return int((idx[1::2] - idx[0::2]).max()) def main(): ap = argparse.ArgumentParser(); ap.add_argument('--out', required=True); a = ap.parse_args(); ledger = [] def check(tag, ok, detail): ledger.append(f"{'PASS' if ok else 'FAIL'} {tag} :: {detail}"); print(ledger[-1], file=log, flush=True) t0 = time.time(); r = tile_slots(); D = len(r) check('G1_D', D == D_T and D == math.prod(q - 2 for q in QS_TILE), f'D = {D} vs {D_T}') g = np.diff(np.concatenate([r, [r[0] + P]])); check('G2_word', int(g.sum()) == P and int(g.max()) == G2, f'sum gaps {int(g.sum())} vs P {P}; max gap {int(g.max())} vs {G2}; distinct gaps {len(np.unique(g))}') print(f'tile built: D = {D} ({time.time() - t0:.1f}s)', file=log, flush=True) primes = [int(p) for p in bg.primes_to(260) if p >= 29] out = {'instrument': 'refined2588.py', 'job': 2588, 'D': D, 'P': P, 'G2': G2, 'primes': primes, 'per_q': {}, 'ledger': ledger} for q in primes: t1 = time.time(); rho = (r % q).astype(np.int32) dq = (np.roll(rho, -1) - rho) % q # residue step to the next slot (cyclic) qual = (dq == 0) | (dq == 2) | (dq == q - 2) R = runs_max_and_hist(qual) # longest cyclic run of qualifying gaps # anchor components: for family +: A = {rho_i, rho_i+2}; family -: A = {rho_i-2, rho_i} prev = (np.roll(rho, 1) - rho) % q hist = {}; Lmax = 0 for fam, allowed in (('+', (0, 2)), ('-', (0, q - 2))): start = ~np.isin(prev, allowed) # previous slot not in A alive = start.copy(); length = np.zeros(D, dtype=np.int8); k = 0 while alive.any() and k < 40: length[alive] += 1 nxt = (np.roll(rho, -(k + 1)) - rho) % q alive &= np.isin(nxt, allowed); k += 1 Ls, cs = np.unique(length[start], return_counts=True) for L, c in zip(Ls, cs): if L > 0: hist[int(L)] = hist.get(int(L), 0) + int(c) Lmax = max(Lmax, int(length.max())) total = sum(L * c for L, c in hist.items()) rec = {'L_refined': Lmax, 'R_loose': R, 'spectrum': hist, 'sum_L_count': total, 'secs': round(time.time() - t1, 1)} out['per_q'][str(q)] = rec print(f'q={q}: L_refined={Lmax} R_loose={R} spectrum={hist} sumLc={total} ({time.time() - t1:.1f}s)', file=log, flush=True) json.dump(out, open(a.out, 'w'), indent=1) pq = out['per_q'] check('F1_all_L_le_4', all(pq[str(q)]['L_refined'] <= 4 for q in primes), f"L by q: {[(q, pq[str(q)]['L_refined']) for q in primes if pq[str(q)]['L_refined'] >= 2]}") for q, spec in CONTROL.items(): check(f'F2_spectrum_q{q}', pq[str(q)]['spectrum'] == spec, f"got {pq[str(q)]['spectrum']} vs #1244 {spec}") check('F2_sum_2D', all(pq[str(q)]['sum_L_count'] == 2 * D for q in primes), f'sum L*count = 2D = {2 * D} at all {len(primes)} primes') check('F3_inequality', all(pq[str(q)]['L_refined'] <= pq[str(q)]['R_loose'] + 1 for q in primes), 'L <= R_loose + 1 at every q') exp_R = {q: RLOOSE_1244.get(q, 0) for q in primes} check('F3_Rloose_matches_1244', all(pq[str(q)]['R_loose'] == exp_R[q] for q in primes), f"mismatches: {[(q, pq[str(q)]['R_loose'], exp_R[q]) for q in primes if pq[str(q)]['R_loose'] != exp_R[q]]}") v = {'F1_success_clause': all('PASS' in l for l in ledger if 'F1' in l), 'F2_controls': all('PASS' in l for l in ledger if 'F2' in l), 'F3_inequality_and_sweep': all('PASS' in l for l in ledger if 'F3' in l), 'L_max_over_q': max(pq[str(q)]['L_refined'] for q in primes), 'L_at_29_31': [pq['29']['L_refined'], pq['31']['L_refined']], 'q_with_L_ge_3': [q for q in primes if pq[str(q)]['L_refined'] >= 3], 'secs': round(time.time() - t0, 1)} out['verdict'] = v; json.dump(out, open(a.out, 'w'), indent=1) print('\n'.join(ledger)); print('VERDICT ' + json.dumps(v, sort_keys=True)); return 0 if __name__ == '__main__': sys.exit(main())