"""Job #2565 (leads: new statistic with a falsifier). THE STATISTIC. For a level x (tile T_x, period M = x#) and a window length H, over the windows [a, a+H) aligned to multiples of H inside each complete period k of the exposure [M, (P+1)M) (the same windows, slot counts A_i, twin counts N_i and period rates lambda_k as rcond2550.py, return #1322): y_i = N_i / lambda_k (occupancy scaled to the period's rate, so periods pool), the conditional mean of y given the tile slot count, in two forms: (a) least squares y = b0 + b1 A + b2 (A - E[A])^2 (slope b1, curvature b2; under linearity b1 = 1, b2 = 0, b0 = 0), (b) ten quantile bins of A, the binned mean ybar_b against the bin mean Abar_b, and the deviation statistic T = sum_b n_b (ybar_b - Abar_b)^2 / v_b, with v_b the thinning null's variance of ybar_b (from the control draws). THE DECISION. The tile-conditioned dispersion R_cond of #1322 and the shortfall of route 109 (#1324) decompose the twin count as N = lambda A + (large-prime part) and read the residual dispersion as the conjecture's large-prime correlations. That reading assumes E[N | A] = lambda A (conditional-mean linearity); #1318 (@nielsegberts) showed that R_cond-type statistics can be moved by the joint law of (N, A) alone, so the assumption has to be measured, not presumed. Under the 4-tuple conjecture the large-prime sieving of a slot is independent of the tile's local slot density to leading order, so linearity is the conjecture's prediction here too; a measured curvature or slope offset would be a property of the joint law that the decomposition does not account for, and would weaken #1322's attribution. THE MATCHED CONTROL. Independent thinning of the tile at rate lambda_k: N_i | A_i ~ Bin(A_i, lambda_k), so E[y | A] = A exactly, b1 = 1, b2 = 0, and the control draws give the null distribution of (b1, b2, T) and the bin variances. PRE-REGISTERED FALSIFIERS (written before the run). F1 (linearity holds at the measured resolution): at every cell (x in 19, 23, 29; H in 2310, 30030) the measured b1 lies within the control's [q005, q995] and b2 within the control's [q005, q995]. F2 (no binned structure): T is below the control's 0.99 quantile at every cell. F3 (resolution): the control sd of b1 at x = 29, H = 30030 is below 0.01, so a 1 % tilt of the conditional mean would be visible (this is the scale statement; it is checked, not assumed). If F1 or F2 fails at x = 29 for both H with the same sign of b2 or of (b1 - 1), the decomposition assumption fails and the shortfall attribution of #1322/#1324 needs the alternative named in #1324's failure clause; if all pass, the decomposition holds to the stated resolution and the shortfall stays a property of the large-prime part. Gates: G1 tile slot count per period = D(T_x); G2 sum of A_i <= D and sum of N_i per period <= twins; G3 control mean of b1 within 3 sd (of the mean) of 1 and of b2 within 3 sd of 0. Stdout: ledger + JSON; stderr: progress. RUN: python cmean2565.py --levels 19,23,29 --out cmean2565.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() PERIODS = {19: 8, 23: 2, 29: 2}; D_T = {19: 378675, 23: 7952175, 29: 214708725} HS = [2310, 30030]; DRAWS, SEED, NBINS = 300, 2565, 10 def block_bool(lo, hi, qs): n = hi - lo; ok = np.ones(n, dtype=bool); ok[(-lo) % 2:: 2] = False for q in qs: for kill in (0, (q - 2) % q): ok[(kill - lo) % q:: q] = False return ok def fit(y, A, EA): X = np.stack([np.ones_like(A), A, (A - EA) ** 2], axis=1) b, *_ = np.linalg.lstsq(X, y, rcond=None); return b def binned(y, A, edges): idx = np.clip(np.searchsorted(edges, A, side="right") - 1, 0, len(edges) - 2) n = np.bincount(idx, minlength=len(edges) - 1).astype(float) ys = np.bincount(idx, weights=y, minlength=len(edges) - 1); As = np.bincount(idx, weights=A, minlength=len(edges) - 1) return n, ys / np.maximum(n, 1), As / np.maximum(n, 1) def main(): ap = argparse.ArgumentParser(); ap.add_argument("--out", required=True); ap.add_argument("--levels", default="19,23,29"); ap.add_argument("--draws", type=int, default=DRAWS) a = ap.parse_args(); log = sys.stderr; levels = [int(v) for v in a.levels.split(",")]; ledger = [] def check(tag, ok, detail): ledger.append(f"{'PASS' if ok else 'FAIL'} {tag} :: {detail}") out = {"instrument": "cmean2565.py", "job": 2565, "preregistered": "see header", "levels": {}, "ledger": ledger} rng = np.random.default_rng(SEED) for x in levels: t0 = time.time(); qs = [int(q) for q in bg.primes_to(x) if q > 2]; M = 2 for q in qs: M *= q P = PERIODS[x]; hi = (P + 1) * M sp = bg.primes_to(int(math.isqrt(hi)) + 1); tpts = bg.twins_in(sp, M, hi, log=log) per_k = {k: int(((tpts >= k * M) & (tpts < (k + 1) * M)).sum()) for k in range(1, P + 1)} print(f"x={x}: twins {sum(per_k.values())} {time.time() - t0:.1f}s", file=log, flush=True) lv = {"M": int(M), "periods": P, "twins_per_k": {str(k): per_k[k] for k in per_k}, "windows": {}} BL = 30030 * 64; nb = (M + BL - 1) // BL A = {H: [] for H in HS}; slots_total = 0 for b in range(nb): lo = b * BL; hi_b = min(M, lo + BL); ok = block_bool(lo, hi_b, qs); slots_total += int(ok.sum()) pre = np.concatenate([[0], np.cumsum(ok, dtype=np.int64)]) for H in HS: nw = (hi_b - lo) // H if nw: A[H].append(pre[H * np.arange(1, nw + 1)] - pre[H * np.arange(nw)]) check(f"G1_slots_x{x}", slots_total == D_T[x], f"streamed {slots_total} vs D(T_{x}) {D_T[x]}") for H in HS: A_H = np.concatenate(A[H]).astype(float); nwin = len(A_H); starts = (np.arange(nwin) * H).astype(np.int64) N = np.zeros((P, nwin)); lam = np.zeros(P) for k in range(1, P + 1): i0 = np.searchsorted(tpts, k * M + starts); i1 = np.searchsorted(tpts, k * M + starts + H); N[k - 1] = i1 - i0 lam[k - 1] = per_k[k] / D_T[x] check(f"G2_x{x}_H{H}", int(A_H.sum()) <= D_T[x] and all(int(N[k].sum()) <= per_k[k + 1] for k in range(P)), f"sum A {int(A_H.sum())} <= D; sum N per period <= twins") EA = float(A_H.mean()); Apool = np.tile(A_H, P) y = np.concatenate([N[k] / lam[k] for k in range(P)]) edges = np.quantile(A_H, np.linspace(0, 1, NBINS + 1)); edges[-1] += 1 b = fit(y, Apool, EA); nbin, ybar, Abar = binned(y, Apool, edges) # measured uncertainty: bootstrap over windows boots = [] for _ in range(a.draws): j = rng.integers(0, nwin, nwin); jj = np.concatenate([j + k * nwin for k in range(P)]) boots.append(fit(y[jj], Apool[jj], EA)) boots = np.array(boots) # matched control: independent thinning at lambda_k cb, cbin = [], [] for _ in range(a.draws): yt = np.concatenate([rng.binomial(A_H.astype(np.int64), lam[k]) / lam[k] for k in range(P)]) cb.append(fit(yt, Apool, EA)); cbin.append(binned(yt, Apool, edges)[1]) cb = np.array(cb); cbin = np.array(cbin); vbin = cbin.var(axis=0) Tc = np.array([float(((cbin[i] - Abar) ** 2 / np.maximum(vbin, 1e-300)).sum()) for i in range(len(cbin))]) T = float((((ybar - Abar) ** 2) / np.maximum(vbin, 1e-300)).sum()) q = lambda arr, p: float(np.quantile(arr, p)) check(f"G3_control_x{x}_H{H}", abs(cb[:, 1].mean() - 1) <= 3 * cb[:, 1].std() / math.sqrt(a.draws) and abs(cb[:, 2].mean()) <= 3 * cb[:, 2].std() / math.sqrt(a.draws), f"control b1 mean {cb[:, 1].mean():.5f}, b2 mean {cb[:, 2].mean():.2e}") cell = {"windows_per_period": int(nwin), "E_A": EA, "sd_A": float(A_H.std()), "lambda_k": lam.tolist(), "b0": float(b[0]), "b1": float(b[1]), "b2": float(b[2]), "boot_sd_b1": float(boots[:, 1].std()), "boot_sd_b2": float(boots[:, 2].std()), "control_b1_mean": float(cb[:, 1].mean()), "control_b1_sd": float(cb[:, 1].std()), "control_b1_q005": q(cb[:, 1], 0.005), "control_b1_q995": q(cb[:, 1], 0.995), "control_b2_mean": float(cb[:, 2].mean()), "control_b2_sd": float(cb[:, 2].std()), "control_b2_q005": q(cb[:, 2], 0.005), "control_b2_q995": q(cb[:, 2], 0.995), "z_b1_vs_1_control": (float(b[1]) - 1) / float(cb[:, 1].std()), "z_b2_vs_0_control": float(b[2]) / float(cb[:, 2].std()), "bins": {"n": nbin.tolist(), "A_mean": Abar.tolist(), "y_mean": ybar.tolist(), "null_sd_ymean": np.sqrt(vbin).tolist(), "z": ((ybar - Abar) / np.sqrt(np.maximum(vbin, 1e-300))).tolist()}, "T": T, "control_T_mean": float(Tc.mean()), "control_T_q99": q(Tc, 0.99), "control_T_q95": q(Tc, 0.95), "F1_b1_in_control_band": bool(q(cb[:, 1], 0.005) <= b[1] <= q(cb[:, 1], 0.995)), "F1_b2_in_control_band": bool(q(cb[:, 2], 0.005) <= b[2] <= q(cb[:, 2], 0.995)), "F2_T_below_q99": bool(T < q(Tc, 0.99))} lv["windows"][str(H)] = cell print(f"x={x} H={H}: n={nwin} E[A]={EA:.2f} sdA={A_H.std():.2f} b1={b[1]:.5f} (ctrl sd {cb[:, 1].std():.5f}, z {(b[1] - 1) / cb[:, 1].std():+.2f}) b2={b[2]:.3e} (ctrl sd {cb[:, 2].std():.2e}, z {b[2] / cb[:, 2].std():+.2f}) T={T:.1f} (ctrl q99 {q(Tc, 0.99):.1f}) {time.time() - t0:.1f}s", file=log, flush=True) out["levels"][str(x)] = lv; json.dump(out, open(a.out, "w"), indent=1) cells = [(x, H, out["levels"][str(x)]["windows"][str(H)]) for x in levels for H in HS] v = {"F1_all_cells": all(c["F1_b1_in_control_band"] and c["F1_b2_in_control_band"] for _, _, c in cells), "F2_all_cells": all(c["F2_T_below_q99"] for _, _, c in cells), "F3_resolution_x29_H30030": (out["levels"]["29"]["windows"]["30030"]["control_b1_sd"] < 0.01) if "29" in out["levels"] else None, "failing_cells": [f"x{x}_H{H}" for x, H, c in cells if not (c["F1_b1_in_control_band"] and c["F1_b2_in_control_band"] and c["F2_T_below_q99"])]} out["verdict"] = v; json.dump(out, open(a.out, "w"), indent=1) print("\n".join(ledger)); print("VERDICT " + json.dumps(v, sort_keys=True)); return 0 if __name__ == "__main__": sys.exit(main())