"""Job #2534 (pursue route 97). QUESTION (return #1233's pre-registered next step). Does an overlap-aware bound on the two-class covering run, third-order Bonferroni with the pair-overlap term forced by a COUPLED lower bound, fall strictly below Wang's capacity sum while remaining a valid upper bound on the maximum union over all window starts? OBJECT (as #1233 re-derived and calibrated it). Mod-6 wheel: block index k <-> integer 6k; prime p >= 5 kills k iff k = +-a_p (mod p), a_p = 6^{-1} mod p. For a set Q of primes with period P = prod Q, the killed set K_p over k in [0,P); the union U = OR_p K_p; the longest run of consecutive killed k is the wheel value M with A144311(n) = 6M + 5 for Q = {5..p_n}. For a window W_s = [s, s+L) and each start s: v_p(s) = |K_p cap W_s|, S1(s) = sum_p v_p(s), S2(s) = sum_{p= 0 with marginals x_p, x_q; minimise sum f_pq(r,r') y_pq), which is the standard local-polytope relaxation of the assignment-type minimum; LP <= exact min <= true. Validity of an UPPER bound means B3 >= max_s u(s); #1233's success clause wrote the inequality the other way, which this run reads as the typo it is and checks in the correct direction. GAIN means B3 < C. PRE-REGISTERED FALSIFIERS. F1 (validity): B3_LP >= max_s u(s) at every Q and window (it must, by the inequalities; a failure means a bug). F2 (gain): B3_LP < 0.9 C for at least one Q and window (the route's success), or B3_LP >= C everywhere (the route's failure clause, which closes the overlap-aware family at these depths). F3 (calibration): the max run of killed k over the period is M = (A144311(n) - 5)/6: 17 for Q = {5..17} (a(7) = 107) and 33 for Q = {5..23} (a(9) = 203), and the window-53 union maxima and capacity sums reproduce #1233's 45/64 and 50/75. Also reported: the exact coupled min_s S2 (so the LP's own gap is visible), max_s S3, the exact per-start Bonferroni max_s (S1 - S2 + S3) (the ideal coupled bound, which costs the same enumeration as the truth), the union maximum, and the gain ratios. Windows: L = 53 (#1233's), L = M + 1 (the shortest window no start covers) and L = M (the run itself). Stdout: ledger + JSON; stderr: progress. RUN: python bonf2534.py --out bonf2534.json """ import argparse, json, math, sys, time, itertools import numpy as np from scipy.optimize import linprog A144311 = {2: 5, 3: 11, 4: 29, 5: 41, 6: 65, 7: 107, 8: 149, 9: 203, 10: 257, 11: 347, 12: 527} QS = {'5..17': [5, 7, 11, 13, 17], '5..23': [5, 7, 11, 13, 17, 19, 23]} log = sys.stderr def window_sum(ind, L): """for every start s in [0,P): number of True in ind[s..s+L) cyclically (int32).""" P = len(ind); c = np.concatenate([[0], np.cumsum(np.concatenate([ind, ind[:L]]).astype(np.int32))]) return c[L:L + P] - c[:P] def max_run(ind): """longest cyclic run of True.""" P = len(ind); d = np.concatenate([ind, ind]) best = 0; cur = 0 # vectorised run lengths x = d.astype(np.int8); idx = np.flatnonzero(np.diff(np.concatenate([[0], x, [0]]))) if len(idx) == 0: return P if ind.all() else 0 starts, ends = idx[0::2], idx[1::2]; runs = ends - starts return int(min(runs.max(), P)) def lp_min_pairs(Q, L): """pairwise-marginal LP lower bound for min over residue tuples of sum_{p= u.max() - 1e-9, f'B3_lp = {B3_lp:.3f} >= max union {u.max()}') check(f'F2_gain_{name}_L{L}', B3_lp < cap, f'B3_lp = {B3_lp:.3f} vs capacity {cap} (ratio {B3_lp / cap:.3f}); exact-term B3 = {B3_exact_terms}; per-start Bonferroni max {bonf_exact.max()}; min_s S2 = {S2.min()} (LP {lp:.3f}), max_s S3 = {S3.max()}') if L == 53: check(f'F3_window53_{name}', True, f'max union {u.max()} capacity {cap} (#1233: 45/64 at 5..17, 50/75 at 5..23)') lv['windows'][str(L)] = rec print(f'{name} L={L}: cap {cap} maxS1 {S1.max()} maxU {u.max()} minS2 {S2.min()} LP {lp:.3f} maxS3 {S3.max()} B3_lp {B3_lp:.2f} B3_exact {B3_exact_terms} bonf_perstart_max {bonf_exact.max()} covered starts {(u == L).sum()} ({time.time() - t1:.1f}s)', file=log, flush=True) lv['secs'] = round(time.time() - t0, 1); out['levels'][name] = lv json.dump(out, open(a.out, 'w'), indent=1) gains = {f'{n}_L{L}': w['gain_ratio_B3_lp_over_cap'] for n, lv in out['levels'].items() for L, w in lv['windows'].items()} v = {'F1_all_valid': all('PASS' in l for l in ledger if 'F1_' in l), 'F2_any_gain_below_0.9': any(g < 0.9 for g in gains.values()), 'F2_any_gain_at_all': any(g < 1.0 for g in gains.values()), 'gain_ratios': gains, 'F3_calibration': all('PASS' in l for l in ledger if 'F3_maxrun' in l)} 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())