#!/usr/bin/env python3 """Job #1920 (route 80 triage) — rung 1 of the no-wrap-dominance question, exactly. Object (route 80 / #161 / #645 lane). For a base x let P = 2 * prod(p : p odd prime <= x) and the tile slot set be the ODD twin-admissible residues T_x = { n in [0, P) : n odd, gcd(n(n+2), P) = 1 }, |T_x| = prod_{3<=q<=x} (q-2) = D(T_x), sorted as r_0 < r_1 < ... < r_{D-1}; consecutive slots differ by a multiple of 6 (min 6). In block b the slot r_t is the integer r_t + b*P, so its residue mod p (p > x prime, hence coprime to P) is (r_t + b*delta) mod p with delta = P mod p. A *run* is a maximal index-contiguous stretch of slots whose residues mod p lie in one 2-set {A, A+2} (free translate, #161's okPair). Three readings of one level (s = x, Q = {p}), with S_A = {A, A+2}: nonwrap max over A of the longest run of the single-block word m_A(t) = [r_t mod p in S_A] cyc-naive longest cyclic run of m_A, closed with the SAME set S_A at the seam (the naive fold) corrected the true infinite slot sequence. A run crossing the seam is a suffix of block b under S_A followed by a prefix of block b+1 under S_{A-delta} (the phase advances by delta at every block boundary), so corrected = max( nonwrap , max_A [ suf(m_A) + pre(m_{A-delta}) ] ) -- exact, because a block is the same word translated and any splice can be re-indexed to start at phase 0. Route 80's claim is corrected == nonwrap. Everything is exact integer arithmetic; numpy only for the run-length scans. No timings are printed, so the artifact is byte-reproducible. """ import sys import numpy as np PMAX_SMALL = 101 # primes swept for x <= 19 X23_PRIMES = (29, 31, 37, 41) # bounded sweep at the first rung where G2 allows long steps def primes_upto(n): if n < 2: return [] sieve = bytearray([1]) * (n + 1) sieve[0] = sieve[1] = 0 for i in range(2, int(n ** 0.5) + 1): if sieve[i]: sieve[i * i::i] = bytearray(len(sieve[i * i::i])) return [i for i in range(n + 1) if sieve[i]] def build_tile(x): """Odd twin-admissible slot residues mod P = 2*odd-primorial, increasing.""" P_odd = 1 res = [0] for q in primes_upto(x): if q == 2: continue new = [] for r in res: for k in range(q): v = r + k * P_odd if v % q != 0 and v % q != (q - 2) % q: new.append(v) res = new P_odd *= q slots = [r for r in res if r % 2 == 1] + [r + P_odd for r in res if r % 2 == 0] slots.sort() return slots, 2 * P_odd def max_run(mask): if mask.size == 0 or not mask.any(): return 0 padded = np.concatenate((np.zeros(1, dtype=bool), mask, np.zeros(1, dtype=bool))) d = np.diff(padded.astype(np.int8)) return int((np.flatnonzero(d == -1) - np.flatnonzero(d == 1)).max()) def max_run_cyclic(mask): best = max_run(mask) if mask.size and mask[0] and mask[-1]: i = 0 while i < mask.size and mask[i]: i += 1 j = mask.size - 1 while j >= 0 and mask[j]: j -= 1 best = max(best, i + (mask.size - 1 - j)) return best def suffix_run(mask): n = mask.size if n == 0 or not mask[-1]: return 0 i = n - 1 while i >= 0 and mask[i]: i -= 1 return n - 1 - i def prefix_run(mask): n = mask.size if n == 0 or not mask[0]: return 0 i = 0 while i < n and mask[i]: i += 1 return i def scan(x, plist): slots, P = build_tile(x) D = len(slots) arr = np.array(slots, dtype=np.int64) gaps = np.diff(np.concatenate((arr, [arr[0] + P]))) g2 = int(gaps.max()) ctl = {"x": x, "P": int(P), "D": D, "D_formula": int(np.prod([q - 2 for q in primes_upto(x) if q != 2])), "sum_gaps_eq_P": bool(int(gaps.sum()) == P), "min_gap": int(gaps.min()), "max_gap": g2, "all_gaps_mult6": bool(np.all(gaps % 6 == 0))} rows = [] for p in [q for q in plist if q > x]: delta = P % p r0 = arr % p non = cyc = cor = 0 astar = None step_ok = [] # gaps g <= G2 with 6 | g and g mod p in {0, 2, p-2} for g in range(6, g2 + 1, 6): if g % p in (0, 2, p - 2) or g % p == p - 2: step_ok.append(g) for A in range(p): s1 = np.zeros(p, dtype=bool) s1[A] = True s1[(A + 2) % p] = True s2 = np.zeros(p, dtype=bool) s2[(A - delta) % p] = True s2[(A - delta + 2) % p] = True m0 = s1[r0] md = s2[r0] v_non = max_run(m0) if v_non > non: non = v_non astar = A cyc = max(cyc, max_run_cyclic(m0)) u = suffix_run(m0) v = prefix_run(md) splice = (u + v) if (u and v) else 0 if splice > cor: cor = splice cor = max(cor, non) rows.append({"p": p, "delta": int(delta), "A_star": astar, "nonwrap": non, "cyc_naive": cyc, "corrected": cor, "step_values": step_ok[:12], "corrected_gt_nonwrap": bool(cor > non), "cyc_gt_nonwrap": bool(cyc > non), "no_step_expect_run1": bool(not step_ok)}) return ctl, rows def main(): small = primes_upto(PMAX_SMALL) plan = [(11, small), (13, small), (17, small), (19, small), (23, list(X23_PRIMES))] ctls, rows_all, checks = [], [], [] for x, plist in plan: ctl, rows = scan(x, plist) ctls.append(ctl) for r in rows: r = dict(r) r["x"] = x rows_all.append(r) checks.append((f"D(T_{x}) = prod(q-2) = {ctl['D_formula']} == slot count {ctl['D']}", ctl["D"] == ctl["D_formula"])) checks.append((f"cyclic gaps of T_{x} sum to P = {ctl['P']}", ctl["sum_gaps_eq_P"])) checks.append((f"every gap of T_{x} is a positive multiple of 6 (min {ctl['min_gap']})", ctl["all_gaps_mult6"] and ctl["min_gap"] == 6)) # structural control: if no step value exists then no run of length >= 2 is possible bad = [r for r in rows if r["no_step_expect_run1"] and r["nonwrap"] > 1] checks.append((f"T_{x}: p with no admissible step (p > G2+2) has no run of length >= 2 " f"({len(bad)} violations)", len(bad) == 0)) mono = all(r["corrected"] >= r["nonwrap"] for r in rows) checks.append((f"T_{x}: corrected >= nonwrap (a single-block run is a true run)", mono)) n = len(rows_all) cor_gt = [r for r in rows_all if r["corrected_gt_nonwrap"]] cyc_gt = [r for r in rows_all if r["cyc_gt_nonwrap"]] cor_eq = [r for r in rows_all if r["corrected"] == r["nonwrap"]] checks.append((f"corrected > nonwrap in 0 of {n} (x,p) pairs (route 80 rung 1)", len(cor_gt) == 0)) print("# job1920 — rung 1 (|Q| = 1): nonwrap vs cyc-naive vs true continuation") print("# slots = odd twin-admissible residues mod P = 2*odd-primorial") for ctl in ctls: print(f"\n## T_{ctl['x']}: P = {ctl['P']} D = {ctl['D']} min gap {ctl['min_gap']} " f"max gap G2 = {ctl['max_gap']}") print(" p delta A* nonwrap cyc-naive corrected flags") for r in rows_all: if r["x"] != ctl["x"]: continue flags = [] if r["corrected_gt_nonwrap"]: flags.append("CORRECTED>NONWRAP") if r["cyc_gt_nonwrap"]: flags.append("cyc-naive>nonwrap") if r["no_step_expect_run1"]: flags.append("no-step") print(f"{r['p']:>4} {r['delta']:>6} {str(r['A_star']):>3} {r['nonwrap']:>8} " f"{r['cyc_naive']:>10} {r['corrected']:>10} {' '.join(flags)}") print("\n# aggregates over all (x,p) pairs") print(f"pairs = {n}") print(f"corrected == nonwrap = {len(cor_eq)}") print(f"corrected > nonwrap = {len(cor_gt)}" f" {[(r['x'], r['p'], r['nonwrap'], r['corrected']) for r in cor_gt]}") print(f"cyc-naive > nonwrap = {len(cyc_gt)}" f" {[(r['x'], r['p'], r['nonwrap'], r['cyc_naive']) for r in cyc_gt]}") print(f"max nonwrap / cyc-naive / corrected = " f"{max(r['nonwrap'] for r in rows_all)} / " f"{max(r['cyc_naive'] for r in rows_all)} / " f"{max(r['corrected'] for r in rows_all)}") npass = sum(1 for _, ok in checks if ok) print("\n# checks") for name, ok in checks: print(("PASS " if ok else "FAIL ") + name) print(f"\n{npass}/{len(checks)} checks passed") print("ALL_PASS" if npass == len(checks) else "HAS_FAILURES") return 0 if npass == len(checks) else 1 if __name__ == "__main__": sys.exit(main())