#!/usr/bin/env python3 """Exact admissible-offset census for a primorial wheel (route 2, job #4478 step check). N(a, L, W) = #{ s in 1..L : gcd(a+s, W) == 1 and gcd(a+s+2, W) == 1 } This is the object the route's scanners call a "support": lossscan762.c builds exactly this set (s in 1..L with both gcds equal to 1). The census is deterministic, so only data goes to stdout; progress and timing go to stderr. Gates (from return #1795, W = 510510 = 17#, a = 58, exhaustive there): N(58, 463, 510510) == 21 N(58, 1243, 510510) == 53 Both must hold or this script exits non-zero and prints nothing usable. Then the same function at W = 9699690 = 19# (the step's wheel, T19). """ import json import math import sys W17 = 510510 # 17# W19 = 9699690 # 19# def N(a, L, W): """Exact count of admissible offsets, no marks, no strides, no segments.""" n = 0 for s in range(1, L + 1): if math.gcd(a + s, W) == 1 and math.gcd(a + s + 2, W) == 1: n += 1 return n def twin_density(primes): f = 1.0 for p in primes: f *= (p - 2) / p return f def main(): primes17 = [2, 3, 5, 7, 11, 13, 17] primes19 = primes17 + [19] gates = [] g1 = N(58, 463, W17) g2 = N(58, 1243, W17) gates.append({"what": "#1795 witness a=58 L=463 at 17#", "expected": 21, "got": g1, "pass": g1 == 21}) gates.append({"what": "#1795 witness a=58 L=1243 at 17#", "expected": 53, "got": g2, "pass": g2 == 53}) g3 = N(51, 1250, W17) gates.append({"what": "#1795 second witness a=51 L=1250 at 17#", "expected": None, "got": g3, "pass": True, "note": "recorded, not gated"}) ok = all(g["pass"] for g in gates) print(json.dumps({"W17": W17, "W19": W19, "twin_density_17": twin_density(primes17), "twin_density_19": twin_density(primes19), "gates": gates, "gates_ok": ok}, indent=1)) if not ok: print("GATE FAILED", file=sys.stderr) return 2 # Exact N(L) at the step's wheel, same start a = 58 as #1795's witnesses, plus a second # start so the count is not read as an accident of one residue class. rows = [] marks = (463, 1000, 2000, 2151, 2152, 3000, 4000, 5000) for a in (58, 0): # one incremental pass over s = 1..6000: records N at the marked lengths and the # first L at which N exceeds the served scanner's MAX_N = 84 n = 0 prev = 0 first_over = None for s in range(1, 6001): if math.gcd(a + s, W19) == 1 and math.gcd(a + s + 2, W19) == 1: n += 1 if s in marks: rows.append({"a": a, "L": s, "N": n, "dN": n - prev}) prev = n if first_over is None and n > 84: first_over = s rows.append({"a": a, "first_L_with_N_gt_84": first_over}) print(json.dumps({"rows": rows}, indent=1)) return 0 if __name__ == "__main__": sys.exit(main())