individual.py

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

2609 bytes, as of the version from 2026-11-20 01:33 (current). Recorded here, not run.

"""T769 individual CM logarithms, reusing the attributed T732 homology evaluator.

The class labels and exact right-action transformation are additional to the
trace implementation. No sum over classes or numerical rational snapping occurs.
All reduction decisions require strictly separated enclosing interval endpoints.
"""
import numberdb.sage as numberdb
from sage.rings.qqbar import _init_qqbar
_init_qqbar()
from sage.rings.rational_field import QQ
from sage.rings.integer_ring import ZZ
from sage.quadratic_forms.binary_qf import BinaryQF
from heegner import Evaluator, selection, nsystem, unique_floor, gcd
from functools import lru_cache

@lru_cache(None)
def representative(N,D,beta,label):
    assert ZZ(D).is_fundamental_discriminant() and gcd(D,N)==1
    assert 0<=beta<2*N and (beta*beta-D)%(4*N)==0
    for A,B,C,red in nsystem(N,D,beta):
        if red!=label:continue
        q=BinaryQF([A,B,C]);reduced,T=q.reduced_form(transformation=True)
        assert tuple(reduced)==label and T.det()==1
        # Verify coefficient action independently of BinaryQF.matrix_action_right.
        p,q1,r,s=T.list()
        transformed=(A*p*p+B*p*r+C*r*r,
                     2*A*p*q1+B*(p*s+q1*r)+2*C*r*s,
                     A*q1*q1+B*q1*s+C*s*s)
        assert transformed==label
        assert A%N==0 and B%(2*N)==beta and gcd([A//N,B,C*N])==1
        return (A,B,C),T
    raise ValueError('Not an eligible reduced proper class')

def arguments(bound=60):
    for p in selection(bound):
        for A,B,C,label in nsystem(p['N'],p['D'],p['beta']):
            yield dict(p,a=int(label[0]),b=int(label[1]),c=int(label[2]))

class IndividualEvaluator(Evaluator):
    @lru_cache(None)
    def individual(self,D,beta,a,b,c):
        N=self.N;C,R=self.C,self.R
        form,T=representative(N,D,beta,(a,b,c));A,B,Cc=form
        w1,w2,delta,kappa,lam,r,s=self.periods()
        tau=C(-QQ(B)/(2*A),R(-D).sqrt()/(2*A))
        raw=self.primitive(tau)
        v=raw.imag()/w2.imag();u=(raw.real()-v*w2.real())/w1.real()
        ku=unique_floor(u+R(1)/2);kv=unique_floor(v+R(1)/2)
        ur=u-ku;vr=v-kv
        assert ur.lower()>-QQ(1)/2 and ur.upper()<QQ(1)/2
        assert vr.lower()>-QQ(1)/2 and vr.upper()<QQ(1)/2
        z=raw-ku*w1-kv*w2
        assert z.real().is_finite() and z.imag().is_finite()
        # Do not discard a component or infer a zero from its midpoint.
        assert not z.real().contains_zero() and not z.imag().contains_zero()
        evidence=dict(form=form,level_to_reduced=T,raw=raw,u=u,v=v,shifts=(ku,kv),reduced_u=ur,reduced_v=vr,periods=(w1,w2))
        return z,evidence