back to table · edit · history · where entries came from · files · download
6111 bytes, as of the version from 2026-11-27 13:58 (current). Recorded here, not run.
"""Reproduce the zeros of parabolic Riley polynomials for NumberDB (T827).
Requirements: SageMath (tested 10.9), numberdb (tested 0.1.10).
sage -pip install numberdb
sage -python generate.py # preview, writes nothing
sage -python generate.py --publish # fill the assigned private draft
sage -python generate.py --verify # compare all stored entries
The ordered parameters p,q,k use odd p>=3, odd 0<q<p, gcd(p,q)=1,
and 1<=k<=(p-1)//2. Default coverage is p<=25, with EVERY q and root.
The bridge meridians are A=[[1,1],[0,1]], B=[[1,0],[x,1]], and the
word alternates A^epsilon_j, B^epsilon_j, epsilon_j=(-1)^floor(j*q/p).
Phi is W[0,0], without factor removal. Roots are ordered by exact real,
then exact imaginary part, increasing; both conjugates are retained.
Exact polynomial arithmetic and QQbar certified algebraic root isolation
establish the roots. Component equality and ordering use exact algebraic arithmetic. Rational
components must be half-integers by algebraic integrality, and candidates
are tested exactly; this is a filter, never a rounding assumption. Rational components stay exact. Other components are
outward enclosures at at least 440 bits for the default 100 decimal digits.
The client writes a 100-significant-digit decimal with last-place uncertainty.
The independent check_zeros.py uses a continuant determinant, exact Sturm
counts, and rational Rouche disks rather than trusting these isolated roots.
"""
import os
import sys
from functools import lru_cache, cmp_to_key
from fractions import Fraction
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing
from sage.rings.qqbar import QQbar
import sage.rings.qqbar as qqbar_module
from sage.rings.real_mpfi import RealIntervalField
# A modular Sage initialization does not run sage.all's late QQbar setup.
if not hasattr(qqbar_module, 'QQbar_I'):
qqbar_module._init_qqbar()
P = PolynomialRing(ZZ, 'x')
x = P.gen()
@lru_cache(maxsize=None)
def polynomial(p, q):
p, q = int(p), int(q)
if p < 3 or p % 2 != 1 or not (0 < q < p) or q % 2 != 1 or ZZ(p).gcd(q) != 1:
raise ValueError('outside the marked Schubert domain')
# First row of the literal word matrix. Multiplication by A updates b;
# multiplication by B updates a. Both remain in ZZ[x].
a, b = P.one(), P.zero()
for j in range(1, p):
e = 1 if (j * q // p) % 2 == 0 else -1
if j % 2:
b = b + e * a
else:
a = a + e * x * b
assert a.degree() == (p - 1) // 2
assert a.leading_coefficient() == 1 and a[0] == 1
assert a.gcd(a.derivative()) == 1
return a
def compare(a, b):
for av, bv in [(a.real(), b.real()), (a.imag(), b.imag())]:
if av < bv: return -1
if av > bv: return 1
return 0
@lru_cache(maxsize=None)
def roots_for_coefficients(coefficients):
f = P(list(coefficients))
rr = f.roots(QQbar, multiplicities=False)
# Sort one representative per conjugate pair. Conjugates have exactly
# equal real parts; asking a generic field comparator to rediscover this
# can create unnecessarily large composita.
representatives = [r for r in rr if r.imag() >= 0]
representatives.sort(key=cmp_to_key(compare))
ordered = []
start = 0
while start < len(representatives):
stop = start + 1
while stop < len(representatives) and representatives[stop].real() == representatives[start].real():
stop += 1
group = []
for r in representatives[start:stop]:
if r.imag() == 0:
group.append(r)
else:
group.extend([r.conjugate(), r])
group.sort(key=lambda a: a.imag())
ordered.extend(group)
start = stop
assert len(ordered) == f.degree()
return tuple(ordered)
def roots(p, q):
return roots_for_coefficients(tuple(polynomial(p,q).list()))
def component(a, digits):
F = RealIntervalField(max(440, numberdb.bits(digits, losing=100)))
interval = F(a)
lo, hi = interval.endpoints()
# Every root is an algebraic integer. Twice either real or imaginary
# component is an algebraic integer too. If rational it is an integer,
# hence the component must be a half-integer. This rules out rationality
# without constructing a minimal polynomial for a generic component.
first, last = (2*lo.exact_rational()).ceil(), (2*hi.exact_rational()).floor()
if first <= last:
assert first == last
candidate = QQ(first)/2
if a == candidate:
return Fraction(str(candidate))
assert lo < hi and not interval.is_NaN()
return numberdb.RealInterval(Fraction(str(lo.exact_rational())), Fraction(str(hi.exact_rational())))
class RileyZeros(numberdb.Generator):
table = os.environ.get('NUMBERDB_TABLE', 'T827')
parameters = ('p', 'q', 'k')
type = 'C'
digits = 100
rigour = 'proven'
def enumerate(self, p_max=25):
for p in range(3, p_max + 1, 2):
for q in range(1, p, 2):
if ZZ(p).gcd(q) == 1:
for k in range(1, (p - 1) // 2 + 1):
yield {'p':p, 'q':q, 'k':k}
def value(self, params, digits):
p, q, k = (int(params[name]) for name in self.parameters)
if not 1 <= k <= (p-1)//2: raise ValueError('invalid root index')
a = roots(p,q)[k-1]
re, im = component(a.real(),digits), component(a.imag(),digits)
if isinstance(im, Fraction) and im == 0:
return QQ(str(re)) if isinstance(re, Fraction) else re
return numberdb.ComplexInterval(re, im)
if __name__ == '__main__':
if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
numberdb.configure(api_key=sys.stdin.read().strip())
g = RileyZeros()
if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH') == '1':
g.publish()
elif '--verify' in sys.argv:
print(g.verify(sample=None))
else:
print(g.preview())