#!/usr/bin/env python3 """Job #1910 controls + witness extraction for the T_23 -> p = 31 census. A. Independent segmented sieve of the FOLDED word over windows of [0, 31*P_23): the folded word is { r : gcd(r, 23#) = gcd(r+2, 23#) = 1, r not= 0,-2 (mod 31) }. Compared as a set with the shift-union word restricted to the same window. B. Witness extraction for the j >= 3 cells at p = 31: the slot triple, the strip class, the killed class, the fused gap interval and the three old gaps. C. Kill-class gap values at p = 31 and the lemma-regime check. D. Cross-check of the witness against the independent sieve. """ import json import numpy as np import sys sys.path.insert(0, __file__.rsplit('/', 1)[0]) from fusion_census import build_tile, criterion P23 = 223092870 Q = (3, 5, 7, 11, 13, 17, 19, 23) def sieve_window(lo, hi, primes=(3, 5, 7, 11, 13, 17, 19, 23, 31)): """Independent exact word: positions r in [lo,hi) with gcd(r,P)=gcd(r+2,P)=1 and r not= 0,-2 (mod p) for the fold prime included in `primes`.""" n = hi - lo ok = np.ones(n, dtype=bool) ok[(-lo) % 2::2] = False # parity: P_x contains 2 (q=2 skipped in the loop) for q in primes: if q == 31: ok[(-lo) % 31::31] = False ok[((-lo - 2) % 31)::31] = False else: ok[(-lo) % q::q] = False ok[((-lo - 2) % q)::q] = False return np.flatnonzero(ok).astype(np.int64) + lo def shift_union_window(slots, Pm, p, lo, hi): """The folded word from the shift-union blocks, restricted to [lo,hi).""" out = [] for k in range(p): s = k * Pm if s >= hi: break a = (-k * Pm) % p c2 = (a - 2) % p r = slots % p keep = (~((r == a) | (r == c2))) pos = s + slots[keep] m = (pos >= lo) & (pos < hi) out.append(pos[m]) return np.sort(np.concatenate(out)) if out else np.array([], dtype=np.int64) if __name__ == '__main__': slots, Pm, g = build_tile() D = slots.size res = {31: slots % 31, 37: slots % 37} out = {} # ---- A. window controls ------------------------------------------------- wins = [(0, 1 << 24), (5 * Pm - 4096, 5 * Pm + 4096), (17 * Pm + 12345, 17 * Pm + 12345 + 8192), (30 * Pm - 5000, 30 * Pm)] ctrl = [] for lo, hi in wins: lo = max(lo, 0) A = sieve_window(lo, hi) B = shift_union_window(slots, Pm, 31, lo, hi) ctrl.append({'window': [lo, hi], 'sieve_count': int(A.size), 'shift_union_count': int(B.size), 'identical': bool(A.size == B.size and np.array_equal(A, B))}) out['fold_window_controls_p31'] = ctrl # T_31 tile control for reading B is in reading_b.py; here check the p=29 fold too ctrl29 = [] for lo, hi in [(0, 1 << 24), (7 * Pm - 2048, 7 * Pm + 2048)]: A = sieve_window(lo, hi, primes=(3, 5, 7, 11, 13, 17, 19, 23, 29)) B = shift_union_window(slots, Pm, 29, lo, hi) ctrl29.append({'window': [lo, hi], 'sieve_count': int(A.size), 'shift_union_count': int(B.size), 'identical': bool(A.size == B.size and np.array_equal(A, B))}) out['fold_window_controls_p29'] = ctrl29 # ---- C. kill-class gap values, lemma regime ----------------------------- for p in (29, 31, 37): cls = sorted(set(int(x) for x in g[((g % p == 0) | (g % p == 2) | (g % p == p - 2))] if x <= 250)) lim = (p - 2) // 4 small = g[g <= lim] inclass_small = int(np.count_nonzero((small % p == 0) | (small % p == 2) | (small % p == p - 2))) out[f'killclass_p{p}'] = {'values_leq_250': cls, 'count_leq_250': len(cls), 'gap_multiplicity': {int(v): int(np.count_nonzero(g == v)) for v in cls}, 'lemma_limit_(p-2)//4': int(lim), 'gaps_at_or_below_limit': int(small.size), 'those_in_kill_class': inclass_small} # ---- B/D. witness for a j >= 3 cell at p = 31 --------------------------- p = 31 r = g % p ok = (r == 0) | (r == 2) | (r == p - 2) both = ok[:-1] & ok[1:] bad = ((r[:-1] == 2) & (r[1:] == 2)) | ((r[:-1] == p - 2) & (r[1:] == p - 2)) idx = np.flatnonzero(both & ~bad) out['p31_three_run_pair_indices'] = int(idx.size) witnesses = [] for i in idx[:200].tolist(): # slots r_i, r_{i+1}, r_{i+2} are consecutive; find the strip class c trip = [int(slots[i]), int(slots[i + 1]), int(slots[i + 2])] residues = [t % p for t in trip] # the 2-element set S = {c, c-2} containing all three residues S = sorted(set(residues)) if len(S) == 1: c = (S[0] + 2) % p # take c = rho+2 else: c = S[1] if (S[1] - S[0]) % p == 2 else S[0] k = next(kk for kk in range(p) if (-kk * Pm) % p == c) # fused gap: previous and next survivor in strip k allslots = slots # survivors in strip k alive = ~((allslots % p == c) | (allslots % p == (c - 2) % p)) # locate the killed triple in the block; the fused gap spans from the # previous alive slot to the next alive slot (cyclically) start = i while start - 1 >= 0 and not alive[start - 1]: start -= 1 end = i + 2 while end + 1 < D and not alive[end + 1]: end += 1 left = int(slots[start - 1]) if start - 1 >= 0 else int(slots[-1]) - Pm right = int(slots[end + 1]) if end + 1 < D else int(slots[0]) + Pm oldgaps = [int(x) for x in g[start - 1:end + 1]] off = k * Pm witnesses.append({'tile': 23, 'fold_p': p, 'strip_k': k, 'absolute_shift': int(off), 'Y_fused_gap_left': left + off, 'Y_base_coordinate': left, 'fused_gap_absolute': [left + off, right + off], 'fused_gap_length': right - left, 'j': end - start + 1, 'killed_slots_absolute': [int(x) + off for x in slots[start:end + 1]], 'killed_slots_base': [int(x) for x in slots[start:end + 1]], 'killed_absolute_residues_mod_p': [int((x + off) % p) for x in slots[start:end + 1]], 'strip_class_a_k': int(c), 'killed_classes': [int(c), int((c - 2) % p)], 'old_gaps_merged': oldgaps, 'gap_pair_mod_p': [int(r[i]), int(r[i + 1])]}) if len(witnesses) >= 3: break out['p31_witnesses'] = witnesses # ---- D. verify the first witness against the independent sieve ---------- if witnesses: w = witnesses[0] lo, hi = w['fused_gap_absolute'][0] - 8, w['fused_gap_absolute'][1] + 8 lo = max(lo, 0) A = set(sieve_window(lo, hi).tolist()) # survivors of the fold ka = w['killed_slots_absolute'] inA = [x for x in ka if x in A] out['witness_verification'] = { 'window': [lo, hi], 'survivors_in_window': sorted(A), 'killed_slots_present_in_folded_word_should_be_empty': inA, 'fused_gap_endpoints_are_survivors': [int(w['fused_gap_absolute'][0]) in A, int(w['fused_gap_absolute'][1]) in A], 'old_gaps_sum_equals_fused_length': sum(w['old_gaps_merged']) == w['fused_gap_length'], 'kills_are_0_or_minus2_mod_p_absolute': all(x % 31 in (0, 29) for x in ka), } print(json.dumps(out, indent=1))