# check2669.py -- route 107 (job 2669): checks for the twin Ramanujan expansion of F(h) = S_4(h)/(2C_2)^2. # stdlib only; deterministic; stdout is the artifact (no timing). # Claims checked: # (A) local Fourier coefficients: f_p(h) - 1 = sum_{b != 0 mod p} |tau_p(b)|^2 e(hb/p), # tau_2 = 1, tau_p(b) = (1 + e(2b/p))/(p-2) for odd p; sigma_p = sum_b |tau_p(b)|^2 = w_p(0). # (B) truncated identity: sum_{|h|> i & 1] r = 1 for q in qs: r *= q inv = {q: pow((r // q) % q, -1, q) for q in qs} for b in range(r): if math.gcd(b, r) != 1: continue w = 1.0 for q in qs: w *= abs(tau_p(q, b * inv[q] % q)) ** 2 rhs += w * KH(H, b / r) return float(lhs), rhs rowsB = [] for ps, H in (([2, 3, 5, 7], 30), ([2, 3, 5, 7, 11], 77), ([2, 3, 5, 7, 11, 13], 200), ([2, 3, 5, 7, 11, 13], 1000)): l, r = check_B(ps, H) rowsB.append({"y": ps[-1], "H": H, "lhs": round(l, 6), "rhs": round(r, 6), "rel_err": float("%.2g" % (abs(l - r) / l))}) out["B_truncated_identity"] = rowsB # (C) C2 = 1.0 for p in primes_upto(2 * 10 ** 6)[1:]: C2 *= p * (p - 2) / (p - 1) ** 2 # truncation error < 1e-6 relative a_pred = 1 / (4 * C2) N = 10 ** 6 sig = [1.0] * (N + 1); sig[0] = 0.0 for p in primes_upto(N): v = 1.0 if p == 2 else 2.0 / (p - 2) for m in range(p, N + 1, p): sig[m] *= v pp = p * p for m in range(pp, N + 1, pp): sig[m] = 0.0 tab = json.load(open("ssum2549.json"))["rows"] Hs = {row["H"] for row in tab} S = {}; acc = 0.0 for r in range(1, N + 1): acc += sig[r] if r in Hs: S[r] = acc rowsC = [] for row in tab: H = row["H"]; L = math.log(H); d = row["defect_over_2C2sq_H"] rowsC.append({"H": H, "D_over_A2H": round(d, 4), "S_H": round(S[H], 4), "diff": round(d - S[H], 4), "diff_over_lnH": round((d - S[H]) / L, 4)}) # refit with a fixed: minimise sum (d - a L^2 - b L - c)^2 over b, c xs = [math.log(row["H"]) for row in tab]; ys = [row["defect_over_2C2sq_H"] - a_pred * x * x for row, x in zip(tab, xs)] n = len(xs); sx = sum(xs); sy = sum(ys); sxx = sum(x * x for x in xs); sxy = sum(x * y for x, y in zip(xs, ys)) b = (n * sxy - sx * sy) / (n * sxx - sx * sx); c = (sy - b * sx) / n res = max(abs(y - b * x - c) for x, y in zip(xs, ys)) out["C2"] = round(C2, 8); out["a_pred_1_over_4C2"] = round(a_pred, 6) out["C_S_vs_table"] = rowsC out["C_refit_a_fixed"] = {"a": round(a_pred, 6), "b": round(b, 4), "c": round(c, 4), "max_abs_resid": round(res, 4)} print(json.dumps(out, indent=1))