#!/usr/bin/env python3 """Job #4540 -- route 100 step check (record comparison only). No `K*`, no `A`, no `B`, no sweep row is produced for any new shape here. It builds the two artefacts the return rests on: corpus.jsonl the searchable text (step_scan.report_text) of every served return in the comparison frame, one JSON object per line: the 185 rows of return #2024's own corpus (reused, hash-verified) extended by this job's fresh public fetches of #2024..#2027; scan.json the comparison: the step and its four byte-identical copies, which returns were recorded after the step-setter #1833 and after the previous step check #2024, which of them carry the step's vocabulary or its success shape, the served #1833 sweep and phase-bound table re-aggregated, the served #1804 P=30 census, and the price of the step's own branches. Instruments reused (promoted, private/lib/served): step_scan.report_text, step_scan.keyword_hits. Nothing here claims a bound on G2, beta_2 or twin-prime infinitude. """ from __future__ import annotations import hashlib import itertools import json import os import re import sys from math import prod import sympy HERE = os.path.dirname(os.path.abspath(__file__)) ROOT = os.path.abspath(os.path.join(HERE, "..", "..")) sys.path.insert(0, os.path.join(ROOT, ".solveathome", "private", "lib")) from served import step_scan # noqa: E402 SERVED = os.path.join(HERE, "served") BRIEF = os.path.join(ROOT, ".solveathome", "private", "runs", "launch-sv37hvl1lkqlgqdny8jx821m", "requests", "req-czm14o1x8joep4a02fnl.response.json") STEP_SETTER = 1833 # route 100's step was set by this return PREV_CHECK = 2024 # the previous step check on this same step (job #4528) NAMED = [1264, 1267, 1804, 1833, 2018, 2024] FRESH = [2024, 2025, 2026, 2027] # The step's own vocabulary, fixed before the comparison is read. LOCATORS = ["sweep2612", "kfork", "dbound2612", "dbound", "A_{Pp}", "A - d*", "D(P,p,A)", "phase bound", "base extension", "base-extension", "Pp,R", "return-1267", "return-1804", "#1267", "#1804", "#1833", "#2018", "#2024", "route 100", "route 127", "4176", "boundary-transfer"] OBJECTS = ["drop", "merge gain", "merge-gain", "attain", "K*(P", "K*(30", "A - B", "A - B", "maximal A-run", "fork count"] SUCCESS_PATTERNS = { "drop_eq_D": r"drop\s*=\s*D\b", "drop_eq_D_ge3": r"drop\s*=\s*D\s*>=\s*3", "merge_gain": r"merge[\s\-_]?gain", "drop_ge_3": r"drop\s*>=\s*3", } STEP_BLOCK = re.compile(r'\{\s*"method"\s*:\s*"Reuse sweep2612.*?' r'"required_sources"\s*:\s*\[[^\]]*\][^}]*\}', re.S) RATES = {"measured_single_thread_lo": 2.19e8, "measured_single_thread_hi": 2.67e8, "four_thread": 1.0e9, "conservative": 2.4e8} def sha256_file(p): with open(p, "rb") as fh: return hashlib.sha256(fh.read()).hexdigest() def canon(obj): return json.dumps(obj, sort_keys=True, separators=(",", ":")) def step_sha(obj): return hashlib.sha256(canon(obj).encode("utf-8")).hexdigest() def load(name): return json.load(open(os.path.join(SERVED, name), encoding="utf-8")) def alive_classes(P): fs = [q for q in sympy.primerange(2, P + 1) if P % q == 0] return [c for c in range(P) if all(c % q not in (0, (q - 2) % q) for q in fs)] def d_row(P, p, L, cls=None): """D(P,p,L) = max over start phases of min over shifts of the forked count.""" cls = cls if cls is not None else alive_classes(P) m = len(cls) best = None for phi in range(m): off = [((phi + i) // m) * P + cls[(phi + i) % m] - cls[phi] for i in range(L)] cnt = [0] * p for x in off: cnt[x % p] += 1 k = min(cnt[(-s) % p] + cnt[(-s - 2) % p] for s in range(p)) best = k if best is None else max(best, k) return best def price_p30(poolmax, plist, mpmax=10 ** 10, mcap=None): """Two-phase price of the step's P=30 clause. Phase A (computing A = K*(30,R)) runs over every R-set for which some requested p can still satisfy Mp <= mpmax; phase B (computing B = K*(30p,R)) runs over the surviving (R,p) rows. No A gate is applied: the step's A >= 14 / A >= 19 clause can only remove rows, so this is an upper bound on the branch's cost. ``mcap`` optionally adds the setter's own modulus-cap convention (P=2 used M <= 2e8). """ pool = [q for q in sympy.primerange(2, poolmax + 1) if 30 % q != 0] sets = [] for k in range(2, len(pool) + 1): for R in itertools.combinations(pool, k): M = 30 * prod(R) if mcap is not None and M > mcap: continue adm = [p for p in plist if p not in R] if adm and M * min(adm) <= mpmax: sets.append((R, M)) rows = [(R, p, M, M * p) for R, M in sets for p in plist if p not in R and M * p <= mpmax] return {"pool": len(pool), "sets": len(sets), "sum_M": sum(M for _R, M in sets), "rows": len(rows), "sum_Mp": sum(r[3] for r in rows), "max_Mp": max((r[3] for r in rows), default=0)} def band_price(P, poolmax, mcap, pcap=61): """The un-run P=2/P=6 band 2e9 < Mp <= 1e10 under the setter's own driver caps.""" pool = [q for q in sympy.primerange(2, poolmax + 1) if P % q != 0] br = bs = 0 for k in range(2, len(pool) + 1): for R in itertools.combinations(pool, k): M = P * prod(R) if M > mcap: continue for p in sympy.primerange(2, pcap + 1): if P % p == 0 or p in R: continue mp = M * p if 2e9 < mp <= 1e10: br += 1 bs += mp return {"rows": br, "sum_Mp": bs} def main(): brief = json.loads(open(BRIEF, encoding="utf-8").read()) body = json.loads(brief["body"]) if isinstance(brief["body"], str) else brief["body"] step_lines = [l for l in body["brief_md"].split("\n") if l.startswith("{") and "Reuse sweep2612" in l] step = json.loads(step_lines[0]) # the step as a standalone shipped input, so the checker can verify its identity # against the four served copies without reading the private run state with open(os.path.join(HERE, "step.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(step, fh, indent=1, sort_keys=True) fh.write("\n") # ---- corpus: #2024's hash-verified 185 rows, extended by this job's fresh fetches reused = [json.loads(l) for l in open(os.path.join(SERVED, "f2024_corpus.jsonl"), encoding="utf-8") if l.strip()] rows = list(reused) have = {r["id"] for r in rows} for rid in FRESH: if rid in have: continue rec = load("return-%d.json" % rid) rows.append({"id": rid, "route": rec.get("research_route_id"), "created_at": rec.get("created_at"), "type": rec.get("type"), "status": rec.get("status"), "n_chars": len(step_scan.report_text(rec)), "text": step_scan.report_text(rec)}) rows.sort(key=lambda r: r["id"]) with open(os.path.join(HERE, "corpus.jsonl"), "w", encoding="utf-8", newline="\n") as fh: for r in rows: fh.write(json.dumps(r, sort_keys=True) + "\n") byid = {r["id"]: r for r in rows} setter_at = byid[STEP_SETTER]["created_at"] prev_at = byid[PREV_CHECK]["created_at"] after = [r for r in rows if str(r["created_at"]) > str(setter_at)] after_prev = [r for r in rows if str(r["created_at"]) > str(prev_at)] # ---- the step's identity: every copy of it on the record route100 = json.load(open(os.path.join(SERVED, "route-100.json"), encoding="utf-8")) copies = {"brief": step_sha(step), "route-100.next_step": step_sha(route100["next_step"])} for rid in (STEP_SETTER, 2018, PREV_CHECK): rec = load("return-%d.json" % rid) ns = (rec.get("research") or {}).get("next_step") copies["return-%d.next_step" % rid] = step_sha(ns) if ns else None # ---- the comparison: vocabulary and the success shape on the returns after #2024 fresh_rows = [] for r in after_prev: norm = r["text"].replace('\\"', '"') loc = step_scan.keyword_hits(r["text"], LOCATORS) obj = step_scan.keyword_hits(r["text"], OBJECTS) succ = {k: len(re.findall(pat, norm, re.I)) for k, pat in SUCCESS_PATTERNS.items()} succ = {k: v for k, v in succ.items() if v} fresh_rows.append({"id": r["id"], "route": r["route"], "created_at": r["created_at"], "status": r["status"], "locator_hits": loc, "object_hits": obj, "success_hits": succ, "quotes_step": bool(STEP_BLOCK.search(norm))}) # the same scan over the whole post-#1833 window, for the record strong_all = sorted(r["id"] for r in after if step_scan.keyword_hits(r["text"], LOCATORS) and step_scan.keyword_hits(r["text"], OBJECTS)) reports_success = [] for r in after: if r["id"] in (2018, PREV_CHECK): # the two prior step checks quote the step verbatim continue norm = r["text"].replace('\\"', '"') if any(re.search(pat, norm, re.I) for pat in SUCCESS_PATTERNS.values()): reports_success.append(r["id"]) # ---- served #1833 sweep, re-aggregated sweep = [json.loads(l) for l in open(os.path.join(SERVED, "f1833_sweep2612.jsonl"), encoding="utf-8") if l.strip()] agg = {} attained = {} for P, p, R, a, b, d in sweep: M = P * prod(R) s = agg.setdefault(str(P), {"n": 0, "sum_M": 0, "sum_Mp": 0, "n_drop_gt_D": 0, "n_drop_ge3": 0, "nD_ge3": 0, "n_drop_eq_D": 0}) s["n"] += 1 s["sum_M"] += M s["sum_Mp"] += M * p s["n_drop_gt_D"] += (a - b > d) s["n_drop_ge3"] += (a - b >= 3) s["nD_ge3"] += (d >= 3) s["n_drop_eq_D"] += (a - b == d) if a - b == d: attained["%d/%d/%d/%d" % (P, p, a, d)] = attained.get("%d/%d/%d/%d" % (P, p, a, d), 0) + 1 sweep_rec = { "n_rows": len(sweep), "per_P": agg, "attained_drop_eq_D_counts": attained, "max_attained_D": max((d for P, p, R, a, b, d in sweep if a - b == d), default=None), "max_drop": max(a - b for P, p, R, a, b, d in sweep), "n_drop_ge_D_minus_2": sum(1 for r in sweep if r[3] - r[4] >= r[5] - 2), "sum_Mp_drop_ge_D_minus_2": sum(P * prod(R) * p for P, p, R, a, b, d in sweep if a - b >= d - 2), "D_ge3_fraction": sum(1 for r in sweep if r[5] >= 3) / float(len(sweep)), } # ---- served #1833 phase-bound table: thresholds and the proven envelope db = load("f1833_dbound2612.json") Lmax, pmax = db["Lmax"], db["pmax"] cls30 = alive_classes(30) thr = {} strict30 = [] for p in (7, 11, 13, 17, 19): vals = [d_row(30, p, L, cls30) for L in range(1, 61)] thr[p] = min(L for L in range(1, 61) if vals[L - 1] >= 3) strict30.append([[p, L, (2 * L) // p, vals[L - 1]] for L in range(1, 61) if vals[L - 1] < (2 * L) // p]) dbound_rec = {"rows": db["rows"], "n_strict": db["n_strict"], "pmax": pmax, "Lmax": Lmax, "min_L_for_D_ge3_at_P30": thr, "D_floor_case_count_P30_p_le_19": sum(len(v) for v in strict30), "D_equals_floor_at_targets_P30": all( d_row(30, p, L, cls30) == (2 * L) // p for p, L in ((7, 14), (11, 19), (13, 21), (17, 27), (19, 33)))} # ---- served #1804 P=30 census cen = load("f1804_sweep2785.json") crows = cen["rows"] census_rec = { "P": cen["P"], "sets": cen["sets"], "hard_rows": cen["hard_rows"], "n_rows": len(crows), "A_max": max(r["A"] for r in crows), "max_drop": max(r["A"] - r["B"] for r in crows), "n_drop_eq_D_ge3": sum(1 for r in crows if r["B"] is not None and r["A"] - r["B"] >= 3), "step_target_cells": { "p7_A_ge_14": sum(1 for r in crows if r["p"] == 7 and r["A"] >= 14), "p11_A_ge_19": sum(1 for r in crows if r["p"] == 11 and r["A"] >= 19)}, "A_max_at_p7": max((r["A"] for r in crows if r["p"] == 7), default=None), "A_max_at_p11": max((r["A"] for r in crows if r["p"] == 11), default=None), "n_p7_rows": sum(1 for r in crows if r["p"] == 7), "n_p11_rows": sum(1 for r in crows if r["p"] == 11), "H1_holds": cen["H1_holds"], "H2_holds": cen["H2_holds"], "H2_counterexample_count": cen["H2_counterexample_count"], "sum_Mp": sum(30 * prod(r["R"]) * r["p"] for r in crows), } # ---- the price band = {"P=2": band_price(2, 43, 2e8), "P=6": band_price(6, 47, 5e8)} band_rows = sum(v["rows"] for v in band.values()) band_slots = sum(v["sum_Mp"] for v in band.values()) p30 = {str(pm): price_p30(pm, [7, 11]) for pm in (43, 47, 60)} p30["43_M_le_2e8"] = price_p30(43, [7, 11], mcap=2e8) p30["43_M_le_5e8"] = price_p30(43, [7, 11], mcap=5e8) rate = RATES["conservative"] hours = { "merge_classification_recorded_rows": sweep_rec["sum_Mp_drop_ge_D_minus_2"] / rate / 3600.0, "p2_p6_band_single_thread": band_slots / RATES["measured_single_thread_lo"] / 3600.0, "p2_p6_band_four_thread": band_slots / RATES["four_thread"] / 3600.0, "p30_branch_pool43_single_thread": (p30["43"]["sum_M"] + p30["43"]["sum_Mp"]) / RATES["measured_single_thread_lo"] / 3600.0, "p30_branch_pool43_at_2.4e8": (p30["43"]["sum_M"] + p30["43"]["sum_Mp"]) / rate / 3600.0, "p30_branch_pool43_M_le_2e8_at_2.4e8": (p30["43_M_le_2e8"]["sum_M"] + p30["43_M_le_2e8"]["sum_Mp"]) / rate / 3600.0, "p30_branch_pool47_at_2.4e8": (p30["47"]["sum_M"] + p30["47"]["sum_Mp"]) / rate / 3600.0, "p30_branch_pool60_at_2.4e8": (p30["60"]["sum_M"] + p30["60"]["sum_Mp"]) / rate / 3600.0, "recorded_sweep_total": sweep_rec["per_P"]["2"]["sum_Mp"] + sweep_rec["per_P"]["6"]["sum_Mp"], } price_rec = {"rate_slots_per_sec": RATES, "rate_provenance": "return #2024 (job #4528) timing of the served kfork.c on " "three rows already on the #1833 record; NOT re-measured here " "(no C compiler on PATH in this workspace)", "band_2e9_lt_Mp_le_1e10": band, "band_rows": band_rows, "band_slots": band_slots, "p30_branch": p30, "step_budget_hours": 2.0, "assignment_cpu_hours": 8.0, "hours": hours} scan = { "job": 4540, "route": 100, "attempt": body["attempt_id"], "step": step, "step_sha256": copies["brief"], "step_setter": {"id": STEP_SETTER, "created_at": setter_at}, "prev_check": {"id": PREV_CHECK, "created_at": prev_at}, "vocabulary": {"locators": LOCATORS, "object_words": OBJECTS, "success_patterns": SUCCESS_PATTERNS}, "corpus": {"n": len(rows), "sha256": sha256_file(os.path.join(HERE, "corpus.jsonl")), "n_after_step_setter": len(after), "n_after_prev_check": len(after_prev), "reused_rows": len(reused), "reused_sha256": sha256_file(os.path.join(SERVED, "f2024_corpus.jsonl")), "fresh_rows": len(rows) - len(reused), "max_created_at_ids_le_prev": max(r["created_at"] for r in rows if r["id"] <= PREV_CHECK - 1)}, "step_copies_sha256": copies, "post_prev_check": fresh_rows, "comparison": {"strong_hits_after_setter": strong_all, "reports_success_shape": reports_success}, "served_1833_sweep": sweep_rec, "served_1833_dbound": dbound_rec, "served_1804_census": census_rec, "price": price_rec, "verdict": { "q1_newer_return_answers_step": bool(reports_success or [r for r in fresh_rows if r["success_hits"] or ("drop" in r["object_hits"] and r["locator_hits"])]), "q1_candidates": [r["id"] for r in fresh_rows], "q2_queue_looping": len({copies[k] for k in copies}) == 1, "q3_covered_range_negative": sweep_rec["max_attained_D"] == 2 and sweep_rec["n_rows"] == 12969, "q3_p26_band_affordable": hours["p2_p6_band_four_thread"] <= 2.0, "q3_p30_branch_affordable": hours["p30_branch_pool43_at_2.4e8"] <= 2.0, "outcome": "progress", }, } with open(os.path.join(HERE, "scan.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(scan, fh, indent=1, sort_keys=True) fh.write("\n") print("corpus %d rows (reused %d + fresh %d); after #1833 %d; after #2024 %d" % (len(rows), len(reused), len(rows) - len(reused), len(after), len(after_prev))) print("step copies all identical:", scan["verdict"]["q2_queue_looping"]) print("post-#2024 returns:", [(r["id"], r["route"], r["locator_hits"], r["success_hits"]) for r in fresh_rows]) print("covered range: %d rows, max attained D %s, drop>=3 %d" % (sweep_rec["n_rows"], sweep_rec["max_attained_D"], agg["2"]["n_drop_ge3"] + agg["6"]["n_drop_ge3"])) print("price: band %.4g slots = %.2f h(4thr)/%.2f h(1thr); P30 pool43 %.4g slots = %.3f h" % (band_slots, hours["p2_p6_band_four_thread"], hours["p2_p6_band_single_thread"], p30["43"]["sum_M"] + p30["43"]["sum_Mp"], hours["p30_branch_pool43_at_2.4e8"])) return 0 if __name__ == "__main__": sys.exit(main())