#!/usr/bin/env python3 """job 2753 / route 117's pre-registered hard-regime sweep (prereg-hardsweep-117-rev1.md). Population A: P=210, |R|=4, every R-set with M <= 5e7 (ascending M), every hard p. Population B: P=210, |R|=5, every R-set with M <= 3e8, every hard p. C-cells: P=2310 / P=30030, |R|=3, M <= 3e8 -- A and the hard-p count only (0 is recorded as empty). Control: the #1267 cell (P=30, R={7,13,19,23}, p=11), excluded from every count. Gates: the five published custody values of #1246/#1250/#1267 must pass, and the control must reproduce A=12, B=10, rise=-2, before a single row of the population is reported. Work budget 1.2e12 slot-passes in ascending M, with the exact cut reported if it is reached. python hardsweep117.py --out hard-sweep-117.json """ import argparse import importlib.util import itertools import json import os import sys import time HERE = os.path.dirname(os.path.abspath(__file__)) VERSION = "1.0.0" WORK_BUDGET = 1.2e12 P_MAX = 97 _spec = importlib.util.spec_from_file_location("streamrun", os.path.join(HERE, "stream-run.py")) _s = importlib.util.module_from_spec(_spec) _spec.loader.exec_module(_s) kstar_stream = _s.kstar_stream GATES = _s.GATES CONTROL = (30, (7, 13, 19, 23), 11, 12, 10) # the #1267 cell: P, R, p, A, B def primes_upto(n): return [q for q in range(2, n + 1) if all(q % d for d in range(2, int(q ** 0.5) + 1))] def gates(): out = [] ok = True for B, S, want in GATES: got, _, _ = kstar_stream(B, S) ok = ok and got == want out.append({"base": B, "R": list(S), "expected": want, "observed": got, "pass": got == want}) P, R, p, wantA, wantB = CONTROL A, _, _ = kstar_stream(P, R) Bv, _, _ = kstar_stream(P * p, R) ok = ok and A == wantA and Bv == wantB out.append({"base": P, "R": list(R), "expected": wantA, "observed": A, "pass": A == wantA, "note": "#1267 A"}) out.append({"base": P * p, "R": list(R), "expected": wantB, "observed": Bv, "pass": Bv == wantB, "note": "#1267 B"}) return ok, out def main(): ap = argparse.ArgumentParser() ap.add_argument("--out", default=None) ap.add_argument("--budget", type=float, default=WORK_BUDGET) ap.add_argument("--slice-slots", type=float, default=None, help="stop this invocation after this many slot-passes (resumable slices); " "the state is carried in ") ap.add_argument("--resume", action="store_true", help="continue from the partial state already in ") a = ap.parse_args() ok, gate_rows = gates() if not ok: print(json.dumps({"ok": False, "stage": "gates", "rows": gate_rows}, indent=1)) return 1 primes = primes_upto(P_MAX) base210 = [q for q in primes if 210 % q] cells = [] for nR, cap in ((4, 5e7), (5, 3e8)): for R in itertools.combinations(base210, nR): M = 210 for q in R: M *= q if M <= cap: cells.append((M, 210, nR, R)) cells.sort() t0 = time.time() spent = 0.0 rows = [] cut = None sets_done = 0 slices = 0 if a.resume and a.out and os.path.exists(a.out): prev = json.load(open(a.out, encoding="utf-8")) rows = prev.get("rows", []) spent = prev.get("population", {}).get("slots_spent", 0.0) sets_done = prev.get("population", {}).get("sets_done", 0) slices = prev.get("population", {}).get("slices", 0) slice_budget = a.slice_slots if a.slice_slots else float("inf") slice_spent = 0.0 for M, P, nR, R in cells[sets_done:]: # A set is completed only when every one of its hard rows is measured: a set cut mid-way # is discarded whole, so a resume never mixes partial rows into the population. pending = [] spent += 2 * M slice_spent += 2 * M if spent > a.budget or slice_spent > slice_budget: cut = {"largest_M_completed": None if not rows else max(r["M"] for r in rows), "sets_left": len(cells) - sets_done, "reason": "work budget or slice limit"} break A, _, _ = kstar_stream(P, R) adm = [p for p in base210 if p not in R] hard = [p for p in adm if p <= 2 * A] stopped = False for p in hard: span = 2 * M * p if spent + span > a.budget or slice_spent + span > slice_budget: stopped = True break Bv, _, _ = kstar_stream(P * p, R) spent += span slice_spent += span pending.append({"P": P, "nR": nR, "R": list(R), "p": p, "A": A, "B": Bv, "rise": Bv - A, "M": M, "Mp": M * p}) if stopped: cut = {"largest_M_completed": None if not rows else max(r["M"] for r in rows), "sets_left": len(cells) - sets_done, "reason": "work budget or slice limit", "set_discarded": M} break rows.extend(pending) sets_done += 1 slices += 1 # C-cells: recorded, not swept. Bounded by the SAME work budget (2*M per set, ascending M) # and by an explicit set cap, because the P=2310, |R|=3 population alone runs into the # thousands of R-sets; any cut is reported, never silent. c_cap = 30 # per P c_budget = 0.075 * a.budget # per P c_cut = None ccells = [] for P in (2310, 30030): c_spent = 0.0 baseP = [q for q in primes if P % q] sets = [] for R in itertools.combinations(baseP, 3): M = P for q in R: M *= q if M <= 3e8: sets.append((M, R)) sets.sort() done = 0 for M, R in sets: if done >= c_cap or c_spent + 2 * M > c_budget: c_cut = {"P": P, "sets_in_cap": len(sets), "sets_done": done, "largest_M_completed": ccells[-1]["M"] if ccells else None} break A, _, _ = kstar_stream(P, R) c_spent += 2 * M done += 1 adm = [p for p in baseP if p not in R] ccells.append({"P": P, "R": list(R), "M": M, "A": A, "hard_p_count": sum(1 for p in adm if p <= 2 * A)}) empty_cells = [c for c in ccells if c["hard_p_count"] == 0] rises = [r["rise"] for r in rows] out = { "tool": "job2753/hardsweep117.py", "version": VERSION, "prereg": "job2753/prereg-hardsweep-117-rev1.md", "gates": {"ok": ok, "rows": gate_rows}, "population": {"A_cells": "P=210,|R|=4,M<=5e7", "B_cells": "P=210,|R|=5,M<=3e8", "sets_total": len(cells), "sets_done": sets_done, "hard_rows": len(rows), "work_budget": a.budget, "slots_spent": spent, "cut": cut, "slices": slices, "complete": sets_done == len(cells) and cut is None}, "counts": {"rise_hist": {str(v): sum(1 for x in rises if x == v) for v in sorted(set(rises))}, "min_rise": min(rises) if rises else None, "rows_rise_le_minus_2": [r for r in rows if r["rise"] <= -2], "rows_rise_le_minus_3": [r for r in rows if r["rise"] <= -3], "F1_fired": any(r["rise"] <= -3 for r in rows), "F2_fired": any(r["rise"] == -2 for r in rows), "P1_holds": all(r["rise"] >= 0 for r in rows)}, "by_cell_min_rise": {}, "c_cells": ccells, "c_cells_empty": empty_cells, "c_cells_cut": c_cut, "c_cells_sets_with_zero_hard": len(empty_cells), "F3_fired": False, "rows": rows, "observation": {"wall_sec": round(time.time() - t0, 1), "note": "wall time is machine- and load-dependent"}, } byc = {} for r in rows: key = "%d/%d" % (r["P"], r["nR"]) byc.setdefault(key, []).append(r["rise"]) out["by_cell_min_rise"] = {k: min(v) for k, v in byc.items()} out["by_cell_rows"] = {k: len(v) for k, v in byc.items()} if a.out: with open(a.out, "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) print(json.dumps({k: v for k, v in out.items() if k not in ("rows", "gates", "c_cells")}, indent=1)) return 0 if __name__ == "__main__": sys.exit(main())