#!/usr/bin/env python3 """ k-certificate.py -- certify K(w0) = sup_{z >= w >= w0} prod_{w <= p <= z} (1 - 2/p)^{-1} / (ln z / ln w)^2 Purpose (job #371): return #26 (break, DHR sieve input) sketched a rescue of the fallback exponent "19 + eps" of paper/beta2-note.md section 6 item 5: fix the residue class mod W = prod_{p < w0} p and sieve only by p >= w0, so that the constant K in the hypothesis prod_{w1 <= p < z1} (1 - h(p))^{-1} <= K (ln z1 / ln w1)^2 for all z1 >= w1 >= 2 is K(w0) above, and s0 = max(19, 18 + 10 ln K) = 19 iff K <= e^{0.1}. Return #26 MEASURED K(23) = 1.103985 on blocks of consecutive primes up to 10^6 (blocks starting at p >= 10^4 cut at 2000 primes) and wrote that making it hold for every z1 "needs an explicit Mertens bound (for example Rosser-Schoenfeld 1962). That is not done here." This script does it. Reduction (elementary, stated in the report): the product only changes when z1 passes a prime and (ln z1/ln w1)^2 is increasing in z1 and decreasing in w1, so the supremum over real z1 >= w1 >= w0 equals the supremum over PRIMES w <= z, w >= w0, of R(w, z) = prod_{w <= p <= z}(1-2/p)^{-1} / (ln z/ln w)^2. (For w1 < w0 the product starts at w0 while the denominator grows: smaller.) Three parts: A. FINITE: all primes w0 <= w < WCUT and all primes w <= z < T, exactly enumerated in 40-digit correctly-rounded decimal arithmetic. B. TAIL IN z: primes w0 <= w < WCUT, real z >= T. Uses only the Rosser-Schoenfeld UPPER bound sum_{p <= x} 1/p < ln ln x + B + 1/(2 ln^2 x) (valid for x >= RS_X_SUM), the exactly computed sum_{p < T} 1/p, and the elementary tail sum_{p >= T} sum_{k>=2} (2/p)^k / k <= 2/(T-2). C. LARGE w: primes w >= WCUT, all z >= w. Uses the R-S upper bound at x = z >= w >= RS_X_SUM and the R-S LOWER bound sum_{p <= x} 1/p > ln ln x + B - 1/(2 ln^2 x) (valid for x > 1) at x = w - 1, plus the elementary tail 2/(w-2). The certified K(w0) is the max of the three parts. Every imported inequality is a parameter below; the report quotes them from the source. """ import sys, math from decimal import Decimal, getcontext getcontext().prec = 40 D = Decimal # ---- imported inequalities: Rosser & Schoenfeld, Illinois J. Math. 6 (1962) 64-94, Theorem 5, p. 70 ---- # (3.17) log log x + B - 1/(2 log^2 x) < sum_{p<=x} 1/p for 1 < x # (3.18) sum_{p<=x} 1/p < log log x + B + 1/(2 log^2 x) for 286 <= x # B = 0.26149 72128 47643 (their (2.7)); read at the page image 2026-09-11. B_MERTENS = D("0.26149721284764278375542683860869585905156664826120") # Mertens' constant B RS_X_SUM = 286 # upper bound (3.18)-type valid for x >= 286 ; lower bound valid for x > 1 # -------------------------------------------------------------------------------- T = int(sys.argv[1]) if len(sys.argv) > 1 else 10**6 WCUT = int(sys.argv[2]) if len(sys.argv) > 2 else 286 # w >= WCUT handled analytically (part C); primes w0 <= w < WCUT scanned (part A, B) W0S = [19, 23, 29, 31, 37, 41, 43, 47, 53, 101, 1009] TARGET = D(1).exp() ** D("0.1") # e^{0.1} def sieve(n): s = bytearray([1]) * (n + 1); s[0] = s[1] = 0 for i in range(2, int(n ** 0.5) + 1): if s[i]: s[i*i::i] = bytearray(len(s[i*i::i])) return [i for i in range(n + 1) if s[i]] primes = sieve(T - 1) # all primes < T P = len(primes) # prefix sums (index k holds the sum over primes[0..k-1]): # S2[k] = sum -ln(1 - 2/p) (p >= 3 only; p = 2 would be infinite, never used since w0 >= 19) # S1[k] = sum 1/p S2 = [D(0)] * (P + 1); S1 = [D(0)] * (P + 1); LL = [None] * P for i, p in enumerate(primes): dp = D(p) S1[i + 1] = S1[i] + 1 / dp S2[i + 1] = S2[i] + (-(1 - 2 / dp).ln() if p > 2 else D(0)) LL[i] = dp.ln().ln() sum_recip_below_T = S1[P] lnT = D(T).ln() def idx(p): # index of prime p import bisect i = bisect.bisect_left(primes, p); assert primes[i] == p; return i print(f"k-certificate: T={T}, WCUT={WCUT}, primes= {RS_X_SUM}; R-S lower bound for x > 1; B = {B_MERTENS:.20f}") print() print("PART A: finite scan, ln R(w,z) = S2(z)-S2(w-)-2(lnln z - lnln w), primes w0<=w (lnR_max, z) for w in wprimes: j = idx(w); base = S2[j]; llw = LL[j] m = None; mz = None for k in range(j, P): v = S2[k + 1] - base - 2 * (LL[k] - llw) if m is None or v > m: m = v; mz = primes[k] best[w] = (m, mz) print(" w | sup_z R(w,z) | at z") for w in wprimes[:12]: m, mz = best[w]; print(f" {w} | {m.exp():.12f} | {mz}") print(" ...") print() print("PART B: z >= T, primes w0<=w= T") def partB(w): j = idx(w) E = (S2[P] - S2[j]) - 2 * (S1[P] - S1[j]) return -2 * S1[j] + 2 * LL[j] + 2 * B_MERTENS + E + 1 / (lnT * lnT) + D(2) / (T - 2) print() print("PART C: primes w >= WCUT, all z >= w: ln R <= 1/ln^2 z + 1/ln^2(w-1) + 2 lnln w - 2 lnln(w-1) + 2/(w-2) <= 2/ln^2(w-1) + 2(lnln w - lnln(w-1)) + 2/(w-2)") def partC_at(w): lw1 = D(w - 1).ln(); lw = D(w).ln() return 2 / (lw1 * lw1) + 2 * (lw.ln() - lw1.ln()) + D(2) / (w - 2) # the bound is decreasing in w; evaluate at the first prime >= WCUT and check monotonicity on a grid wC = next(p for p in primes if p >= WCUT) cC = partC_at(wC) mono_ok = all(partC_at(q) <= partC_at(p) for p, q in zip(primes[idx(wC):idx(wC)+2000], primes[idx(wC)+1:idx(wC)+2001])) print(f" first prime >= WCUT: {wC}; bound there: ln R <= {cC:.10f}, R <= {cC.exp():.10f}; decreasing on the next 2000 primes: {mono_ok}") assert wC >= RS_X_SUM, "part C needs w >= RS_X_SUM for the R-S upper bound at z >= w" print() print("CERTIFICATE per w0: K(w0) <= max(A, B, C) [A, B exact maxima over primes w in [w0, WCUT)]") print(" w0 | A: finite sup (w,z) | B: z>=T bound | C: w>=WCUT bound | K(w0) <= | K <= e^0.1 ? | s0 = max(19, 18+10 ln K)") for w0 in W0S: ws = [w for w in wprimes if w >= w0] if ws: A_w = max(ws, key=lambda w: best[w][0]); A = best[A_w][0]; Az = best[A_w][1] Bv = max(partB(w) for w in ws) Astr = f"{A.exp():.9f} at (w={A_w}, z={Az})" else: A = D("-inf"); Bv = D("-inf"); Astr = "(no prime in [w0, WCUT))" K = max(A, Bv, cC).exp() if ws else cC.exp() s0 = max(D(19), 18 + 10 * K.ln()) print(f" {w0} | {Astr} | {(Bv.exp() if ws else D('nan')):.6f} | {cC.exp():.6f} | {K:.9f} | {'yes' if K <= TARGET else 'NO'} | {s0:.6f}") print() print("side arithmetic (connection B of the report): 6226553025 * 35 =", 6226553025 * 35, "; prod_(3<=q<=37)(q-2) =", math.prod(q - 2 for q in sieve(37) if q > 2))