generate.py

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

3053 bytes, as of the version from 2026-11-19 23:48 (current). Recorded here, not run.

"""Reproduce the Mahler-measure table T767.

Requirements: SageMath and numberdb (sage -pip install numberdb).
  sage -python generate.py             # compute and check, without writing
  sage -python generate.py --publish   # fill the assigned draft using own key

The sole parameter k is the real coefficient in
(x+x^-1)^2 (y+y^-1)^2 (1+z)^3 z^-2 - k. The default selection is 0,
both signed integer bands 128 <= |k| <= 256, and 1458. It is an exterior
reference slice, not the full real domain. Zero is exact by multiplicativity
and Jensen's formula. Samart, arXiv:1205.4803v2, Prop. 1.3(ii), includes
both endpoints. Rogers, arXiv:0704.2438v4, Eq. (2.5), fixes normalization.

Let C_n=binomial(2n,n)^2 binomial(3n,n). For the selected nonzero k,
A(k)=log|k|-sum_{n>=1} C_n/(n k^n). Exact rational recurrence multipliers
are evaluated in Arb balls at ceil((digits+45) log2(10)) bits. For n>=1,
|t_{n+1}/t_n|=6n(2n+1)(3n+1)(3n+2)/((n+1)^4 |k|)<108/|k|<1.
After summing t_N, the entire remaining absolute tail is at most
|t_N| q/(1-q), q=108/|k|. This bound is added to the ball radius.
The stopping bound is 10^(-digits-20). This also bounds the alternating
negative-k case without assuming cancellation. No binary floats occur.
"""
import os
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField

def selected_arguments():
    yield 0
    for n in range(128,257):
        yield n
        yield -n
    yield 1458

def evaluate(k,digits=100,diagnostics=False):
    k=ZZ(k)
    if k==0:
        return (ZZ(0),{'terms':0,'accuracy_bits':'exact'}) if diagnostics else ZZ(0)
    if abs(k)<128:
        raise ValueError('This exterior evaluator requires |k| >= 128, or k=0.')
    R=RealBallField(numberdb.bits(digits+45))
    q=QQ(108)/abs(k)
    term=R(QQ(12)/k);total=term;n=1
    threshold=R(10)**(-digits-20)
    tail=abs(term)*R(q/(1-q))
    while not tail < threshold:
        ratio=QQ(6*n*(2*n+1)*(3*n+1)*(3*n+2))/(ZZ(n+1)**4*k)
        term*=R(ratio);total+=term;n+=1
        tail=abs(term)*R(q/(1-q))
    result=(R(abs(k)).log()-total).add_error(tail)
    assert result.is_finite() and result.accuracy()>numberdb.bits(digits+15)
    if diagnostics:
        return result,{'terms':n,'accuracy_bits':int(result.accuracy()),'tail_bound':str(tail)}
    return result

class MahlerMeasures(numberdb.Generator):
    table=os.environ.get('NUMBERDB_TABLE','T767')
    parameters=['k']
    type='R'
    digits=100
    rigour='proven'
    def enumerate(self):
        for k in selected_arguments():yield {'k':k}
    def value(self,params,digits):return evaluate(params['k'],digits)

if __name__=='__main__':
    import sys
    g=MahlerMeasures()
    if '--publish' in sys.argv:
        if g.table=='TBD':raise SystemExit('Assign NUMBERDB_TABLE to the authorized draft.')
        print(g.publish())
    else:
        vals=[evaluate(k) for k in selected_arguments()]
        print('Computed',len(vals),'values; nonzero balls are finite; zero is exact.')