generate.py

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

2842 bytes, as of the version from 2026-11-27 13:33 (current). Recorded here, not run.

"""T828: Two-variable Riley polynomials of 2-bridge knots.

Requirements: SageMath and numberdb (sage -pip install numberdb).
  sage -python generate.py                 # compute and check the finite selection
  sage -python generate.py --verify        # reproduce every stored entry
  sage -python generate.py --publish       # fill the already authorized draft

The default command writes nothing. Parameters p,q name marked Schubert
presentations: p>=3 odd; 0<q<p odd; gcd(p,q)=1. All admissible q are retained.
The default prefix is p<=49. Integer polynomials in x,y are exact, with x the
positive lower-left matrix coordinate and y=x+(M-M^-1)^2. The scalar recurrence
is Jo--Kim, arXiv:2601.17433v1, Example 6.5 and Corollary 6.6. Its sign sequence
runs from the centre outwards, e_i=epsilon_(n+1-i), n=(p-1)/2. No floating
arithmetic, polynomial rescaling, factoring or removal of components is used.
"""
import os
import math
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.polynomial.polynomial_ring_constructor import PolynomialRing

P = PolynomialRing(ZZ, names=('x', 'y'))
x, y = P.gens()
P_MAX = 49


def riley(p, q):
    p, q = int(p), int(q)
    if not (p >= 3 and p % 2 == 1 and 0 < q < p and q % 2 == 1
            and math.gcd(p, q) == 1):
        raise ValueError('Expected odd p>=3, odd 0<q<p, gcd(p,q)=1')
    n = (p - 1) // 2
    e = [ZZ(-1)**((j*q)//p) for j in range(n, 0, -1)]
    f = [P.one(), 1+y]
    if n >= 2:
        f.append(y*y + 3*y + 1 if e[0] == e[1] else x*y-y+1)
    for k in range(3, n+1):
        if e[k-2] == e[k-1]:
            f.append((y+1)*(f[k-1]+f[k-2])-f[k-3])
        else:
            f.append((x-1)*(f[k-1]-f[k-2])+f[k-3])
    return f[n]


class RileyGenerator(numberdb.Generator):
    table = os.environ.get('NUMBERDB_TABLE', 'T828')
    parameters = ('p', 'q')
    type = 'Z[]'
    rigour = 'exact'
    digits = 100  # ignored for exact polynomial types

    def enumerate(self, p_max=P_MAX):
        for p in range(3, int(p_max)+1, 2):
            for q in range(1, p, 2):
                if math.gcd(p, q) == 1:
                    yield {'p': p, 'q': q}

    def value(self, params, digits=100):
        return riley(params['p'], params['q'])


if __name__ == '__main__':
    import sys
    g = RileyGenerator()
    if '--publish' in sys.argv:
        print(g.publish(message='Fill exact Riley polynomials; proposal https://github.com/numberdb/numberdb-data/issues/384'))
    elif '--verify' in sys.argv:
        print(g.verify(sample=None))
    else:
        values = [g.value(p) for p in g.enumerate()]
        assert len(values) == 255
        assert all(c.parent() is ZZ for f in values for c in f.coefficients())
        print('Computed 255 exact integer polynomials; run independent_check.py on a document export for mathematical checks.')