"""Evaluate the Li–Liu diagonal at real s=c/log(N), N=2^k.""" import argparse import math import mpmath as mp import numpy as np from scipy import fft, special def powers_of_five(k): modulus = 1 << k size = modulus // 4 if not (pow(5, size, modulus) == 1 and pow(5, size // 2, modulus) != 1): raise ValueError("Wrong order for the generator") residues = np.empty(size, dtype=np.int64) residues[0] = 1 step = 5 length = 1 while length < size: residues[length : 2 * length] = (residues[:length] * step) % modulus step = step * step % modulus length *= 2 return residues def hurwitz_with_derivative(u, a, cutoff): """Euler–Maclaurin with six Bernoulli terms, differentiated in u.""" value = np.zeros_like(a) derivative = np.zeros_like(a) for j in range(cutoff): log_y = np.log(a + j) term = np.exp(-u * log_y) value += term derivative -= log_y * term y = a + cutoff log_y = np.log(y) base = np.exp(-u * log_y) integral = y * base / (u - 1) value += integral + base / 2 derivative += integral * (-log_y - 1 / (u - 1)) - log_y * base / 2 for order, bernoulli in enumerate((1/6, -1/30, 1/42, -1/30, 5/66, -691/2730), 1): r = 2 * order - 1 coeff = bernoulli * special.poch(u, r) / math.factorial(r + 1) term = coeff * base / y**r value += term derivative += term * (sum(1 / (u + j) for j in range(r)) - log_y) return value, derivative def log_derivatives(k, u, cutoff=12): """One representative of each conjugate pair, including both real characters.""" N = 1 << k residues = powers_of_five(k) size = len(residues) odd = np.empty(size) odd_prime = np.empty(size) for start in range(0, size, 65536): sl = slice(start, min(start + 65536, size)) a = residues[sl] / N left, dleft = hurwitz_with_derivative(u, a, cutoff) right, dright = hurwitz_with_derivative(u, 1 - a, cutoff) odd[sl] = left - right odd_prime[sl] = dleft - dright den = fft.rfft(odd) num = fft.rfft(odd_prime) return num / den - math.log(N), float(np.min(np.abs(den)) * N**(-u)) def moment(g): squares = np.abs(g)**2 return (squares[0] + squares[-1] + 2 * np.sum(squares[1:-1])) / (2 * (len(g)-1)) def primes_to(limit): sieve = np.ones(limit + 1, dtype=bool) sieve[:2] = False for p in range(2, math.isqrt(limit) + 1): if sieve[p]: sieve[p*p::p] = False return np.flatnonzero(sieve) def model(k, c, primes, limit): """Return D, K and separate upper bounds for the two omitted prime tails.""" log_N = k * math.log(2) w = 2 * c / log_N if not 0 < w < 1: raise ValueError("Model evaluation requires 0 < 2c/log(N) < 1") v = 1 + mp.mpf(w) # (log ζ)'' counts the kth prime power with multiplicity k. diagonal = float(mp.diff(lambda z: mp.log(mp.zeta(z)), v, 2)) log_p = np.log(primes) diagonal -= np.sum((log_p / np.expm1((1 + w) * log_p))**2) diagonal -= math.log(2)**2 / math.expm1((1 + w) * math.log(2)) defect = -np.expm1(-w * log_p[1:]) / (primes[1:] - 1) local = (2 - 2**(-w)) * math.exp(np.sum(np.log1p(-defect**2))) gamma = math.exp(2 * (special.gammaln(.75 - w/4) - special.gammaln(.75 + w/4))) continuous = (math.exp(-2*c) * math.pi**w * local * gamma * float(mp.zeta(1 + mp.mpf(w)) * mp.zeta(1 - mp.mpf(w)))) b = 1 + 2*w L = math.log(limit) diagonal_tail = (limit**(-b) * (L**2/b + 2*L/b**2 + 2/b**3) / (1 - limit**(-1-w))**2) product_tail = abs(continuous) / (limit * (1 - 1/limit)**2) return diagonal, continuous, diagonal_tail, product_tail def check_transform(): """Independent small-modulus check using arbitrary-precision Hurwitz zeta.""" k = 5 N = 1 << k u = mp.mpf("0.68") g, _ = log_derivatives(k, float(u)) residues = [int(a) for a in powers_of_five(k)] error = 0. for j, got in enumerate(g): phases = [mp.exp(-2j * mp.pi * j * t / len(residues)) for t in range(len(residues))] def L(z): return N**(-z) * mp.fsum( phase * (mp.zeta(z, mp.mpf(a)/N) - mp.zeta(z, 1-mp.mpf(a)/N)) for a, phase in zip(residues, phases) ) error = max(error, float(abs(got - mp.diff(L, u)/L(u)))) if error > 1e-10: raise ArithmeticError(f"Direct comparison failed: {error}") return error def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--levels", type=int, nargs="+", default=[15, 18]) parser.add_argument("--c", type=float, nargs="+", default=[1.25]) args = parser.parse_args() mp.mp.dps = 45 if any(k < 4 or k > 28 for k in args.levels): parser.error("The adjacent-level comparison supports 4 <= k <= 28") print(f"Direct 45-digit check at N=32: max absolute difference {check_transform():.3g}", flush=True) limit = 2_000_000 primes = primes_to(limit) print("k c in_strip A D_plus_K residual/logN primitive_res/logN inherited_res/logN " "model_tails/logN min_abs_L crosscheck", flush=True) for c in args.c: for k in args.levels: log_N = k * math.log(2) s = c / log_N u = .5 + s diagonal, continuous, dtail, ktail = model(k, c, primes, limit) estimate = diagonal + continuous g, min_L = log_derivatives(k, u) # At the same u, even frequencies are characters from the lower level. inherited, _ = log_derivatives(k-1, u, cutoff=20) discrepancy = np.max(np.abs(g[::2] - inherited)) if discrepancy > 1e-8: raise ArithmeticError(f"Lower-level comparison failed: {discrepancy}") A = moment(g) gain = 2**(2*s) old = moment(inherited) - (diagonal + gain * continuous) primitive = np.mean(np.abs(g[1::2])**2) - (diagonal + (2-gain) * continuous) if abs((old + primitive)/2 - (A-estimate)) > 1e-8: raise ArithmeticError("Conductor split does not reproduce the full moment") print(f"{k} {c:g} {1/log_N < s < 1/8} {A:.9f} {estimate:.9f} " f"{(A-estimate)/log_N:+.8f} {primitive/log_N:+.8f} {old/log_N:+.8f} " f"{(dtail+gain*ktail)/log_N:.2g} {min_L:.5g} {discrepancy:.2g}", flush=True) if __name__ == "__main__": main()