#!/usr/bin/env python3 """job1460b — period-normalised control for the route-37 ratio (triage). Script 1 showed, on the range n < 1e6, both (a) a decreasing level series r = 0.9182, 0.8859, 0.8556, 0.8169, 0.7725 at x = 11,13,17,19,23 (b) a strong decreasing RANGE drift at fixed level: at x = 11, r = 0.7381 (n<1e5) -> 0.9182 (n<1e6). The admissibility pattern is periodic in n with period M = x#, so the number of *periods* covered by n < 1e6 is 433 (x=11), 33 (x=13), 1.96 (x=17), 0.103 (x=19), 0.0045 (x=23). The "level series" (a) therefore compares slices covering wildly different fractions of a period. This script holds the period count k fixed (k = 1,2,4,8,16 periods, i.e. n < k*M, aligned at multiples of M) and measures r_k(x) = W(+1,+1)/W(-1,-1), the level-intrinsic object the route should be indexing by. Gates before any ratio: G1 pi_2(1e6) == 8169 (independent Eratosthenes sieve). G2 residue-marking admissibility == gcd(n(n+2), x#) == 1 on a prefix, every level. G3 lam multiplicative on 200 random pairs. G5 PERIOD GATE: the admissible-slot count over exactly one period equals the closed form prod_{p odd <= x} (p-2) exactly, and over k periods equals k times it. This is the arithmetic check that the marking and the period alignment are right (no empirical input). G6 CROSS-INSTRUMENT: at fixed range n < 1e6 the ratios equal script 1's values for x = 11,13,17,19. Timing to stderr only. """ import json import math import os import random import sys import time T0 = time.time() HERE = os.path.dirname(os.path.abspath(__file__)) LEVELS = [11, 13, 17, 19] KLIST = [1, 2, 4, 8, 16] FIXED_RANGE = 1_000_000 # script 1's fixed-range values at n < 1e6, for the cross-instrument gate G6: S1 = {"11": 0.9182, "13": 0.8859, "17": 0.8556, "19": 0.8169} N = 2 * 9_699_690 + 4 # two periods at x = 19 is the largest range measured OUT = os.path.join(HERE, "job1460b-periods.json") par = bytearray(N + 1) is_comp = bytearray(N + 1) primes = [] for i in range(2, N + 1): if not is_comp[i]: primes.append(i) par[i] = 1 for p in primes: ip = i * p if ip > N: break is_comp[ip] = 1 par[ip] = par[i] ^ 1 if i % p == 0: break sieve_s = time.time() - T0 L = [1 - 2 * par[i] for i in range(N + 1)] L[0] = 0 L[1] = 1 isp = bytearray([1]) * (N + 2) isp[0] = isp[1] = 0 for i in range(2, math.isqrt(N + 1) + 1): if isp[i]: isp[i * i:: i] = bytearray(len(range(i * i, N + 2, i))) pi2_1e6 = sum(1 for n in range(3, 10 ** 6 + 1, 2) if isp[n] and isp[n + 2]) gate_g1 = (pi2_1e6 == 8169) random.seed(1460) gate_g3 = bool(all(L[a] * L[b] == L[a * b] for a, b in ((random.randint(2, 97), random.randint(2, 997)) for _ in range(200)))) def xsharp_of(x): m = 1 for p in primes: if p > x: break m *= p return m def closed_form_slots(x): """number of n mod x# with gcd(n(n+2), x#) = 1: 1 (p=2: n odd) * prod_{odd p<=x}(p-2).""" m = 1 for p in primes: if p > x: break if p > 2: m *= (p - 2) return m def adm_bad(x): bad = bytearray(N + 1) for p in primes: if p > x: break bad[0::p] = b"\x01" * len(range(0, N + 1, p)) if p > 2: bad[p - 2:: p] = b"\x01" * len(range(p - 2, N + 1, p)) return bad gate_g2 = True g2_detail = {} for x in LEVELS: M = xsharp_of(x) bad = adm_bad(x) mm = sum(1 for n in range(2, 5000) if bad[n] != (0 if math.gcd(n * (n + 2), M) == 1 else 1)) g2_detail[str(x)] = {"M_xsharp": M, "prefix_mismatches": mm} if mm: gate_g2 = False # ---------------- measurement ---------------- gate_g5 = True g5_detail = {} gate_g6 = True g6_detail = {} res = {} for x in LEVELS: M = xsharp_of(x) bad = adm_bad(x) cf = closed_form_slots(x) ks = [k for k in KLIST if k * M + 2 <= N] bounds = sorted([k * M - 1 for k in ks] + [FIXED_RANGE - 1]) c = {(-1, -1): 0, (-1, 1): 0, (1, -1): 0, (1, 1): 0} tw = 0 snaps = {} j = 0 hi = max(bounds) for n in range(3, hi + 1, 2): while j < len(bounds) and n > bounds[j]: snaps[bounds[j]] = (dict(c), tw) j += 1 if not bad[n]: c[(L[n], L[n + 2])] += 1 if isp[n] and isp[n + 2]: tw += 1 while j < len(bounds): snaps[bounds[j]] = (dict(c), tw) j += 1 res[x] = {"M": M, "closed_form_slots_per_period": cf, "k_measured": ks} cc1, tt1 = snaps[FIXED_RANGE - 1] r1 = cc1[(1, 1)] / cc1[(-1, -1)] if cc1[(-1, -1)] else None g6_detail[str(x)] = {"reference_script1": S1[str(x)], "recomputed": r1, "counts": {f"{a}{b}": v for (a, b), v in sorted(cc1.items())}, "match": r1 is not None and abs(r1 - S1[str(x)]) < 5e-5} if not g6_detail[str(x)]["match"]: gate_g6 = False for k in ks: cc, t = snaps[k * M - 1] slots = sum(cc.values()) gg = cc[(-1, -1)] bb = cc[(1, 1)] res[x][f"k={k}"] = { "slots": slots, "expected_slots_k_times_closed_form": k * cf, "slots_match_closed_form": slots == k * cf, "counts": {f"{a}{b}": v for (a, b), v in sorted(cc.items())}, "ratio": bb / gg if gg else None, "twin_share_of_good": (t / gg) if gg else None, } if slots != k * cf: gate_g5 = False g5_detail[str(x)] = {"closed_form_slots_per_period": cf, "measured_one_period_slots": res[x][f"k={ks[0]}"]["slots"], "pass": res[x][f"k={ks[0]}"]["slots"] == cf} out = { "instrument": "job1460b-periods.py", "purpose": "hold the number of admissibility periods fixed while the level x changes", "xsharp_19": xsharp_of(19), "gates": { "G1_pi2_1e6_is_8169": {"value": pi2_1e6, "pass": bool(gate_g1)}, "G2_residue_vs_gcd_prefix": {"detail": g2_detail, "pass": bool(gate_g2)}, "G3_multiplicative_200_trials": {"pass": gate_g3}, "G5_period_slot_count_closed_form": {"detail": g5_detail, "pass": bool(gate_g5)}, "G6_consistent_with_job1460_script1": {"detail": g6_detail, "pass": bool(gate_g6), "note": "script 1 measured these on n < 1e6"}, }, "all_gates_pass": bool(gate_g1 and gate_g2 and gate_g3 and gate_g5 and gate_g6), "period_series": {str(x): {k: v for k, v in res[x].items() if k.startswith("k=")} for x in LEVELS}, "period_meta": {str(x): {k: v for k, v in res[x].items() if not k.startswith("k=")} for x in LEVELS}, "elapsed_s": round(time.time() - T0, 3), } with open(OUT, "w") as f: json.dump(out, f, indent=1, sort_keys=True) print(json.dumps({"gates": {k: v.get("pass") for k, v in out["gates"].items()}, "all_gates_pass": out["all_gates_pass"], "pi2_1e6": pi2_1e6})) print("r over k periods (n < k*M), by level:") for x in LEVELS: row = [] for k in res[x]["k_measured"]: d = res[x][f"k={k}"] row.append(f"k={k}:{d['ratio']:.4f}" if d["ratio"] is not None else f"k={k}:n/a") print(f" x={x:2d} M={res[x]['M']:>8d} slots/period={res[x]['closed_form_slots_per_period']:>4d} " + " ".join(row)) print("periods covered by n < 1e6:", json.dumps({str(x): round(10 ** 6 / xsharp_of(x), 4) for x in LEVELS + [23]})) print("wrote", OUT, file=sys.stderr) print(f"elapsed_s={out['elapsed_s']}", file=sys.stderr)