"""Verify the three analytic four-dimensional volume bounds with rational arithmetic.""" from fractions import Fraction from math import isqrt def arctangent_bounds(denominator): """Bound arctan(1 / denominator) by adjacent alternating partial sums.""" lower = sum( Fraction((-1) ** k, (2 * k + 1) * denominator ** (2 * k + 1)) for k in range(40) ) upper = lower + Fraction(1, 81 * denominator**81) return lower, upper def square_root_bounds(value): """Return rational bounds one unit apart at the chosen decimal scale.""" scale = 10**45 scaled_square = value.numerator * scale**2 // value.denominator lower_numerator = isqrt(scaled_square) return Fraction(lower_numerator, scale), Fraction(lower_numerator + 1, scale) def volume_bounds(area_lower, area_upper, pi_lower, pi_upper): """Bound pi^2/32 times the square of a + sqrt(a^2 + 24a/5).""" coefficient = Fraction(24, 5) sqrt_lower, _ = square_root_bounds(area_lower**2 + coefficient * area_lower) _, sqrt_upper = square_root_bounds(area_upper**2 + coefficient * area_upper) return ( pi_lower**2 * (area_lower + sqrt_lower)**2 / 32, pi_upper**2 * (area_upper + sqrt_upper)**2 / 32, ) def main(): atan_5_lower, atan_5_upper = arctangent_bounds(5) atan_239_lower, atan_239_upper = arctangent_bounds(239) pi_lower = 16 * atan_5_lower - 4 * atan_239_upper pi_upper = 16 * atan_5_upper - 4 * atan_239_lower basic_area = Fraction(11, 112) refined_shift = Fraction(729, 8960000) # Cauchy's projection formula gives a >= 3/(4*pi) times Jiang's 3D bound. projection_scale = Fraction(3, 4) * Fraction(1651, 4000) cases = ( ("Basic spectral", basic_area, basic_area, "0.19337103300563562", "0.19337103300563563"), ("Refined spectral", basic_area + refined_shift / pi_upper, basic_area + refined_shift / pi_lower, "0.19342924501517866", "0.19342924501517867"), ("Projection", projection_scale / pi_upper, projection_scale / pi_lower, "0.19409618680258640", "0.19409618680258641"), ) for label, area_lower, area_upper, decimal_lower, decimal_upper in cases: lower, upper = volume_bounds(area_lower, area_upper, pi_lower, pi_upper) if not Fraction(decimal_lower) < lower <= upper < Fraction(decimal_upper): raise ArithmeticError(f"Failed to enclose the {label.lower()} constant") print(f"{label}: ({decimal_lower}, {decimal_upper})") if __name__ == "__main__": main()