#!/usr/bin/env python3 """liftchain.py -- does the free paired maximum lift from one level to the next? Same object and conventions as transfacet.py: adm(tau) = { r mod W : gcd(r,W)=1, gcd(r+tau,W)=1 }, W = x#, cover(tau) = (longest cyclic gap between consecutive admissibles) - 1, 1 + max_even_tau cover(tau) = A288815(pi(x)), cover(2) = A144311(pi(x)). For each consecutive pair of levels (x, x' = next prime), take the attaining set A_x of the maximum at x and ask whether some lift tau' == tau (mod W), gcd(tau', W'/2) = 1, attains the maximum at x'. The maximum at x' is the value computed here when W' <= FULL_LIMIT, otherwise the published A288815 value is used as external evidence (the published ladder is the exact maximum, so attaining it proves the level-x' maximiser is a lift). stdout is the artefact; progress goes to stderr. """ import json import math import sys import time import numpy as np A288815 = [2, 6, 18, 30, 66, 150, 192, 258, 366, 450, 570, 708, 894, 1044, 1284, 1422, 1656, 1902, 2190, 2460, 2622] A144311 = [1, 5, 11, 29, 41, 65, 107, 149, 203, 257, 347, 527, 545, 617, 707, 869, 965, 1079, 1283, 1397, 1529, 1709] FULL_LIMIT = 100000 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 = {} idx = np.arange(W, dtype=np.int64) 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() 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) wrap = alive[0] + W - alive[-1] return int(max(int(d.max()), int(wrap))) - 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 main(): argv = sys.argv[1:] out_path = None if "--out" in argv: i = argv.index("--out") out_path = argv[i + 1] del argv[i:i + 2] pairs = argv or ["5:7", "7:11", "11:13", "13:17", "17:19"] report = {"tool": "liftchain.py/1", "pairs": [], "ok": True} for spec in pairs: xa, xb = (int(v) for v in spec.split(":")) psa, psb = primes_upto(xa), primes_upto(xb) Wa, Wb = math.prod(psa), math.prod(psb) na, nb = len(psa), len(psb) t0 = time.time() ma, mb = make_masks(psa, Wa), make_masks(psb, Wb) if Wa <= FULL_LIMIT: best_a, arg_a = sweep_max(ma, psa, Wa) max_a_source = "computed here (full sweep)" else: # use the whole coprime class as the source odd = [p for p in psa if p != 2] arg_a = [t for t in range(0, Wa, 2) if all(t % p for p in odd)] best_a = max(cover_of(ma, psa, Wa, t) for t in arg_a) arg_a = [t for t in arg_a if cover_of(ma, psa, Wa, t) == best_a] max_a_source = "computed here over the coprime class" if Wb <= FULL_LIMIT: best_b, arg_b = sweep_max(mb, psb, Wb) max_b_source = "computed here (full sweep)" pub_b = None else: best_b = None pub_b = A288815[nb - 1] - 1 max_b_source = "published A288815(%d) - 1 = %d (external evidence)" % (nb, pub_b) target = best_b if best_b is not None else pub_b q = psb[-1] lifts = [] for tau in arg_a: for k in range(q): t2 = tau + k * Wa if t2 % 2: continue if math.gcd(t2, Wb // 2) != 1: continue lifts.append(t2) best_lift, best_lift_at = -1, [] for t2 in lifts: v = cover_of(mb, psb, Wb, t2) if v > best_lift: best_lift, best_lift_at = v, [t2] elif v == best_lift: best_lift_at.append(t2) # control: lift the fixed twin offset tau = 2 the same way ctrl = [t2 for k in range(q) for t2 in (2 + k * Wa,) if t2 % 2 == 0 and math.gcd(t2, Wb // 2) == 1] ctrl_best = max((cover_of(mb, psb, Wb, t2) for t2 in ctrl), default=None) rec = { "pair": "%d->%d" % (xa, xb), "Wa": Wa, "Wb": Wb, "max_a": best_a, "source_max_a": max_a_source, "argmax_a_count": len(arg_a), "max_b": best_b, "published_max_b": pub_b, "target_b": target, "source_max_b": max_b_source, "lifts_tested": len(lifts), "best_lift_cover": best_lift, "lift_attains_max_b": (best_lift == target), "lift_witnesses": best_lift_at[:8], "control_tau2_lift_cover": ctrl_best, "control_gap_to_max_b": (target - ctrl_best) if ctrl_best is not None else None, } report["pairs"].append(rec) print("%s: max_a=%d args=%d -> best lift %d vs target %d attains=%s ctrl(tau=2) %s [%.1fs]" % (rec["pair"], best_a, len(arg_a), best_lift, target, rec["lift_attains_max_b"], ctrl_best, time.time() - t0), file=sys.stderr, flush=True) report["ok"] = None not in [p["best_lift_cover"] for p in report["pairs"]] text = json.dumps(report, indent=1, sort_keys=True) if out_path: with open(out_path, "w", encoding="utf-8") as fh: fh.write(text + "\n") print(text) return 0 if report["ok"] else 1 if __name__ == "__main__": sys.exit(main())