#!/usr/bin/env python3 """transfacet.py -- the offset family's covering capacity read by DIVISOR SIGNATURE. Object (all conventions stated, all gates external). For a primorial W = x# = p_1...p_n and an even offset tau in [0, W), let adm(tau) = { r in [0,W) : gcd(r,W) = 1 and gcd((r+tau) mod W, W) = 1 }, cover(tau) = (max cyclic gap between consecutive elements of adm(tau)) - 1, i.e. the length of the longest cyclic run of residues that the two classes {0,-tau} kill at every prime. A prime p | tau collapses the two classes to the single class {0} mod p, so with S(tau) = { p <= x : p | tau } the killed density at p is 1/p for p in S and 2/p otherwise. S is the divisor SIGNATURE of tau; S = {2} is the full two-class (fixed twin) end and S -> all primes is the one-class end tau = 0. Published anchors (each fetched from OEIS this run, terms as served): A048670 j(p_n#) = 2,4,6,10,14,22,26,34,40,46,58,66,... A144311 twin-slot kill-run ladder = 1,5,11,29,41,65,107,149,203,257,347,527,... A288815 paired Jacobsthal on p_n# = 2,6,18,30,66,150,192,258,366,450,570,... GATES (must pass before any new number is read): G1 cover(0) + 1 == A048670(n) G2 cover(2) == A144311(n) G3 1 + max_tau cover(tau) == A288815(n) MEASUREMENT (the new table): the attaining set of the maximum, its divisor signatures, and -- the hypothesis the route needs -- whether the maximum is attained at the HIGH-divisibility (nearly one-class) end of the family or at the LOW-divisibility (two-class) end. stdout is the artefact and is byte-reproducible; progress and wall time go to stderr. """ import json import math import sys import time from itertools import combinations 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] 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) of residues killed by the class set of tau=t mod p.""" 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() # p = 2, tau even -> single class {0} for p in ps[1:]: k |= masks[p][tau % p] return k def cover_from_killed(k, W): """longest cyclic run of killed residues; -1 if nothing is admissible.""" alive = np.flatnonzero(~k) if alive.size == 0: return W - 1 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 signature(tau, ps): return tuple(p for p in ps if tau % p == 0) 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] full = "--full" in argv if full: argv.remove("--full") levels = [int(a) for a in argv] or [5, 7, 11, 13, 17] report = {"tool": "transfacet.py/1", "levels": [], "gates": [], "ok": True} for x in levels: ps = primes_upto(x) n = len(ps) W = math.prod(ps) t0 = time.time() masks = make_masks(ps, W) odd = [p for p in ps if p != 2] taus = np.arange(0, W, 2, dtype=np.int64) # ---- gates ------------------------------------------------------- c0 = cover_from_killed(killed_mask(masks, ps, W, 0), W) c2 = cover_from_killed(killed_mask(masks, ps, W, 2), W) gate = {} if n < len(A048670): gate["G1_cover0_plus1_vs_A048670"] = {"got": c0 + 1, "want": A048670[n - 1], "pass": c0 + 1 == A048670[n - 1]} if n <= len(A144311): gate["G2_cover2_vs_A144311"] = {"got": c2, "want": A144311[n - 1], "pass": c2 == A144311[n - 1]} print("level x=%d n=%d W=%d cover(0)=%d cover(2)=%d [%.1fs]" % (x, n, W, c0, c2, time.time() - t0), file=sys.stderr, flush=True) # ---- sweep over every even tau (skipped for W above FULL_LIMIT unless --full) FULL_LIMIT = 100000 did_full = full or W <= FULL_LIMIT best = -1 argmax = [] if did_full: for tau in taus: v = cover_from_killed(killed_mask(masks, ps, W, int(tau)), W) if v > best: best, argmax = v, [int(tau)] elif v == best: argmax.append(int(tau)) if n <= len(A288815): gate["G3_1_plus_max_vs_A288815"] = {"got": best + 1, "want": A288815[n - 1], "pass": best + 1 == A288815[n - 1]} # ---- the signature reading of the attaining set ------------------ sigs = [signature(t, ps) for t in argmax] sig_size = [len(s) for s in sigs] missing = [tuple(p for p in odd if p not in s) for s in sigs] cands = {} for p in odd: tau = W // p cands["W/%d" % p] = {"tau": tau, "signature": list(signature(tau, ps)), "cover": cover_from_killed(killed_mask(masks, ps, W, tau), W)} # low-divisibility control: tau even and coprime to every odd prime. # exact when the family is small; above LOW_CAP a disclosed evenly-spaced sample. LOW_CAP = 200000 low_full = [int(t) for t in taus if all(t % p for p in odd)] low_sampled = len(low_full) > LOW_CAP if low_sampled: step = len(low_full) // LOW_CAP + 1 low = low_full[::step] else: low = low_full low_best = -1 low_arg = [] low_hist = {} low_sum = 0 low_sq = 0 for tau in low: v = cover_from_killed(killed_mask(masks, ps, W, tau), W) low_hist[v] = low_hist.get(v, 0) + 1 low_sum += v low_sq += v * v if v > low_best: low_best, low_arg = v, [int(tau)] elif v == low_best: low_arg.append(int(tau)) low_n = len(low) low_mean = low_sum / low_n if low_n else None low_var = (low_sq / low_n - low_mean ** 2) if low_n else None low_sd = math.sqrt(low_var) if low_var and low_var > 0 else 0.0 # high-divisibility end: tau divisible by at least len(odd)-1 of the odd primes hi_thresh = len(odd) - 2 hi = [int(t) for t in taus if len(signature(int(t), ps)) - 1 >= hi_thresh] hi_best = -1 hi_arg = [] hi_hist = {} for tau in hi: v = cover_from_killed(killed_mask(masks, ps, W, tau), W) hi_hist[v] = hi_hist.get(v, 0) + 1 if v > hi_best: hi_best, hi_arg = v, [int(tau)] elif v == hi_best: hi_arg.append(int(tau)) report["levels"].append({ "x": x, "n": n, "W": W, "full_sweep": bool(did_full), "cover0": c0, "cover2": c2, "max_cover": best, "max_plus1": (best + 1) if did_full else None, "argmax_count": len(argmax), "argmax_tau": argmax[:40], "argmax_sig_sizes": sorted(set(sig_size)), "argmax_missing_primes": [list(m) for m in sorted(set(missing))][:20], "distinct_argmax_signatures": len(set(sigs)), "W_over_p_candidates": cands, "low_div_family_size": len(low), "low_div_family_full_size": len(low_full), "low_div_sampled": low_sampled, "low_div_max_cover": low_best, "low_div_argmax": low_arg[:10], "low_div_excess_over_cover2": low_best - c2, "low_div_mean": round(low_mean, 4) if low_mean is not None else None, "low_div_sd": round(low_sd, 4), "low_div_max_in_sd_above_mean": ( round((low_best - low_mean) / low_sd, 4) if low_sd else None), "low_div_hist_top8": sorted(low_hist.items())[-8:], "high_div_family_size": len(hi), "high_div_max_cover": hi_best, "high_div_argmax": hi_arg[:10], "high_div_hist_top8": sorted(hi_hist.items())[-8:], "hypothesis_high_div_attains_max": (hi_best == best) if did_full else None, "hypothesis_low_div_attains_max": (low_best == best) if did_full else None, # when the full sweep was skipped, the published maximum plus the low-class # maximum is what decides membership: if the low class attains the published # value, the attaining set lies inside the low class (the published value being # the exact maximum, used as external evidence). "low_class_attains_published_max": ( (n <= len(A288815)) and (low_best + 1 == A288815[n - 1])), "published_max_plus1": A288815[n - 1] if n <= len(A288815) else None, }) report["gates"].append({"x": x, **gate}) print("level x=%d done: full_sweep=%s low_max=%d hi_max=%d (published-1 %s) [%.1fs]" % (x, did_full, low_best, hi_best, (A288815[n - 1] - 1) if n <= len(A288815) else "n/a", time.time() - t0), file=sys.stderr, flush=True) bad = [g for g in report["gates"] for k, v in g.items() if isinstance(v, dict) and not v["pass"]] report["ok"] = not bad 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())