generate.py

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

2648 bytes, as of the version from 2026-11-26 12:33 (current). Recorded here, not run.

"""T818: denominator-cleared type R_I q-Lommel polynomials.

Requires numberdb and SageMath (or passagemath with polynomial/Singular support).
    sage -pip install numberdb
    sage -python generate.py                 # preview; no writes
    sage -python generate.py --verify        # check every stored entry
    sage -python generate.py --publish       # fill the authorized target draft

The default prefix is n=0,...,5. All x,c,q coefficients are retained exactly
in ZZ[x,c,q], in that variable order. The recurrence is Definition 2.4 of
Kim--Stanton, arXiv:2105.10096v2, multiplied by (c;q)_(n+1).
There is no floating-point arithmetic, branch selection or precision parameter
in this exact computation. --publish writes entries; it does not offer or
publish a table. Credentials/provenance belong to the caller's environment.
"""
import argparse
from functools import lru_cache
import os
import sys
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', 'c', 'q'))
x, c, q = P.gens()
DEFAULT_MAX_N = 5

@lru_cache(None)
def polynomial(n):
    n = int(n)
    if n < 0:
        raise ValueError('n must be nonnegative')
    if n == 0:
        return P.one()
    if n == 1:
        return (1-c)*x-1
    j = n-1
    return ((1-c*q**j)*x-q**j)*polynomial(j) - c*q**(2*j-1)*x*polynomial(j-1)

class TypeRIQLommel(numberdb.Generator):
    table = 'T818'
    parameters = ('n',)
    type = 'Z[]'
    rigour = 'exact'
    digits = 100  # ignored for exact polynomial output

    def enumerate(self, max_n=DEFAULT_MAX_N):
        for n in range(int(max_n)+1):
            yield {'n': n}

    def value(self, params, digits):
        return polynomial(int(params['n']))

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--publish', action='store_true')
    parser.add_argument('--verify', action='store_true')
    parser.add_argument('--max-n', type=int, default=DEFAULT_MAX_N)
    args = parser.parse_args()
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN'):
        os.environ['NUMBERDB_API_KEY'] = sys.stdin.read().strip()
    generator = TypeRIQLommel()
    if args.verify:
        print(generator.verify(sample=None, max_n=args.max_n))
    elif args.publish or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(generator.publish(max_n=args.max_n, removing=False,
                                message=os.environ.get('NUMBERDB_EDIT_MESSAGE','Fill exact type R_I q-Lommel polynomials')))
    else:
        print(generator.preview(max_n=args.max_n))