generate.py

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

3950 bytes, as of the version from 2026-11-20 00:19 (current). Recorded here, not run.

"""Generator for T768: ordinary logarithmic Mahler measure of the quartic pencil.

Requires numberdb and SageMath (or passagemath with arb and rational polynomials).
Install the client with `sage -pip install numberdb`.
Run `sage -python generate.py` to verify all entries; add --publish to upload
entries only to the assigned draft. The default selection is 0, 4..16,
648^(1/4), 2304^(1/4), 28; positive real roots are exact identities.

For k>4, exact rational constant terms with ratio <=256/k^4 bound the tail.
At k=4, split the integrated Clausen square at t=1/2 and use the Gauss
connection formula at t=1. U and V coefficients are positive and at most 1.
Their N-term remainders are <=2*s^N for 0<=s<=1/2. With C=|A|+|B|<4,
the error in (g(s)^2-1)/(1-s), after truncating U,V and 1/(1-s), is
<400*s^N. Its integrated error is <=400*2^(-N-1)/(N+1).
The low-t half uses its independent geometric bound. Gamma, log and zeta
are enclosed by Arb. Working precision is ceil(digits*log2(10))+100 bits;
N=ceil((digits+25)*log2(10))+10 for the endpoint, giving >120 digits at 100.
See mathematical-checks.md for derivation and executable independent checks.
Attribution and credentials belong to the caller, never this reusable file.
"""
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.integer_ring import ZZ
from sage.rings.real_arb import RealBallField
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from functools import lru_cache
import math,os,sys

ROOTS={'648^(1/4)':648,'2304^(1/4)':2304}
def fourth_power(k):
    return ZZ(ROOTS[k]) if k in ROOTS else ZZ(k)**4

def low_integral(z,R,digits):
    # c_n=(1/4)_n(1/2)_n(3/4)_n/(n!)^3. Ratio c_(n+1)/c_n<1.
    z=QQ(z);term=QQ(1);total=QQ(0);n=0;target=QQ(1)/ZZ(10)**(digits+25)
    while True:
        n+=1
        term*=QQ((4*n-3)*(2*n-1)*(4*n-1))/(32*n**3)*z
        total+=term/n
        bound=term*z/(n+1)/(1-z)
        if bound<target:break
    return R(total).add_error(R(bound)),n

def integrate_poly(p,offset):
    return sum((c*QQ(1)/2**(j+1)/(QQ(j)+offset+1) for j,c in enumerate(p.list())),QQ(0))

@lru_cache(maxsize=8)
def endpoint(digits):
    R=RealBallField(numberdb.bits(digits,losing=100));N=int(math.ceil((digits+25)*math.log2(10)))+10
    P=PolynomialRing(QQ,'s');s=P.gen();u=[QQ(1)];v=[QQ(1)]
    for n in range(1,N):
        u.append(u[-1]*QQ((8*n-7)*(8*n-5))/(32*n*(2*n-1)))
        v.append(v[-1]*QQ((8*n-1)*(8*n-3))/(32*n*(2*n+1)))
    U=P(u);V=P(v);W=P([1]*N)
    A=R(QQ(1)/2).gamma()/(R(QQ(7)/8).gamma()*R(QQ(5)/8).gamma())
    B=R(-QQ(1)/2).gamma()/(R(QQ(1)/8).gamma()*R(QQ(3)/8).gamma())
    assert abs(A)+abs(B)<4
    high=A*A*R(integrate_poly(U*U*W,QQ(0)))+B*B*R(integrate_poly(s*V*V*W,QQ(0)))-R(integrate_poly(W,QQ(0)))+2*A*B*R(QQ(1)/2).sqrt()*R(integrate_poly(U*V*W,QQ(1)/2))
    high=high.add_error(R(QQ(400)/((N+1)*ZZ(2)**(N+1))))
    low,_=low_integral(QQ(1)/2,R,digits)
    return R(4).log()-(low+high)/4

class QuarticMahler(numberdb.Generator):
    table=os.environ.get('NUMBERDB_TABLE','T768')
    parameters=['k'];type='R';digits=100;rigour='proven'
    def enumerate(self):
        yield {'k':'0'}
        for k in range(4,17):yield {'k':str(k)}
        for k in ROOTS:yield {'k':k}
        yield {'k':'28'}
    def value(self,params,digits):
        k=str(params['k']);R=RealBallField(numberdb.bits(digits,losing=100))
        if k=='0':return 7*R(3).zeta()/(2*R.pi()**2)
        if k=='4':return endpoint(digits)
        u=fourth_power(k);assert u>256
        # log(k)=log(u)/4 avoids any rounded-root substitution.
        integral,_=low_integral(QQ(256)/u,R,digits)
        return (R(u).log()-integral)/4

if __name__=='__main__':
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':os.environ['NUMBERDB_API_KEY']=sys.stdin.read().strip()
    g=QuarticMahler()
    if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH')=='1':g.publish()
    else:g.verify(sample=None)