#!/usr/bin/env python3 """ Job #1328 / route 25 triage: independent replication of #587's lambda ladder. For x = 7..29 rebuild the twin admissible tile T_x = {n in [0,x#): n, n+2 coprime to x#} from scratch, derive Ghat(x) = max gap and m*(T_x) = max{m : maxsum_m < 4*Ghat} from the tile itself (NOT from the published ladder), and report lambda = m*.gbar/Ghat. Census is asserted against the closed form prod_{3<=p<=x}(p-2). Ghat is asserted against the published ladder only where #587/#584 state it. stdout is the artifact. """ import sys, time import numpy as np ALLP = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31] PUBLISHED_GHAT = {29: 258, 31: 348} # the two stated in the brief / #587 PUBLISHED_LAMBDA = {7: 2.800, 11: 2.444, 13: 2.758, 17: 2.547, 19: 2.562, 23: 2.475, 29: 2.336} def level(x): primes = [p for p in ALLP if p <= x] primorial = 1 for p in primes: primorial *= p census = 1 for p in primes: if p > 2: census *= (p - 2) return primes, primorial, census def tile(primes, primorial): keep = np.ones(primorial, dtype=bool) for p in primes: keep[0::p] = False if p > 2: keep[(-2) % p::p] = False return np.flatnonzero(keep) def main(): print("x\tx#\t\tD=|T_x|\t\tgbar\t\tGhat\tGhat/gbar\t4Ghat\tm*\tlambda\t#587") for x in (7, 11, 13, 17, 19, 23, 29): primes, primorial, census = level(x) t0 = time.time() pos = tile(primes, primorial) assert pos.size == census, (x, pos.size, census) # cyclic gap word: wrap the first element up by one period ext = np.concatenate((pos, pos[:64] + primorial)) gaps = ext[1:] - ext[:-1] ghat = int(gaps.max()) if x in PUBLISHED_GHAT: assert ghat == PUBLISHED_GHAT[x], (x, ghat, PUBLISHED_GHAT[x]) assert int(gaps[:census].sum()) == primorial, (x, int(gaps[:census].sum())) budget = 4 * ghat gbar = primorial / census mstar = None for m in range(1, 64): if m >= ext.size: break maxsum = int((ext[m:] - ext[:-m])[:census].max()) if maxsum < budget: mstar = m else: break lam = mstar * gbar / ghat pub = PUBLISHED_LAMBDA.get(x) flag = "" if pub is None else (" MATCH" if abs(lam - pub) < 5e-4 else f" DIFFERS ({pub})") print(f"{x}\t{primorial}\t{census}\t\t{gbar:.4f}\t\t{ghat}\t" f"{ghat/gbar:.4f}\t\t{budget}\t{mstar}\t{lam:.4f}\t{pub}{flag}", flush=True) print(f" (rebuilt in {time.time()-t0:.2f}s; sum(gaps)=x# asserted; " f"census asserted against prod(p-2))", file=sys.stderr) if __name__ == "__main__": main()