#!/usr/bin/env python3 """Route 98 triage probe: exact full-period K* for the two-class covering run. Independent, from the definitions only (no reuse of #1243's scripts). Object (route 98 / returns #609, #901): slots(P) = residues r in [0, P) with gcd(r, P) = gcd(r+2, P) = 1 (twin-admissible). r killed by q iff q | r or q | r+2. K*(P, R) = length of the longest *cyclic* run of consecutive slots (in the periodic slot sequence of modulus P, extended over the full period M = P * prod(R)) each of which is killed by some q in R (R coprime to P). Sandwich (route 98), for p prime not|P and R coprime to Pp: K*(P, R) <= K*(Pp, R) <= K*(P, R u {p}) - 1. Proven legs: (i) K*(Pp,R) <= K*(P,R u {p}); (ii) K*(Pp,R) >= K*(P,R) when p > 2*K*(P,R). Open: C1 unconditional lower bound (hard regime p <= 2L), C2 the -1 strictness, C3 full. """ import numpy as np from math import gcd from sympy import primerange, isprime def slots_mod(P): return [r for r in range(P) if gcd(r, P) == 1 and gcd(r + 2, P) == 1] def longest_cyclic_run(killed, N): """Longest run of True in a circular boolean array of length N.""" if bool(killed.all()): return N false_idx = np.flatnonzero(~killed) if false_idx.size == 0: return N ext = np.concatenate([false_idx, false_idx + N]) gaps = np.diff(ext) return int(gaps.max()) - 1 def kstar(P, R): """Exact K*(P, R). P base modulus, R list of distinct primes coprime to P.""" R = list(R) slots = np.asarray(slots_mod(P), dtype=np.int64) D = slots.size prodR = 1 for q in R: prodR *= q N = D * prodR k = np.arange(prodR, dtype=np.int64) # consecutive-slot ordering: block k holds slots[k] + k*P, blocks in order x = (k[:, None] * P + slots[None, :]).ravel() # length N killed = np.zeros(N, dtype=bool) for q in R: killed |= (x % q == 0) | ((x + 2) % q == 0) return longest_cyclic_run(killed, N) # ---------------------------------------------------------------- validation def validate(): # Return #609 table of exact K* values (level s, P=P(s)#, Q=(s,2s]). table = [ (30, [7], 2), (30, [7, 11], 3), (210, [11, 13], 3), (210, [11, 13, 17], 5), (210, [11, 13, 17, 19], 8), (2310, [13, 17, 19], 6), ] print("== validation vs #609 table ==") ok = True for P, Q, want in table: got = kstar(P, Q) mark = "OK" if got == want else "MISMATCH" if got != want: ok = False print(f" K*({P}, {Q}) = {got} (want {want}) {mark}") print(" validation:", "PASS" if ok else "FAIL") return ok # ---------------------------------------------------------------- probe def probe(): print("\n== sandwich probe ==") # (base P, p-range, R pool). p must not divide P; R primes coprime to P and != p. configs = [ (30, list(primerange(7, 48)), [7, 11, 13, 17, 19, 23]), (210, list(primerange(11, 40)), [11, 13, 17, 19, 23]), (2310, list(primerange(13, 44)), [13, 17, 19]), ] total = 0 hard = 0 viol = {"transfer": [], "cond_lb": [], "C1_lb": [], "C2_minus1": [], "sandwich": []} for P, prange, pool in configs: for p in prange: if P % p == 0: continue Rpool = [q for q in pool if q != p] # all nonempty subsets of size 1..3 Rs = [] from itertools import combinations for sz in (1, 2, 3): for c in combinations(Rpool, sz): Rs.append(list(c)) for R in Rs: L1 = kstar(P, R) # K*(P, R) L2 = kstar(P * p, R) # K*(Pp, R) L3 = kstar(P, R + [p]) # K*(P, R u {p}) total += 1 ishard = p <= 2 * L1 if ishard: hard += 1 # proven legs if not (L2 <= L3): viol["transfer"].append((P, p, tuple(R), L1, L2, L3)) if p > 2 * L1 and not (L2 >= L1): viol["cond_lb"].append((P, p, tuple(R), L1, L2, L3)) # open conjectures if not (L2 >= L1): viol["C1_lb"].append((P, p, tuple(R), L1, L2, L3)) if not (L2 <= L3 - 1): viol["C2_minus1"].append((P, p, tuple(R), L1, L2, L3)) if not (L1 <= L2 <= L3 - 1): viol["sandwich"].append((P, p, tuple(R), L1, L2, L3)) print(f" triples tested: {total} (hard-regime p<=2L: {hard})") for name in ("transfer", "cond_lb", "C1_lb", "C2_minus1", "sandwich"): v = viol[name] print(f" {name}: {len(v)} violation(s)") for w in v[:5]: print(" ", w) print("\n summary:", "ALL HOLD" if all(len(v) == 0 for v in viol.values()) else "VIOLATIONS FOUND") if __name__ == "__main__": import sys if validate(): probe() else: print("validation failed; stopping before probe") sys.exit(1)