"""Test the two-tail witness, the matching-parity identity, and actual signed Hankel moments.""" from fractions import Fraction as F from itertools import product from math import prod import mpmath as mp import sympy as sp def witness_checks(): tests = integer = one_missing = nonprimitive = 0 for D in range(1,8): qs = (D,2*D,3*D) for f in product((-1,0,1), repeat=D): for e in (-1,1): g = [f[j % D]-e*f[-j % D] for j in range(1,D+1)] if not any(g): continue j0 = next(j for j,v in enumerate(g, 1) if v) for w in ((1,0,0),(1,-1,0),(0,1,-1),(1,-2,3),(-1,1,1)): star = max(i for i,v in enumerate(w) if v) a = F(j0, qs[star]) positive = negative = 0 for q,weight in zip(qs,w): k = q*a if k.denominator == 1: positive += weight*f[int(k)%D] negative += weight*f[-int(k)%D] assert positive-e*negative == w[star]*g[j0-1] != 0 tests += 1 integer += a == 1 one_missing += (positive == 0) != (negative == 0) nonprimitive += a.denominator < qs[star] print(f"Two-tail identity passed {tests} profile/parity/weight cases at periods 1..7.") print(f"Cases with integer witness: {integer}; exactly one tail residue zero: {one_missing}; fraction reduced: {nonprimitive}.") def fourier_checks(): mp.mp.dps = 85 errmax = mp.mpf(0) tests = 0 for D in (1,2,3,4,5,8): for j in range(2,11): sign = (-1)**j # Symmetrize basis profiles independently, including the 0 and D/2 classes. for k in range(D): f = [int(r == k)+sign*int((-r)%D == k) for r in range(D)] if not any(f): continue lhs = 2 * sum(v*mp.hurwitz(j, mp.mpf(r)/D) for r in range(1,D+1) if (v:=f[r%D]))/D**j mixed = 0 for ell in range(D): c = sum(v*mp.expjpi(mp.mpf(-2*ell*r)/D) for r,v in enumerate(f))/D b = sp.bernoulli(j, sp.Rational(ell,D)) mixed += c*mp.mpf(int(b.p))/int(b.q) rhs = -(2*mp.pi*1j)**j/mp.factorial(j)*mixed err = abs(lhs-rhs) errmax = max(errmax, err) assert err < mp.mpf("1e-72") tests += 1 # f(n)=1-9*1_{3|n} is even and its L-value is exactly zero at j=2. assert F(1) - 9*F(1,3**2) == 0 and F(1) - 9*F(1,3**4) != 0 print(f"Passed {tests} Fourier/Bernoulli vs Hurwitz-sum evaluations, 85 decimal digits.") print("Largest absolute discrepancy:", mp.nstr(errmax,5)) print("Exact matching-parity zero example: D=3, f(n)=1-9*1_{3|n}, L_f(2)=0.") def interval_product(x,y): candidates = [a*b for a in x for b in y] return min(candidates), max(candidates) def interval_difference(x,y): return x[0]-y[1], x[1]-y[0] def determinant_check(): # Quartic-imaginary profile, with overlapping 5- and 10-grids. Positive # kernel constants can be removed before testing signs of Hankel minors. n,s = 2,12 fractions = [F(a,10) for a in range(1,10) if a != 5] # denominators 5 and 10 profile = (0,0,1,-1,0) atoms = [(F(j,q),w*profile[j%5]) for q,w in ((5,1),(10,-2)) for j in range(1,q+1) if profile[j%5]] V = 20 h = len(fractions) degrees = (0,2,4) partial = dict.fromkeys(degrees, F(0)) for v in range(V): for a,w in atoms: t = v+a kernel = prod(t+th+k for th in fractions for k in range(n)) / (t*(t+1)*(t+2))**s for j in degrees: partial[j] += 2*w*kernel*(t+1)**j intervals = {} for j in degrees: power = 3*s-2*h-j # For t>=v>=V>=2, numerator and moment factors are bounded by # (2t)^(2h+j), denominator below by t^(3s), and both tails contribute. tail = 2**(1+2*h+j) * sum(abs(w) for _,w in atoms) * (F(1,V**power)+F(1,(power-1)*V**(power-1))) intervals[j] = partial[j]-tail,partial[j]+tail a,b,c = (intervals[j] for j in degrees) minors = [a, interval_product(a,b), interval_product(b,interval_difference(interval_product(a,c),interval_product(b,b)))] signs = [] for k,I in enumerate(minors,1): assert I[0] > 0 or I[1] < 0 signs.append(1 if I[0] > 0 else -1) print(f"Signed Hankel minor {k}, certified sign {signs[-1]:+d}, approximate relative enclosure width {float((I[1]-I[0])/min(abs(y) for y in I)):.3g}.") print("The enclosures use exact rational finite sums and a rigorous infinite-tail bound.") if __name__ == "__main__": witness_checks() fourier_checks() determinant_check()