#!/usr/bin/env python3 """Step check for job #4259 (route 147): is the 5536-row P=30 slice already answered? No A/B computation is run and no census is reproduced. Four checks: A. Re-enumerate the step's own domain from its stated predicates (R a set of 3..5 distinct primes from 7..97, p in {7,11,13}\\R, 25000000 < 30*prod(R)*p <= 3e8) and compare the counts with #1516's served table (7736 / 2200 / 5536). B. Inclusion: every row of that slice lies inside the population #1812 measured (P=30, R from primes 7..97, |R| in 3..6, M = 30*prod(R) <= 3e8, every hard p <= 97, p not dividing P, p not in R), or is settled by #1267's floor. C. The served half: locate the census's six drop rows (from #1367 / #1804) inside the slice window and compare with the 5 drops #1521 quotes for its 2200 rows. D. Re-derive #1833's proven phase bound D(P,p,L) at P=30 for p in {7,11,13} and the L values it quotes, and check D <= floor(2L/p) everywhere. Prints a JSON summary; asserts every decisive equality. """ import itertools import json import os import sys sys.stdout.reconfigure(encoding="utf-8", errors="replace") HERE = os.path.dirname(os.path.abspath(__file__)) PRIMES = [7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97] P = 30 PS = (7, 11, 13) LO, HI = 25000000, 300000000 out = {"job": 4259, "route": 147, "checks": {}, "failures": []} LINES = [] def say(msg=""): print(msg) LINES.append(msg) def check(name, ok, detail): out["checks"][name] = {"ok": bool(ok), "detail": detail} if not ok: out["failures"].append(name) say("%-38s %s %s" % (name, "PASS" if ok else "FAIL", detail)) # ---------------------------------------------------------------- A: the domain rows_all, rows_served, rows_new = [], [], [] rsets_with_row = {3: set(), 4: set(), 5: set()} sum_mp = 0 for k in (3, 4, 5): for R in itertools.combinations(PRIMES, k): M = P for q in R: M *= q if M > HI: # Mp >= M*p >= M*7, so no p can fit continue for p in PS: if p in R: continue Mp = M * p if Mp > HI: continue rows_all.append((k, R, p, M, Mp)) rsets_with_row[k].add(R) sum_mp += Mp if Mp <= LO: rows_served.append((k, R, p, M, Mp)) else: rows_new.append((k, R, p, M, Mp)) by_k = {k: sum(1 for r in rows_all if r[0] == k) for k in (3, 4, 5)} new_by_k = {k: sum(1 for r in rows_new if r[0] == k) for k in (3, 4, 5)} check("A total rows (Mp <= 3e8)", len(rows_all) == 7736, len(rows_all)) check("A served window rows (Mp <= 2.5e7)", len(rows_served) == 2200, len(rows_served)) check("A new rows (2.5e7 < Mp <= 3e8)", len(rows_new) == 5536, len(rows_new)) check("A per-|R| row split", by_k == {3: 3990, 4: 3740, 5: 6}, by_k) check("A sum(Mp) = 7.550e11", 7.5495e11 <= sum_mp <= 7.5505e11, "%.4e" % sum_mp) # #1516's 'R-sets' column is the R-sets scanned under the base-period cap M <= 3e8; # the sets actually contributing a row are fewer (e.g. R = {7,11,13} has no p left). rsets_scanned = {} for k in (3, 4, 5): n = 0 for R in itertools.combinations(PRIMES, k): M = P for q in R: M *= q if M <= HI: n += 1 rsets_scanned[k] = n check("A R-set column = sets with M <= 3e8", rsets_scanned == {3: 1540, 4: 6330, 5: 2093}, "%s (sets with a row: %s)" % (rsets_scanned, {k: len(v) for k, v in rsets_with_row.items()})) out["new_by_k"] = new_by_k # #1384: the |R|=5 class at P=30 is already complete -- exactly 12 (R,p) rows with Mp <= 3e8. r5_all = [] for R in itertools.combinations(PRIMES, 5): M = P for q in R: M *= q for p in PRIMES: if p in R or P % p == 0: continue if M * p <= HI: r5_all.append((R, p, M * p)) check("A |R|=5 reachable set is exactly 12 rows", len(r5_all) == 12, len(r5_all)) out["new_mp_min"] = min(r[4] for r in rows_new) out["new_mp_max"] = max(r[4] for r in rows_new) new_r5 = [(r, p, Mp) for (k, r, p, M, Mp) in rows_new if k == 5] check("A the six |R|=5 slice rows are inside it", all(any(r == R and pp == p for r, pp, _ in r5_all) for R, p, _ in new_r5), "") out["new_r5"] = [[list(r), p, Mp] for r, p, Mp in new_r5] say(" new rows by |R|: %s Mp range %.4e .. %.4e" % (new_by_k, out["new_mp_min"], out["new_mp_max"])) say(" |R|=5 rows inside the Mp window: %s (served class per #1384)" % (out["new_r5"],)) # ------------------------------------------------------- B: inclusion in #1812 bad = [] for k, R, p, M, Mp in rows_new: if not (M <= HI and 3 <= k <= 6 and all(7 <= q <= 97 for q in R) and p in PRIMES and P % p and p not in R): bad.append((k, R, p, M, Mp)) check("B every new row inside #1812's population", not bad, "%d violations; M <= %d <= 3e8" % (len(bad), max(r[3] for r in rows_new))) genuinely_new = [(k, R, p, M, Mp) for (k, R, p, M, Mp) in rows_new if k <= 4] check("B new rows excluding the served |R|=5 class", len(genuinely_new) == len(rows_new) - len(new_r5), "%d genuinely new (%d |R|=5 = served controls)" % (len(genuinely_new), len(new_r5))) # ---------------------------------------------------- C: the served half's drops # The census's six drop rows as #1367 states them and #1804 lists them. drops = [({"7", "13", "19", "23"}, 11, 2), ({"7", "11", "19"}, 13, 1), ({"7", "13", "17", "23"}, 11, 1), ({"7", "13", "19", "23"}, 17, 1), ({"7", "17", "19", "23"}, 11, 1), ({"7", "17", "19", "23"}, 13, 1)] in_slice, out_slice = [], [] for R, p, d in drops: M = P for q in sorted(R): M *= int(q) Mp = M * p rec = {"R": sorted(R, key=int), "p": p, "d": d, "Mp": Mp} (in_slice if (p in PS and p not in R and Mp <= HI) else out_slice).append(rec) check("C census drops inside the slice window", len(in_slice) == 5, json.dumps(in_slice)) check("C of those, one has d = 2", sum(1 for r in in_slice if r["d"] == 2) == 1, "") check("C all five are in the served half (Mp <= 2.5e7)", all(r["Mp"] <= LO for r in in_slice), "max Mp %d" % max(r["Mp"] for r in in_slice)) check("C the sixth drop lies outside (p = 17)", len(out_slice) == 1 and out_slice[0]["p"] == 17, json.dumps(out_slice)) out["slice_drops"] = in_slice # ------------------------------------------------- D: #1833's phase bound at P=30 def admissible(Q): qs = [q for q in range(2, Q + 1) if Q % q == 0] return [r for r in range(Q) if all(r % q not in (0, (q - 2) % q) for q in qs)] def Dbound(Q, p, L): c = admissible(Q) m = len(c) best = 0 for phi in range(m): o = [((phi + i) // m) * Q + c[(phi + i) % m] - c[phi] for i in range(L)] mn = min(sum(1 for x in o if (x + s) % p in (0, (p - 2) % p)) for s in range(p)) best = max(best, mn) return best check("D admissible classes mod 30 = [11,17,29]", admissible(30) == [11, 17, 29], admissible(30)) quoted = {(7, 4): 0, (7, 5): 0, (7, 6): 0, (7, 7): 0, (7, 11): 2, (11, 17): 2, (11, 18): 2, (13, 20): 2} got = {k: Dbound(30, k[0], k[1]) for k in quoted} floors = {k: (2 * k[1]) // k[0] for k in quoted} check("D quoted (p,L) values reproduce", got == quoted, "got %s floors %s" % (got, floors)) first3 = {p: next(L for L in range(1, 61) if Dbound(30, p, L) >= 3) for p in PS} check("D first L with D >= 3 is 14/19/21", first3 == {7: 14, 11: 19, 13: 21}, first3) ok_pig = all(Dbound(30, p, L) <= (2 * L) // p for p in PS for L in range(1, 61)) check("D piggyback D <= floor(2L/p), L <= 60", ok_pig, "checked 3*60 shapes") out["D_first_ge3"] = first3 with open(os.path.join(HERE, "stepcheck.json"), "w", encoding="utf-8", newline="") as fh: json.dump(out, fh, indent=1, ensure_ascii=False) fh.write("\n") say() say("failures: %s" % (out["failures"] or "none",)) with open(os.path.join(HERE, "stepcheck.out"), "w", encoding="utf-8", newline="\n") as fh: fh.write("\n".join(LINES) + "\n") sys.exit(1 if out["failures"] else 0)