#!/usr/bin/env python3 """job #1965 — validation gate for the walk convention, and the corrected ladder. `job1965-comb31.py` logs D_mine = max A - min A with A_i = (i-1) - rho*r_i (the walk value AT the i-th point). The sup of G over integers sits just AFTER a point (A_i + 1 - rho) and the inf just BEFORE the next one (A_i + rho), so the exact pair is sup = max_i (A_i + 1 - rho) , inf = min_i (A_i + rho) -> D_x = D_mine + 1 - 2*rho provided min A + rho < 0 (else the endpoint u = 0 contributes inf = 0). This script checks both the identity and that endpoint clause on the published ladder @7..@29, printing max A, min A and the corrected slack against the published values (2.68/4.29/6.61/12.36/16.41/28.99/53.64). """ import json import sys import numpy as np PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] MIDS = [7, 11, 13, 17, 19, 23, 29, 31] PUBLISHED = {7: 2.68, 11: 4.29, 13: 6.61, 17: 12.36, 19: 16.41, 23: 28.99, 29: 53.64} CH = 1 << 24 def extremes(x): W, ms, N = 1, [], 2 for p in PRIMES: if p <= x: W *= p ms = [p for p in MIDS if p <= x] for p in ms: N *= p - 2 rho = N / W amax, amin = -1e18, 1e18 count = 0 for base in range(0, W, CH): size = min(CH, W - base) a = np.ones(size, dtype=bool) for p in ms: a[(-base) % p::p] = False a[(p - 2 - base) % p::p] = False mask = np.zeros(size, dtype=bool) for c in (11, 17): mask[(-base + c) % 30::30] = True a &= mask f = np.flatnonzero(a) if f.size: vals = (count + np.arange(f.size)) - rho * (base + f) amax = max(amax, float(vals.max())) amin = min(amin, float(vals.min())) count += int(f.size) return W, N, count, rho, amax, amin def main(): out = [] for x in [7, 11, 13, 17, 19, 23, 29]: W, N, count, rho, amax, amin = extremes(x) d_corr = (amax + 1 - rho) - min(amin + rho, 0.0) d_mine = amax - amin slack = 2 * 3 ** (len([p for p in MIDS if p <= x])) / d_corr rec = {"level": x, "count_ok": count == N, "rho": rho, "maxA": amax, "minA": amin, "minA_plus_rho": amin + rho, "D_mine": d_mine, "D_corrected": d_corr, "slack_corrected": round(slack, 4), "slack_published": PUBLISHED[x], "rel_err_pct": round(100 * (slack - PUBLISHED[x]) / PUBLISHED[x], 3)} out.append(rec) print(json.dumps(rec, sort_keys=True), flush=True) print(json.dumps({"all_reproduce_within_1pct": all(abs(r["rel_err_pct"]) < 1.0 for r in out)})) with open(sys.argv[1], "w", encoding="utf-8") as fh: json.dump(out, fh, indent=1, sort_keys=True) if __name__ == "__main__": main()