"""Scalar verification for An explicit threshold for two primes and four powers of two.""" import argparse from collections import Counter from fractions import Fraction as Q from math import comb, factorial from pathlib import Path import sys # Isolated mode drops the script directory. Add the bundled modules explicitly. sys.path.insert(0, str(Path(__file__).resolve().parent)) from intervals import LOG2, PI, box, fixed, ln, sqrt from design import A, B, SAME, arithmetic_checks, order_sum, facet_scalars from series import verify_series TEN = ln(10) RATE = Q(67, 200) CF = 10**44 CW = 10**48 CSV = 10**18 ZMIN = Q(".1665") class Checks: def __init__(self, details): self.details = details self.counts = Counter() self.locator = None def at(self, locator): self.locator = locator def record(self, tag, note, ok): if self.locator is None: raise ValueError("missing equation locator") if not ok: raise ArithmeticError(f"{self.locator} {tag}: {note}") self.counts[tag] += 1 if self.details: print(f" {self.locator:18s} {tag:11s} {note}") def lt(self, tag, note, x, y): self.record(tag, note, box(x).hi < box(y).lo) def le(self, tag, note, x, y): self.record(tag, note, box(x).hi <= box(y).lo) def eq(self, tag, note, x, y): self.record(tag, note, x == y) def negligible(self, tag, note, log_x, places=30): """Use a strict rational upper bound for exp(log_x), even at huge scale.""" self.lt(tag, note, log_x, -places*TEN) return Q(1, 10**places) def show(label, x, places): b = box(x) print(f" {label}: [{fixed(b.lo, places, False)}, {fixed(b.hi, places, True)}]") def constants(ck): ck.at("(1.2), (3.1)") ck.lt("elementary", "Machin enclosure", PI, Q(22, 7)) ck.lt("elementary", "e upper bound", 1, ln(Q("2.719"))) ck.lt("elementary", "e lower bound", ln(Q(8, 3)), 1) ck.lt("elementary", "log 2 lower", Q(".693"), LOG2) ck.lt("elementary", "log 2 upper", LOG2, Q(".694")) ck.at("(5.1)") harmonic = sum(Q(1, n) for n in range(1, 101)) ck.lt("order", "Euler constant via H_100-log 100", harmonic-ln(100), ln(Q("1.8"))) logx = ln(100**3) # Log of the product bound divided by log Y; both correction factors decrease. rslog = ln(Q("1.5")*Q("1.8")) + ln(1+1/(2*logx**2)) + 2*100**2/((100**3-2)*logx) ck.lt("order", "Rosser-Schoenfeld product at Y=100", rslog, ln(3)) ck.le("order", "product theorem range", 286, 100**3) ck.at("(3.1)") ck.lt("zero", "Dirichlet series integral plus initial terms", 4+2, 10) ck.lt("zero", "unit window, at q=1 and |b|=0 after removing common log", ln(3)+29, 39*LOG2+40*ln(8)) ck.at("(3.3)") ck.lt("zero", "Gaussian prefactor", 2*Q("2.719")*sqrt(PI), 10) # For j>=2 bound exp(-j^2) by exp(-2j) < (3/8)^(2j). y = Q(3, 8)**2 gaussian_series = 2+3*Q(3, 8)+y**2*(4/(1-y)+y/(1-y)**2) ck.lt("zero", "Gaussian weighted row series", gaussian_series, 4) ck.lt("zero", "Gram operator constant", 10*80*4, 10**4) ck.at("(3.2)") ck.le("zero", "smoothed Perron H(1) Taylor remainder, |1/Y|<=1", (1+Q(1, 4))**2-1, 1) ck.lt("zero", "sinh(x)/x-1 <= x^2/4, x<=1", Q(1, 6)/(1-Q(1, 20)), Q(1, 4)) ck.at("(3.3)") ck.lt("zero", "unit count in a shell of length 2U", 4*40, 200) ck.lt("zero", "dyadic reciprocal-square series with J>=5", 800*(2+4*LOG2/5+6*LOG2**2/25), 10**4) ck.lt("zero", "four terms of the moving-window variance", 4*((10**4*800+2*16*10**8)*8**2+(2*10**4)**2), 10**14) ck.at("(3.5)") ck.lt("zero", "clipped windows per character", 4*10**14+3*8*10**12, 10**16) ck.lt("zero", "reference change and nonunit classes", 2*10**16+2*3*16+3*4, CSV) ck.at("(3.6)") ck.lt("zero", "level decomposition", 2*128, 1024) ck.at("(4.1)") ck.lt("arcs", "Gamma and zero prefactor after angle change", 80*sqrt(2*PI)*32*sqrt(1+2*PI)+30, 10**5) ck.lt("arcs", "geometric sum with logarithmic factor, log(32q/d)>=log(32)", 8+24/ln(32), 32) ck.at("(4.1)-(4.2)") deriv = 3*Q("2.719")*sum(comb(3, j)*8**j*factorial(3-j) for j in range(4)) ck.lt("arcs", "cutoff transform: three derivatives and 1+|u|", 8*deriv/(2*PI)**3, 10**6) ck.at("(4.2)") ck.lt("arcs", "Plancherel strips coefficient", Q(6, 5)*sqrt(4), 4) ck.lt("arcs", "translate Fourier norm", 3*Q(2, 3), 4) ck.lt("arcs", "distinct denominator charge", Q(1, 3)+1+3, 5) ck.eq("arcs", "weighted orthogonality and integration", 4*16*5, 320) ck.lt("arcs", "sum of squares of local coefficients", 1+2*(1+3*Q(1, 25))/4, 2) ck.at("(4.3)") ck.lt("arcs", "six small primes in q/phi(q)", Q(2*3*5*7*11*13, 1*2*4*6*10*12), 6) ck.eq("arcs", "local factors on sum and difference coefficients", Q(8, 3)*Q(3, 4), 2) ck.at("(4.4)") ck.eq("arcs", "diagonal factor at three", 1+Q(1, 2)*(1+3*Q(1, 25)), Q(3, 2)*SAME) ck.eq("arcs", "cost of inserting the prime three in G", 1+Q(1, 2), Q(3, 2)) ck.at("(4.3)") ck.lt("arcs", "all remaining primes in q/phi(q)", Q(17, 16)**8, 17) ck.lt("arcs", "divisors below prime 17", 1/(1-sqrt(sqrt(Q(1, 2))))**2, 40) ck.le("arcs", "Ramanujan tail integral", 36*(1+Q(4, 3)), 108) ck.lt("arcs", "tail after both 3-components and P/3", (2*108*40**6)**4*2*3**3, (10**13)**4) ck.lt("arcs", "singular coefficient envelope", 2*2*SAME*3, 30) ck.lt("arcs", "arc completion coefficient", 2*3, 20) ck.at("(5.2)-(5.3)") ck.eq("order", "period price from the absolute weighted design mass", 2*20, 40) ck.eq("order", "maximum finite-period log coefficient", max(6*k+6 for k in (2, 3, 4)), 30) ck.at("(5.4)") ck.lt("sieve", "absolute Euler mass", ln(Q(3, 2))+Q(9, 4), ln(15)) ck.lt("sieve", "logarithmic Euler moment", 15*(LOG2/2+6*(1+LOG2)), 165) ck.lt("sieve", "harmonic convolution error", 15+165, 200) ck.lt("sieve", "twin-product lower conversion", 1, 2*Q(".6601618158")) ck.at("(7.3)") ck.lt("sieve", "twin-product lower endpoint used for the margins", Q(".6601"), Q(".6601618158")) ck.at("(5.4)") ck.lt("sieve", "twin-product upper conversion", Q(".6601618159"), Q(".660162")) ck.lt("sieve", "normalized total multiplier", Q("4.005")+Q("0.000001"), Q("4.006")) ck.at("(6.2)") ck.lt("window", "distortion constant", ln(6456)+2*(12*PI+7), ln(CF)) ck.lt("window", "odd-step allowance", 6+RATE*LOG2, 7) ck.at("(6.3)") ck.lt("window", "Fejer convolution amplitude", (PI**2/4)**2, 7) ck.lt("window", "zero-mode constant", ln(7*CF)+RATE*LOG2, ln(CW)) ck.at("(6.5)") ck.lt("window", "divisor shell for p<=1024", Q(16, 15)**10, 2) ck.at("(6.4)") ck.eq("window", "squared large-prime cost", 2*(1/Q(".01")), 200) ck.lt("window", "at most four completed groups", 1, 5*Q(".23")) ck.eq("window", "maximum group exponent", Q(".23")+Q(".01"), Q(".24")) ck.eq("window", "color moment for tau^10", 2**10, 1024) ck.lt("window", "weighted lift prefactor", 7*sqrt(6)*2**100*sqrt(CF), 10**54) ck.lt("window", "weighted lift including ell and binary logarithm", 4*10**54, 10**60) ck.eq("window", "row exponent", (3*RATE-1)/2, Q(".0025")) ck.at("(6.8)") ck.lt("window", "two largest endpoints clear minimum", ZMIN, Q(".6670")*2/8) ck.at("(6.3)") ck.le("window", "sum of absolute facet slopes used for displacement", 4*4, 24) ck.at("(6.8)") ck.eq("window", "two small endpoints ceiling", 2*ZMIN, Q(".333")) ck.lt("boxes", "rectangle count", 64*4*2**8, 10**5) ck.le("boxes", "subdivisions of grouped product intervals", max(k*(s-k) for s in (2, 4, 6, 8) for k in range(1, s)), 64) ck.at("(6.6)") ck.lt("boxes", "separated multiplier-block constant", max(4, 3*4, 3*2), 30) ck.eq("boxes", "reciprocal Type I slot exponent", 1-Q(".3329"), Q(".6671")) ck.eq("boxes", "cofactor length divided by the approximant denominator", 1-Q(".49"), Q(".51")) ck.at("(6.7)") ck.eq("boxes", "sum of absolute identity multipliers", sum(comb(4, j) for j in range(1, 5)), 15) ck.eq("boxes", "cubic and mixed color counts", (8**3, 8**2*2), (512, 128)) ck.eq("boxes", "two omitted exponents", (511+2-520, 127+2-135), (-7, -6)) ck.eq("boxes", "omitted polynomial coefficients", 2*15**2, 450) ck.at("(6.8)") ck.lt("boxes", "long-side mean square constant", 6**2*2, 100) ck.eq("boxes", "long-side mean square exponent", 63+2, 65) ck.at("(6.6)") ck.lt("boxes", "Type I and short-box prefactors", 4*2**8*(6*2**8 + 6*3*2*30*5), 10**10) ck.le("boxes", "Type I log exponent", 8+1+1+1+520, 532) ck.at("(6.9)") ck.lt("rows", "summed high-row prefactor", 1024*CSV*10**60*10**5, 10**87) ck.eq("rows", "high-row log exponent", 5+515+8, 528) ck.at("(6.10)") ck.lt("rows", "summed low-row prefactor", 100*36*8*(2*CW+1)*12**2*(10**5)**2, 10**67) ck.eq("rows", "low-row log exponent", 65+2+2*135+1+2+16, 356) ck.at("(6.1)") ck.eq("rows", "signed mass factor after translations", Q(14*16, 2), 112) ck.eq("rows", "pointwise squared saving", 1-2*Q(".6671")+RATE-Q(".00005"), Q(".000750")) ck.eq("rows", "low-|S| saving", 1-Q("1.30")+RATE-Q(".00005"), Q(".03495")) arithmetic_checks(ck) def endpoint(ck, w, period_cap, diagonal_cap, extras_cap): """Bounds on the whole ray starting at w; only decreasing majorants enter.""" w = Q(w) t = w+LOG2 V = 1+t logt = ln(t) logV = ln(w+2) # upper bound for log(1+t) root = sqrt(t*LOG2) length = (t-root-2*LOG2)/LOG2 # lower bound for L and ell print(f"log X = {w}") ck.at("(1.1)-(1.2)") ck.lt("scale", "extent of the decimal threshold", Q("17.35") if w == 40000000 else Q("43.35"), t/TEN/10**6) ck.lt("scale", "upper decimal order", t/TEN/10**6+Q(1, 10**6), Q("17.45") if w == 40000000 else Q("43.45")) ck.at("(5.1)-(5.3)") ck.lt("scale", "nonempty ranges and order product", 100, length) ck.lt("scale", "log(2N) <= 2 ell", t+LOG2, 2*length) ck.lt("scale", "upper log ell via ell<=t/log 2", t/LOG2, 2*V) ck.at("(6.3)") ck.lt("scale", "four powers fit inside X", 3*LOG2, root) ck.at("(1.2), (4.2)") ck.lt("scale", "2P