#!/usr/bin/env python3 """verify_job4128.py -- deterministic checker for job #4128 (route 2, W = 19#). Reads results_job4128.json (digested scanner output) and re-derives every claim of the return. Stdlib only, no compiler needed. Exit 0 iff every check passes; prints a JSON summary {"all_pass", "checks", "failed"} on stdout and the same as JSON on --json. Claims checked -------------- 1. Digest integrity: wheel, Q, ranked_starts, and histogram consistency of every scan. 2. 17# controls: L_c = 463, L_e = 1243 (return #1795), L_F = 420 (this work). 3. L_F = 594 at 19#: minF(L) <= 0 for every L < 594, minF(594) >= 1. 4. L_e = 1705 at 19#: envelope max loss 0 on the whole scanned ladder L <= 1704, positive at 1705. 5. L_c at 19#: chordal max loss 0 on the scanned ladder L <= 650 (so L_c >= 651), and a witnessed chordal loss at a = 4186, L = 1704 by all-phase enumeration (so L_c <= 1704). 6. The decisive comparison: at L = 593 = L_F - 1 both envelope and chordal max loss are 0 over all 9,699,690 starts, so (loss monotone in L) neither onset is below L_F. 7. Cross-instrument consistency: fastscan's minimum_first_order equals the fprofile value minF(L) at every scanned length. 8. Loss monotonicity along the scanned ladders (data check). """ import argparse import json import os import sys HERE = os.path.dirname(os.path.abspath(__file__)) W19 = 9699690 Q19 = [23, 29, 31, 37] W17 = 510510 Q17 = [19, 23, 29, 31] class Checks: def __init__(self): self.n = 0 self.failed = [] def __call__(self, name, ok): self.n += 1 if not ok: self.failed.append(name) return ok def decode_profile(rl): out = {} for i, (start, val) in enumerate(rl): end = rl[i + 1][0] if i + 1 < len(rl) else None out[start] = (val, end) return out def profile_at(rl, L): val = None for start, v in rl: if start <= L: val = v else: break return val def main(): ap = argparse.ArgumentParser() ap.add_argument("--results", default=os.path.join(HERE, "results_job4128.json")) ap.add_argument("--json", action="store_true") a = ap.parse_args() with open(a.results, encoding="utf-8") as fh: R = json.load(fh) c = Checks() scans = R["scans"] env = {s["L"]: s for s in scans if s["mode"] == "envelope" and s["W"] == W19} cho = {s["L"]: s for s in scans if s["mode"] == "chordal" and s["W"] == W19} env17 = {s["L"]: s for s in scans if s["mode"] == "envelope" and s["W"] == W17} cho17 = {s["L"]: s for s in scans if s["mode"] == "chordal" and s["W"] == W17} # 1. digest integrity for tag, d, q in (("19#", scans, Q19),): for s in scans: w = W19 if s["W"] == W19 else W17 qq = Q19 if s["W"] == W19 else Q17 c("integrity:%s:L%d:q" % (s["mode"], s["L"]), list(s["q"]) == list(qq)) c("integrity:%s:L%d:starts" % (s["mode"], s["L"]), s["ranked_starts"] == w) hist = dict((int(k), int(v)) for k, v in s["loss_histogram"]) c("integrity:%s:L%d:hist_sum" % (s["mode"], s["L"]), sum(hist.values()) == w) c("integrity:%s:L%d:hist_max" % (s["mode"], s["L"]), max(hist) == s["global_max_loss"]) c("integrity:%s:L%d:hist_pos" % (s["mode"], s["L"]), sum(v for k, v in hist.items() if k > 0) == s["starts_with_positive_loss"]) # 2. 17# controls (#1795) c("control17:L_c=463:zero_at_462", cho17[462]["global_max_loss"] == 0) c("control17:L_c=463:pos_at_463", cho17[463]["global_max_loss"] == 1) c("control17:L_e=1243:zero_at_1242", env17[1242]["global_max_loss"] == 0) c("control17:L_e=1243:pos_at_1243", env17[1243]["global_max_loss"] == 1) p17 = R["minF_profile_w17"] c("control17:first_L_minF_ge_1=420", p17["first_L_minF_ge_1"] == 420) c("control17:minF(419)=0", profile_at(p17["run_length_pairs"], 419) == 0) c("control17:minF(420)=1", profile_at(p17["run_length_pairs"], 420) == 1) c("control17:no_L<420_with_minF>=1", all(profile_at(p17["run_length_pairs"], L) <= 0 for L in range(420))) # 3. L_F = 594 p19 = R["minF_profile_w19"] rl = p19["run_length_pairs"] c("L_F:first_L_minF_ge_1=594", p19["first_L_minF_ge_1"] == 594) c("L_F:minF(594)>=1", profile_at(rl, 594) >= 1) c("L_F:minF(L)<=0 for all L<594", all(profile_at(rl, L) <= 0 for L in range(594))) c("L_F:Lmax covers 2000", p19["Lmax"] >= 2000) # 4. L_e = 1705 below = [L for L in env if L <= 1704] above = [L for L in env if L >= 1705] c("L_e:scanned_below_covers_1690s", max(below) == 1704) c("L_e:zero_at_every_scanned_L<=1704", all(env[L]["global_max_loss"] == 0 for L in below)) c("L_e:positive_at_1705", env[1705]["global_max_loss"] >= 1) c("L_e:positive_at_every_scanned_L>=1705", all(env[L]["global_max_loss"] >= 1 for L in above)) # 5. L_c bracket cz = [L for L in cho if cho[L]["global_max_loss"] == 0] cp = [L for L in cho if cho[L]["global_max_loss"] > 0] c("L_c:chordal_scanned_at_593_and_650", 593 in cho and 650 in cho) c("L_c:zero_at_593", cho[593]["global_max_loss"] == 0) c("L_c:zero_at_650", cho[650]["global_max_loss"] == 0) c("L_c:lower_bound_651", (max(cz) + 1) == 651) c("L_c:positive_scan_at_900", 900 in cho and cho[900]["global_max_loss"] >= 1) c("L_c:upper_bound_900", bool(cp) and min(cp) == 900) ind = [r for r in R["independent_all_phase"]["checks"] if r["a"] == 4186 and r["L"] == 1704] c("L_c:independent_all_phase_row_present", len(ind) == 1) c("L_c:independent_all_phase_witness_at_1704", bool(ind) and ind[0]["max_chordal_loss"] >= 1) c("L_c:upper_bound_1704_by_witness", bool(ind) and ind[0]["max_chordal_loss"] >= 1) c("L_c:envelope_zero_at_1704_and_chordal_positive", env[1704]["global_max_loss"] == 0 and bool(ind) and ind[0]["max_chordal_loss"] >= 1) # 6. the decisive comparison at L = L_F - 1 = 593 c("decisive:envelope_zero_at_593_over_all_starts", env[593]["global_max_loss"] == 0 and env[593]["ranked_starts"] == W19) c("decisive:chordal_zero_at_593_over_all_starts", cho[593]["global_max_loss"] == 0 and cho[593]["ranked_starts"] == W19) c("decisive:minF(593)=0", env[593]["minimum_first_order"] == 0) ep = [L for L in env if env[L]["global_max_loss"] >= 1] c("decisive:L_c>=L_F", (max(cz) + 1) >= 594) c("decisive:L_e>=L_F", bool(ep) and min(ep) >= 594) c("decisive:ordering_L_F= 0) out = {"all_pass": not c.failed, "checks": c.n, "failed": c.failed} print(json.dumps(out)) if not a.json: for f in c.failed: print("FAIL:", f, file=sys.stderr) return 0 if out["all_pass"] else 1 if __name__ == "__main__": sys.exit(main())