# -*- coding: utf-8 -*- """Read B(2^j)/2^j, instead of bounding it. Source of every definition: `research/fixed-endpoint-discrepancy-validation.js` (the corpus's own validator) and `research/fixed-endpoint-discrepancy.md` (2.8)/(2.9). Nothing here is new mathematics: this is the corpus's finite bookkeeping, run at scales its contract did not allow. x in [2^j], N = x+2 f(n) = Lambda(n-2) * mu(n) for n in (x/2, x] e0 = floor(x^(1/2 - EPSP)), e1 = floor(x^(1/2 + EPS)) EPS = EPSP = 1/60 P(lo,hi) = -sum_{e odd sqfree in [lo,hi)} sum_{m in (x/(2e), x/e], (m,e)=1, mu(m)!=0} mu(m) log(m) Lambda(em-2) [P_low, P_band] T_I^low = +sum_{eV} mu(k); TII(m)=sum_{a|m, a>U} mu(a)gam(m/a) **B(x) = T_II^low + P_band** [(2.8)] Thresholds this window compares against, both from the corpus: H_B : B(2^j)/2^j >= -(C_2 - c_0) (c_0 > 0 arbitrary) direct twin consumer : B(2^j)/2^j >= -(C_2 - 1/200) and, for the sibling consumer, handoff consumer : D^(e1)(2^j)/2^j >= -4/25 = -0.16 with D^(e1) = P(1,e1) - Q(1,e1) Output is per-j as it is computed, so the reach is visible even if the run is stopped. """ import sys import time import numpy as np from math import isqrt sys.stdout.reconfigure(encoding='utf-8') EPS = EPSP = 1.0 / 60.0 C2 = 0.6601618158468695739278121100145557784326233602847334133194484233354056423 THRESH_HB_FIXED = C2 # c_0 -> 0 THRESH_TWIN = C2 - 0.005 # -(C_2 - 1/200) THRESH_HANDOFF = 0.16 # 4/25 U, V = 3, 3 def sieve(N): """exact Lambda (von Mangoldt, prime powers) and mu (Moebius), same semantics as the corpus.""" mu = np.ones(N + 1, dtype=np.int8) mu[0] = 0 lam = np.zeros(N + 1, dtype=np.float64) is_p = np.ones(N + 1, dtype=bool) is_p[:2] = False for p in range(2, N + 1): if not is_p[p]: continue is_p[p * p::p] = False for q in range(p, N + 1, p): mu[q] = -mu[q] pp = p * p if pp <= N: mu[pp::pp] = 0 # squarefree sign is the toggle above; kill the rest # Lambda(q) = log p at prime powers q = p^k, and 0 elsewhere (the corpus's own semantics) for p in range(2, N + 1): if not is_p[p]: continue q = p while q <= N: lam[q] = np.log(p) q *= p return lam, mu, is_p def gamma_V(mu, V, N): g = np.zeros(N + 1, dtype=np.float64) for k in range(V + 1, N + 1): if mu[k]: g[k::k] += mu[k] return g def conv_TII(mu, gam, U, N): T = np.zeros(N + 1, dtype=np.float64) for a in range(U + 1, N + 1): if mu[a]: T[a::a] += mu[a] * gam[1:N // a + 1] return T def conv_TI(mu, U, V, N): c = {} for d in range(1, U + 1): for k in range(1, V + 1): c[d * k] = c.get(d * k, 0) + mu[d] * mu[k] T = np.zeros(N + 1, dtype=np.float64) for r, v in c.items(): if v: T[r::r] += v return T def reads(j): x = 2 ** j N = x + 2 lam, mu, is_p = sieve(N) e1 = int(x ** (0.5 + EPS)) e0 = int(x ** (0.5 - EPSP)) gam = gamma_V(mu, V, N) TII = conv_TII(mu, gam, U, N) TI = conv_TI(mu, U, V, N) lamp = lam[:x + 1] # Lambda(k), k <= x logm = np.zeros(x + 1, dtype=np.float64) logm[1:] = np.log(np.arange(1, x + 1)) def e_list(lo, hi): out = [] for e in range(1, max(hi, 2)): if e < lo or e >= hi or not (e & 1) or mu[e] == 0: continue out.append(e) return out def inner(e, need_mu_m): """m in (x/(2e), x/e], (m,e)=1, [mu(m)!=0 if needed]; returns (m_index, Lambda(em-2)).""" lo = x // (2 * e) + 1 hi = x // e if hi < lo: return None m = np.arange(lo, hi + 1) if need_mu_m: m = m[mu[m] != 0] if m.size == 0: return None if e > 1: m = m[np.gcd(m, e) == 1] if m.size == 0: return None return m def P(lo, hi): s = 0.0 for e in e_list(lo, hi): m = inner(e, True) if m is None: continue base = e * (m - 1) + (e - 2) # e*m - 2 L = lamp[base] nz = L != 0 if not nz.any(): continue s -= float(np.sum(mu[m][nz].astype(np.float64) * logm[m][nz] * L[nz])) return s def TI_low(): # + sum ... log(m) Lambda(em-2) TI(m) s = 0.0 for e in e_list(1, e0): m = inner(e, False) if m is None: continue base = e * (m - 1) + (e - 2) L = lamp[base] nz = L != 0 if not nz.any(): continue s += float(np.sum(logm[m][nz] * L[nz] * TI[m][nz])) return s def TII_low(): # - sum ... log(m) Lambda(em-2) TII(m) s = 0.0 for e in e_list(1, e0): m = inner(e, False) if m is None: continue base = e * (m - 1) + (e - 2) L = lamp[base] nz = L != 0 if not nz.any(): continue s -= float(np.sum(logm[m][nz] * L[nz] * TII[m][nz])) return s def Q(lo, hi): n = np.arange(x // 2 + 1, x + 1) F = lamp[n - 2] * mu[n] M = float(np.sum(F)) Fl = float(np.sum(F * logm[n])) s = 0.0 for e in e_list(lo, hi): s += mu[e] / float(phi(e, mu, is_p)) * (M * np.log(e) - Fl) return s # ---- GATE 1 (Vaughan identity, the corpus's own assertion): the split is legitimate for the # chosen (U,V) only if mu(m) = TII(m) - TI(m) + [m<=U]mu(m) + [m<=V]mu(m) for all m <= 4096. c = {} for d in range(1, U + 1): for k in range(1, V + 1): c[d * k] = c.get(d * k, 0) + int(mu[d]) * int(mu[k]) gamd = np.zeros(N + 1, dtype=np.int64) for k in range(V + 1, N + 1): if mu[k]: gamd[k::k] += int(mu[k]) # Gate 1 must cover EVERY m the sums actually use, i.e. m <= x/e <= x. A divisor-sieve # reconstruction up to GCAP, plus a sparse spot-check at the top of the used range. GCAP = min(N, 50000) tii_all = np.zeros(GCAP + 1, dtype=np.int64) for a in range(U + 1, GCAP + 1): if mu[a]: tii_all[a::a] += int(mu[a]) * gamd[1:GCAP // a + 1] ti_all = np.zeros(GCAP + 1, dtype=np.int64) for r, v in c.items(): if v: ti_all[r::r] += v vbad = 0 for m in range(1, GCAP + 1): rhs = int(tii_all[m]) - int(ti_all[m]) + (int(mu[m]) if m <= U else 0) + (int(mu[m]) if m <= V else 0) if rhs != int(mu[m]): vbad += 1 if vbad: raise SystemExit(f'GATE 1 FAILED: Vaughan identity fails at {vbad} m <= {GCAP} for (U,V)=({U},{V})') # algebraic spot-check at the top of the used m-range (each is O(tau(m))) for m in (GCAP + 7, x // 2 + 1, x // 2 + 3, x - 1): if 1 <= m <= N: a_ = [a for a in range(U + 1, m + 1) if m % a == 0] tii = sum(int(mu[a]) * int(gamd[m // a]) for a in a_) tii2 = sum(v for r, v in c.items() if r <= U * V and m % r == 0) rhs = tii - tii2 + (int(mu[m]) if m <= U else 0) + (int(mu[m]) if m <= V else 0) if rhs != int(mu[m]): raise SystemExit(f'GATE 1 spot-check FAILED at m={m} for (U,V)=({U},{V})') t1 = time.time() tI = TI_low() tII = TII_low() Pband = P(e0, e1) Plow = tI + tII Dall = P(1, e1) - Q(1, e1) B = tII + Pband # ---- GATE 2 (the split-independent identity): T_I^low + B = P(1,e_1), exactly, for every (U,V). P1e1 = P(1, e1) if abs(tI + B - P1e1) > 1e-6 * max(1.0, abs(P1e1)): raise SystemExit(f'GATE 2 FAILED: T_I^low + B = {tI + B} but P(1,e_1) = {P1e1}') # the corpus's own odd Mobius mean, verbatim from its validator: M = sum_{(x/2,x]} Lambda(n-2)mu(n) n = np.arange(x // 2 + 1, x + 1) M = float(np.sum(lamp[n - 2] * mu[n])) dt = time.time() - t1 return dict(x=x, e0=e0, e1=e1, tI=tI, tII=tII, Pband=Pband, Plow=Plow, B=B, Dall=Dall, M=M, P1e1=P1e1, secs=dt, # two independent re-derivations of the same P_low, for the gates Plow_direct=P(1, e0), n_e=len(e_list(1, e1))) def phi(n, mu, is_p): r, m = n, n for p in range(2, n + 1): if p * p > m: break if m % p == 0: r = r // p * (p - 1) while m % p == 0: m //= p if m > 1: r = r // m * (m - 1) return r def main(): global U, V, EPSP argv = sys.argv[1:] if '--uv' in argv: i = argv.index('--uv') U, V = (int(t) for t in argv[i + 1].split(',')) del argv[i:i + 2] if '--epsp' in argv: i = argv.index('--epsp') EPSP = float(argv[i + 1]) del argv[i:i + 2] js = [int(a) for a in argv] or [10, 12, 14, 16, 18, 20, 22, 24] print(f"EPSP = {EPSP:.6f} ; Vaughan (U,V) = ({U},{V}) ; C_2 = {C2:.10f}") print(f"thresholds: H_B (c_0->0) B/x >= -{THRESH_HB_FIXED:.6f} ; direct twin B/x >= " f"-{THRESH_TWIN:.6f} ; handoff D/x >= -{THRESH_HANDOFF:.2f}") print() hdr = (f"{'j':>3s}(UV) {'x':>9s} {'T_I/x':>8s} {'T_II/x':>8s} {'P_band/x':>8s} {'B/x':>8s} " f"{'P(1,e1)/x':>8s} {'(B+2C2M)/x':>10s} {'D/x':>8s} {'cancel':>9s} " f"{'|B|/x thr':>9s} {'s':>5s}") print(hdr) print('-' * len(hdr)) for j in js: r = reads(j) x = r['x'] gate = abs(r['Plow'] - r['Plow_direct']) warn = '' if gate <= 1e-6 * max(1.0, abs(r['Plow'])) else f' GATE-FAIL {gate:.3e}' l5 = np.log(x) ** 5 cancel = abs(r['tI'] + r['tII']) / abs(r['tII']) if r['tII'] else float('nan') handoff = (r['B'] + 2 * C2 * r['M']) / x print(f"{j:>3d}({U},{V}) {x:>9d} {r['tI']/x:>8.4f} {r['tII']/x:>8.4f} {r['Pband']/x:>8.4f} " f"{r['B']/x:>8.4f} {r['P1e1']/x:>8.4f} {handoff:>10.4f} {r['Dall']/x:>8.4f} " f"{cancel:>9.2e} {abs(r['B'])/x/THRESH_TWIN:>9.2f} {r['secs']:>5.1f}{warn}") print(f' ^ T_I/x T_II/x P_band/x B/x P(1,e1)/x (B+2C2M)/x D/x cancel gap') sys.stdout.flush() print() print('thresholds, restated: direct twin B/x >= -0.655162 ; handoff (B+2C2M)/x >= -0.16 ; D/x >= -0.16') if __name__ == '__main__': main()