"""Certify the interior comparison for the planar circle-packing witness. The coefficient data and the exact witness are from: https://github.com/openai/math/tree/main/preprints/A-sharp-Fourier-certificate-for-planar-circle-packing-September-23-2026 Proposition 3.4 of that preprint bounds the two coefficient-list errors. This checker verifies the additional inequality G_1'' > 0 on [0, 1]. It uses integer interval arithmetic and needs only the Python standard library. """ from dataclasses import dataclass from fractions import Fraction from math import comb, factorial, isqrt from typing import NamedTuple # Table 2 gives these positive-node coefficients times 10**10. TABLE = """ 1 -670689128 -6398628799 -250018302 4107732082 3 93524468 564897270 -186215974 -65204793 4 -64146977 121133118 82882809 -327822296 7 -1358193 -16329465 1979670 21637038 9 -2932910 -940875 3636920 2145806 12 3646952 -34846939 -6005382 34369042 13 3183411 63030995 -574123 -75237042 15 11390977 27049982 -11312377 -34985096 16 -5593246 13405071 5915710 -10980954 19 54905 -1515007 -120136 1498351 21 -210208 -634307 177992 747946 24 976077 -804949 -1037705 105643 25 -824472 7003719 1011732 -6510015 27 611891 4536095 -428528 -4440927 28 -472882 -107613 399655 403751 31 30744 -112653 -31773 90515 33 -4974 -105568 1240 99081 36 128313 246018 -114876 -267388 37 -176685 505187 166591 -396209 39 -21638 472037 32128 -402283 40 -18461 -165597 10836 164974 43 4565 -2296 -4050 547 45 1477 -10734 -1524 8978 48 10748 50050 -8611 -45048 49 -20506 7495 17354 -266 51 -10361 29035 9641 -21534 52 2121 -26523 -2269 23159 55 425 858 -344 -839 57 302 -632 -266 463 60 382 5658 -231 -4688 61 -1481 -4320 1140 4098 63 -1494 -352 1265 647 64 558 -2609 -491 2114 67 21 169 -14 -145 69 34 13 -28 -18 72 -55 394 53 -301 73 -21 -805 5 685 75 -136 -379 108 338 76 70 -144 -58 104 79 -1 19 1 -15 81 2 9 -2 -8 84 -13 3 11 0 85 13 -87 -11 70 87 -6 -60 4 49 88 6 5 -4 -5 91 0 1 0 -1 93 0 1 0 -1 96 -2 -4 1 3 97 2 -6 -2 4 99 0 -6 0 5 100 0 2 0 -2 """ NODE_ZERO = ((Fraction(1), Fraction(11, 25)), (Fraction(0), Fraction(-46, 125))) CONSTANTS = (Fraction(-13, 1000), Fraction(17, 1000)) COEFFICIENTS = [{0: pair} for pair in NODE_ZERO] for line in TABLE.strip().splitlines(): n, c1, d1, c2, d2 = map(int, line.split()) for data, c, d in zip(COEFFICIENTS, (c1, c2), (d1, d2)): data[n] = (Fraction(c, 10**10), Fraction(d, 10**10)) SCALE = 1 << 112 def ceil_ratio(numerator, denominator): return -((-numerator) // denominator) @dataclass(frozen=True) class Interval: """Endpoints are integers in units of 1/SCALE.""" lo: int hi: int @staticmethod def rational(value): if isinstance(value, Interval): return value value = Fraction(value) numerator = value.numerator * SCALE denominator = value.denominator return Interval(numerator // denominator, ceil_ratio(numerator, denominator)) def __add__(self, other): other = self.rational(other) return Interval(self.lo + other.lo, self.hi + other.hi) __radd__ = __add__ def __neg__(self): return Interval(-self.hi, -self.lo) def __sub__(self, other): return self + -self.rational(other) def __mul__(self, other): other = self.rational(other) products = ( self.lo * other.lo, self.lo * other.hi, self.hi * other.lo, self.hi * other.hi, ) return Interval(min(products) // SCALE, ceil_ratio(max(products), SCALE)) __rmul__ = __mul__ def __truediv__(self, other): other = self.rational(other) if other.lo <= 0 <= other.hi: raise ArithmeticError("division by an interval containing zero") inverse = Interval( SCALE**2 // other.hi, ceil_ratio(SCALE**2, other.lo) ) return self * inverse class ComplexBox(NamedTuple): real: Interval imag: Interval def __add__(self, other): return ComplexBox(self.real + other.real, self.imag + other.imag) def __sub__(self, other): return ComplexBox(self.real - other.real, self.imag - other.imag) def __mul__(self, other): a, b = self c, d = other return ComplexBox(a * c - b * d, a * d + b * c) def scale(self, factor): return ComplexBox(self.real * factor, self.imag * factor) def times_i(self): return ComplexBox(-self.imag, self.real) ZERO = Interval(0, 0) ONE = Interval(SCALE, SCALE) COMPLEX_ZERO = ComplexBox(ZERO, ZERO) COMPLEX_ONE = ComplexBox(ONE, ZERO) def atan_inverse_bounds(q): partial = sum( Fraction((-1)**j, (2*j + 1)*q**(2*j + 1)) for j in range(60) ) return partial, partial + Fraction(1, 121*q**121) def pi_interval(): low5, high5 = atan_inverse_bounds(5) low239, high239 = atan_inverse_bounds(239) # Machin's formula and the alternating series remainder. return Interval( Interval.rational(16*low5 - 4*high239).lo, Interval.rational(16*high5 - 4*low239).hi, ) PI = pi_interval() SQRT3_LO = isqrt(3 * SCALE**2) B = Interval(SQRT3_LO, SQRT3_LO + 1) / 2 H = Fraction(2, 5) B_INVERSE_SQUARED = Fraction(4, 3) DEGREE = 30 def exp_box(z): """Enclose exp(z) for each argument in this proof, all of norm at most 6.""" term = result = COMPLEX_ONE for k in range(1, 65): term = (term * z).scale(Fraction(1, k)) result = result + term # The remaining absolute scalar series is bounded by a geometric sum. return result + ComplexBox(Interval(-1, 1), Interval(-1, 1)) def interpolation_rule(): """Closed interpolatory quadrature averaging over [-1,1].""" nodes = [Fraction(2*i, 15) - 1 for i in range(16)] weights = [] for node in nodes: polynomial = [Fraction(1)] for other in nodes: if node == other: continue updated = [Fraction(0)] * (len(polynomial) + 1) for power, coefficient in enumerate(polynomial): quotient = coefficient / (node - other) updated[power] -= other * quotient updated[power + 1] += quotient polynomial = updated weights.append(sum(polynomial[k]/(k + 1) for k in range(0, 16, 2))) for k in range(16): expected = Fraction(1, k + 1) if k % 2 == 0 else 0 assert sum(w * x**k for x, w in zip(nodes, weights)) == expected assert sum(map(abs, weights)) < 9 return tuple(zip(nodes, weights)) def phase_and_product_data(): roots = [COMPLEX_ONE] step = ComplexBox(B, Interval.rational(Fraction(1, 2))) for _ in range(11): roots.append(roots[-1] * step) product = [ ComplexBox(Interval.rational(real), B * imaginary_b) for real, imaginary_b in [ (5, 0), (-1, 2), (1, 2), (-2, 0), (Fraction(-1, 2), 1), (-1, -2), (1, 0) ] ] return roots, product def folded_density_terms(piece, roots, product): """Coefficients of a_n+t b_n multiplying exp(-i*pi*n*t).""" result = [] for data in COEFFICIENTS: terms = [(COMPLEX_ZERO, COMPLEX_ZERO)] * 101 for n, (c, d) in data.items(): mass = moment = COMPLEX_ZERO for j in range(piece, 7): value = product[j] * roots[(j*n) % 12] mass = mass + value moment = moment + value.scale(Fraction(j, 6)) coefficient = PI * PI * (2*c) terms[n] = ( mass.times_i().scale(PI*(2*d)) - moment.scale(coefficient), mass.scale(coefficient), ) result.append(terms) return result def density_value(terms, point, phase): total = COMPLEX_ZERO for constant, linear in reversed(terms): total = total * phase + constant + linear.scale(point) return total def add_taylor_terms(coefficients, point, mass1, mass2): """Add the Gaussian and Fourier terms of one quadrature point or atom.""" t = Interval.rational(point) h = Interval.rational(H) factor = ComplexBox(h, t) denominator = h*h + t*t gaussian_rate = ComplexBox(-(PI*h), PI*t) fourier_rate = factor.scale(-(PI * B_INVERSE_SQUARED / denominator)) multiplier = factor.scale(ONE / (B*denominator)) for mass, rate in ((mass1, gaussian_rate), (mass2*multiplier, fourier_rate)): term = (mass * exp_box(rate.scale(Fraction(1, 2)))) * rate * rate for j in range(DEGREE + 1): coefficients[j] = coefficients[j] + term.real term = (term * rate).scale(Fraction(1, j + 1)) def taylor_coefficients(): quadrature = interpolation_rule() roots, product = phase_and_product_data() coefficients = [ZERO] * (DEGREE + 1) for piece in range(1, 7): terms1, terms2 = folded_density_terms(piece, roots, product) for k in range(8): # One interval of length 1/48 inside the piece of length 1/6. midpoint = Fraction(16*(piece - 1) + 2*k + 1, 96) for node, weight in quadrature: point = midpoint + node/96 phase = exp_box(ComplexBox(ZERO, -PI*point)) mass1 = density_value(terms1, point, phase).scale(weight/48) mass2 = density_value(terms2, point, phase).scale(weight/48) add_taylor_terms(coefficients, point, mass1, mass2) for j, value in enumerate(product): folding = 1 if j == 0 else 2 mass1, mass2 = (value.scale(folding*c) for c in CONSTANTS) add_taylor_terms(coefficients, Fraction(j, 6), mass1, mass2) return coefficients def bernstein_coefficients(taylor): """Convert powers of s-1/2 to degree-DEGREE Bernstein coefficients.""" powers = [ sum( taylor[j] * (comb(j, k) * Fraction(-1, 2)**(j-k)) for j in range(k, DEGREE + 1) ) for k in range(DEGREE + 1) ] return [ sum(powers[j] * Fraction(comb(k, j), comb(DEGREE, j)) for j in range(k + 1)) for k in range(DEGREE + 1) ] def verify(): # The absolute complex-exponential tail after term 64 is below 1/SCALE. assert Fraction(6**65, factorial(65)) / (1 - Fraction(6, 66)) < Fraction(1, SCALE) # On the t disks of radius 1/24, bound exp(pi*n/24) by (8/7)**n. x = Fraction(22, 7*24) exp_upper = sum(x**k/factorial(k) for k in range(8)) exp_upper += x**8/factorial(8) / (1 - x/9) assert exp_upper < Fraction(8, 7) for data in COEFFICIENTS: norm = sum((abs(c) + abs(d)) * Fraction(8, 7)**n for n, (c, d) in data.items()) assert norm < 3 # |P_1|+...+|P_6| < 15. On each disk, the folded density is below 1000. p = Fraction(22, 7) assert 2*p*15*3*p*Fraction(25, 24) < 1000 assert p*(Fraction(25, 24) + H) < 5 assert p*B_INVERSE_SQUARED/(H - Fraction(1, 24)) < 12 assert 1/(Fraction(5, 6)*(H - Fraction(1, 24))) < 4 analytic_integrand_bound = 700_000 assert 1000*(5**2 + 4*12**2) < analytic_integrand_bound # Each integration segment has half-length 1/96. Cauchy's estimate and # degree-15 exactness give this uniform quadrature error on [0,1]. quadrature_error = 10*analytic_integrand_bound * Fraction(1, 4)**16 / Fraction(3, 4) assert quadrature_error < Fraction(3, 1000) # The quadrature has absolute mass less than 9 times the density bound, # plus less than 1 for the atoms, in each of the two cardinal functions. assert 25*max(map(abs, CONSTANTS)) < 1 taylor_error = 9001*(5**2 + 4*12**2)*Fraction(6**(DEGREE+1), factorial(DEGREE+1)) assert taylor_error < Fraction(1, 100) # Proposition 3.4 and Lemma 2.1 of the source bound the two exact-minus- # tabulated measure norms by 36 * 0.00003. On the real integration axis, # the squared physical rate is less than 12, the Fourier rate less than # 11, and its multiplier less than 3. assert 65*p*p/18 < 36 and 32*p/3 < 36 assert p*p*(1 + H*H) < 12 and p*B_INVERSE_SQUARED/H < 11 assert 1/(Fraction(5, 6)*H) <= 3 coefficient_error = Fraction(36*3*(12 + 3*11**2), 100_000) assert coefficient_error < Fraction(1, 2) bernstein = bernstein_coefficients(taylor_coefficients()) minimum = min(Fraction(coef.lo, SCALE) for coef in bernstein) assert minimum > 2 assert minimum - quadrature_error - taylor_error - coefficient_error > 1 print("All 31 Bernstein coefficients exceed 2.") print("The certified uniform bound is G_1'' > 1 on [0, 1].") if __name__ == "__main__": if not __debug__: raise RuntimeError("Run the checker without -O or -OO to enable assertions.") verify()