#!/usr/bin/env python3 """Independent checker for job #4528 (route 100 step check). stdlib + numpy + sympy only. It re-derives every number and every classification scan.json states, from the raw served artefacts and the shipped corpus, with its own implementations: the vocabulary scan, the success-shape scan, the phase bound D(P,p,L) (an incremental evaluation, not the promoted module's per-L recomputation), the population enumeration, the sweep aggregates, and the price arithmetic. python3 check-job4528.py # exit 0 only when every check passes Inputs are resolved as ./ or ./served/. No network, no credential. 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 import numpy as np import sympy from sympy import Mod, invert from sympy.combinatorics import Permutation CHECKS = [] def check(name, ok, detail=""): CHECKS.append((name, bool(ok), detail)) print("%-4s %s%s" % ("PASS" if ok else "FAIL", name, (" -- " + detail) if detail else "")) return bool(ok) def find(name): for cand in (name, os.path.join("served", name)): if os.path.exists(cand): return cand raise SystemExit("missing input: %s" % name) def sha256_file(p): with open(p, "rb") as fh: return hashlib.sha256(fh.read()).hexdigest() # ---------------------------------------------------------------- phase bound D def alive_classes(P): fs = [q for q in sympy.primerange(2, P + 1) if P % q == 0] if sympy.prod(fs) != P: raise ValueError("P not squarefree-ish") return [c for c in range(P) if all(c % q not in (0, (q - 2) % q) for q in fs)] def d_table_incremental(P, p_max, L_max, floor_ge=1): """{(p,L): (floor, D, min_phi)} for one P, evaluated incrementally in L. Independent of the promoted module: the offset multiset is grown one slot at a time and k_phi(s) is read off the residue counts. """ cls = alive_classes(P) m = len(cls) per_phi = [[] for _ in range(m)] for phi in range(m): base = cls[phi] per_phi[phi] = [((phi + i) // m) * P + cls[(phi + i) % m] - base for i in range(L_max)] out = {} for p in sympy.primerange(2, p_max + 1): if P % p == 0: continue cnts = [[0] * p for _ in range(m)] for L in range(1, L_max + 1): fl = (2 * L) // p best = worst = None for phi in range(m): c = cnts[phi] c[per_phi[phi][L - 1] % p] += 1 k = min(c[(-s) % p] + c[(-s - 2) % p] for s in range(p)) best = k if best is None else max(best, k) worst = k if worst is None else min(worst, k) if fl < floor_ge: continue out[(p, L)] = (fl, best, worst) return out def main(): scan = json.load(open(find("scan.json"), encoding="utf-8")) corpus = [json.loads(l) for l in open(find("corpus.jsonl"), encoding="utf-8") if l.strip()] byid = {r["id"]: r for r in corpus} step = scan["step"] setter = scan["step_setter"]["id"] t_setter = scan["step_setter"]["created_at"] # 1 -- corpus integrity check("corpus.jsonl parses: 185 unique returns, each with created_at and text", len(corpus) == 185 and len(byid) == 185 and all(r.get("created_at") and r.get("text") for r in corpus), "n=%d" % len(corpus)) check("corpus.jsonl sha256 equals the one scan.json records", sha256_file(find("corpus.jsonl")) == scan["corpus"]["sha256"]) # 2 -- the comparison frame check("the step-setter #1833 is in the corpus with the recorded timestamp", setter in byid and byid[setter]["created_at"] == t_setter, t_setter) after = [r for r in corpus if str(r["created_at"]) > str(t_setter)] check("returns recorded after #1833: 181 (scan.json agrees)", len(after) == 181 and scan["corpus"]["n_after_step_setter"] == 181, "n=%d" % len(after)) # 3 -- independent vocabulary scan loc, obj = scan["vocabulary"]["locators"], scan["vocabulary"]["object_words"] strong = sorted(r["id"] for r in after if any(w.lower() in r["text"].lower() for w in loc) and any(w.lower() in r["text"].lower() for w in obj)) check("independent vocabulary scan reproduces the strong-hit set", strong == sorted(int(k) for k in scan["comparison"]["strong_hits"]), "%d hits" % len(strong)) # 4 -- the success shape, recomputed step_block = re.compile(r'\{\s*"method"\s*:\s*"Reuse sweep2612.*?' r'"required_sources"\s*:\s*\[[^\]]*\][^}]*\}', re.S) occ, cands = [], set() for r in after: norm = r["text"].replace('\\"', '"') blocks = [(m.start(), m.end()) for m in step_block.finditer(norm)] for k, pat in scan["success_patterns"].items(): for m in re.finditer(pat, norm, re.I): cands.add(r["id"]) occ.append((r["id"], k, m.start(), any(s <= m.start() < e for s, e in blocks))) rec_occ = [(o["return"], o["pattern"], o["offset"], o["in_step_block"]) for o in scan["comparison"]["success_shape_occurrences"]] check("success-shape occurrences recomputed exactly (%d occurrences, 12 in the step block)" % len(occ), sorted(rec_occ) == sorted(occ), "candidates %s" % sorted(cands)) check("the only return whose text carries a success phrase is #2018 (the prior step check)", sorted(cands) == [2018], "candidates %s" % sorted(cands)) # #2018 is exempt only because it declares the step still open and quotes it verbatim t18 = byid[2018]["text"].replace('\\"', '"') quoted = bool(step_block.search(t18)) open_decl = ('"outcome": "promising"' in t18) or ('"outcome":"promising"' in t18) check("#2018 quotes the step verbatim and declares outcome promising (so it is not a report)", quoted and open_decl) check("no success-shape report survives the exemption rule: reports_success_shape == []", scan["comparison"]["reports_success_shape"] == []) # 5 -- the served #1833 phase-bound table, recomputed whole db = json.load(open(find("f1833_dbound2612.json"), encoding="utf-8")) Lmax, pmax = db["Lmax"], db["pmax"] strict_served = db["strict"] rows, strict = 0, [] for P in (2, 6, 30, 210, 2310): tab = d_table_incremental(P, pmax, Lmax) for (p, L), (fl, d, dmin) in tab.items(): rows += 1 if d < fl: strict.append([P, p, L, fl, d, dmin]) check("served dbound2612.json re-derived: rows and n_strict", rows == db["rows"] == scan["served_1833_dbound"]["rows"] and len(strict) == db["n_strict"] == scan["served_1833_dbound"]["n_strict"], "rows=%d strict=%d" % (rows, len(strict))) check("every strict entry re-derived exactly (D < floor(2L/p))", sorted(strict) == sorted(strict_served)) check("D <= floor(2L/p) on all %d shapes; strict on %d" % (rows, len(strict)), all(d <= fl for P in (2, 6, 30, 210, 2310) for (_p, _L), (fl, d, _m) in d_table_incremental(P, pmax, Lmax).items())) t30 = d_table_incremental(30, 97, 60, floor_ge=0) thr = {p: min(L for L in range(1, 61) if t30[(p, L)][1] >= 3) for p in (7, 11, 13, 17, 19)} check("smallest L with D(30,p,L) >= 3 is 14/19/21/27/33 for p=7/11/13/17/19", thr == {7: 14, 11: 19, 13: 21, 17: 27, 19: 33} and scan["served_1833_dbound"]["min_L_for_D_ge3_at_P30"] == {str(k): v for k, v in thr.items()}, str(thr)) check("D(30,7,L)=0 for L<=7; D=2 at (30,7,11),(30,11,17),(30,11,18),(30,13,20)", all(t30[(7, L)][1] == 0 for L in range(1, 8)) and all(t30[k][1] == 2 for k in ((7, 11), (11, 17), (11, 18), (13, 20)))) check("scan.json's sampled D(30) values agree with the recomputation", scan["served_1833_dbound"]["served_values_agree"] is True) # 6 -- the served #1833 sweep, recomputed from the raw jsonl lines = [json.loads(l) for l in open(find("f1833_sweep2612.jsonl"), encoding="utf-8") if l.strip()] per_P, maxdrop, att = {}, {}, {} for P, p, R, a, b, d in lines: M = P for q in R: M *= q mp = M * p s = per_P.setdefault(str(P), {"n": 0, "sum_Mp": 0, "max_Mp": 0, "nD_ge3": 0, "n_drop_ge3": 0, "n_drop_gt_D": 0, "n_drop_eq_D": 0}) s["n"] += 1 s["sum_Mp"] += mp s["max_Mp"] = max(s["max_Mp"], mp) s["nD_ge3"] += (d >= 3) s["n_drop_ge3"] += (a - b >= 3) s["n_drop_gt_D"] += (a - b > d) s["n_drop_eq_D"] += (a - b == d) maxdrop["(%d, %d)" % (P, p)] = max(maxdrop.get("(%d, %d)" % (P, p), -10 ** 9), a - b) if a - b == d: k = "%d/%d/%d/%d" % (P, p, a, d) att[k] = att.get(k, 0) + 1 rec = scan["served_1833_sweep"] check("sweep2612.jsonl: 12969 rows, per-base aggregates re-derived exactly", len(lines) == rec["n_rows"] == 12969 and per_P == rec["per_P"], "P=2 %d rows, P=6 %d rows" % (per_P["2"]["n"], per_P["6"]["n"])) check("guard holds: no row has drop > D; 1350 rows have drop >= 3", per_P["2"]["n_drop_gt_D"] == per_P["6"]["n_drop_gt_D"] == 0 and per_P["2"]["n_drop_ge3"] + per_P["6"]["n_drop_ge3"] == 1350) check("drop = D occurs on 45 rows, all at (P=2,p=3,A=4,D=2); max attained D is 2", att == {"2/3/4/2": 45} and att == rec["attained_drop_eq_D_counts"] and rec["max_attained_D"] == 2 and rec["drop_eq_D_ge3_rows"] == []) check("8269 of the 12969 rows have D >= 3, none of them attains D", per_P["2"]["nD_ge3"] + per_P["6"]["nD_ge3"] == 8269 and per_P["2"]["nD_ge3"] == 7234 and per_P["6"]["nD_ge3"] == 1035) check("max drop per (P,p) re-derived (P=2 p=3:17, p=11:6, p=13:8; P=6 p=11:2, p=13:2)", maxdrop == rec["max_drop_per_Pp"] and maxdrop["(2, 3)"] == 17 and maxdrop["(2, 11)"] == 6 and maxdrop["(2, 13)"] == 8) summ = json.load(open(find("f1833_sweep2612.json"), encoding="utf-8")) check("sweep2612.json summary agrees (sets 4209/3321, Mp_reached 1994416710, no witness)", all(summ["bases"][b]["sets"] == scan["served_1833_sweep"]["summary_file"][b]["sets"] for b in ("2", "6")) and summ["bases"]["2"]["sets"] == 4209 and summ["bases"]["6"]["sets"] == 3321 and summ["bases"]["2"]["Mp_reached"] == summ["bases"]["6"]["Mp_reached"] == 1994416710 and summ["bases"]["2"]["drop_eq_D_ge3"] == [] and summ["bases"]["6"]["drop_eq_D_ge3"] == [] and summ["bases"]["2"]["guard_drop_gt_D"] == []) # 7 -- the step's population and price, re-enumerated from the served driver's own caps ssrc = open(find("f1833_sweep2612.py"), encoding="utf-8").read() conf = re.search(r'CONF = \[\(2, \[q for q in primes_upto\((\d+)\) if q >= 3\], ([\d.e+]+)\), ' r'\(6, \[q for q in primes_upto\((\d+)\) if q >= 5\], ([\d.e+]+)\)\]', ssrc) mp3 = re.search(r'MP3, MP2, PMAX, WALL = ([\d.e+]+), ([\d.e+]+), (\d+), (\d+)', ssrc) check("the served driver's caps are what the price used (pools 3..43/5..47, M caps 2e8/5e8, p<=61)", bool(conf) and int(conf.group(1)) == 43 and int(conf.group(3)) == 47 and float(conf.group(2)) == 2e8 and float(conf.group(4)) == 5e8 and bool(mp3) and float(mp3.group(1)) == 2e9 and int(mp3.group(3)) == 61) pr = sympy.primerange pop, band_mp = {}, [] for P, pcap, mcap in ((2, 43, 2e8), (6, 47, 5e8)): pool = [q for q in pr(3 if P == 2 else 5, pcap + 1)] sets, rows_ub, sum_ub, br, bs = 0, 0, 0, 0, 0 for n in range(2, len(pool) + 1): for R in itertools.combinations(pool, n): M = P for q in R: M *= q if M > mcap: continue sets += 1 for p in pr(2, 62): if P % p == 0 or p in R: continue mp = M * p if mp <= 1e10: rows_ub += 1 sum_ub += mp if mp > 2e9: br += 1 bs += mp band_mp.append(mp) pop[str(P)] = {"sets": sets, "rows_ub_1e10": rows_ub, "sum_Mp_ub_1e10": sum_ub, "band_rows": br, "band_sum_Mp": bs} check("population re-enumerated: 4209 and 3321 R-sets (the served set counts)", pop == scan["price"]["population_ub"] and pop["2"]["sets"] == 4209 and pop["6"]["sets"] == 3321) band_slots = sum(v["band_sum_Mp"] for v in pop.values()) check("the step's new band (2e9 < Mp <= 1e10) holds %d rows / %.4g slots (upper bound, D-gate ignored)" % (sum(v["band_rows"] for v in pop.values()), band_slots), band_slots == scan["price"]["band_slots_ub"] == 64843442592008) # 8 -- the price, at the measured rates timings = scan["price"]["timings"] rates = [mp / s for _P, _p, _R, mp, s in timings if s >= 0.1] check("measured instrument rates from the timings bracket the 2.4e8 slots/s rate", all(1.5e8 < r < 4.0e8 for r in rates) and min(rates) <= scan["price"]["rate_slots_per_sec"]["measured_single_thread"] <= max(rates), "rates %.3g..%.3g" % (min(rates), max(rates))) hours = {} for label, rate in scan["price"]["rate_slots_per_sec"].items(): hours[label] = round(band_slots / rate / 3600.0, 2) check("price arithmetic at %s: %.4g h" % (label, hours[label]), abs(hours[label] - scan["price"]["hours_upper_bound_population"][ "at_single_thread" if "single" in label else "at_four_thread"]) < 0.01) frac = per_P["2"]["nD_ge3"] + per_P["6"]["nD_ge3"] frac = frac / float(len(lines)) check("D >= 3 scaling reproduces 0.6376 and its hours", abs(frac - scan["served_1833_sweep"]["D_ge3_fraction"]) < 1e-4 and abs(round(band_slots * frac / 1e9 / 3600, 2) - scan["price"]["hours_at_D_ge3_fraction"]["at_four_thread"]) < 0.01) check("the step's own 2-hour budget is below every priced reading of the full band", min(hours.values()) > scan["price"]["step_budget_hours"] > 0 and min(scan["price"]["hours_at_D_ge3_fraction"].values()) > 2.0, "cheapest reading %.2f h" % min(scan["price"]["hours_at_D_ge3_fraction"].values())) bm = np.array(sorted(band_mp), dtype=np.float64) reach = {} for label, rate in scan["price"]["rate_slots_per_sec"].items(): budget = 2.0 * 3600.0 * rate cum = np.cumsum(bm) k = int(np.searchsorted(cum, budget, side="right")) reach["%s_%s" % ("single_thread" if "single" in label else "four_thread", "2.4e8" if "single" in label else "1.0e9")] = { "rows_reachable": k, "rows_band": len(bm), "slots": int(cum[k - 1]) if k else 0, "budget_slots": budget, "fraction_of_band": round(k / len(bm), 4)} check("numpy cumsum reproduces the reach table within the step's 2-hour budget", all(reach[k]["rows_reachable"] == scan["price"]["reach_within_step_budget"][k]["rows_reachable"] for k in reach), str({k: v["rows_reachable"] for k, v in reach.items()})) # 9 -- the instrument cross-check and the sympy identities timed = {(t[0], t[1], tuple(t[2])): t[3] for t in timings} onrec = {} for P, p, R, a, b, d in lines: if (P, p, tuple(R)) in timed: onrec[(P, p, tuple(R))] = (a, b) check("the three timed rows are on the #1833 record with the A,B the served kfork.c printed", all(k in onrec for k in timed) and onrec[(6, 5, (11, 13, 17, 23, 29, 41))] == (10, 14) and onrec[(2, 7, (5, 19, 23, 31, 37))] == (12, 13) and onrec[(6, 5, (11, 19, 23, 31))] == (5, 7)) ks = open(find("f1804_kfork.c"), encoding="utf-8").read() check("kfork.c defines the two fork residues (0 and -2 mod p) and the min over translates", "t0 = ((p - rm) % p) * Minv % p" in ks and "t1 = ((2 * p - 2 - rm) % p) * Minv % p" in ks and "cnt[t0]++; cnt[t1]++;" in ks and "for (int t = 0; t < p; t++) if (cnt[t] < mn)" in ks) ok_id, ok_perm = True, True for (P, p, R), (a, b) in onrec.items(): M = P for q in R: M *= q if Mod(M, p) == 0: ok_id = False continue Minv = int(invert(M % p, p)) for rm in range(p): t0 = ((p - rm) % p) * Minv % p t1 = ((2 * p - 2 - rm) % p) * Minv % p if Mod(M * t0 + rm, p) != 0 or Mod(M * t1 + 2 + rm, p) != 0: ok_id = False ok_perm &= (Permutation([(-s) % p for s in range(p)]).is_Identity is False and Permutation([(-s) % p for s in range(p)]).signature() in (1, -1) and len(set((-s) % p for s in range(p))) == p and len(set((-s - 2) % p for s in range(p))) == p) check("sympy: the translate fork identity M*t0 = -rm, M*t1 = -2-rm (mod p) holds on the timed rows", ok_id) check("sympy: s -> -s and s -> -s-2 are permutations of Z/p (the pigeonhole sum_s k(s) = 2L)", ok_perm) tab = d_table_incremental(30, 97, 60) sym_ok = True for (p, L) in ((7, 14), (11, 19), (13, 21), (7, 11)): cls = alive_classes(30) m = len(cls) for phi in range(m): o = [((phi + i) // m) * 30 + cls[(phi + i) % m] - cls[phi] for i in range(L)] c = [0] * p for x in o: c[Mod(x, p)] += 1 k = min(c[(-s) % p] + c[(-s - 2) % p] for s in range(p)) if k > tab[(p, L)][1]: sym_ok = False check("sympy Mod re-evaluates the same D(30,p,L) on the threshold shapes", sym_ok) # 10 -- publication gate: the machine-identifying absolute forms (a Windows drive # letter, and the three common POSIX user/system roots). A drive letter # immediately followed by an escape (\n, \r, \t) is an escaped newline in served # LaTeX -- measured, not assumed. UNC forms are not gated: the served corpus' # LaTeX word-breaks collide with them, and a share names no local user or drive. # The three POSIX prefixes are split so that this checker's own source carries no # literal absolute path for the gate below to trip on. posix = "|".join(["/ho" + "me/", "/Us" + "ers/", "/m" + "nt/"]) ABS_DATA = re.compile(r"(?