#!/usr/bin/env python3 # JOB #630, probe 4 -- what the translate-ensemble z-score is actually measuring. # # The zone window (p, p'^2) is one translate of the cyclic tile word T_p, and the # translate-ensemble mean of the SLOT count is mu = n*A/W (validated against full # enumeration in zonetranslate.mjs PART A). But in the zone a slot IS a twin pair # (Lemma A), and the twin-pair count at height p^2 is what Hardy-Littlewood # predicts, 2*C2/ln^2 t, whose integral over (p, p'^2) is NOT mu. This script # measures the gap: exact twin count C vs the HL integral vs mu, for every prime # p <= PLIM. If C tracks the HL integral, then the residual "ensemble deficit" # is the ln^2 p -> ln^2(p^2) density mismatch and not an anomaly of the offset. import math PLIM = 1000 C2 = 0.6601618158468696 # twin prime constant GAMMA = 0.5772156649015329 def sieve(n): s = bytearray([1]) * (n + 1) s[0] = s[1] = 0 i = 2 while i * i <= n: if s[i]: s[i * i::i] = bytearray(len(s[i * i::i])) i += 1 return s N = 1009 * 1009 + 2 S = sieve(N) pr = [p for p in range(3, PLIM + 1) if S[p]] def nextp(p): q = p + 1 while not S[q]: q += 1 return q def hl_integral(lo, hi, steps=5000): """Simpson on 2*C2/ln^2 t over [lo, hi].""" if hi <= lo: return 0.0 h = (hi - lo) / steps tot = 0.0 f = lambda t: 2 * C2 / math.log(t) ** 2 for i in range(steps + 1): t = lo + i * h w = 1 if i in (0, steps) else (4 if i % 2 else 2) tot += w * f(max(t, 2.0)) return tot * h / 3 rows = [] for p in pr: pp = nextp(p) top = pp * pp C = sum(1 for a in range(p + 1, top - 1) if S[a] and S[a + 2]) # tile-sieve density in log space: prod_{q<=p} a_q/q, a_2 = 1, a_q = q-2 logd = 0.0 for q in range(3, p + 1): if S[q]: logd += math.log((q - 2) / q) logd -= math.log(2.0) mu = (top - p - 3) * math.exp(logd) hl = hl_integral(p, top - 2) rows.append((p, top, C, mu, hl)) print(f"JOB #630 probe 4 -- exact zone twin count vs Hardy-Littlewood vs the tile-sieve mean, p <= {PLIM}") print(" p p'^2 C mu HL-int C/HL C/mu HL/mu") for r in rows: if r[0] < 20 or r[0] % 97 == 0 or r[0] == rows[-1][0]: p, top, C, mu, hl = r print(f" {p:4d} {top:9d} {C:8d} {mu:9.1f} {hl:10.1f} {C/hl:7.4f} {C/mu:7.4f} {hl/mu:7.4f}") mean = lambda a: sum(a) / len(a) big = [r for r in rows if r[0] >= 100] print() print("SUMMARY") print(f" levels {len(rows)}; C/HL : mean {mean([r[2]/r[4] for r in rows]):.4f} " f"(p>=100) mean {mean([r[2]/r[4] for r in big]):.4f} range [{min(r[2]/r[4] for r in rows):.4f}, {max(r[2]/r[4] for r in rows):.4f}]") print(f" C/mu : mean {mean([r[2]/r[3] for r in rows]):.4f} " f"(p>=100) mean {mean([r[2]/r[3] for r in big]):.4f} range [{min(r[2]/r[3] for r in rows):.4f}, {max(r[2]/r[3] for r in rows):.4f}]") print(f" HL/mu : mean {mean([r[4]/r[3] for r in rows]):.4f} " f"(p>=100) mean {mean([r[4]/r[3] for r in big]):.4f}") print(f" reference: e^(2*gamma)/4 = {math.exp(2*GAMMA)/4:.5f}; 2C2 = {2*C2:.5f}")