"""Job #1643 (pursue route 52 rev 2). QUESTION (#855's next step): does the closed form's T_29 class census, N_g(T_29) = c_29({0,2,g,g+2}) - rho_g(T_29) with rho_g the finite alternating sum of CRT products over subsets of M_g = {6,12,...,g-6}, agree class by class with an independently built T_29 census, and does D(theta) at the T_23 -> T_29 fold agree with the closed form for theta = 12, 18, 24, 30, 36? OBJECTS (as #854/#855 define them): T_x = {r mod x# : gcd(r(r+2), x#) = 1} read cyclically; D(T_x) = #T_x = prod_{3<=q<=x}(q-2); N_g(T_x) = number of openers r whose NEXT opener is r+g (= number of cyclic gaps equal to g); cop_x(g) = #{r in T_x : r+g in T_x} = c_x({0,2,g,g+2}) with c_x(O) = prod_{q<=x}(q - #{(-o) mod q : o in O}); rho_g = cop(g) - N_g = pairs with an opener strictly between; C_g (fold T_p -> T_q) = N_g(T_q) - (q-2) N_g(T_p); D(theta) = sum_{g>=theta} C_g. INSTRUMENT (independent of #855's job1642-checks.py): the tiles are built by a blocked sieve over [0, x#) (the T_29 build of this handle's job #2588, refined2588.py, whose gap word matched #1244's spectra), the census is the histogram of the cyclic gap word, cop(g) is MEASURED directly by shifting three mod-30 class bitmaps, and rho_ie(g) is computed by the alternating sum. PRE-REGISTERED before the run. P1 (totals and #855's fifth-rung table): D(T_29) = 214,708,725, D(T_23) = 7,952,175, N_6(T_29) = 17,506,125 = prod_{5<=q<=29}(q-4), N_12 = 46,683,000, N_18 = 27,184,430, N_24 = 14,178,528, N_30 = 39,735,054, N_36 = 10,497,320, and D(12) at the fold = 1,400,490 = 2 N_6(T_23). P2 (product structure, every class): cop_29(g) measured = c_29({0,2,g,g+2}) for every even g up to G2(T_29) = 258, and likewise at T_23 (G2 = 176 per the record; measured here). P3 (the closure, alternating sum): N_g(T_29) = cop_29(g) - rho_ie(g) for every g <= G_IE = 138 (2^22 - 1 terms at most); same at T_23. P4 (fold): sum_g C_g = 0; D(theta) measured = D(theta) from closed forms (N_g by products and rho_ie) for theta in {12,18,24,30,36}; the initial negative segment of C_g reported. FALSIFIER: any class g <= G_IE with N_g != cop - rho_ie (report the first failing g), or any cop(g) != product. Stdout: ledger + JSON; stderr: progress. Memory ~3 GB, ~15 min.""" import argparse, json, math, sys, time, itertools import numpy as np ap = argparse.ArgumentParser(); ap.add_argument('--out', default='census1643.json'); ap.add_argument('--gie', type=int, default=138); a = ap.parse_args() log = sys.stderr; t0 = time.time(); led = [] def check(tag, ok, detail): led.append(f"{'PASS' if ok else 'FAIL'} {tag} :: {detail}"); print(led[-1], file=log, flush=True) CLASSES = (11, 17, 29) def primes_upto(x): return [p for p in range(2, x + 1) if all(p % q for q in range(2, int(p ** 0.5) + 1))] 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 build(x): qs = [q for q in primes_upto(x) if q >= 3]; P = 2 * math.prod(qs) BL = 30030 * 64; parts = [] for lo in range(0, P, BL): hi = min(P, lo + BL); parts.append(np.flatnonzero(block_bool(lo, hi, qs)).astype(np.int64) + lo) r = np.concatenate(parts); return P, r def class_bitmaps(P, r): """bool arrays A_c[j] = (30 j + c in T), for c in CLASSES, length P/30.""" n = P // 30; A = {} for c in CLASSES: sel = r[(r % 30) == c]; A[c] = np.zeros(n, dtype=bool); A[c][(sel - c) // 30] = True return A def cop_measured(P, A, g): """#{r in T : r+g in T} by class shifts; g even, g = 0 mod 6 for slots (otherwise the count is 0 by residues mod 3).""" n = P // 30; total = 0 for c in CLASSES: c2 = (c + g) % 30 if c2 not in CLASSES: continue k = (c + g - c2) // 30 # r = 30 j + c -> r + g = 30 (j + k) + c2 src = A[c]; dst = np.roll(A[c2], -k) # dst[j] = A_c2[(j + k) mod n] (cyclic in r mod P since 30 n = P) total += int(np.count_nonzero(src & dst)) return total def c_x(offsets, qs): v = 1 for q in qs: v *= q - len({(-o) % q for o in offsets}) if v == 0: return 0 return v def rho_ie(g, qs): M = list(range(6, g, 6)); tot = 0; base = (0, 2, g, g + 2) for k in range(1, len(M) + 1): sign = 1 if k % 2 == 1 else -1 for S in itertools.combinations(M, k): offs = base + tuple(h for H in S for h in (H, H + 2)) tot += sign * c_x(offs, qs) return tot out = {'instrument': 'census1643.py', 'job': 1643, 'G_IE': a.gie, 'tiles': {}} tiles = {} for x in (23, 29): t1 = time.time(); qs_all = primes_upto(x); P, r = build(x); D = len(r) g = np.diff(np.concatenate([r, [r[0] + P]])); Ng = np.bincount(g); G2 = int(g.max()) A = class_bitmaps(P, r); del r print(f'T_{x}: P={P} D={D} G2={G2} built ({time.time() - t1:.0f}s)', file=log, flush=True) census = {int(k): int(Ng[k]) for k in range(len(Ng)) if Ng[k]} cop_meas = {}; cop_prod = {}; bad_prod = [] for gg in range(6, G2 + 1, 6): cop_meas[gg] = cop_measured(P, A, gg); cop_prod[gg] = c_x((0, 2, gg, gg + 2), qs_all) if cop_meas[gg] != cop_prod[gg]: bad_prod.append(gg) # classes not divisible by 6 must be empty (openers are 5 mod 6) non6 = {k: v for k, v in census.items() if k % 6} print(f'T_{x}: cop measured for {len(cop_meas)} classes ({time.time() - t1:.0f}s)', file=log, flush=True) rho_meas = {gg: cop_meas[gg] - census.get(gg, 0) for gg in cop_meas} rho_ie_v = {}; bad_ie = [] for gg in range(6, min(a.gie, G2) + 1, 6): rho_ie_v[gg] = rho_ie(gg, qs_all) if rho_ie_v[gg] != rho_meas[gg]: bad_ie.append(gg) if gg % 36 == 0: print(f' rho_ie up to g={gg} ({time.time() - t1:.0f}s)', file=log, flush=True) del A tiles[x] = {'P': P, 'D': D, 'G2': G2, 'census': census, 'cop_measured': cop_meas, 'cop_product': cop_prod, 'rho_measured': rho_meas, 'rho_ie': rho_ie_v, 'classes_not_0_mod_6': non6, 'bad_product_classes': bad_prod, 'bad_ie_classes': bad_ie, 'secs': round(time.time() - t1, 1)} check(f'T{x}_D', D == math.prod(q - 2 for q in qs_all if q >= 3), f'D = {D}') check(f'T{x}_classes_multiple_of_6', not non6, f'non-6 classes: {non6}') check(f'T{x}_P2_cop_is_product_all_classes', not bad_prod, f'{len(cop_meas)} classes to G2 = {G2}; mismatches {bad_prod}') check(f'T{x}_P3_closure_N_eq_cop_minus_rho_ie', not bad_ie, f'classes g <= {min(a.gie, G2)}; first failing {bad_ie[:3]}') out['tiles'][str(x)] = {k: (v if k not in ('census', 'cop_measured', 'cop_product', 'rho_measured', 'rho_ie') else {str(kk): vv for kk, vv in v.items()}) for k, v in tiles[x].items()} # P1 table c29 = tiles[29]['census']; c23 = tiles[23]['census'] table = {6: 17506125, 12: 46683000, 18: 27184430, 24: 14178528, 30: 39735054, 36: 10497320} check('P1_totals', tiles[29]['D'] == 214708725 and tiles[23]['D'] == 7952175, f"D29={tiles[29]['D']} D23={tiles[23]['D']}") check('P1_fifth_rung_table', all(c29.get(g, 0) == v for g, v in table.items()), f"measured {{ {', '.join(f'{g}: {c29.get(g,0)}' for g in table)} }}") check('P1_N6_product', c29.get(6, 0) == math.prod(q - 4 for q in primes_upto(29) if q >= 5), f"N_6(T_29) = {c29.get(6,0)}") # P4 fold allg = sorted(set(c29) | set(c23)); C = {g: c29.get(g, 0) - 27 * c23.get(g, 0) for g in allg} Dth = {th: sum(v for g, v in C.items() if g >= th) for th in (6, 12, 18, 24, 30, 36, 42, 48)} # closed-form D(theta) = -sum_{g