#!/usr/bin/env python3 """period_probe.py — job 4581 (rescue, route 175). Two exact, cheap questions about the mechanism #2042 records as HEURISTIC: H1. For a squarefree r, W_r(H) = sum_{h<=H} w_r(h) with w_r = prod_{p|r} w_p and w_p = f_p - 1 (#1834 Lemma 1). #2042 asserts "the mean value of W_r is -sigma(r)/2". What is the EXACT period mean of W_r? Predicted from #1834 Lemma 1's Fourier form: mean_{a=0..r-1} W_r(a) = -sigma(r) - T_r, T_r = (1/r) sum_{a=1}^{r-1} a w_r(a) = sum_{b!=0} |tau_r(b)|^2 / (e(b/r) - 1), so for prime p (T_p = -sigma(p)/2) the mean is -sigma(p)/2, while for squarefree composite r the CRT factorisation gives T_r = 0 and hence mean = -sigma(r). H2. Which value do the individual levels actually realise at a reachable H? Nothing here re-runs #2038's or #2042's computations: it is a level-by-level probe of the expansion F = sum_{r squarefree} w_r, which neither served script computes. """ from __future__ import annotations import json import math from fractions import Fraction as Fr H = 10 ** 4 YS = [2, 3, 5, 7, 11, 13, 17, 19, 23] # level set for the split (511 r's) SMALL = [2, 3, 5, 7, 11, 13, 15, 21, 33, 35, 39, 105] # primes and squarefree composites def nu(p: int, h: int) -> int: """#{0,2,h,h+2 mod p}.""" return len({0 % p, 2 % p, h % p, (h + 2) % p}) def f_p(p: int, h: int) -> Fr: if p == 2: return Fr(2) if h % 2 == 0 else Fr(0) return Fr(1 - Fr(nu(p, h), p)) / (1 - Fr(2, p)) ** 2 def w_p(p: int, h: int) -> Fr: return f_p(p, h) - 1 def divisors_squarefree(ps): out = [1] for p in ps: out += [r * p for r in out] return sorted(out) def w_r_exact(ps_r, h) -> Fr: v = Fr(1) for p in ps_r: v *= w_p(p, h) return v def main() -> int: out = {"H": H, "level_primes": YS} # ---- H1: exact period means (rational arithmetic) ------------------------------------- h1 = [] for r in SMALL: ps = [p for p in SMALL if p <= r and r % p == 0] ps = [p for p in [2, 3, 5, 7, 11, 13] if r % p == 0] wv = [w_r_exact(ps, h) for h in range(0, r)] # w_r is r-periodic P = [sum(wv[1:a + 1]) for a in range(0, r)] # P(a) = sum_{h=1..a} w_r(h) mean = sum(P) / r Tr = sum(a * wv[a] for a in range(1, r)) / r sig = Fr(1) for p in ps: sig *= Fr(1) if p == 2 else Fr(2, p - 2) h1.append({ "r": r, "primes": ps, "sigma_r": str(sig), "period_mean": str(mean), "minus_sigma_half": str(-sig / 2), "minus_sigma": str(-sig), "T_r": str(Tr), "matches_-sigma/2": mean == -sig / 2, "matches_-sigma": mean == -sig, }) # ---- H2: level split of the expansion at H, top level y = 23 (floats; H2 is a # structural probe, not a certificate) -------------------------------------------------- def wf(p: int, h: int) -> float: """float w_p, exact shape from #1834 Lemma 1.""" if p == 2: return 1.0 if h % 2 == 0 else -1.0 return float(Fr(1 - Fr(nu(p, h), p)) / (1 - Fr(2, p)) ** 2) - 1.0 rs = divisors_squarefree(YS) W = {} for r in rs: if r == 1: continue ps = [p for p in YS if r % p == 0] acc = 0.0 for h in range(1, H + 1): v = 1.0 for p in ps: v *= wf(p, h) acc += v W[r] = acc total = sum(W.values()) primes = [r for r in W if len([p for p in YS if r % p == 0]) == 1] comps = [r for r in W if r not in primes] split = { "level_y": YS[-1], "n_squarefree_r": len(W), "sum_W_all": float(total), "sum_W_prime_r": float(sum(W[r] for r in primes)), "sum_W_composite_r": float(sum(W[r] for r in comps)), "pred_minus_S_half_x": None, } def sigma(r): s = Fr(1) for p in YS: if r % p == 0: s *= Fr(1) if p == 2 else Fr(2, p - 2) return s S = sum(sigma(r) for r in W) split["sum_minus_sigma_half"] = float(-S / 2) split["sum_minus_sigma"] = float(-S) split["sum_minus_sigma_half_primes"] = float(-sum(sigma(r) for r in primes) / 2) split["sum_minus_sigma_half_composites"] = float(-sum(sigma(r) for r in comps) / 2) split["sum_minus_sigma_composites"] = float(-sum(sigma(r) for r in comps)) # per-level detail for the 12 smallest composites and all primes <= 31 per = [] for r in sorted(W, key=lambda x: (len([p for p in YS if x % p == 0]), x))[:40]: isprime = len([p for p in YS if r % p == 0]) == 1 per.append({"r": r, "prime": isprime, "omega": len([p for p in YS if r % p == 0]), "W_r": float(W[r]), "minus_sigma_2": float(-sigma(r) / 2), "minus_sigma": float(-sigma(r)), "sigma": float(sigma(r))}) split["per_level"] = per out["H1_period_means"] = h1 out["H2_level_split"] = split print(json.dumps(out, indent=1)) return 0 if __name__ == "__main__": raise SystemExit(main())