program.py

back to table · edit · history · where entries came from · files · download

1500 bytes, as of the version from 2026-11-01 21:11 (current). Recorded here, not run.

from math import comb, factorial
from sage.all import ComplexBallField, PolynomialRing, RealBallField


def jensen_roots(d, n, bits=896):
    """Enclose the ordered roots when all d roots are real and simple."""
    assert d >= 1 and n >= 0
    C, R = ComplexBallField(bits), RealBallField(bits)
    P = PolynomialRing(C, 'z')
    s = C(1)/2 + P.gen()
    length = 2*(n+d) + 1
    f = (s*(s-1)/2 * ((-s/2)*C.pi().log())._exp_series(length)
         * (s/2)._gamma_series(length) * s._zeta_series(length))
    assert all(f[2*j].imag().contains_zero() for j in range(n, n+d+1))
    a = [comb(d, j)*factorial(n+j)*f[2*(n+j)].real()
         for j in range(d+1)]
    J = PolynomialRing(R, 'X')(a)
    candidates = sorted(P(a).roots(multiplicities=False),
                        key=lambda z: z.real().mid())
    assert len(candidates) == d
    roots = []
    for z in candidates:
        assert z.imag().contains_zero() and z.real().is_finite()
        mid = z.real().mid()
        radius = R(2)**(-(bits//2))*max(R(1), abs(R(mid)))
        root = R(mid, radius.upper())
        lo, hi = R(mid)-radius/2, R(mid)+radius/2
        assert lo in root and hi in root
        left, right = J(lo), J(hi)
        assert (left < 0 < right) or (right < 0 < left)
        assert not roots or roots[-1].upper() < root.lower()
        roots.append(root)
    return roots


# Choose one degree and shift. Increase bits if certification fails.
for k, root in enumerate(jensen_roots(3, 0), start=1):
    print(k, root)