generate.py

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

3995 bytes, as of the version from 2026-11-30 16:30 (current). Recorded here, not run.

"""T870: p-adic L-function derivatives at zero for imaginary quadratic characters.

Install SageMath with p-adics and number fields, then `sage -pip install numberdb`.
Run `sage -python generate.py` to preview (no writes), or
`sage -python generate.py --publish` to fill the already-created draft.
The NumberDB API key and actual engine/model provenance belong in the environment.
Keep certified_log.py beside this file. Default coverage is all negative
fundamental |D|<=43 and split primes 5<=p<=43, ordered by |D|,p.

The Gamma sum uses PARI's Morita Gamma at exact a/|D|, including p|a.
The exact ideal certificate and bounded modular logarithm independently certify
its residue. Returned Sage Qp values carry O(p**N), where N=v+ceil(log_p(10**digits)).
PARI tracked precision alone is not used as a proof: every returned residue is
compared with the exact modular algebraic route at the full retained modulus.
Gross--Dasgupta (2022), Sections 2--3, gives both identities, including 4/w.
The chosen alpha generates the conjugate of (p,sqrt(D)-r0)**h and is a local unit.
The modular logarithm error proof is in certified_log.py and numerical-method.md.
"""
import os,sys
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.padics.factory import Qp
from sage.rings.number_field.number_field import QuadraticField
from sage.arith.misc import kronecker
from certified_log import pairs,reduced_forms,coefficients,relative_digits,unit_derivative
from functools import lru_cache

@lru_cache(None)
def arithmetic(D,p):
    D=int(D);p=int(p);K=QuadraticField(D,'t');t=K.gen()
    assert int(K.discriminant())==D
    h=int(K.class_number(proof=True));w=int(K.number_of_roots_of_unity())
    assert h==len(reduced_forms(D))
    assert -sum(QQ(int(kronecker(D,a))*a)/(-D) for a in range(1,-D+1))==QQ(2*h)/w
    r0=min(r for r in range(1,p) if (r*r-D)%p==0)
    x,y=coefficients(D,p,h,r0);alpha=(ZZ(x)+ZZ(y)*t)/ZZ(2)
    P=K.ideal(p,t-r0);Q=K.ideal(p,t+r0)
    assert P!=Q and P*Q==K.ideal(p)
    assert alpha in K.maximal_order() and alpha.norm()==p**h
    assert K.ideal(alpha)==Q**h
    assert K.ideal(alpha).valuation(P)==0 and K.ideal(alpha).valuation(Q)==h
    return {'D':D,'p':p,'h':h,'w':w,'r0':r0,'x':x,'y':y,'norm':p**h,'ideal_equality':True,'forms':[list(f) for f in reduced_forms(D)],'alpha':str(alpha),'prime_ideal':str(P),'conjugate_prime_ideal':str(Q)}

@lru_cache(None)
def compute(D,p,digits=100):
    D=int(D);p=int(p);digits=int(digits);A=arithmetic(D,p);n=relative_digits(p,digits)
    R=Qp(p,prec=n+24,print_mode='val-unit');N=-D
    g=sum((int(kronecker(D,a))*R(QQ(a)/N).gamma(algorithm='pari').log() for a in range(1,N+1) if kronecker(D,a)),R(0))
    assert g and g.valuation()>=1
    v=int(g.valuation());absolute=v+n;assert g.precision_absolute()>=absolute
    cert,details=unit_derivative(D,p,A['x'],A['y'],A['w'],absolute)
    assert (int(g.lift())-cert)%p**absolute==0
    result=R(cert).add_bigoh(absolute)
    assert result.precision_relative()==n and result.valuation()==v
    return result,dict(A,valuation=v,relative_precision=n,absolute_precision=absolute,residue=str(cert),gamma_residue=str(int(g.lift())%p**absolute),gamma_absolute_precision=int(g.precision_absolute()),**details)

class Derivatives(numberdb.Generator):
    table='T870';parameters=['D','p'];type='Qp';digits=100;rigour='proven'
    files=('generate.py','certified_log.py')
    def enumerate(self):
        for D,p in pairs():yield {'D':ZZ(D),'p':ZZ(p)}
    def value(self,params,digits):return compute(int(params['D']),int(params['p']),digits)[0]

if __name__=='__main__':
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':numberdb.configure(api_key=sys.stdin.read().strip())
    generator=Derivatives()
    if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH')=='1':generator.publish(message='Create draft; wanted request https://github.com/numberdb/numberdb-data/issues/411')
    else:generator.preview()