generate.py

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

3693 bytes, as of the version from 2026-11-17 16:08 (current). Recorded here, not run.

"""T740: Determinants of even-power Bessel moments.

Install: sage -pip install numberdb
Check:   sage -python generate.py
Fill an authorized draft explicitly: sage -python generate.py --publish

Chuang--Yu, arXiv:2306.15216v2, Corollary 39 gives the two products below.
Rows a=0..r-1 and columns j=0..r-1 are ordered increasingly; n is the
factor count and r=floor((n+1)/2). The period normalization is Corollary 26.
All roots are positive real roots. Exact rational arguments, products,
Arb pi, square roots and gamma propagate rigorous error bounds. Working
precision is ceil(100*log2(10))+96=429 bits for 100 decimal digits.
The default selection is every n=1..16, bessel then period. The order-eight
cutoff is a practical initial prefix; the family and evaluator extend further.
No credentials or agent/session attribution belong in this reusable source.
"""
import argparse
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.rings.complex_arb import ComplexBallField


def determinant(n, digits=100):
    n = int(n)
    if n < 1:
        raise ValueError('n must be a positive integer')
    R = RealBallField(numberdb.bits(digits, losing=96))
    r = (n+1)//2
    if n % 2:
        answer = R.pi().sqrt()**(r*(r+1)) * R(2).sqrt()**(r*(r-3))
        for a in range(1,r):
            answer *= R(a)**(r-a) / R(2*a+1).sqrt()**(2*a+1)
    else:
        answer = R.pi().sqrt()**((r+1)**2) / (R(2).sqrt()**(r*(r+3))*R(QQ(r+1)/2).gamma())
        for a in range(1,r):
            answer *= R(QQ((2*a+1)**(r-a))/QQ((a+1)**(a+1)))
    if not answer.is_finite() or not answer > 0:
        raise ArithmeticError('Expected a finite positive determinant enclosure')
    return answer


def normalized(n, normalization, digits=100):
    n=int(n);v=determinant(n,digits)
    C=ComplexBallField(v.parent().precision())
    if normalization == 'bessel':
        return C(v)
    if normalization != 'period':
        raise ValueError('normalization must be bessel or period')
    r=(n+1)//2;s=r*(r-1)//2
    scale = (-1)**(n*r-s) * QQ(2)**(n*r-2*s) * v.parent().pi()**s
    # Algebraic phase fixes the vanishing component exactly.
    return C(v*scale) * C.gen(0)**s


def stored_text(value, digits=100):
    """Faithful canonical display for the proven pure components in this family.

    Some older clients retain an exactly zero component and put a minus
    after i*. Inspect the native exact zeros and serialize the nonzero ball
    directly. This changes only display, preserving its uncertainty.
    """
    from numberdb._write import to_text
    if value.imag().is_zero():
        return to_text(value.real(),digits)
    if not value.real().is_zero():
        raise ArithmeticError('This family must be real or purely imaginary')
    imag=value.imag()
    if imag < 0:
        return '-i*' + to_text(-imag,digits)
    return 'i*' + to_text(imag,digits)


class EvenPowerBessel(numberdb.Generator):
    table='T740'
    parameters=('n','normalization')
    type='C'
    digits=100
    rigour='proven'
    files=('generate.py',)

    def enumerate(self):
        for n in range(1,17):
            for normalization in ('bessel','period'):
                yield {'n':n,'normalization':normalization}

    def value(self,params,digits):
        return normalized(params['n'],params['normalization'],digits)


if __name__ == '__main__':
    parser=argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--publish',action='store_true')
    options=parser.parse_args()
    generator=EvenPowerBessel()
    if options.publish:
        generator.publish()
    else:
        print(generator.verify(sample=None))