generate.py

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

6369 bytes, as of the version from 2026-12-02 04:01 (current). Recorded here, not run.

"""T888: du Bois-Reymond constants, integer orders 2 through 30.

Install numberdb in SageMath, then:
    sage -pip install numberdb
    sage -python generate.py               # verify all stored entries, no writes
    sage -python generate.py --publish     # fill this private draft explicitly

Only the numberdb package and SageMath are needed. Import this module and call
DuBoisReymond().value({'m': 7}, 100) for another integer order. Precision and
the convergent series length grow with the requested decimal precision.

The first K=32 strictly positive roots of sin(x)-x*cos(x) are bracketed on
(k*pi,(k+1/2)*pi), excluding zero. On each interval (-1)^k*f is increasing;
the endpoint signs and the absence of roots in the intervening half-periods
certify the index. Root intervals propagate into the positive lobe sum.

For the tail let z=1/((k+1/2)*pi), x=1/z-delta(z). The analytic small branch
satisfies delta=atan(z/(1-z*delta)); equivalently delta'=1/(1-z*delta)^2,
delta(0)=0. Its formal coefficients and those of
H_m=((1-z*delta)^2+z^2)^(-m/2) are computed exactly over QQ.
Only even powers occur in H_m. Each z^(m+2*j) sums by Hurwitz zeta.

On |z|<=1/4 the fixed-point map contracts |delta|<=1/2: its image has
modulus <=14/45, its derivative <=4/45, and the denominator of H has
modulus >=45/64. Thus |H_m|<=(64/45)^(m/2), and Cauchy's estimate bounds
all omitted coefficients. The explicit whole-tail bound is implemented in
tail_error(), with a positive integral upper bound for Hurwitz zeta.

At 100 digits: 768 working bits, 50 tail coefficients, 512 root bisections.
Every result must have >=110 supported relative decimal digits. These are
rigorous numerical enclosures, not claims of exact rational constants.
MathWorld equations (1)–(4), DLMF 10.21.15 and 25.11.1 support the quantity
and spectral summation; bounds and derivation are detailed in method.md.
Credentials and session provenance are configured externally.
"""
import os,sys,json,math
from functools import lru_cache
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField
from sage.symbolic.ring import SR  # initialize symbolic dependencies of series
from sage.rings.power_series_ring import PowerSeriesRing

ROOT_COUNT=32

def settings(digits):
    if int(digits)<2:raise ValueError('digits must be at least two')
    bits=max(768,numberdb.bits(digits,losing=320))
    J=max(48,math.ceil((int(digits)+38)/2.8))
    return bits,J

def endpoints(v):
    return [str(v.lower().exact_rational()),str(v.upper().exact_rational())]

@lru_cache(maxsize=None)
def coefficients(J):
    P=PowerSeriesRing(QQ,'z',default_prec=2*J+2)
    z=P.gen();d=P(0).add_bigoh(2*J+1)
    for _ in range(J+1):
        d=((1-z*d)**(-2)).integral().add_bigoh(2*J+1)
    assert ((1-z*d)**2*d.derivative()-1).valuation()>=2*J
    assert all(d[j]==0 for j in range(0,2*J,2))
    # Check the original root equation as a formal identity, not just the ODE.
    residual=d.sin()-z*d.cos()-z*d*d.sin()
    assert residual.valuation()>=2*J+1
    base=((1-z*d)**2+z*z).add_bigoh(2*J)
    rows={}
    for m in range(2,31):
        h=base**(-QQ(m)/2)
        assert all(h[j]==0 for j in range(1,2*J,2))
        rows[m]=tuple(h[2*j] for j in range(J))
        assert all(type(v).__name__ in ('Rational','Integer') for v in rows[m])
    return d,base,rows

@lru_cache(maxsize=None)
def roots(bits):
    B=RealBallField(bits);pi=B.pi();result=[];cert=[]
    for k in range(1,ROOT_COUNT+1):
        lo=QQ(k);hi=QQ(k)+QQ(1)/2
        sign=(-1)**k
        for _ in range(bits-256):
            q=(lo+hi)/2;x=B(q)*pi
            f=sign*(x.sin()-x*x.cos())
            if f<0:lo=q
            elif f>0:hi=q
            else:raise ArithmeticError('Bisection sign became unresolved')
        x=B(lo).union(B(hi))*pi
        flo=sign*((B(lo)*pi).sin()-B(lo)*pi*(B(lo)*pi).cos())
        fhi=sign*((B(hi)*pi).sin()-B(hi)*pi*(B(hi)*pi).cos())
        assert flo<0 and fhi>0 and x.is_finite()
        result.append(x)
        cert.append({'k':k,'q_lower':str(lo),'q_upper':str(hi),
                     'x_interval':endpoints(x),'signed_f_lower':str(flo),
                     'signed_f_upper':str(fhi),'accuracy_bits':int(x.accuracy())})
    return tuple(result),cert

@lru_cache(maxsize=None)
def moments(s,bits):
    B=RealBallField(bits);a=B(QQ(2*ROOT_COUNT+3)/2)
    return B(s).zeta(a)/B.pi()**s

def tail_error(m,J,bits):
    B=RealBallField(bits);a=B(QQ(2*ROOT_COUNT+3)/2);pi=B.pi();rho=B(QQ(1)/4)
    s=m+2*J;M=(B(QQ(64)/45))**(QQ(m)/2);q=1/(rho*pi*a)
    assert q<1
    zeta_upper=a**(-s)+a**(1-s)/(s-1)
    return 2*M*rho**(-2*J)/(1-q*q)*pi**(-s)*zeta_upper

def compute(m,digits=100):
    m=int(m)
    if m<2:raise ValueError('m must be an integer >=2')
    bits,J=settings(digits);B=RealBallField(bits)
    d,base,rows=coefficients(J)
    h=rows[m] if m in rows else tuple((base**(-QQ(m)/2))[2*j] for j in range(J))
    xs,_=roots(bits)
    prefix=2*sum(((1+x*x).sqrt()**(-m) for x in xs),B(0))
    tail=2*sum((B(c)*moments(m+2*j,bits) for j,c in enumerate(h)),B(0))
    error=tail_error(m,J,bits)
    value=(prefix+tail).add_error(error)
    assert value.is_finite() and value>0
    assert value.accuracy()>numberdb.bits(digits+10)
    return value,{'m':m,'working_bits':bits,'K':ROOT_COUNT,'J':J,
                  'value_interval':endpoints(value),'prefix_interval':endpoints(prefix),
                  'tail_interval':endpoints(tail),'tail_error_interval':endpoints(error),
                  'accuracy_bits':int(value.accuracy())}

class DuBoisReymond(numberdb.Generator):
    table='T888'
    parameters=('m',)
    type='R'
    digits=100
    rigour='proven'

    def enumerate(self,m_max=30):
        for m in range(2,int(m_max)+1):yield {'m':m}

    def value(self,params,digits):
        raw=QQ(params['m'])
        if raw.denominator()!=1:raise ValueError('m must be an integer')
        return compute(int(raw),digits)[0]

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