"""T769: Elliptic logarithms of individual Heegner points on genus-one modular curves.

Install SageMath 10.9 and numberdb, and keep individual.py and heegner.py beside
this file. The heegner.py helper is reused verbatim from T732 with its legacy
attribution; source hashes and its role are recorded in research.md.
    sage -pip install numberdb
    sage -python generate.py            # read-only full reproduction check
    sage -python generate.py --publish  # fill the authorized private draft

Parameters (N,D,beta,a,b,c) identify each proper class by its reduced primitive
positive-definite form. Defaults exhaust all twelve genus-one levels and every
eligible fundamental |D|<=60, orientation and proper class: 468 individual points.
The full integral homology period lattice and normalized weight-two form are
computed directly on X_0(N), not inferred from an isogenous curve. Elliptic-curve
point counts provide exact coefficients, identified by a Sturm-bound comparison.
Arb balls at 560 bits propagate the quadratic argument, primitive tail
2*r^(M+1)/(1-r), full periods, and lattice reduction. No class sum, averaging,
coordinate reconstruction or exact-zero snapping is used. All current coordinates
are strictly separated from the half-open reduction boundary. BoundaryError on a
new case requires an exact symmetry argument or more precision, never a midpoint
choice. The command writes entries additively and neither offers nor publishes.
"""
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from individual import IndividualEvaluator, arguments
from functools import lru_cache

class IndividualHeegnerLogarithms(numberdb.Generator):
    table='T769'
    parameters=('N','D','beta','a','b','c')
    type='C'
    digits=100
    rigour='proven'
    files=('generate.py','individual.py','heegner.py')
    @staticmethod
    @lru_cache(None)
    def evaluator(N,digits):
        return IndividualEvaluator(int(N),max(560,numberdb.bits(digits,losing=200)))
    def enumerate(self,bound=60):
        yield from arguments(bound)
    def value(self,params,digits):
        N,D,beta,a,b,c=(int(params[k]) for k in self.parameters)
        return self.evaluator(N,digits).individual(D,beta,a,b,c)[0]

if __name__=='__main__':
    import sys,os
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN')=='1':
        numberdb.configure(api_key=sys.stdin.read().strip())
    g=IndividualHeegnerLogarithms()
    if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH')=='1':
        message=os.environ.get('NUMBERDB_EDIT_MESSAGE','')
        g.publish(removing=False,message=message)
    else:
        print(g.verify(sample=None))
