generate.py

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

5954 bytes, as of the version from 2026-11-20 09:32 (current). Recorded here, not run.

"""T775: Minimal polynomials of CM coefficients of the mirror quartic K3 family.

Requires SageMath (PARI, polynomial factorization and real Arb) and numberdb.
    sage -pip install numberdb
    sage -python generate.py                 # verify, no writes by default
    sage -python generate.py --publish       # fill an authorized existing draft

The only parameter is the positive integer r, tau=i*sqrt(r), discriminant -4r.
The monic polynomial is over QQ in x, for the positive coefficient t_r, not -4*t_r.
Default selection: all 1<=r<=10, retaining square factors and conductors.

Exact construction: H=polclass(-4*r), m=4096/R, j=(m+16)^3/m, and
256*t^4*m=m^2+128*m+4096. Rational resultants and irreducible factorization
produce candidates. A bounded eta product at >=600 bits excludes every wrong
factor and identifies the positive embedding. Exact endpoint signs and a
nonvanishing derivative certify a unique simple root in the saved bracket.
The CM theorem and exact modular identities, not a small residual, establish
annihilation. Factor degrees are not assumed from the transformed polynomial.

The positive log-product tail after N terms is <=q^(N+1)/(1-q), where
q=exp(-2*pi*sqrt(r)). Arb propagates this bound through both square roots.
The eta routine reuses the checked implementation attached to T774, with new
exact elimination and explicit excluded-factor evidence. No sibling values
are inputs. See mathematical-checks.md for sources and limitations.
Credentials and agent/model provenance belong in the calling environment.
"""
import os
import sys
import re
from functools import lru_cache
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.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.libs.pari import pari

S = PolynomialRing(QQ, 'x')
x = S.gen()


def positive_index(r):
    if isinstance(r, str):
        if not re.fullmatch(r'[1-9][0-9]*', r):
            raise ValueError('r must be a positive integer')
        r = ZZ(r)
    if isinstance(r, float) or ZZ(r) != r or ZZ(r) <= 0:
        raise ValueError('r must be a positive integer')
    return ZZ(r)


@lru_cache(maxsize=256)
def eta_quotient(r, working_bits=600):
    r = positive_index(r)
    B = RealBallField(working_bits)
    q = (-2 * B.pi() * B(r).sqrt()).exp()
    total = B(0)
    power = q
    n = 0
    while True:
        n += 1
        total += (1 + power).log()
        power *= q
        tail = power / (1-q)
        if tail < B(2)**(-working_bits-24):
            break
    total = total.add_error(tail)
    R = (-24*total).exp()/q
    if not R.is_finite() or not R > 0:
        raise ArithmeticError('Invalid eta quotient enclosure')
    return R, n, tail


def coefficient(r, working_bits=600):
    R, _, _ = eta_quotient(positive_index(r), working_bits)
    t = ((R+128+4096/R)/256).sqrt().sqrt()
    if not t.is_finite() or not t > 1 or t.accuracy() < 450:
        raise ArithmeticError('Positive branch is not sufficiently isolated')
    return t


def choose_factor(poly, enclosure):
    factors = [f.monic() for f, multiplicity in poly.factor()]
    compatible = [f for f in factors if f(enclosure).contains_zero()]
    if len(compatible) != 1:
        raise ArithmeticError('Embedding does not isolate exactly one irreducible factor')
    chosen = compatible[0]
    excluded = [str(f) for f in factors if f != chosen]
    assert all(not f(enclosure).contains_zero() for f in factors if f != chosen)
    return chosen, excluded


@lru_cache(maxsize=256)
def minimal_polynomial_with_evidence(r, working_bits=600):
    r = positive_index(r)
    H = S(pari(-4*r).polclass())
    P = PolynomialRing(QQ, 'm')
    m = P.gen()
    h = H.degree()
    E = sum((H[i]*(m+16)**(3*i)*m**(h-i) for i in range(h+1)), P(0))
    R, terms, tail = eta_quotient(r, working_bits)
    mb = 4096/R
    f, excluded_m = choose_factor(E, mb)
    A = PolynomialRing(S, 'm')
    mm = A.gen()
    resultant = S(A(f.list()).resultant(256*x**4*mm-(mm**2+128*mm+4096)))
    t = coefficient(r, working_bits)
    M, excluded_t = choose_factor(resultant, t)
    assert M.base_ring() is QQ and M.is_monic() and M.is_irreducible()
    lo, hi = t.lower().exact_rational(), t.upper().exact_rational()
    assert lo > 1 and M(lo)*M(hi) < 0
    assert not M.derivative()(t).contains_zero()
    evidence = {'r':int(r), 'discriminant':int(-4*r), 'class_number':int(h),
                'class_polynomial':str(H), 'eta_m_polynomial':str(E),
                'selected_m_factor':str(f), 'excluded_m_factors':excluded_m,
                'resultant':str(resultant), 'excluded_t_factors':excluded_t,
                'minimal_polynomial':str(M), 'degree':int(M.degree()),
                'root_lower':str(lo), 'root_upper':str(hi),
                'opposite_exact_endpoint_signs':True, 'derivative_excludes_zero':True,
                'working_bits':working_bits, 'eta_terms':terms,
                'eta_tail_bound':str(tail), 'eta_accuracy_bits':int(t.accuracy()),
                'native_type':type(M).__name__}
    return M, evidence


def minimal_polynomial(r):
    return minimal_polynomial_with_evidence(positive_index(r))[0]


class MirrorQuarticCMMinimalPolynomials(numberdb.Generator):
    table = 'T775'
    parameters = ('r',)
    type = 'Q[]'
    digits = 100
    rigour = 'exact'

    def enumerate(self, limit=10):
        for r in range(1, int(limit)+1):
            yield {'r':r}

    def value(self, params, digits):
        return minimal_polynomial(params['r'])


if __name__ == '__main__':
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        numberdb.configure(api_key=sys.stdin.read().strip())
    generator = MirrorQuarticCMMinimalPolynomials()
    if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(generator.publish())
    else:
        print(generator.verify(sample=None))