generate.py

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

3413 bytes, as of the version from 2026-11-17 13:03. Recorded here, not run.

"""Reproduce T738, Guillera hypergeometric periods.

Requires numberdb, SageMath (or passagemath-symbolics), mpmath.
    sage -pip install numberdb mpmath
    sage -python generate.py              # read-only full verification
    sage -python generate.py --preview    # compute without writing
    sage -python generate.py --publish    # explicitly fill this draft

For private reads set NUMBERDB_API_KEY; session provenance belongs in the
environment. The computation is mpmath's unregularized hypergeometric analytic
continuation at 150 and 200 decimal digits for the default 100-digit output.
Repeated parameters are passed unchanged. Agreement is heuristic, not a proof
of a truncation bound. Exact argument formulas are recomputed at each precision.
The positive quadratic argument loses about seven decimal digits to subtraction;
the 50-digit guard covers this loss, measured against ball/independent checks.
"""
import os, sys
from functools import lru_cache
from math import gcd
import numberdb.sage as numberdb
from sage.rings.real_mpfr import RealField
from sage.rings.rational_field import QQ
import mpmath as mp

# Ordered source rows 1--15, followed by both embeddings of row 16, DPVZ
# Table 2.10 p.5, https://jvoight.github.io/articles/hgm-asai-061920.pdf.
SELECTION = (
    ('2.2.2.2.2','-1/4'), ('2.2.2.2.2','-4'),
    ('2.2.2.2.2','-1/1024'), ('2.2.2.2.2','-1024'),
    ('2.2.2.3','27/64'), ('2.2.2.3','-27'), ('2.5','-3125/256'),
    ('2.2.2.4','1/16'), ('2.3.4','-1/48'), ('2.3.4','-27/16'),
    ('2.3.6','-729/4096'), ('2.3.6','729/15625'),
    ('2.3.6','-1/512000'), ('2.4.6','-1/1024'), ('2.8','1/2401'),
    ('2.2.2.3','-18414+8235*sqrt(5)'),
    ('2.2.2.3','-18414-8235*sqrt(5)'),
)

def alpha(template):
    return [QQ(j)/QQ(d) for d in map(int,template.split('.'))
            for j in range(1,d) if gcd(j,d)==1]

def mp_rational(q):
    q=QQ(q)
    return mp.mpf(int(q.numerator()))/int(q.denominator())

def argument(identity):
    if identity=='-18414+8235*sqrt(5)': return -18414+8235*mp.sqrt(5)
    if identity=='-18414-8235*sqrt(5)': return -18414-8235*mp.sqrt(5)
    return mp_rational(identity)

@lru_cache(maxsize=None)
def compute(template,z,working):
    with mp.workdps(int(working)):
        upper=[mp_rational(a) for a in alpha(template)]
        value=mp.hyper(upper,[1]*4,argument(z))
        if not mp.isfinite(value) or mp.im(value)!=0 or value<=0:
            raise ArithmeticError('nonfinite, nonreal or nonpositive period')
        return mp.nstr(value,int(working))

class GuilleraPeriods(numberdb.Generator):
    table='T738'
    parameters=('template','z')
    type='R'
    digits=100
    rigour='heuristic (agreement-checked)'
    files=('generate.py',)
    def enumerate(self):
        for template,z in SELECTION:
            yield {'template':template,'z':z}
    def value(self,params,digits):
        return numberdb.agreeing(
            lambda working: compute(str(params['template']),str(params['z']),working),
            at=(int(digits)+50,int(digits)+100))

if __name__=='__main__':
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':
        numberdb.configure(api_key=sys.stdin.read().strip().split('=',1)[-1].strip().strip('"\''))
    g=GuilleraPeriods()
    if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH')=='1':
        g.publish()
    elif '--preview' in sys.argv:
        g.preview()
    else:
        g.verify(sample=None)