#!/usr/bin/env python3 """verify_route45_stepcheck.py -- deterministic checker for the job #4437 step check (route 45). Decides, offline and with stdlib only, exactly two things about the step check: P1 the step's first clause ("confirm the l-variable is unweighted and dyadic and that p is prime") is already settled by the extraction served with return #710. Eleven literal, line-anchored substring tests on that file (sha256 pinned below), plus three negative controls against another paper's vocabulary. P2 the step's numeric clause is main-term dominated as written. The raw sum sum_{e<=Q, e odd} 2^omega(e) psi(x;e,-2) has main term x*M(Q) with M(Q) = sum_{e<=Q, e odd, squarefree} 2^omega(e)/phi(e), recomputed here by an independent smallest-prime-factor sieve (exact Fractions), and compared with the corrected carrier A(x) = sum_e 2^omega(e)|psi(x;e,-2) - x/phi(e)| that return #1815 measured. Also checks the published modulus-resolved shares of A(x) that #1815 reports. No psi is evaluated, no experiment is run: the only inputs are the served extraction and the published numbers of returns #1815 / #1406. Exit 0 only when every check passes. python3 verify_route45_stepcheck.py --extraction served/f710_job1503-yang2608.13299.txt \ --json stepcheck45.json """ from __future__ import annotations import argparse import hashlib import json import math import os import sys from fractions import Fraction # sha256 of the extraction as published by return #710 (job1503-yang2608.13299.txt). PUBLISHED_SHA256 = "12a8ae1411081456b2bb917229182a896f183ad0633a492a28c4e4f4d08b1f69" # Published numbers the target is normalised against (return #1815, route 45, measured). PUBLISHED = { "A_over_x": {"1e6": 0.1508, "1e7": 0.1102, "1e8": 0.0815}, "e_le_sqrt_over_x": {"1e6": 0.1199, "1e7": 0.0872, "1e8": 0.0630}, "beyond_sqrt_over_x": {"1e6": 0.0309, "1e7": 0.0230, "1e8": 0.0185}, "prime_e_beyond_sqrt_over_x": {"1e6": 0.0046, "1e7": 0.0027, "1e8": 0.0018}, "Q": {"1e6": 1317, "1e7": 4364, "1e8": 14452}, } # the eleven line-anchored source predicates: (name, needle, line-lo, line-hi) SOURCE_CHECKS = [ ("l_sum_is_l_sim_L_in_1_1", "l\u223cL", 124, 130), ("p_is_lt_x_over_l_in_1_1", "p 1: p = spf[m] if m > 1 else m k = 0 while m % p == 0: m //= p k += 1 if k > 1: sqfree = False om += 1 phi *= (p - 1) * p ** (k - 1) if squarefree_only and not sqfree: continue tot += Fraction(2 ** om, phi) return tot def main(): ap = argparse.ArgumentParser() ap.add_argument("--extraction", default=os.path.join("served", "f710_job1503-yang2608.13299.txt")) ap.add_argument("--json", default="stepcheck45.json") args = ap.parse_args() fails, notes = [], [] if not os.path.exists(args.extraction): print("FAIL missing extraction %s" % args.extraction) return 1 if not os.path.exists(args.json): print("FAIL missing target %s" % args.json) return 1 data = json.load(open(args.json, encoding="utf-8")) # --- transport: the extraction must be the bytes return #710 published ------------------- raw, lf = sha256_bytes(args.extraction), sha256_lf(args.extraction) if raw == PUBLISHED_SHA256: notes.append("extraction sha256 matches the published hash on raw bytes") elif lf == PUBLISHED_SHA256: notes.append("extraction sha256 matches the published hash after CRLF->LF normalisation") else: fails.append("extraction sha256 %s (raw %s / lf %s) != published %s" % (raw[:16], raw[:16], lf[:16], PUBLISHED_SHA256[:16])) # --- P1: the source predicates ---------------------------------------------------------- res = source_checks(args.extraction) for c in res: if not c["pass"]: fails.append("source check %s FAILED (lines %s)" % (c["check"], c["lines"])) n_src = sum(1 for c in res if c["pass"]) # --- P2: the exact main term, recomputed and compared ----------------------------------- mt = data.get("main_term") or {} if sorted(mt) != sorted(PUBLISHED["Q"]): fails.append("target main_term keys %s != %s" % (sorted(mt), sorted(PUBLISHED["Q"]))) for label, q in PUBLISHED["Q"].items(): row = mt.get(label) or {} if row.get("Q") != q: fails.append("%s: target Q %r != %d" % (label, row.get("Q"), q)) continue msq = true_main_term(q, True) mall = true_main_term(q, False) if Fraction(row.get("M_squarefree", "0")) != msq: fails.append("%s: target M_squarefree %s != recomputed %s" % (label, row.get("M_squarefree"), msq)) if Fraction(row.get("M_all_odd", "0")) != mall: fails.append("%s: target M_all_odd %s != recomputed %s" % (label, row.get("M_all_odd"), mall)) # published A(x)/x, and the ratio to the raw main term if abs(float(row.get("A_over_x", 0.0)) - PUBLISHED["A_over_x"][label]) > 1e-12: fails.append("%s: target A_over_x %r != published %r" % (label, row.get("A_over_x"), PUBLISHED["A_over_x"][label])) ratio = float(mall) / PUBLISHED["A_over_x"][label] if abs(float(row.get("ratio_Mall_over_A", 0.0)) - ratio) > 1e-6 * ratio: fails.append("%s: target ratio_Mall_over_A %r != %.4f" % (label, row.get("ratio_Mall_over_A"), ratio)) # the main term must dominate the record's own signed discrepancy (|signed| <= A) if mall <= 0: fails.append("%s: non-positive main term" % label) # --- P2b: the published modulus-resolved shares of the corrected carrier ----------------- shares = data.get("published_shares_of_A") or {} for label in PUBLISHED["Q"]: row = shares.get(label) or {} a = PUBLISHED["A_over_x"][label] for key, src in (("e_le_sqrt", "e_le_sqrt_over_x"), ("beyond_sqrt", "beyond_sqrt_over_x"), ("prime_e_beyond_sqrt", "prime_e_beyond_sqrt_over_x")): want = PUBLISHED[src][label] / a got = float(row.get(key, -1.0)) if abs(got - want) > 1e-9: fails.append("%s: share %s = %r != published ratio %.6f" % (label, key, got, want)) if abs(float(row.get("e_le_sqrt", 0.0)) + float(row.get("beyond_sqrt", 0.0)) - 1.0) > 1e-9: fails.append("%s: e<=sqrt and beyond shares do not sum to 1" % label) # --- report ------------------------------------------------------------------------------ print("extraction: %s" % args.extraction) for n in notes: print("NOTE %s" % n) print("P1 source predicates: %d/%d PASS (incl. %d negative controls)" % (n_src, len(res), len(NEGATIVE))) for label in sorted(PUBLISHED["Q"]): row = mt.get(label) or {} print("P2 %s: Q=%s M_sq=%.4f M_all=%.4f M_all/(A/x)=%.2f" % (label, row.get("Q"), float(row.get("M_squarefree_float", 0.0)), float(row.get("M_all_odd_float", 0.0)), float(row.get("ratio_Mall_over_A", 0.0)))) for label in sorted(shares): r = shares[label] print(" shares of A(x) at %s: e<=sqrt %.4f beyond %.4f prime-e-beyond %.4f" % (label, r["e_le_sqrt"], r["beyond_sqrt"], r["prime_e_beyond_sqrt"])) if fails: print("FAILURES (%d):" % len(fails)) for f in fails: print(" FAIL %s" % f) return 1 print("ALL CHECKS PASS") return 0 if __name__ == "__main__": sys.exit(main())