# tilevar2548.py -- job #2548 (cross-lane synthesis): does the twin tile's window-count variance equal the singular-series # sum truncated to the tile's primes, and how much of the measured twin-count under-dispersion does the tile explain? # For a level x (tile T_x: r = 5 mod 6 with r, r+2 coprime to 5..x, period M = x#) and a window length H: # A(a) = number of tile slots in [a, a+H), a = 0..M-1 (all starts, uniform); E[A] = H D/M, Var[A] over the period. # Claim (exact, periodic autocorrelation): Var[A] = sum_{0<|h|= 5]; M = 6 for p in ps: M *= p r = np.arange(M); ok = (r % 6 == 5) for p in ps: ok &= (r % p != 0) & ((r + 2) % p != 0) return M, ok def window_var(ok, M, H): pre = np.concatenate([[0], np.cumsum(np.concatenate([ok, ok[:H]]))]) # cyclic A = pre[H:H + M] - pre[:M] return float(A.mean()), float(A.var()), np.bincount(A) def trunc_ratio(h, x): # S_4^{(<=x)}(h) / (2C_2^{(<=x)})^2 for even h (0 and +-2 give the degenerate tuples; treat generally by residue counting) r = 1.0 for p in primes_to(x): nu = len({0 % p, 2 % p, h % p, (h + 2) % p}); nu2 = 1 if p == 2 else 2 r *= ((1 - nu / p) / (1 - 1 / p) ** 4) / (((1 - nu2 / p) / (1 - 1 / p) ** 2) ** 2) return r out = {} for x, Hs, lam, meas in ((13, [2310, 6930], 0.147740, {2310: 0.749}), (19, [2310, 30030], 0.109925, {2310: 0.826, 30030: 0.768})): M, ok = tile(x); D = int(ok.sum()); d = D / M lv = dict(M=M, D=D, density=d, windows={}) for H in Hs: EA, VA, hist = window_var(ok, M, H) # right-hand side from truncated singular series (odd h contribute nothing: both r and r+h odd impossible for odd h) rhs = H * d * (1 - d) for h in range(1, H): c = d * d * trunc_ratio(h, x) if h % 2 == 0 else 0.0 # odd h: r and r + h cannot both be = 5 (mod 6) rhs += 2 * (H - h) * (c - d * d) R_tile = 1 - lam + lam * VA / EA lv['windows'][str(H)] = dict(E_A=EA, Var_A=VA, Var_over_E=VA / EA, rhs_truncated_singular_series=rhs, identity_rel_err=(abs(VA - rhs) / VA if VA else None), min_A=int(np.flatnonzero(hist)[0]), max_A=int(np.flatnonzero(hist)[-1]), R_tile_model=R_tile, R_measured_1302=meas.get(H)) print(f"x={x} H={H}: E[A]={EA:.4f} Var[A]={VA:.4f} Var/E={VA/EA:.4f} | truncated-series rhs={rhs:.4f} rel.err={(abs(VA-rhs)/VA if VA else float("nan")):.2e} | R_tile=1-lam+lam*Var/E={R_tile:.4f} vs measured R={meas.get(H)} (lam={lam})", flush=True) out[str(x)] = lv json.dump(out, open('tilevar2548.json', 'w'), indent=1)