# classz1995.py -- job #1995: a new finite statistic with a pre-registered falsifier. # # QUESTION. Return #1061 / #1062 (route 85) showed that the anchored count S(x) of paper/anchored-note.md, the number of twin # pairs (r, r+2) with y < r < W and r = 11 or 17 mod 30, follows the Hardy-Littlewood integral (4/3) C2 int_y^W dt/ln^2 t to # the square-root scale at all ten computed levels. Referee report #67 (item 1.2) pointed out that the combined two-class # statement "does not separately establish the asymptotic in each of the two classes". The censuses cannot decide this: they # count slots, not primes. STATISTIC: the per-class Poisson-normalised deviation # z_a(x) = (S_a(x) - S_HL/3) / sqrt(S_HL/3), S_HL/3 = (2/3) C2 int_y^W dt/ln^2 t, a in {11, 17, 29}, # where S_a(x) = #{r = a mod 30 : y < r < W, r and r+2 prime} (the third class, 29, is the "House 29" the note's comb omits), # and the class-difference statistic d_ab(x) = (S_a - S_b)/sqrt(S_a + S_b), at x = 7, 11, 13, 17, 19, 23, 29 (W up to 6.47e9, # segmented sieve). Hardy-Littlewood in the progressions mod 30 gives every class the same singular series (the local factors # at 2, 3, 5 are identical), so each class carries one third of 2 C2 int dt/ln^2 t. # PRE-REGISTERED FALSIFIERS (posted as the claim of job #1995 before this run; written here before the first execution): # F1 (HL per class at Poisson scale): max over the 21 values (7 levels x 3 classes) of |z_a(x)| <= 3.5. # Falsified by one value beyond 3.5 in absolute value. # F2 (class equidistribution): every class difference d_ab(x) (three pairs per level) lies within [-3.5, 3.5]. # CONTROL: multinomial relabelling of the actual twin pairs at each level with equal class probabilities (seed 20260918, # 1000 draws): the distribution of max_a |z_a| and of max |d_ab| under the null of equidistribution; the real values # are reported with their percentile in the control. # SCALE at which an effect would be visible: at x = 29 each class holds about 4.1e6 pairs (sigma about 2000), so a relative # class bias of 1.5e-3 would appear at 3 sigma; at x = 23, 2e5 pairs per class, sigma 450, relative bias 7e-3. # Timing goes to stderr only. import sys, math, time, json import numpy as np from scipy.special import expi t0 = time.time() def li(t): return float(expi(math.log(t))) def I2(a, b): return (li(b) - b / math.log(b)) - (li(a) - a / math.log(a)) C2 = 0.6601618158468696 LEVELS = [7, 11, 13, 17, 19, 23, 29] PRIMES = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] Wmax = math.prod(PRIMES) # 29# = 6469693230 root = math.isqrt(Wmax) + 1 small = np.ones(root + 1, dtype=bool); small[:2] = False for i in range(2, int(root ** .5) + 1): if small[i]: small[i * i::i] = False SP = np.flatnonzero(small) print(f'small primes to {root}: {len(SP)}', file=sys.stderr) # segmented sieve over [0, Wmax + 3); per segment accumulate twin pairs by class of r (r = 11, 17, 29 mod 30) into a # cumulative array indexed by r, but we only need counts at the level boundaries W and at y(x): record running totals when # crossing each boundary. Boundaries: for each level, y (exclusive: pairs with r <= y are subtracted) and W (pairs with r < W). Ws = {x: math.prod(p for p in PRIMES if p <= x) for x in LEVELS} def yof(W): ys = SP[SP <= math.isqrt(W)] return int(ys[-1]) if len(ys) and ys[-1] > 1 else None ys = {x: yof(Ws[x]) for x in LEVELS} # y(7)=13 needs primes to sqrt(210)=14: SP covers it. marks = sorted(set([ys[x] + 1 for x in LEVELS] + [Ws[x] for x in LEVELS])) # count pairs with r < mark counts = {m: np.zeros(3, dtype=np.int64) for m in marks} running = np.zeros(3, dtype=np.int64) SEG = 60_000_000 lo = 0; mi = 0 while lo < Wmax + 3: hi = min(lo + SEG, Wmax + 3) seg = np.ones(hi - lo, dtype=bool) if lo == 0: seg[:2] = False for p in SP: p = int(p) if p * p >= hi: break start = max(p * p, ((lo + p - 1) // p) * p) seg[start - lo::p] = False # twin pairs with r in [lo, hi-2): need seg[r] and seg[r+2]; the pairs with r = hi-2, hi-1 are handled by carrying two cells if hi < Wmax + 3: # extend by two cells from the next segment: sieve them cheaply by trial division with SP ext = [] for n in (hi, hi + 1): isp = True for p in SP: p = int(p) if p * p > n: break if n % p == 0: isp = False; break ext.append(isp) segx = np.concatenate((seg, np.array(ext, dtype=bool))) else: segx = np.concatenate((seg, np.array([False, False], dtype=bool))) # past W_max + 2: never a lower member r < W r = np.arange(lo, hi, dtype=np.int64) tw = segx[:hi - lo] & segx[2:hi - lo + 2] cls = r % 30 # advance marks inside this segment in order while mi < len(marks) and marks[mi] < hi: m = marks[mi] sel = tw & (r < m) for j, a in enumerate((11, 17, 29)): counts[m][j] = running[j] + int(np.count_nonzero(sel & (cls == a))) mi += 1 for j, a in enumerate((11, 17, 29)): running[j] += int(np.count_nonzero(tw & (cls == a))) print(f'segment [{lo}, {hi}) done, {time.time() - t0:.0f} s', file=sys.stderr) lo = hi while mi < len(marks): counts[marks[mi]] = running.copy(); mi += 1 rng = np.random.default_rng(20260918) out = {'levels': {}} print(' x W y S_11 S_17 S_29 S_HL/3 z_11 z_17 z_29 d_11,17 d_11,29 d_17,29 comb share (11+17)/all ctrl pct of max|z| / max|d|') allz = []; alld = [] for x in LEVELS: W, y = Ws[x], ys[x] S = counts[W] - counts[y + 1] # pairs with y < r < W shl3 = (2 / 3) * C2 * I2(y, W) z = (S - shl3) / math.sqrt(shl3) tot = int(S.sum()); d = [(S[i] - S[j]) / math.sqrt(S[i] + S[j]) for i, j in ((0, 1), (0, 2), (1, 2))] # control: multinomial relabelling of the tot actual pairs draws = rng.multinomial(tot, [1 / 3, 1 / 3, 1 / 3], size=1000) zc = (draws - tot / 3) / math.sqrt(tot / 3); maxzc = np.abs(zc).max(axis=1) dc = np.abs(np.stack([(draws[:, i] - draws[:, j]) / np.sqrt(draws[:, i] + draws[:, j]) for i, j in ((0, 1), (0, 2), (1, 2))], axis=1)).max(axis=1) pz = float((maxzc <= np.abs(z).max()).mean()); pd = float((dc <= max(abs(v) for v in d)).mean()) allz += list(z); alld += d lev = {'x': x, 'W': W, 'y': y, 'S': [int(v) for v in S], 'S_HL_third': shl3, 'z': [float(v) for v in z], 'd': [float(v) for v in d], 'comb_share': (int(S[0] + S[1]) / tot if tot else None), 'ctrl_pct_maxz': pz, 'ctrl_pct_maxd': pd} out['levels'][str(x)] = lev print(f'{x:2d} {W:12d} {y:9d} {S[0]:8d} {S[1]:8d} {S[2]:8d} {shl3:12.2f} {z[0]:+7.3f} {z[1]:+7.3f} {z[2]:+7.3f} {d[0]:+8.3f} {d[1]:+8.3f} {d[2]:+8.3f} {lev["comb_share"] if lev["comb_share"] is None else round(lev["comb_share"], 5)} {pz:.3f} / {pd:.3f}') F1 = max(abs(v) for v in allz) <= 3.5; F2 = max(abs(v) for v in alld) <= 3.5 out['F1_max_abs_z'] = max(abs(v) for v in allz); out['F1_pass'] = bool(F1); out['F2_max_abs_d'] = max(abs(v) for v in alld); out['F2_pass'] = bool(F2) print(f'F1 max |z_a| over 21 values = {out["F1_max_abs_z"]:.3f} -> {"pass" if F1 else "FIRED"}; F2 max |d_ab| over 21 values = {out["F2_max_abs_d"]:.3f} -> {"pass" if F2 else "FIRED"}') print('cross-check: S_11 + S_17 at x = 23 must equal the note S(23) = 597475:', int(out['levels']['23']['S'][0] + out['levels']['23']['S'][1]), '; at x = 29: 12307838 vs', int(out['levels']['29']['S'][0] + out['levels']['29']['S'][1])) json.dump(out, open('classz1995.json', 'w'), indent=1)