generate.py

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

3767 bytes, as of the version from 2026-11-27 18:50. Recorded here, not run.

"""T835: Laplacian determinants of CM flat tori.

Requires SageMath (or passagemath with Arb) and numberdb.
  sage -python generate.py               # check every stored entry, no writes
  sage -python generate.py --preview     # compute/compare, no writes
  sage -python generate.py --publish     # additive entries upload to this draft
Configure your own API key and engine/model/run provenance for uploads.

The primitive reduced coefficients identify an unoriented area-one CM lattice.
Both det and logdet are stored, in parameter order a,b,c,convention.
The default selection is exhaustive for 3 <= 4*a*c-b*b <= 100.

L = log(y)-pi*y/3+4*sum(log(abs(1-Q**n))), Q=exp(2*pi*i*tau).
The omitted logarithmic tail is bounded by
4*r**(N+1)/((1-r)*(1-r**(N+1))), r=abs(Q)<1.
All arithmetic, including tau and r, uses Arb enclosures. The tail is added
outward before exponentiation. Working precision is bits(digits, losing=128),
with a minimum of 480 bits; truncation targets digits+35 decimal places.
DLMF 23.17.8 and Faulhuber arXiv:1709.06006v3, section 2.2 (2.24).
"""
import argparse
from functools import lru_cache
from math import gcd, isqrt
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField
from sage.rings.complex_arb import ComplexBallField
from sage.rings.integer_ring import ZZ


def shapes(bound=100):
    """All primitive reduced forms modulo orientation, ordered by discriminant."""
    rows=[]
    for a in range(1,isqrt(bound//3)+1):
        for b in range(a+1):
            for c in range(a,(bound+b*b)//(4*a)+1):
                d=4*a*c-b*b
                if 3<=d<=bound and gcd(gcd(a,b),c)==1:
                    rows.append((d,a,b,c))
    return [(a,b,c) for d,a,b,c in sorted(rows)]


@lru_cache(maxsize=4096)
def evaluate(a,b,c,digits=100):
    a,b,c=map(ZZ,(a,b,c));d=4*a*c-b*b
    if not (a>0 and d>0 and gcd(gcd(a,b),c)==1):
        raise ValueError('A primitive positive definite integral form is required')
    precision=max(480,numberdb.bits(digits,losing=128))
    R=RealBallField(precision); C=ComplexBallField(precision)
    y=R(d).sqrt()/(2*a);tau=C(-R(b)/(2*a),y)
    Q=(2*C.pi()*C(0,1)*tau).exp();r=abs(Q)
    assert r<1
    target=R(10)**(-(digits+35));N=0
    while True:
        tail=4*r**(N+1)/((1-r)*(1-r**(N+1)))
        if tail<target:break
        N+=1
    L=y.log()-R.pi()*y/3
    power=Q
    for n in range(1,N+1):
        L+=4*abs(1-power).log()
        power*=Q
    L=L.add_error(tail.upper());D=L.exp()
    assert L.is_finite() and D.is_finite() and D>0
    return D,L,{'bits':precision,'factors':N,'tail_bound':str(tail.upper()),
                'det_accuracy_bits':int(D.accuracy()),'logdet_accuracy_bits':int(L.accuracy())}


class CMFlatTorusDeterminants(numberdb.Generator):
    table='T835'
    parameters=('a','b','c','convention')
    type='R'
    digits=100
    rigour='proven'

    def enumerate(self,bound=100):
        for a,b,c in shapes(bound):
            for convention in ('det','logdet'):
                yield {'a':a,'b':b,'c':c,'convention':convention}

    def value(self,params,digits):
        D,L,_=evaluate(*(int(params[k]) for k in ('a','b','c')),digits)
        convention=params['convention']
        if convention=='det':return D
        if convention=='logdet':return L
        raise ValueError('convention must be det or logdet')


if __name__=='__main__':
    p=argparse.ArgumentParser(description=__doc__)
    g=p.add_mutually_exclusive_group();g.add_argument('--publish',action='store_true');g.add_argument('--preview',action='store_true')
    args=p.parse_args();generator=CMFlatTorusDeterminants()
    if args.publish:print(generator.publish(removing=False))
    elif args.preview:print(generator.preview())
    else:print(generator.verify(sample=None))