"""Independent finite checks of the new radial formulas, not analytic proofs.""" import itertools import math import unittest import sympy as sp class RadialRefinements(unittest.TestCase): def test_first_correction_from_exact_gamma_ratios(self): # Substitute m=1/u into the exact coefficient after radial integration. # Differentiate its finite numerator/denominator at u=0, rather than # using the logarithmic expansion used in the manuscript's proof. u = sp.Symbol("u") for n, degree in itertools.product((1, 2, 5), (2, 3, 4)): for ks in itertools.product(range(5), repeat=degree): count = sum(ks) if count > 4: continue weight = sum((j + 1) * k for j, k in enumerate(ks)) excess = weight - count numerator = sp.prod(1 - i * u for i in range(count)) denominator = sp.prod(degree + (n - r) * u for r in range(1, weight + 1)) ratio = sp.sympify(numerator) / denominator constant = ratio.subs(u, 0) if excess == 0 else 0 linear = (sp.diff(ratio, u).subs(u, 0) if excess == 0 else ratio.subs(u, 0) if excess == 1 else 0) expected_constant = sp.Rational(1, degree ** count) if excess == 0 else 0 expected_linear = 0 if excess == 0: expected_linear = -sp.Rational( (degree - 1) * count * (count - 1) + 2 * (n - 1) * count, 2 * degree ** (count + 1)) elif excess == 1: expected_linear = sp.Rational(1, degree ** weight) with self.subTest(n=n, degree=degree, multi_index=ks): self.assertEqual(constant, expected_constant) self.assertEqual(linear, expected_linear) def test_zero_leading_period_example(self): t = sp.Symbol("t", real=True) phase = sp.exp(2 * sp.pi * sp.I * t) self.assertEqual(sp.integrate(phase, (t, 0, 1)), 0) correction = sp.integrate( phase * (sp.pi ** 2 * t ** 2 - sp.pi * sp.I * t), (t, 0, 1)) self.assertEqual(sp.simplify(correction), -sp.pi * sp.I / 2) def test_integer_gamma_replication(self): for alpha in range(1, 5): xs = sp.symbols("x:" + str(alpha)) for exponent in range(7): polynomial = sp.Poly(sum(xs) ** exponent, *xs) replicated = sum(coefficient * math.prod(math.factorial(e) for e in powers) for powers, coefficient in polynomial.terms()) self.assertEqual(replicated, sp.rf(alpha, exponent)) if __name__ == "__main__": unittest.main()