"""Job #4567 (first look, route 117 rev 4). QUESTION: can the step's A pass (sum M = 1.85e13 slots, #1979) and B pass be pruned BEFORE any K* is computed, by an exact capacity bound, and by how much? OBJECT (#1267): P = 30, slots = residues r with gcd(r,30) = gcd(r+2,30) = 1, i.e. r = 11, 17, 29 (mod 30); q kills slot r iff r = 0 or -2 (mod q); K*(30,R) = A = the longest (cyclic) run of consecutive slots each killed by some q in R, over the period 30 prod R. LEMMA (capacity; elementary). Let o_0 < o_1 < ... be the slot offsets from a starting slot of type t (t = the start residue 11, 17 or 29) and cap_q(t, L) = max_{s mod q} #{i < L : s + o_i = 0 or -2 (mod q)}. If a run of L consecutive slots starting at n_0 (type t) is killed by R, every slot is killed by some q, so L <= sum_{q in R} #{i < L : n_0 + o_i in {0,-2} mod q} <= sum_{q in R} cap_q(t, L). Sub-runs of killed runs are killed, so K*(30,R) >= L implies exists t: sum_q cap_q(t, L) >= L. Hence Ahat(R) := max{L <= 64 : exists t, sum_q cap_q(t,L) >= L} >= A (sound upper bound). USE. #1833 proves drop <= D(30,p,A); a drop of 2 needs A >= L2(p) (#1979 dgate30.json: 11,12,14,18,22,39,34,36,48,50,54 for p = 7,11,13,17,19,23,29,31,41,43,47; no p >= 53 and not p = 37 admits a drop of 2 at A <= 60). A row (R,p) can drop by 2 only if Ahat(R) >= L2(p); an R-set needs its A pass only if some admissible p (prime <= 97, p not in R, p not 2,3,5) has Ahat(R) >= L2(p). POPULATION (#1979, the step): R from primes 7..97, |R| in {5,6}, M = 30 prod R in (3e8, 3e9]. PRE-REGISTERED. G1 (population): 13,890 R-sets with |R| = 5 and 1,059 with |R| = 6 at M <= 3e9, of which 12,854 have M > 3e8; sum M over the new sets ~1.85e13 (#1979). G2 (soundness, a theorem check on real data): Ahat(R) >= A for every R-set of #1812's served sweep2775b.json (A known, 14,008 rows) and for the #1267 witness R = {7,13,19,23} (A = 12). A failure means a bug, not a counterexample. M1 (measurement): the fraction of new R-sets whose A pass is skipped, the fraction of their sum M saved, the rows (R,p) with L2(p) defined that survive, and their sum Mp against the unpruned sum. DECISION RULE: if the filter removes >= 50% of either the A-pass cost or the drop-2-eligible B-pass cost, return "progress" with the step restated to run the filter first; otherwise "promising" with the step copied. Deterministic; stdout is the artifact.""" import sys, json, math, itertools import numpy as np led = [] def check(tag, ok, detail): led.append(f"{'PASS' if ok else 'FAIL'} {tag} :: {detail}"); print(led[-1], file=sys.stderr, flush=True) PR = [q for q in range(7, 98) if all(q % d for d in range(2, int(q ** 0.5) + 1))] LMAX = 64 L2 = {7: 11, 11: 12, 13: 14, 17: 18, 19: 22, 23: 39, 29: 34, 31: 36, 41: 48, 43: 50, 47: 54} dg = json.load(open('r1979-dgate30.json', encoding='utf-8'))['thresholds'] assert {int(p): v['min_A_drop2_permitted'] for p, v in dg.items() if v['min_A_drop2_permitted'] is not None} == L2 # slot offsets from each start type def offsets(start, n): out = []; x = start while len(out) < n: if x % 30 in (11, 17, 29): out.append(x - start) x += 1 return np.array(out, dtype=np.int64) OFF = {t: offsets(t, LMAX) for t in (11, 17, 29)} # cap[q][t][L] = max_s #{i < L : (s + o_i) mod q in {0, q-2}} cap = {} for q in PR: cap[q] = {} for t, o in OFF.items(): s = np.arange(q)[:, None]; hit = (((s + o[None, :]) % q == 0) | ((s + o[None, :]) % q == q - 2)).astype(np.int64) cum = np.cumsum(hit, axis=1) # cum[s, L-1] = count over i < L cap[q][t] = np.concatenate(([0], cum.max(axis=0))) # index L = 0..LMAX def Ahat(R): best = 0 for t in (11, 17, 29): tot = np.sum([cap[q][t] for q in R], axis=0) ok = np.flatnonzero(tot[1:] >= np.arange(1, LMAX + 1)) + 1 # the condition must hold at L itself; A >= L requires it at every L' <= L, so the bound is the first failure minus 1 fail = np.flatnonzero(tot[1:] < np.arange(1, LMAX + 1)) first_fail = int(fail[0]) + 1 if fail.size else LMAX + 1 best = max(best, first_fail - 1) return best # ---- G1 population sets = {k: [R for R in itertools.combinations(PR, k) if 30 * math.prod(R) <= 3 * 10 ** 9] for k in (5, 6)} new = [R for k in (5, 6) for R in sets[k] if 30 * math.prod(R) > 3 * 10 ** 8] sumM_new = sum(30 * math.prod(R) for R in new) check('G1_population_matches_1979', len(sets[5]) == 13890 and len(sets[6]) == 1059 and len(new) == 12854 and abs(sumM_new / 1.85e13 - 1) < 0.01, f'|R|=5: {len(sets[5])}, |R|=6: {len(sets[6])}, new (M > 3e8): {len(new)}, sum M over new = {sumM_new:.4e} (#1979: 13,890 / 1,059 / 12,854; 1.85e13)') allsets = sets[5] + sets[6] sumM_all = sum(30 * math.prod(R) for R in allsets) pall = [q for q in PR] sumMp_allp = sum(30 * math.prod(R) * p for R in allsets for p in pall if p not in R) led.append(f"{'PASS' if abs(sumM_all / 1.85e13 - 1) < 0.01 and abs((sumM_all + sumMp_allp) / 15492573486057570 - 1) < 0.01 else 'FAIL'} G1b_POSTHOC_1979_prices_are_over_all_14949_sets :: sum M over all {len(allsets)} sets (M <= 3e9) = {sumM_all:.4e} (#1979 1.85e13); A pass + sum Mp over every p <= 97 not in R = {sumM_all + sumMp_allp:.6e} (#1979 work_step_slots 1.549257e16)") print(led[-1], file=sys.stderr, flush=True) # ---- G2 soundness on #1812's served rows sw = json.load(open('r1812-sweep2775b.json', encoding='utf-8')) Aserved = {} for r in sw['rows']: Aserved[tuple(r['R'])] = r['A'] viol = [(R, A, Ahat(R)) for R, A in Aserved.items() if Ahat(R) < A] w1267 = Ahat((7, 13, 19, 23)) gap = [Ahat(R) - A for R, A in Aserved.items()] check('G2_capacity_bound_is_sound_on_served_A', not viol and w1267 >= 12, f'{len(Aserved)} served R-sets (#1812 sweep2775b.json): Ahat >= A in all, violations {viol[:3]}; #1267 witness Ahat = {w1267} (A = 12); Ahat - A: min {min(gap)}, median {int(np.median(gap))}, max {max(gap)}') # ---- M1 saving on the new population rows_all = 0; rows_keep = 0; sumMp_all = 0; sumMp_keep = 0; sets_skip = 0; sumM_skip = 0 by_p_all = {p: 0 for p in L2}; by_p_keep = {p: 0 for p in L2}; ahist = {} for R in new: M = 30 * math.prod(R); ah = Ahat(R); ahist[ah] = ahist.get(ah, 0) + 1 ps = [p for p in L2 if p not in R] keep_any = False for p in ps: rows_all += 1; sumMp_all += M * p; by_p_all[p] += 1 if ah >= L2[p]: rows_keep += 1; sumMp_keep += M * p; by_p_keep[p] += 1; keep_any = True if not keep_any: sets_skip += 1; sumM_skip += M fracA = sumM_skip / sumM_new; fracB = 1 - sumMp_keep / sumMp_all keep_list = [] for R in new: ah = Ahat(R); ps = [p for p in sorted(L2) if p not in R and ah >= L2[p]] if ps: keep_list.append({'R': list(R), 'M': 30 * math.prod(R), 'Ahat': ah, 'p_kept': ps}) keep_list.sort(key=lambda d: (d['M'], d['R'])) json.dump({'note': 'route 117 step population after the capacity pre-filter (job #4567): R-sets needing an A pass, with the p whose drop-2 threshold L2(p) <= Ahat(R)', 'L2': L2, 'rows': keep_list}, open('keep4567.json', 'w'), separators=(',', ':')) rate = 20652082504410 / (983.0 * 6) # #1812's measured slots per thread-second (kstar.c) led.append(f"INFO price at #1812's measured kstar.c rate ({rate:.3e} slots per thread-second): A pass on the {len(keep_list)} kept R-sets {(sumM_new - sumM_skip) / rate / 3600:.2f} CPU-h; B pass on the {rows_keep} kept rows at most {sumMp_keep / rate / 3600:.2f} CPU-h (before the exact D gate on the true A); unpruned step {15492573486057570 / rate / 3600:.0f} CPU-h") led.append(f"INFO M1 A pass: {sets_skip} of {len(new)} new R-sets need no K* at all ({sets_skip / len(new):.1%}); sum M saved {sumM_skip:.4e} of {sumM_new:.4e} ({fracA:.1%}); Ahat histogram {dict(sorted(ahist.items()))}") led.append(f"INFO M1 B pass (rows with a drop-2 threshold, p in {sorted(L2)}): {rows_keep} of {rows_all} rows survive; sum Mp {sumMp_keep:.4e} of {sumMp_all:.4e} (saved {fracB:.1%}); per p (all/kept) {dict((p, (by_p_all[p], by_p_keep[p])) for p in sorted(L2))}") decision = 'progress' if max(fracA, fracB) >= 0.5 else 'promising' led.append(f"INFO DECISION (pre-registered rule, >= 50% of either cost): {decision}") print('\n'.join(led)) print('VERDICT ' + json.dumps({'sound': not viol, 'new_sets': len(new), 'sets_skip': sets_skip, 'fracA_saved': fracA, 'rows_all': rows_all, 'rows_keep': rows_keep, 'fracB_saved': fracB, 'sumM_keep': sumM_new - sumM_skip, 'sumMp_keep': sumMp_keep, 'decision': decision})) json.dump({'Ahat_hist_new': ahist, 'by_p_all': by_p_all, 'by_p_keep': by_p_keep, 'served_gap_hist': {int(g): gap.count(g) for g in sorted(set(gap))}, 'ledger': led}, open('fresh4567.json', 'w'), indent=1)