generate.py

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

6282 bytes, as of the version from 2026-11-20 06:18 (current). Recorded here, not run.

"""Central L-values for the rank-zero elliptic-curve table (T771).

Install SageMath (or the required passagemath arithmetic modules), then run:
    sage -pip install numberdb
Keep roster.json beside this file. With an actual assigned target:
    sage -python generate.py                # check every stored entry
    sage -python generate.py --publish      # additive submission to that draft

The default enumeration is source curve number 1 in every rank-zero Cremona
isogeny class through conductor 100. roster.py reconstructs roster.json from
the two SHA-256-pinned ecdata files; it can select a larger conductor bound.
The value function also handles any supplied rank-zero minimal-model (N,c4,c6)
triple: when absent from the roster, it reconstructs the short rational model
and takes its reduced global minimal model, rejecting changed invariants.

Every a_p is computed by exact point counting on the integral minimal model,
including singular reductions. At good primes the Euler factor is
1-a_p*T+p*T^2; at bad primes it is 1-a_p*T. Multiplicativity then gives a_n.
At root number +1 the split Mellin series is 2*sum(a_n*q^n/n), with
q=exp(-2*pi/sqrt(N)). Hasse's bound gives |a_n|<=d(n)*sqrt(n)<=2*n;
the omitted tail is at most 4*q^(M+1)/(1-q). All transcendental operations
and the tail use Arb balls, with at least 640 working bits. M increases
until the tail is below 2^(-bits+80); the returned ball includes that error.
No periods, BSD quotients or analytic Sha routines generate these values.

The separate build_check.py compares PARI lfun at 832/1024 bits, exact Euler
coefficients and rank-zero descent bounds. lfun agreement is an independent
implementation check, not the source of the certified bound.
"""
import argparse
import json
from functools import lru_cache
from pathlib import Path

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
from sage.libs.pari import pari

BASE=Path(__file__).resolve().parent
ROSTER=json.loads((BASE/'roster.json').read_text())
ROWS=ROSTER['curves']
BY_KEY={(r['N'],r['c4'],r['c6']):r for r in ROWS}


def prime_sieve(limit):
    composite=[False]*(limit+1)
    for n in range(2,limit+1):
        if not composite[n]:
            yield n
            for k in range(n*n,limit+1,n):
                composite[k]=True


def count_ap(ainvs,p):
    """p+1 minus the projective point count, also for singular reduction."""
    a1,a2,a3,a4,a6=map(int,ainvs)
    if p==2:
        affine=sum((y*y+a1*x*y+a3*y-x**3-a2*x*x-a4*x-a6)%p==0
                   for x in range(p) for y in range(p))
        return p-affine
    chi_sum=0
    for x in range(p):
        d=((a1*x+a3)**2+4*(x**3+a2*x*x+a4*x+a6))%p
        if d:
            chi_sum += 1 if pow(d,(p-1)//2,p)==1 else -1
    return -chi_sum


def euler_coefficients(ainvs,disc,limit):
    a=[0]*(limit+1)
    a[1]=1
    factors={}
    for p in prime_sieve(limit):
        ap=count_ap(ainvs,p)
        bad=(disc%p==0)
        assert not bad or ap in (-1,0,1)
        factors[p]={'a_p':ap,'bad':bad}
        pk=p
        prevprev,prev=1,ap
        powers=[]
        while pk<=limit:
            powers.append((pk,prev))
            prevprev,prev=prev,ap*prev-(0 if bad else p*prevprev)
            pk*=p
        # Existing support uses only earlier primes, hence gcd(m,p)=1.
        for m in range(limit,0,-1):
            if a[m] and m%p:
                for pk,v in powers:
                    if m*pk<=limit:
                        a[m*pk]=a[m]*v
    assert all(type(v) is int for v in a)
    return a,factors


def curve_input(params):
    key=tuple(int(params[k]) for k in ('N','c4','c6'))
    if key in BY_KEY:
        ainvs=BY_KEY[key]['ainvs']
    else:
        N,c4,c6=key
        P,change=pari([QQ(-c4)/48, QQ(-c6)/864]).ellinit().ellminimalmodel()
        ainvs=[int(x) for x in list(P)[:5]]
    P=pari(ainvs).ellinit()
    assert int(P.ellglobalred()[0])==key[0], 'Conductor does not match'
    # PARI ell structures expose c4,c6 at zero-based indices 9,10.
    assert (int(P[9]),int(P[10]))==key[1:], 'Minimal-model invariants do not match'
    assert int(P.ellrootno())==1, 'The positive-root-number formula is inapplicable'
    return ainvs,P


@lru_cache(maxsize=256)
def evaluate(N,c4,c6,digits=100):
    ainvs,P=curve_input({'N':N,'c4':c4,'c6':c6})
    bits=max(640,numberdb.bits(digits,losing=256))
    R=RealBallField(bits)
    q=(-2*R.pi()/R(N).sqrt()).exp()
    M=16
    target=R(2)**(-bits+80)
    while True:
        tail=4*q**(M+1)/(1-q)
        if tail<target:
            break
        M+=16
    a,factors=euler_coefficients(ainvs,int(P.disc()),M)
    S=R(0)
    qn=R(1)
    for n in range(1,M+1):
        qn*=q
        S+=R(QQ(a[n])/ZZ(n))*qn
    result=(2*S).add_error(tail)
    assert result.is_finite() and not result.contains_zero()
    assert result>0 and result.accuracy()>numberdb.bits(digits,losing=0)
    return result,{'bits':bits,'M':M,'tail_upper':str(tail.upper().exact_rational()),
                  'radius_upper':str(result.rad().exact_rational()),
                  'accuracy_bits':int(result.accuracy()),
                  'lower':str(result.lower().exact_rational()),
                  'upper':str(result.upper().exact_rational()),
                  'prime_factors':factors}


class CentralLValues(numberdb.Generator):
    table='T771'
    parameters=('N','c4','c6')
    type='R'
    digits=100
    rigour='proven'
    files=('generate.py','roster.json','roster.py')

    def enumerate(self,limit=100):
        if limit>ROSTER['conductor_bound']:
            raise ValueError('Reconstruct the pinned roster at the larger bound first')
        for row in ROWS:
            if row['curve_number']==1 and row['N']<=limit:
                yield {k:ZZ(row[k]) for k in self.parameters}

    def value(self,params,digits):
        key=tuple(int(params[k]) for k in self.parameters)
        return evaluate(*key,int(digits))[0]


if __name__=='__main__':
    parser=argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--publish',action='store_true')
    args=parser.parse_args()
    g=CentralLValues()
    if args.publish:
        print(g.publish(overwrite=False))
    else:
        print(g.verify(sample=None))