"""Job #2658 (route 35 rev 14, pursue): the lag-H covariance of twin counts, and the H = 510510 variance over [10^9, 10^10). Pre-registered here before the run (the design of #1302's next step): Data: twin pairs by smaller member from the segmented sieve of #1029/#1297 over [10^6, 10^10). Covariance: for H in {2310, 30030, 510510} and each decade [10^d, 10^(d+1)), d = 6..9, the adjacent pairs of intervals I_i = [a_i, a_i + H), J_i = [a_i + H, a_i + 2H) with a_i = multiples of 2H inside the decade (so the pairs are disjoint); with m, m' the intervals' own Hardy-Littlewood means, C = sum (N_i - m_i)(N'_i - m'_i) / sum m_i (a covariance in units of the mean, Poisson-independent = 0), bootstrap band over pairs (400 draws, seed 2658). Prediction (4-tuple conjecture): E[N N'] = sum over even h in (0, 2H) of w(h) S_4(h) / ln^4 X with w(h) = min(h, 2H - h) (the number of n in I with n + h in J), so C_HL = [sum_h w(h) S_4(h) - H^2 (2 C_2)^2] / (ln^4 X) / (2 C_2 H / ln^2 X), S_4 the singular series of {0, 2, h, h+2} computed exactly per h as in var2656.py (p = 2, 3 explicit; local factors sieved). Variance: the R statistic of var2656.py for H = 510510 over [10^9, 10^10) (aligned and offset), against its prediction. Falsifier (fixed here): C_HL (decade midpoint) inside the bootstrap band at H = 2310 and 30030 in every decade 10^6..10^9, and the 10^9-decade variance cell inside its band. Added, labelled: the same at H = 510510 and the 10^9 decade for all lengths; the interval-integrated predictions. Controls: G0 pi_2(10^6) = 8169; total twins in [10^6, 10^10) = pi_2(10^10) - pi_2(10^6) = 27412679 - 8169 (OEIS A007508). Stdout: ledger + verdict (deterministic); stderr: progress. RUN: python cov2658.py --out cov2658.json """ import argparse, json, math, sys, time import numpy as np from importlib.machinery import SourceFileLoader bg = SourceFileLoader("bg", "../job1936/job1936-blockgrain.py").load_module() vr = SourceFileLoader("vr", "../job2656/var2656.py").load_module() C2 = vr.C2; HS = [2310, 30030, 510510]; DECADES = [6, 7, 8, 9]; DRAWS, SEED = 400, 2658; PMAX_EULER = 10 ** 6 def singular_weighted(H, primes, wfun, hmax): """sum over even h in (0, hmax) of wfun(h) * S_4(h), absolute scale ((2 C_2)^2 restored), S_4 exact per h.""" logC4 = sum(math.log((1 - 4.0 / p) / (1 - 2.0 / p) ** 2) for p in primes if p > 3) - 4.0 / (PMAX_EULER * math.log(PMAX_EULER)) C4 = math.exp(logC4) hs = np.arange(2, hmax, 2) ratio = np.full(len(hs), 2.0 * C4) * np.where(hs % 3 == 0, 3.0, 0.0) for p in primes: if p <= 3: continue if p > hmax + 2: break c_h = (1 - 2.0 / p) / (1 - 4.0 / p); c_pm = (1 - 3.0 / p) / (1 - 4.0 / p) ratio[np.arange(((-2) % (2 * p)) // 2, len(hs), p)] *= c_h ratio[np.arange(0, len(hs), p)] *= c_pm ratio[np.arange(((-4) % (2 * p)) // 2, len(hs), p)] *= c_pm w = wfun(hs.astype(float)) return float((w * ratio).sum()) * (2 * C2) ** 2 def main(): ap = argparse.ArgumentParser(); ap.add_argument("--out", required=True); ap.add_argument("--draws", type=int, default=DRAWS) a = ap.parse_args(); log = sys.stderr; t0 = time.time(); ledger = [] def check(tag, ok, detail): ledger.append(f"{'PASS' if ok else 'FAIL'} {tag} :: {detail}") sp0 = bg.primes_to(int(math.isqrt(10 ** 6)) + 1); tw0 = bg.twins_in(sp0, 3, 10 ** 6 - 1) check("G0_pi2_1e6", len(tw0) == 8169, f"observed {len(tw0)} published 8169") lo, hi = 10 ** 6, 10 ** 10 sp = bg.primes_to(int(math.isqrt(hi + 2)) + 1) tpts = bg.twins_in(sp, lo, hi, log=log) check("G0b_pi2_1e10_minus_1e6", len(tpts) == 27412679 - 8169, f"observed {len(tpts)} published {27412679 - 8169}") print(f"twins {len(tpts)} {time.time() - t0:.1f}s", file=log, flush=True) primes = [int(p) for p in bg.primes_to(PMAX_EULER)] rng = np.random.default_rng(SEED) out = {"instrument": "cov2658.py", "job": 2658, "route": 35, "C2": C2, "preregistered": "see header", "covariance": {}, "variance_1e9": {}, "ledger": ledger} for H in HS: # covariance sum: w(h) = min(h, 2H - h) over even h in (0, 2H); variance sum as in var2656 scov = singular_weighted(H, primes, lambda h: np.minimum(h, 2 * H - h), 2 * H) svar = 2 * singular_weighted(H, primes, lambda h: H - h, H) print(f"H={H}: cov sum/(H^2(2C2)^2) = {scov / (H * H * (2 * C2) ** 2):.6f}; var sum = {svar / (H * H * (2 * C2) ** 2):.6f} {time.time() - t0:.1f}s", file=log, flush=True) res = {"H": H, "cov_sum_relative": scov / (H * H * (2 * C2) ** 2), "var_sum_relative": svar / (H * H * (2 * C2) ** 2), "decades": {}} for d in DECADES: D0, D1 = 10 ** d, 10 ** (d + 1) first = ((D0 + 2 * H - 1) // (2 * H)) * (2 * H) starts = np.arange(first, D1 - 2 * H + 1, 2 * H, dtype=np.int64) if len(starts) < 5: continue i0 = np.searchsorted(tpts, starts); i1 = np.searchsorted(tpts, starts + H); i2 = np.searchsorted(tpts, starts + 2 * H) N = (i1 - i0).astype(float); N2 = (i2 - i1).astype(float) m = vr.hl_means_vec(starts.astype(float), H); m2 = vr.hl_means_vec(starts.astype(float) + H, H) dev = (N - m) * (N2 - m2); Cst = float(dev.sum() / m.sum()) boots = [] for _ in range(a.draws): j = rng.integers(0, len(N), len(N)); boots.append(float(dev[j].sum() / m[j].sum())) boots = np.array(boots) Xmid = math.sqrt(D0 * D1); L2 = math.log(Xmid) ** 2 C_HL = (scov - H * H * (2 * C2) ** 2) / (L2 * L2) / (2 * C2 * H / L2) Xi = starts.astype(float) + H; C_int = float(((scov - H * H * (2 * C2) ** 2) / np.log(Xi) ** 4).sum() / m.sum()) cell = {"pairs": int(len(N)), "C_measured": Cst, "boot_q05": float(np.quantile(boots, 0.05)), "boot_q95": float(np.quantile(boots, 0.95)), "boot_sd": float(boots.std()), "C_HL_mid": C_HL, "C_HL_integrated_added": C_int, "in_band": bool(np.quantile(boots, 0.05) <= C_HL <= np.quantile(boots, 0.95)), "R_var_aligned_for_reference": float(((N - m) ** 2).sum() / m.sum())} res["decades"][str(d)] = cell print(f" H={H} decade 1e{d}: pairs={len(N)} C={Cst:+.4f} [{cell['boot_q05']:+.4f},{cell['boot_q95']:+.4f}] C_HL(mid)={C_HL:+.4f} C_HL(int)={C_int:+.4f} in_band={cell['in_band']}", file=log, flush=True) out["covariance"][str(H)] = res # variance cells in the 10^9 decade (pre-registered: H = 510510; added: the other two) for H in HS: svar = 2 * singular_weighted(H, primes, lambda h: H - h, H) D0, D1 = 10 ** 9, 10 ** 10; cell = {} for name, off in (("aligned", 0), ("offset", H // 2)): first = ((D0 - off + H - 1) // H) * H + off starts = np.arange(first, D1 - H + 1, H, dtype=np.int64) i0 = np.searchsorted(tpts, starts); i1 = np.searchsorted(tpts, starts + H) N = (i1 - i0).astype(float); m = vr.hl_means_vec(starts.astype(float), H) R = float(((N - m) ** 2).sum() / m.sum()); boots = [] for _ in range(a.draws): j = rng.integers(0, len(N), len(N)); boots.append(float(((N[j] - m[j]) ** 2).sum() / m[j].sum())) boots = np.array(boots) cell[name] = {"intervals": int(len(N)), "R": R, "boot_q05": float(np.quantile(boots, 0.05)), "boot_q95": float(np.quantile(boots, 0.95)), "boot_sd": float(boots.std())} Xmid = math.sqrt(D0 * D1); L2 = math.log(Xmid) ** 2; mean = H * 2 * C2 / L2 R_HL = 1 + (svar - H * H * (2 * C2) ** 2) / (L2 * L2) / mean first = ((D0 + H - 1) // H) * H; st = np.arange(first, D1 - H + 1, H, dtype=np.int64).astype(float) R_int = float(1 + ((svar - H * H * (2 * C2) ** 2) / np.log(st + H / 2) ** 4).sum() / vr.hl_means_vec(st, H).sum()) al = cell["aligned"]; of = cell["offset"] cell["R_HL_mid"] = R_HL; cell["R_HL_integrated_added"] = R_int; cell["in_band"] = bool(al["boot_q05"] <= R_HL <= al["boot_q95"]) cell["aligned_offset_agree"] = bool(abs(al["R"] - of["R"]) <= 2 * math.hypot(al["boot_sd"], of["boot_sd"])) out["variance_1e9"][str(H)] = cell print(f"variance decade 1e9 H={H}: n={al['intervals']} R={al['R']:.4f} [{al['boot_q05']:.4f},{al['boot_q95']:.4f}] offset {of['R']:.4f} R_HL(mid)={R_HL:.4f} (int {R_int:.4f}) in_band={cell['in_band']}", file=log, flush=True) verdict = {} for d in (6, 7, 8, 9): cells = [out["covariance"][str(H)]["decades"].get(str(d)) for H in (2310, 30030)] verdict[f"cov_decade_1e{d}"] = {"both_in_band": all(c is not None and c["in_band"] for c in cells)} verdict["variance_510510_1e9_in_band"] = out["variance_1e9"]["510510"]["in_band"] verdict["falsifier_met"] = all(verdict[f"cov_decade_1e{d}"]["both_in_band"] for d in (6, 7, 8, 9)) and verdict["variance_510510_1e9_in_band"] out["verdict"] = verdict json.dump(out, open(a.out, "w"), indent=1) print("\n".join(ledger)); print("VERDICT " + json.dumps(verdict, sort_keys=True)) return 0 if __name__ == "__main__": sys.exit(main())