generate.py

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

4649 bytes, as of the version from 2026-11-18 04:29 (current). Recorded here, not run.

"""T743: Boyd Family 3.5B: ordinary logarithmic Mahler measures.

Install: sage -pip install numberdb mpmath
Check: sage -python generate.py
Fill the authorized draft: sage -python generate.py --publish
Default execution verifies only; it never offers or publishes a draft.

Q_k=(x^2+x+1)y^2+(x^4+k*x^3+(2*k-4)*x^2+k*x+1)y+x^2*(x^2+x+1).
The actual coefficient k is used, without the source's comparison shift.
Source: Bertin and Zudilin, arXiv:1601.07583, The second family.
After an invertible torus substitution, the quadratic is a*y^2+b*y+a,
a=s+1, b=s^2+k*s+2*k-6, s=2*cos(theta). Jensen's formula gives
the numerator logarithm below because the leading coefficient has measure
zero. For negative discriminant its contribution is log|a|, not zero.
All discriminant contacts and a=0 are split. A sine-squared map smooths
square-root contacts. At k=5 the cyclotomic factor is removed algebraically.

The default selection is k=2 once, then 2+sqrt(n),2-sqrt(n), 1<=n<=36,
positive square root, square cases reduced to integers. The mathematical
domain is all real k. See argument-selection.md for mixed selection roles.

For 100 requested digits the working precisions are 140 and 180 decimal
digits. Exact algebraic input intervals are recomputed at each precision;
both endpoints are numerically propagated. Their hull is numerical input
sensitivity evidence, not a theorem of monotonicity for q or certified
quadrature. The final rigour is heuristic (agreement-checked).
No precomputed data file is needed. Session attribution stays in the caller.
"""
import argparse
import math
import re
from functools import lru_cache
import numberdb.sage as numberdb
from sage.rings.real_mpfi import RealIntervalField
from mpmath import mp


def key(n,sign=1):
    r=math.isqrt(n)
    if r*r==n:
        return str(2+sign*r)
    return '2%ssqrt(%d)'%('+' if sign>0 else '-',n)


def parse_key(k):
    k=str(k)
    if re.fullmatch(r'-?\d+',k):
        t=int(k)-2
        return t*t,1 if t>=0 else -1
    m=re.fullmatch(r'2([+-])sqrt\((\d+)\)',k)
    if not m:
        raise ValueError('Use an integer or 2+sqrt(n) or 2-sqrt(n), n>=0')
    return int(m.group(2)),1 if m.group(1)=='+' else -1


def contacts(k):
    d=mp.sqrt(k*k-4*k+20)
    roots=[4-k, (-(k+2)+d)/2, (-(k+2)-d)/2,mp.mpf(-1)]
    return sorted(set([mp.mpf(0),mp.pi]+[mp.acos(s/2) for s in roots if -2<s<2]))


def mahler_at(k):
    if k==5:
        # Q_5=(x^2+x+1)*(y^2+(x^2+4*x+1)*y+x^2).
        return mp.quad(lambda t:mp.acosh(2+mp.cos(t)),[0,mp.pi/2,mp.pi])/mp.pi
    bounds=contacts(k)
    def f(theta):
        s=2*mp.cos(theta);a=s+1;b=s*s+k*s+2*k-6
        D=b*b-4*a*a
        if D>0:
            return mp.log((abs(b)+mp.sqrt(D))/2)
        return mp.log(abs(a))
    total=mp.mpf(0)
    for left,right in zip(bounds,bounds[1:]):
        def mapped(u):
            if u==0 or u==mp.pi/2:
                return mp.mpf(0)
            t=left+(right-left)*mp.sin(u)**2
            return f(t)*(right-left)*mp.sin(2*u)
        total+=mp.quad(mapped,[0,mp.pi/4,mp.pi/2])
    return total/mp.pi


def endpoint_quadrature(n,sign,working):
    F=RealIntervalField(numberdb.bits(working,losing=32))
    k=F(2)+sign*F(n).sqrt()
    endpoints=[k.lower().exact_rational(),k.upper().exact_rational()]
    values=[]
    for endpoint in dict.fromkeys(endpoints):
        with mp.workdps(working+20):
            x=mp.mpf(str(endpoint.numerator()))/mp.mpf(str(endpoint.denominator()))
            with mp.workdps(working):
                y=mahler_at(x)
            values.append(mp.nstr(y,working))
    lo=min(F(v).lower() for v in values);hi=max(F(v).upper() for v in values)
    return F(lo,hi)


@lru_cache(maxsize=None)
def computed(n,sign,digits):
    return numberdb.agreeing(lambda w:endpoint_quadrature(n,sign,w),at=(digits+40,digits+80))


class Boyd35B(numberdb.Generator):
    table='T743'
    parameters=('k',)
    type='R'
    digits=100
    rigour='heuristic (agreement-checked)'

    def enumerate(self,limit=36):
        yield {'k':'2'}
        for n in range(1,int(limit)+1):
            for sign in (1,-1):
                yield {'k':key(n,sign)}

    def value(self,params,digits):
        n,sign=parse_key(params['k'])
        result={'number':computed(n,sign,int(digits))}
        if math.isqrt(n)**2!=n:
            result['param-latex']=r'$2%s\sqrt{%d}$'%('+' if sign>0 else '-',n)
        return result


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