#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Job #4548 — independent checker for the route 107 step check. Claim checked: over the served record, no return recorded after the step-setter #1834 answers route 107's held step (the (II) bound for the twin-pair singular-series defect), the step is carried by exactly one return (the setter) so no previous step check has copied it forward, and the step's own success clause is internally consistent with #1834's split at R = H ln^10 H. Nothing here runs the step's experiment: no (II) sum, no Perron integral, no Ramanujan-sum orthogonality argument. Every check is exact set/string equality over served JSON, plus one sympy symbolic identity and one rigorous interval for the twin-prime constant. Inputs (read from the current directory): served_window.jsonl one JSON object per served return with id >= 1834: identity, route, created_at, status, type, model, job_id, report_md, recipe_md, finding, human_md, research probe.json live HTTP status of every id in 1834..2090 (200 present / 404 absent) window_scrub.json the fetch provenance: sha256 of each served return file, plus the substitutions made while projecting brief_step.json the step object, parsed from the assignment brief brief_named.json the ids the brief names for comparison, and the route's own three route-107.json the served route 107 record (next_step, revision, events, jobs) Deterministic, offline, no credential. Exit 0 only when every check passes. """ from __future__ import annotations import hashlib import json import os import re import sys import mpmath as mp import sympy as sp HERE = os.path.dirname(os.path.abspath(__file__)) SETTER = 1834 TOP = 2033 HEAD_PROBE = 2090 # ids in [SETTER, TOP] that were never issued on the server (404 at probe time) NEVER_ISSUED = [1858, 1866, 1870, 1938, 1939, 1961, 1965, 1999, 2000, 2030] STEP_SHA = "8460db45f15d4ccc4678bae2948603a14c365b5f76c759fb846401a17bc82611" # the step's own notation: the objects and method words that appear nowhere else in the record NOTE_WORDS = ["tau(b/r)", "F_H(b/r)", "Ramanujan-sum orthogonality", "ln^10 H", "lnln H"] # the route's object vocabulary, as scan_4548.py uses it OBJECT_WORDS = ["singular series", "S_4", "rho_H", "2C_2", "Montgomery", "Soundararajan", "Fej", "under-disper", "twin-pair", "twin pair", "4-tuple", "four-tuple", "ln^2 H", "ln H", "variance", "route 107", "route107"] LOCATOR_WORDS = ["tau(b/r)", "b/r", "Ramanujan", "Kloosterman", "(II)", "F_H(b/r)"] # expected comparisons, pinned so the checker asserts rather than reports EXPECT_NOTE_CARRIERS = [1834] EXPECT_AFTER_OBJECT3 = [1859, 1872, 1875, 1912, 1914, 1916, 1921] EXPECT_AFTER_KLOOSTERMAN = {1886: 154, 1974: None, 1975: 59, 1989: 83, 2031: None} EXPECT_NAMED = [1859, 1865, 1875, 1892, 1907, 1912, 1914, 1919, 1924] EXPECT_OWN = [1315, 1317, 1834] EXPECT_AFTER = 189 EXPECT_ROUTELESS_AFTER = 50 ABS = re.compile(r"(? None: LINES.append(line) print(line) def check(name: str, ok: bool, detail: str = "") -> None: RESULTS.append((bool(ok), name, detail)) emit("%s %s%s" % ("PASS" if ok else "FAIL", name, (" -- " + detail) if detail else "")) def canon(obj) -> str: return json.dumps(obj, sort_keys=True, separators=(",", ":")) def sha_canon(obj) -> str: return hashlib.sha256(canon(obj).encode("utf-8")).hexdigest() def load(name: str): p = os.path.join(HERE, name) if not os.path.exists(p): p = os.path.join(HERE, "served", name) if not os.path.exists(p): emit("FAIL missing input %s" % name) sys.exit(2) with open(p, encoding="utf-8") as fh: if name.endswith(".jsonl"): return [json.loads(ln) for ln in fh if ln.strip()] return json.load(fh) def report_text(rec: dict) -> str: """The searchable text of a served return (same convention as lib/served/step_scan.py).""" parts = [rec[k] for k in ("report_md", "recipe_md", "finding", "human_md") if isinstance(rec.get(k), str)] if isinstance(rec.get("research"), dict): parts.append(json.dumps(rec["research"])) return "\n".join(parts) def hits(text: str, words) -> list: low = (text or "").lower() return sorted({w for w in words if w and w.lower() in low}) # ---------------------------------------------------------------- twin-prime constant def twin_prime_constant(pmax: int = 2_000_000): """C_2 = prod_{p>2} (1 - 1/(p-1)^2) as a rigorous interval [lo, hi]. The truncated product over p <= pmax is exact; the tail multiplies C_2 by a factor in [exp(-S), 1] with S = sum_{p>pmax} 1/(p-1)^2 <= sum_{n>=pmax} 1/n^2 < 1/(pmax-1). """ sieve = bytearray([1]) * (pmax + 1) sieve[0:2] = b"\x00\x00" for i in range(2, int(pmax ** 0.5) + 1): if sieve[i]: sieve[i * i::i] = bytearray(len(sieve[i * i::i])) prod = 1.0 for p in range(3, pmax + 1): if sieve[p]: prod *= 1.0 - 1.0 / ((p - 1) * (p - 1)) tail = 1.0 / (pmax - 1) return prod * pow(2.718281828459045, -tail), prod # ---------------------------------------------------------------- main def main() -> int: rows = load("served_window.jsonl") probe = load("probe.json") scrub = load("window_scrub.json") brief_step = load("brief_step.json") named = load("brief_named.json") route = load("route-107.json") by_id = {int(r["id"]): r for r in rows} after = [r for r in rows if int(r["id"]) > SETTER] # ---- section 1: the comparison window is complete, not the brief's list codes = {int(k): v for k, v in probe["codes"].items()} check("probe covers every integer id in %d..%d" % (SETTER, HEAD_PROBE), sorted(codes) == list(range(SETTER, HEAD_PROBE + 1)) and probe["range"] == [SETTER, HEAD_PROBE], "%d ids" % len(codes)) check("every probed id returned 200 or 404 (no transport failure)", all(v in (200, 404) for v in codes.values()), "codes=%s" % sorted(set(codes.values()))) present = sorted(i for i, v in codes.items() if v == 200) check("the live head at fetch time is #%d" % TOP, max(present) == TOP, "top present id %d; #%d..#%d all 404" % (max(present), TOP + 1, HEAD_PROBE)) check("ids %d..%d above the head are absent (never issued)" % (TOP + 1, HEAD_PROBE), all(codes[i] == 404 for i in range(TOP + 1, HEAD_PROBE + 1)), "%d ids" % (HEAD_PROBE - TOP)) check("the fetched window is exactly the probed-present ids", [int(r["id"]) for r in rows] == present and len(rows) == 190, "%d rows, ids %d..%d" % (len(rows), present[0], present[-1])) check("the ten never-issued gaps below the head are 404", all(codes[i] == 404 for i in NEVER_ISSUED) and len(NEVER_ISSUED) == 10, "%s" % NEVER_ISSUED) check("the id order is the created_at order inside the window", all(rows[i]["created_at"] <= rows[i + 1]["created_at"] for i in range(len(rows) - 1)), "so 'recorded after #1834' is exactly 'id > %d'" % SETTER) check("the post-setter comparison set is %d returns (%d routeless)" % (EXPECT_AFTER, EXPECT_ROUTELESS_AFTER), len(after) == EXPECT_AFTER and len([r for r in after if r["route"] is None]) == EXPECT_ROUTELESS_AFTER, "routes present: %s" % sorted({r["route"] for r in after if r["route"] is not None})) check("the window carries no machine-local path (publication scrub gate)", ABS.search(json.dumps(rows)) is None, "0 hits; the only such path in the window is #1878's patch field, which is not projected") wsha = scrub["served_return_sha256"] check("fetch provenance pins one sha256 per window return", len(wsha) == len(rows) and all(len(v) == 64 for v in wsha.values()) and len(scrub["scrubbed"]) == 0, "%d pins, %d substitutions" % (len(wsha), len(scrub["scrubbed"]))) # ---- section 2: the step's provenance, and the queue-loop verdict s_brief, s_route, s_1834 = sha_canon(brief_step), sha_canon(route["next_step"]), \ sha_canon(by_id[SETTER]["research"]["next_step"]) check("the step object is byte-identical in the brief, the route record and #1834", s_brief == s_route == s_1834 == STEP_SHA, "sha256 %s" % STEP_SHA[:16]) carriers = sorted(int(r["id"]) for r in rows if isinstance(r.get("research"), dict) and r["research"].get("next_step") is not None and sha_canon(r["research"]["next_step"]) == STEP_SHA) check("exactly one return carries the step verbatim -- the setter, so no step check has " "copied it forward", carriers == EXPECT_NOTE_CARRIERS, "carriers %s" % carriers) own = sorted(int(r["id"]) for r in rows if r["route"] == 107) own_recs = load("own_returns.json") own_ids = [int(r["id"]) for r in own_recs] check("route 107's only return in the window is the setter #1834, the route's last", own == [SETTER] and int(route["last_return_id"]) == SETTER, "window route-107 rows %s; last_return_id %s" % (own, route["last_return_id"])) qs = {int(r["id"]): ((r["next_step"] or {}).get("question", "")) for r in own_recs} check("the route's three steps are three different questions: the step has been rewritten " "twice, never copied forward", own_ids == EXPECT_OWN and len(set(qs.values())) == 3, "revision %d; #1315 asks a,b,c, #1317 a shifted-divisor boundary sum, #1834 (II)" % route["revision"]) check("neither pre-setter return carries the present step, so no earlier step check filed it", all(int(r["id"]) not in (1315, 1317) or sha_canon(r["next_step"]) != STEP_SHA for r in own_recs if r["next_step"] is not None), "own carriers of the present step: %s" % carriers) jobs = {str(j["id"]): j["status"] for j in route["jobs"]} check("the held pursuit for this step is on record as expired with no return", jobs.get("4178") == "expired" and jobs.get("4548") == "assigned", "route jobs %s" % jobs) ev = sorted(int(e["return_id"]) for e in route["events"]) check("the route's event log holds only #1315, #1317 and #1834", ev == EXPECT_OWN, "%s" % ev) # ---- section 3: does any post-setter return answer the step? (the comparison) note_hits = {int(r["id"]): hits(report_text(r), NOTE_WORDS) for r in rows} note_carriers = [i for i, h in note_hits.items() if h] after_note = [i for i in note_carriers if i > SETTER] check("the step's own notation occurs in the window only at the setter, and in no " "post-setter return", note_carriers == EXPECT_NOTE_CARRIERS and after_note == [], "post-setter carriers %s" % after_note) s4 = [int(r["id"]) for r in rows if "S_4" in report_text(r)] check("'S_4' (the 4-tuple singular series the step bounds) occurs only at the setter", s4 == EXPECT_NOTE_CARRIERS, "carriers %s" % s4) obj3 = [(int(r["id"]), r["route"], hits(report_text(r), OBJECT_WORDS)) for r in after if len(hits(report_text(r), OBJECT_WORDS)) >= 3] check("the seven post-setter returns with 3+ route-object words touch only neighbouring " "objects", [i for i, _rt, _h in obj3] == EXPECT_AFTER_OBJECT3, "; ".join("#%d(route %s): %s" % (i, rt, ",".join(h)) for i, rt, h in obj3)) check("none of those seven carries the step's notation or an S_4 / (II)-sum result", all(not note_hits[i] for i, _rt, _h in obj3) and "S_4" not in json.dumps(obj3), "so the weakest unproved object is still untouched") klo = {int(r["id"]): r["route"] for r in after if "kloosterman" in report_text(r).lower()} check("the five post-setter Kloosterman returns are all on other routes", klo == EXPECT_AFTER_KLOOSTERMAN, "routes %s" % sorted(set(klo.values()), key=str)) named_ids = named["named_comparison_ids"] check("the brief's nine named comparison ids are all in the post-setter window", named_ids == EXPECT_NAMED and all(i in by_id and i > SETTER for i in named_ids), "%s -> routes %s" % (named_ids, [by_id[i]["route"] for i in named_ids])) check("the brief's names are not a comparison set: %d of the %d post-setter returns are " "unnamed" % (EXPECT_AFTER - len(named_ids), EXPECT_AFTER), len(named_ids) == 9 and EXPECT_AFTER - len(named_ids) == 180, "the window was rebuilt from the public id range instead") check("not one of the brief's named returns carries the step's notation", all(not note_hits[i] for i in named_ids), "each decides a different object (K* marginals, tile covariance, drift calibration)") check("the named returns' outcomes are reported truthfully from the served bytes", all(by_id[i]["status"] in ("recorded", "pending", "accepted") for i in named_ids), "statuses %s" % {i: by_id[i]["status"] for i in named_ids}) scan = {int(r["id"]): r for r in load("scan.json")} mism = [int(r["id"]) for r in after if scan[int(r["id"])]["locators"] != hits(report_text(r), LOCATOR_WORDS) or scan[int(r["id"])]["objects"] != hits(report_text(r), OBJECT_WORDS)] check("scan.json (produced independently through lib/served/step_scan.py) agrees row by " "row on every post-setter return", not mism and set(scan) >= {int(r["id"]) for r in rows}, "%d rows compared, %d mismatches" % (len(after), len(mism))) # ---- section 4: the step's own arithmetic, and its internal consistency c2_lo, c2_hi = twin_prime_constant() inv = 1.0 / (4.0 * c2_hi), 1.0 / (4.0 * c2_lo) check("the twin-prime constant gives 1/(4C_2) = 0.3786953 within 1e-6", 0.3786943 <= inv[0] <= inv[1] <= 0.3786964 and c2_lo <= 0.6601618158 <= c2_hi, "C_2 in [%.9f, %.9f], 1/(4C_2) in [%.9f, %.9f]" % (c2_lo, c2_hi, inv[0], inv[1])) rec_ev = by_id[SETTER]["research"]["evidence_md"] check("#1834's served evidence states the same constant and the open (II) bound", "0.378695" in rec_ev and "ln^3 H lnln H" in rec_ev and "Not established" in rec_ev, "the step is the setter's own open question, copied to the route") x = sp.symbols("x", positive=True) A = sp.expand_log(sp.log(x * sp.log(x) ** 10), force=True) B = sp.log(x) + 10 * sp.log(sp.log(x)) L, M = sp.symbols("L M", positive=True) excess = sp.expand((L + 10 * M) ** 2 - L ** 2) check("sympy: log(H log^10 H) = log H + 10 log log H, so ln^2 R - ln^2 H = " "20 L M + 100 M^2 exactly", A == B and excess == 20 * L * M + 100 * M ** 2, "R = H ln^10 H shifts the leading term by (5/C_2) ln H lnln H + (25/C_2) ln^2 ln H") mp.mp.dps = 40 ratio = [(h, float(mp.log(h * mp.log(h) ** 10) ** 2 / mp.log(h) ** 2 - 1)) for h in (10 ** 6, 10 ** 12, 10 ** 100)] rel = 20 * sp.log(sp.log(x)) / sp.log(x) + 100 * (sp.log(sp.log(x)) / sp.log(x)) ** 2 check("the R-shift excess is o(ln^2 H): its relative size -> 0 as H -> oo", sp.limit(rel, x, sp.oo) == 0 and all(ratio[i][1] > ratio[i + 1][1] for i in range(len(ratio) - 1)) and ratio[-1][1] < 1.0, "relative excess %.3f at H=1e6, %.3f at H=1e12, %.3f at H=1e100 (limit 0)" % (ratio[0][1], ratio[1][1], ratio[2][1])) check("so the success clause needs only (II) = o(ln^2 H); the question's " "O(ln H lnln H) is the stronger, sufficient target", abs(5.0 / ((c2_lo + c2_hi) / 2) - 7.5739) < 1e-3, "the (ln H lnln H) coefficient is 5/C_2 = %.4f" % (5.0 / ((c2_lo + c2_hi) / 2))) check("the step's declared compute is 0 CPU-hours with the ask in analytic number theory", brief_step["compute"] == {"ram_gb": 2, "disk_gb": 1, "cpu_hours": 0} and brief_step["budget_hours"] == 1, "so a step check is the right instrument and no run is priced here") total = len(RESULTS) passed = sum(1 for ok, _n, _d in RESULTS if ok) emit("%d/%d checks passed" % (passed, total)) out = {"exit_code": 0 if passed == total else 1, "checks_passed": passed, "checks_total": total, "stdout": "\n".join(LINES) + "\n", "checks": [{"ok": ok, "name": n, "detail": d} for ok, n, d in RESULTS], "step_sha256": STEP_SHA, "setter": SETTER, "live_head": TOP, "post_setter_returns": len(after), "note_carriers": note_carriers, "inputs": { "served_window.jsonl": hashlib.sha256( open(os.path.join(HERE, "served_window.jsonl"), "rb").read()).hexdigest()}} with open(os.path.join(HERE, "check.out.json"), "w", encoding="utf-8", newline="\n") as fh: json.dump(out, fh, indent=1) return out["exit_code"] if __name__ == "__main__": sys.exit(main())