#!/usr/bin/env python3 """check2559.py -- independent recomputation of the finite claims of job #2559. Object and conventions (identical to the submitted producer, restated so this file stands alone). W = x# = product of the primes <= x. An offset tau is EVEN and taken in [0, W). adm(tau) = { r in [0,W) : gcd(r,W) = 1 and gcd((r+tau) mod W, W) = 1 } cover(tau)= (longest cyclic gap between consecutive elements of adm(tau)) - 1 cover is the covering capacity of the two residue classes {0, -tau} mod every prime <= x; at a prime p | tau the two classes collapse to one, so the DIVISOR SIGNATURE S(tau) = { p <= x : p | tau } is the only local datum that decides the local kill density (1/p on S, 2/p off S). FACETS. odd(x) = primes p with 3 <= p <= x, m = len(odd(x)). LOW facet: tau even, tau % p != 0 for every p in odd(x) (signature {2}: the generic two-class local datum; tau = 2, the project's fixed twin offset, lies here) HIGH facet: at least m - 2 of the odd primes divide tau (near the one-class end tau = 0, where the classical Jacobsthal ladder A048670 lives) Published anchors used only as the comparison values of the gates: A048670(n) = one-class Jacobsthal on p_n# A288815(n) = paired Jacobsthal on p_n# A144311(n) = twin-slot kill-run ladder (FULL gates: cover(0)+1, cover(2), 1+max) LIFT. Levels x -> x' (next prime). A tau at level x lifts to tau' if tau' == tau (mod W); every even tau' in [0, W') with that congruence is tested (no further filter). The complete lift family of the level-x attaining set contains |argmax(x)| * p' offsets. Usage: python3 check2559.py --measure # print this run's numbers as JSON, no comparison python3 check2559.py claims-2559.json # compare against a claim file; exit 0 iff all pass Printed comparison lines are " PASS|FAIL vs " and the last line is "VERDICT pass" or "VERDICT fail". Nothing is executed remotely and no network access is used. """ import json import math import sys import time import numpy as np A048670 = [2, 4, 6, 10, 14, 22, 26, 34, 40, 46, 58, 66, 74, 90, 100, 106, 118, 132, 152, 174, 190, 200, 216, 234, 258, 264, 282, 300, 312, 330] A144311 = [1, 5, 11, 29, 41, 65, 107, 149, 203, 257, 347, 527, 545, 617, 707, 869, 965, 1079, 1283, 1397, 1529, 1709] A288815 = [2, 6, 18, 30, 66, 150, 192, 258, 366, 450, 570, 708, 894, 1044, 1284, 1422, 1656, 1902, 2190, 2460, 2622] FULL_LIMIT = 100000 # levels with W <= this are swept exhaustively over every even tau GATE_LEVELS = [5, 7, 11, 13] FACET_LEVELS = [5, 7, 11, 13, 17] PAIRS = [(5, 7), (7, 11), (11, 13), (13, 17)] def primes_upto(x): out = [] for c in range(2, x + 1): if all(c % q for q in out if q * q <= c): out.append(c) return out def make_masks(ps, W): """masks[p][t] = boolean array over [0,W): residues killed by the class set of tau = t mod p.""" idx = np.arange(W, dtype=np.int64) masks = {} for p in ps: rem = idx % p per_t = [] for t in range(p): k = rem == 0 if t % p != 0: k = k | (rem == (p - t) % p) per_t.append(k) masks[p] = per_t return masks def killed_mask(masks, ps, W, tau): k = masks[ps[0]][0].copy() # p = 2 and tau even: single class {0} for p in ps[1:]: k |= masks[p][tau % p] return k def cover_from_killed(k, W): alive = np.flatnonzero(~k) if alive.size <= 1: return W - 1 d = np.diff(alive) return int(max(int(d.max()), int(alive[0] + W - alive[-1]))) - 1 def cover_of(masks, ps, W, tau): return cover_from_killed(killed_mask(masks, ps, W, tau), W) def sweep_max(masks, ps, W): best, arg = -1, [] for tau in range(0, W, 2): v = cover_of(masks, ps, W, tau) if v > best: best, arg = v, [tau] elif v == best: arg.append(tau) return best, arg def low_family(W, odd): return [t for t in range(0, W, 2) if all(t % p for p in odd)] def high_family(W, odd): need = len(odd) - 2 return [t for t in range(0, W, 2) if sum(1 for p in odd if t % p == 0) >= need] def max_over(masks, ps, W, taus): best, arg = -1, [] for t in taus: v = cover_of(masks, ps, W, t) if v > best: best, arg = v, [t] elif v == best: arg.append(t) return best, arg def signature_ok(taus, odd): return all(all(t % p for p in odd) for t in taus) def measure(log=print): out = {"tool": "check2559.py/1", "gates": {}, "facets": {}, "lifts": []} masks_cache = {} def masks_for(x): if x not in masks_cache: ps = primes_upto(x) masks_cache[x] = (ps, math.prod(ps), make_masks(ps, math.prod(ps))) return masks_cache[x] for x in GATE_LEVELS: ps, W, mk = masks_for(x) n = len(ps) t0 = time.time() c0 = cover_of(mk, ps, W, 0) c2 = cover_of(mk, ps, W, 2) best, arg = sweep_max(mk, ps, W) g = {"x": x, "W": W, "n": n, "cover0_plus1": c0 + 1, "A048670": A048670[n - 1], "cover2": c2, "A144311": A144311[n - 1], "max_plus1": best + 1, "A288815": A288815[n - 1], "argmax_count": len(arg), "argmax_all_low_facet": signature_ok(arg, [p for p in ps if p != 2]), "seconds": round(time.time() - t0, 2)} out["gates"][str(x)] = g log("gate x=%d W=%d cover0+1=%d=%d cover2=%d=%d max+1=%d=%d argmax=%d low=%s [%.1fs]" % (x, W, c0 + 1, A048670[n - 1], c2, A144311[n - 1], best + 1, A288815[n - 1], len(arg), g["argmax_all_low_facet"], g["seconds"])) for x in FACET_LEVELS: ps, W, mk = masks_for(x) n = len(ps) odd = [p for p in ps if p != 2] t0 = time.time() low = low_family(W, odd) hi = high_family(W, odd) low_best, low_arg = max_over(mk, ps, W, low) hi_best, _ = max_over(mk, ps, W, hi) rec = {"x": x, "W": W, "low_size": len(low), "low_max": low_best, "low_max_count": len(low_arg), "high_size": len(hi), "high_max": hi_best, "high_deg_at_x5": (n - 3 <= 0), "cover0_plus1": cover_of(mk, ps, W, 0) + 1, "cover2": cover_of(mk, ps, W, 2), "full_sweep": W <= FULL_LIMIT, "seconds": round(time.time() - t0, 2)} out["facets"][str(x)] = rec log("facet x=%d W=%d low %d/%d max %d high %d/%d max %d full_sweep=%s [%.1fs]" % (x, W, len(low_arg), len(low), low_best, len(hi), len(hi), hi_best, rec["full_sweep"], rec["seconds"])) for xa, xb in PAIRS: psa, Wa, mka = masks_for(xa) psb, Wb, mkb = masks_for(xb) _, arg_a = sweep_max(mka, psa, Wa) if Wb <= FULL_LIMIT: target, src = sweep_max(mkb, psb, Wb)[0], "computed full sweep" else: target, src = A288815[len(psb) - 1] - 1, "published A288815(n)-1" q = psb[-1] lifts = [tau + k * Wa for tau in arg_a for k in range(q) if (tau + k * Wa) % 2 == 0 and tau + k * Wa < Wb] best, wit = max_over(mkb, psb, Wb, lifts) rec = {"pair": "%d->%d" % (xa, xb), "argmax_a_count": len(arg_a), "lifts_tested": len(lifts), "best_lift": best, "target": target, "target_source": src, "attains": best == target, "witnesses": wit[:6]} out["lifts"].append(rec) log("%s: %d argmax at x=%d, %d lifts tested, best %d vs target %d (%s) attains=%s" % (rec["pair"], len(arg_a), xa, len(lifts), best, target, src, rec["attains"])) return out def main(): args = sys.argv[1:] if not args or args[0] in ("-h", "--help"): print(__doc__) return 0 if args[0] == "--measure": print(json.dumps(measure(log=lambda s: print(s, file=sys.stderr)), indent=1, sort_keys=True)) return 0 with open(args[0], encoding="utf-8") as fh: claims = json.load(fh) got = measure(log=lambda s: print(s, file=sys.stderr)) cid, fails = 0, 0 def check(cid, claimed, measured): nonlocal fails ok = claimed == measured fails += 0 if ok else 1 print("%s %s %s vs %s" % (cid, "PASS" if ok else "FAIL", measured, claimed)) return ok for x, exp in sorted(claims["gates"].items(), key=lambda kv: int(kv[0])): m = got["gates"][x] for key, val in sorted(exp.items()): cid += 1 check("G%d.%s" % (cid, key), val, m[key]) for x, exp in sorted(claims["facets"].items(), key=lambda kv: int(kv[0])): m = got["facets"][x] for key, val in sorted(exp.items()): cid += 1 check("F%d.%s" % (cid, key), val, m[key]) by_pair = {r["pair"]: r for r in got["lifts"]} for exp in claims["lifts"]: m = by_pair[exp["pair"]] for key, val in sorted(exp.items()): if key == "pair": continue cid += 1 check("L%d.%s.%s" % (cid, exp["pair"], key), val, m[key]) print("VERDICT %s" % ("fail" if fails else "pass")) return 1 if fails else 0 if __name__ == "__main__": sys.exit(main())