#!/usr/bin/env python3 """job1460 — triage probe for route 37 (split-aware gate). Route 37 (and its evidence return #662) reads the delta = +1 class ratio r(x) = W(+1,+1) / W(-1,-1) of admissible twin slots (gcd(n(n+2), x#) = 1, lam = (-1)^Omega) at x = 11, 13, 17 on the range n < 1e6 as 0.9182 / 0.8859 / 0.8556 and reads it as a *decreasing level trend* it wants to extend to x = 19, 23 and extrapolate ("a ratio tending to 1 says the blind class saturates ... a ratio tending to 0 would make a delta statistic discriminating"). The route's next experiment changes the level and holds the range fixed. Before that experiment is worth its budget, triage has to know whether r reads as a *level* effect at all or whether it is (partly) a *range* effect: at fixed level, does r drift with the cutoff n < P? If the two drifts are the same size, the three points are not a level series and the planned extrapolation measures an artefact. This instrument measures both drifts and the first two new levels in one process. Reuses return #662's definitions verbatim (admissible twin slot = gcd(n(n+2), x#) = 1; lam from an Omega-parity sieve; good class (-1,-1); blind class (+1,+1); delta = lam(n)lam(n+2)) and its gates, and adds a HARD reproduction gate against #662's published counts. Gates, all evaluated before any ratio is read: G1 pi_2(1e6) == 8169 exactly, from an independent Eratosthenes sieve. G2 the admissibility array (per-prime residue marking) agrees with the gcd(n(n+2), x#) formulation on a prefix, at every level. G3 lam is multiplicative on 200 random pairs. G4 REPRODUCTION: the four class counts at x = 11, 13, 17 on n < 1e6 equal return #662's published counts exactly. If this fails, nothing below is a comparison with the record. Outputs the level series at fixed range and the range series at fixed level, plus a bounded sieve-rate measurement for the route's 2-window feasibility question. Timing goes to stderr only (stdout is byte-identical between runs) and into --out as `elapsed_s`. """ import json import math import os import random import sys import time T0 = time.time() HERE = os.path.dirname(os.path.abspath(__file__)) N = int(sys.argv[1]) if len(sys.argv) > 1 else 1_000_000 OUT = os.path.join(HERE, "job1460-splitratio.json") LEVELS = [11, 13, 17, 19, 23] PREFIXES = [100_000, 250_000, 500_000, 1_000_000] FIXED_RANGE = 1_000_000 # the range #662 used FIXED_LEVEL_FOR_RANGE_SERIES = 17 # ---- Omega parity (lambda), linear sieve ------------------------------------------------ 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 # ---- G1: independent prime indicator and pi_2 ------------------------------------------------- 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, min(N, 10 ** 6) + 1, 2) if isp[n] and isp[n + 2]) gate_g1 = (pi2_1e6 == 8169) # ---- G3: multiplicativity --------------------------------------------------------------- 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)))) # ---- admissibility by residue marking, gated against gcd ------------------------------------ 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)) # p | n if p > 2: bad[p - 2:: p] = b"\x01" * len(range(p - 2, N + 1, p)) # p | n+2 return bad xsharp = 1 for p in primes: if p > max(LEVELS): break xsharp *= p gate_g2 = True g2_detail = {} for x in LEVELS: M = 1 for p in primes: if p > x: break M *= p bad = adm_bad(x) mismatch = 0 for n in range(2, 5000): if bad[n] != (0 if math.gcd(n * (n + 2), M) == 1 else 1): mismatch += 1 g2_detail[str(x)] = {"M_xsharp": M, "prefix_mismatches": mismatch} if mismatch: gate_g2 = False # ---- G4: exact reproduction of return #662's published counts -------------------------------- G4_EXPECT = { "11": {"-1-1": 15226, "-11": 14635, "1-1": 14597, "11": 13981}, "13": {"-1-1": 13090, "-11": 12363, "1-1": 12398, "11": 11596}, "17": {"-1-1": 11750, "-11": 10913, "1-1": 10911, "11": 10053}, } # ---- measurement: one odd-n pass per level, snapshotting at each prefix ----------------------- def measuring(): res = {} for x in LEVELS: bad = adm_bad(x) c = {(-1, -1): 0, (-1, 1): 0, (1, -1): 0, (1, 1): 0} snaps = {} k = 0 for n in range(3, min(N - 2, 999_999) + 1, 2): while k < len(PREFIXES) and n >= PREFIXES[k]: snaps[PREFIXES[k]] = dict(c) k += 1 if not bad[n]: c[(L[n], L[n + 2])] += 1 while k < len(PREFIXES): snaps[PREFIXES[k]] = dict(c) k += 1 res[x] = snaps return res res = measuring() def ratio(c): gg = c[(-1, -1)] bb = c[(1, 1)] tot = sum(c.values()) return { "good_negneg": gg, "blind_pospos": bb, "slots": tot, "ratio_blind_over_good": (bb / gg) if gg else None, "delta_plus1_mass": gg + bb, "delta_minus1_mass": c[(-1, 1)] + c[(1, -1)], "delta_mean": ((gg + bb) - (c[(-1, 1)] + c[(1, -1)])) / tot if tot else None, "counts": {f"{a}{b}": v for (a, b), v in sorted(c.items())}, } levels_out = {str(x): {str(P): ratio(res[x][P]) for P in PREFIXES} for x in LEVELS} # G4 on the fixed range #662 used g4_detail = {} gate_g4 = True for x in (11, 13, 17): got = levels_out[str(x)][str(FIXED_RANGE)]["counts"] exp = G4_EXPECT[str(x)] g4_detail[str(x)] = {"expected": exp, "got": got, "match": got == exp} if got != exp: gate_g4 = False # range series at fixed levels (drift with cutoff, level held) range_series = {str(x): {str(P): levels_out[str(x)][str(P)]["ratio_blind_over_good"] for P in PREFIXES} for x in LEVELS} # ---- feasibility: measured sieve rate -> cost of the route's 2 x# windows --------------------- M19 = 2 * 9_699_690 M23 = 2 * 223_092_870 rate = N / sieve_s if sieve_s > 0 else None probe = { "sieve_N": N, "sieve_seconds_measured": round(sieve_s, 3), "rate_slots_per_s": round(rate, 1) if rate else None, "two_windows_x19_slots": M19, "two_windows_x23_slots": M23, "extrapolated_s_for_x19_2windows": round(M19 / rate, 1) if rate else None, "extrapolated_s_for_x23_2windows": round(M23 / rate, 1) if rate else None, "note": "pure-Python linear Omega-parity sieve, one core; extrapolation is linear in slots and " "is a lower bound (the same process also scans the slots)", } out = { "instrument": "job1460-splitratio.py", "purpose": "route 37 triage: is r(x) = W(+1,+1)/W(-1,-1) a level effect or a range effect?", "definitions": "admissible twin slot: gcd(n(n+2), x#) = 1; lam = (-1)^Omega; good class " "(lam(n),lam(n+2)) = (-1,-1); blind class = (+1,+1); delta = lam(n)lam(n+2)", "N": N, "levels": LEVELS, "prefixes": PREFIXES, "xsharp_23": xsharp, "gates": { "G1_pi2_1e6_is_8169": {"value": pi2_1e6, "pass": bool(gate_g1)}, "G2_residue_array_vs_gcd_prefix": {"detail": g2_detail, "pass": bool(gate_g2)}, "G3_liouville_multiplicative_200_trials": {"pass": gate_g3}, "G4_reproduces_662_counts_at_1e6": {"detail": g4_detail, "pass": bool(gate_g4)}, }, "all_gates_pass": bool(gate_g1 and gate_g2 and gate_g3 and gate_g4), "level_series_at_1e6": {str(x): levels_out[str(x)][str(FIXED_RANGE)] for x in LEVELS}, "range_series": range_series, "feasibility": probe, "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["pass"] if isinstance(v, dict) and "pass" in v else v for k, v in out["gates"].items()}, "all_gates_pass": out["all_gates_pass"], "pi2_1e6": pi2_1e6})) print("level series at n < 1e6 (x: slots, good, blind, ratio, delta_mean):") for x in LEVELS: d = out["level_series_at_1e6"][str(x)] print(f" x={x:2d} slots={d['slots']:>6d} good={d['good_negneg']:>6d} blind={d['blind_pospos']:>6d} " f"r={d['ratio_blind_over_good']:.4f} delta_mean={d['delta_mean']:+.4f}") print("range series (ratio at n < P):") for x in LEVELS: print(f" x={x:2d} " + " ".join(f"{P}:{range_series[str(x)][str(P)]:.4f}" for P in PREFIXES)) print(json.dumps(probe)) print("wrote", OUT, file=sys.stderr) print(f"elapsed_s={out['elapsed_s']}", file=sys.stderr)