"""Job #4495 (route 15 pursuit, step of #2006): attained patterns vs "extras", and a full-period CRT covering census. PRE-REGISTERED gates (stdout is the artifact; timing on stderr): G1 #2006's extras are not length-G patterns: every extra r listed in #2006's served classifier.json is NOT a T_w slot (#2006's crtmodel.offsets() tests only r+G, never r), and #2006's own crt_count(r, G, x, w) equals the corrected count COUNT(r+d, G-d) of the shorter window that starts at the first T_w slot r+d > r: the extras count gaps of length G-d < G. G2 The corrected census (census4495.COUNT/CERT, both ends required) agrees with a full-period numpy sieve at every (x, w) with 5 <= w < x <= 23: the nonzero-count residues mod w# are exactly the residues of the attaining starts, COUNT(r) equals the multiplicity at every r, CERT(r, G) = 0 for every T_w slot r (no gap > G), and sum_r CERT(r, G-6) = nmax. G3 At w = 19 over all 378,675 T_19 slots, x = 23..43 with the ladder's G (204, 258, 348, 528, 546, 618): sum COUNT = the record's nmax (4, 2, 4, 2, 4, 8), CERT(G) = 0 everywhere (G2(x#) <= G), and sum CERT(G-6) = nmax. G4 Every covering vector reconstructs by CRT to a position p mod x# that passes the direct gcd test (p and p+G are T_x slots, no T_x slot strictly inside); the set is closed under sigma(p) = -p-G-2 mod x#; and it equals the served positions (31#, 41# #1791; 37# #426; 43# #1073) and the served 23# residues (#2006). """ import sys, os, json, time, hashlib, importlib.util from math import gcd from collections import Counter from concurrent.futures import ProcessPoolExecutor import numpy as np HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import census4495 as C PR = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43] LADDER = {23: (204, 4), 29: (258, 2), 31: (348, 4), 37: (528, 2), 41: (546, 4), 43: (618, 8)} SERVED_POS = {31: [8813641451, 191746848329, 69494902091, 131065587689], 37: [544899485411, 6875838648869], 41: [3784200788231, 300466062738431, 43469017770041, 260781245756621], 43: [830330079152051, 7479311447941811, 10521814083213911, 11679449232244271, 12252431252517359, 5603449883727599, 2560947248455499, 1403312099425139]} SERVED_RES23 = [8268737, 2294657, 7404827, 1430747] H2006 = {'crtmodel.py': 'b517d40f8885f61ce520c772c40228ca211c1d4b54c50e1d96e2b3a0df5c7290', 'classifier.json': '97769942f47e0a653e0654454aca25c3f299406f1e4a89b786c1aef4424786cc'} def prim(x): r = 1 for q in PR: if q <= x: r *= q return r def sieve(x): """Full period of x#: (G, sorted attaining starts), cyclic.""" P = prim(x) f = np.ones(P, dtype=bool) for q in PR: if q <= x: f[0::q] = False f[(q - 2) % q::q] = False s = np.nonzero(f)[0].astype(np.int64) del f d = np.diff(s) wrap = int(s[0] + P - s[-1]) G = max(int(d.max()), wrap) starts = [int(v) for v in s[:-1][d == G]] + ([int(s[-1])] if wrap == G else []) return G, sorted(starts) def run_census(x, G, mode, w): """Whole census at base w in this process: {r: (count, vectors)} over nonzero r.""" C.setbase(w) flags = C.slots19(); S = np.nonzero(flags)[0] Sext = [int(v) + k * C.B19 for k in range(2 + G // C.B19 + 1) for v in S] # enough periods to cover (r, r+G] Q = [q for q in C.FREE_ALL if q <= x] out = {} for v in S: r = int(v) c, vecs = C.problem(r, G, Q, mode, Sext, flags) if c: out[r] = (c, vecs) return out def chunk19(args): x, G, mode, lo, hi = args C.setbase(19) g = globals() if 'F19' not in g: g['F19'] = C.slots19(); S = np.nonzero(g['F19'])[0] g['S19'] = [int(v) for v in S]; g['SX19'] = g['S19'] + [v + C.B19 for v in g['S19']] Q = [q for q in C.FREE_ALL if q <= x] out = {} for r in g['S19'][lo:hi]: c, vecs = C.problem(r, G, Q, mode, g['SX19'], g['F19']) if c: out[r] = (c, vecs) return (x, G, mode), out def crt(r, B, vec): """p mod B*prod(q) with p = r mod B and p = m mod q for (q, m) in vec.""" p, M = r % B, B for q, m in vec: t = ((m - p) * pow(M, -1, q)) % q p += M * t; M *= q return p % M, M def attains(p, G, x): P = prim(x) if gcd(p * (p + 2), P) != 1 or gcd((p + G) * (p + G + 2), P) != 1: return False return all(gcd(n * (n + 2), P) != 1 for n in range(p + 1, p + G)) def main(): t0 = time.time(); led = [] # ---- G1: #2006's extras for nm, h in H2006.items(): assert hashlib.sha256(open(os.path.join(HERE, 's2006', nm), 'rb').read()).hexdigest() == h, nm spec = importlib.util.spec_from_file_location('m2006', os.path.join(HERE, 's2006', 'crtmodel.py')) M = importlib.util.module_from_spec(spec); spec.loader.exec_module(M) rows = json.load(open(os.path.join(HERE, 's2006', 'classifier.json'), encoding='utf-8')) g1 = True; g1rows = []; g1b_rows = [] for row in rows: x, w, G = row['x'], row['w'], row['G']; B = prim(w) C.setbase(w); flags = C.slots19(); S = np.nonzero(flags)[0] Sext = [int(v) + k * C.B19 for k in range(2 + G // C.B19 + 1) for v in S] Q = [q for q in C.FREE_ALL if q <= x] ds = Counter(); nonslot = 0; match = 0; exact = 0; ge = 0 for r in row['extra']: isslot = gcd(r * (r + 2), B) == 1 nonslot += not isslot d = next(k for k in range(1, G) if flags[(r + k) % B]) theirs = M.crt_count(r, G, x, w) ours, _ = C.problem((r + d) % B, G - d, Q, 'count', Sext, flags) # POST-HOC (after run 1): #2006's crt_count also excludes the classes m in {0, q-2} that kill r itself, a # non-slot, so its count is the shorter window's with offset -d additionally spared ours2, _ = C.problem((r + d) % B, G - d, Q, 'count', Sext, flags, xforb=(-d,)) match += (theirs == ours and theirs > 0); ds[G - d] += 1 exact += (theirs == ours2 and theirs > 0); ge += (ours >= theirs > 0) g1b_rows.append((x, w, len(row['extra']), exact, ge)) ok = nonslot == len(row['extra']) and match == len(row['extra']) g1 = g1 and ok g1rows.append({'x': x, 'w': w, 'G': G, 'extras': len(row['extra']), 'extras_not_T_w_slot': nonslot, 'crt_count_equals_shorter_window_count': match, 'true_gap_lengths_counted': dict(sorted(ds.items()))}) print(f" #2006 extras x={x} w={w} G={G}: {len(row['extra'])} extras, {nonslot} are not T_w slots, " f"{match} have crt_count == COUNT(r+d, G-d) > 0; gap lengths actually counted {dict(sorted(ds.items()))}") g1b = all(e == n and g == n for _, _, n, e, g in g1b_rows) print(' G1b (post-hoc): ' + '; '.join(f'x={x} w={w}: {e}/{n} exact with r spared, {g}/{n} have COUNT(r+d,G-d) >= crt_count > 0' for x, w, n, e, g in g1b_rows)) nsl = sum(r['extras_not_T_w_slot'] for r in g1rows); nex = sum(r['extras'] for r in g1rows) led.append(f"{'PASS' if nsl == nex else 'FAIL'} G1a_extras_not_slots :: {nsl}/{nex} extras of #2006's classifier.json are not T_w slots") led.append(f"{'PASS' if g1b else 'FAIL'} G1b_POSTHOC_crt_count_is_shorter_window_with_r_spared :: #2006's crt_count on every extra equals " f"COUNT(r+d, G-d) with offset -d also spared, and COUNT(r+d, G-d) >= it > 0 (label: added after run 1)") led.append(f"{'PASS' if g1 else 'FAIL'} G1_extras_are_shorter_gaps :: every one of the {sum(r['extras'] for r in g1rows)} " f"extras in #2006's classifier.json is a non-slot r whose count is that of the shorter window [r+d, r+G]") # ---- G2: corrected census vs full-period sieve g2 = True; g2rows = []; sv = {} for x in (11, 13, 17, 19, 23): sv[x] = sieve(x) print(f" sieves: " + ', '.join(f"{x}#: G={sv[x][0]} nmax={len(sv[x][1])}" for x in sv), file=sys.stderr) for x in (11, 13, 17, 19, 23): G, starts = sv[x] for w in (5, 7, 11, 13, 17, 19): if w >= x: continue B = prim(w) cnt = run_census(x, G, 'count', w) crt_ = run_census(x, G, 'cert', w) cm6 = run_census(x, G - 6, 'cert', w) mult = Counter(s % B for s in starts) ok = (set(cnt) == set(mult) and all(cnt[r][0] == mult[r] for r in mult) and not crt_ and sum(v[0] for v in cm6.values()) == len(starts)) g2 = g2 and ok g2rows.append({'x': x, 'w': w, 'G': G, 'nmax': len(starts), 'nonzero_r': len(cnt), 'attained_r': len(mult), 'sum_count': sum(v[0] for v in cnt.values()), 'cert_G_nonzero': len(crt_), 'sum_cert_Gm6': sum(v[0] for v in cm6.values()), 'ok': ok}) print(f" corrected census x={x} w={w} G={G}: nonzero r {len(cnt)} vs attained r {len(mult)}, sum COUNT " f"{sum(v[0] for v in cnt.values())} vs nmax {len(starts)}, CERT(G)>0 at {len(crt_)} r, " f"sum CERT(G-6) {sum(v[0] for v in cm6.values())}: {'ok' if ok else 'MISMATCH'}") led.append(f"{'PASS' if g2 else 'FAIL'} G2_corrected_census_equals_sieve :: {sum(r['ok'] for r in g2rows)}/{len(g2rows)} " f"(x, w) pairs, x = 11..23, w = 5..19: nonzero set == attained set, COUNT == multiplicity, CERT(G) == 0, " f"sum CERT(G-6) == nmax") # ---- G3: w = 19 census at 23..43 tasks = [] for x, (G, _) in LADDER.items(): for mode, g in (('count', G), ('cert', G), ('cert', G - 6)): for lo in range(0, 378675, 50000): tasks.append((x, g, mode, lo, lo + 50000)) res = {} with ProcessPoolExecutor(8) as ex: for key, out in ex.map(chunk19, tasks): res.setdefault(key, {}).update(out) g3 = True; g3rows = [] for x, (G, nmax) in LADDER.items(): cnt = res.get((x, G, 'count'), {}); ce = res.get((x, G, 'cert'), {}); cm = res.get((x, G - 6, 'cert'), {}) sc = sum(v[0] for v in cnt.values()); scm = sum(v[0] for v in cm.values()) ok = sc == nmax and not ce and scm == nmax g3 = g3 and ok g3rows.append({'x': x, 'G': G, 'record_nmax': nmax, 'sum_count': sc, 'residues': {str(r): v[0] for r, v in sorted(cnt.items())}, 'cert_G_nonzero': len(ce), 'sum_cert_Gm6': scm, 'ok': ok}) print(f" w=19 census x={x} G={G}: sum COUNT {sc} (record {nmax}) over residues {dict(sorted((r, v[0]) for r, v in cnt.items()))}; " f"CERT(G)>0 at {len(ce)} of 378675 T_19 slots; sum CERT(G-6) {scm}") led.append(f"{'PASS' if g3 else 'FAIL'} G3_w19_census_reproduces_ladder :: x = 23..43: sum COUNT = " f"{[r['sum_count'] for r in g3rows]} (record {[LADDER[x][1] for x in LADDER]}), no gap > G at any level, sum CERT(G-6) = nmax") # ---- G4: positions g4 = True; posrows = {} for x, (G, nmax) in LADDER.items(): P = prim(x); pos = set() for r, (c, vecs) in res[(x, G, 'count')].items(): assert vecs is not None and len(vecs) == c for v in vecs: p, Mod = crt(r, prim(19), v) assert Mod == P pos.add(p) allok = all(attains(p, G, x) for p in pos) sig = all(((-p - G - 2) % P) in pos for p in pos) served = SERVED_POS.get(x) eq = (sorted(pos) == sorted(served)) if served else (sorted({p % prim(19) for p in pos}) == sorted(SERVED_RES23) if x == 23 else None) ok = allok and sig and len(pos) == nmax and eq is not False g4 = g4 and ok posrows[x] = {'G': G, 'positions': sorted(pos), 'direct_gcd_ok': allok, 'sigma_closed': sig, 'equals_served': eq} print(f" positions x={x} G={G}: {sorted(pos)}; direct gcd test {'all pass' if allok else 'FAIL'}; sigma-closed {sig}; " f"equals served {eq}") led.append(f"{'PASS' if g4 else 'FAIL'} G4_positions_certified_and_equal_served :: " f"{sum(len(v['positions']) for v in posrows.values())} positions at 23..43, each passes the direct gcd test, " f"every level's set is sigma-closed and equals the served list (29# has no served list: 2 positions)") print('\n'.join(led)) print('VERDICT ' + json.dumps({'G1': g1, 'G1a': nsl == nex, 'G1b_posthoc': g1b, 'G2': g2, 'G3': g3, 'G4': g4, 'nmax': {x: len(posrows[x]['positions']) for x in posrows}})) json.dump({'g1': g1rows, 'g1b_posthoc': g1b_rows, 'g2': g2rows, 'g3': g3rows, 'positions': {str(k): v for k, v in posrows.items()}}, open(os.path.join(HERE, 'fresh4495.json'), 'w'), indent=1) print(f'elapsed {time.time() - t0:.0f} s wall', file=sys.stderr) if __name__ == '__main__': main()