generate.py

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

3476 bytes, as of the version from 2026-11-28 02:00 (current). Recorded here, not run.

"""Generator for T840: p-adic Jacobi sums of Teichmuller-character powers.

Install SageMath 10.9 or later, then install the client and run with:
    sage -pip install numberdb
    sage -python generate.py                 # preview, no write
    sage -python generate.py --verify        # all stored entries
    sage -python generate.py --publish       # fill the already authorized draft
Credentials and NUMBERDB_ENGINE/MODEL/RUN_ID belong in the session environment.
The default selection is all nondegenerate unordered pairs whose individual
character orders are <=12 at primes 5<=p<=43. Product order is unrestricted.
Each Teichmuller lift is computed in Qp at n+8 absolute digits; finite sums
and inverse powers of units carry their own precision, with no analytic tail.
Retain n=max(100,ceil(log_p(10^digits))) relative digits and N=n+valuation
absolute digits. Integer comparisons compute n without floating logarithms.
Sources: Young, p-adic hypergeometric functions, p.3 (2.5)-(2.9), with the
opposite Jacobi sign; Gross-Koblitz, Ann. Math.109 (1979), pp.569-570.
"""
import argparse
from functools import lru_cache
from math import gcd
import os

import numberdb.sage as numberdb
from sage.rings.padics.factory import Qp


def is_prime(p):
    return p >= 2 and all(p % k for k in range(2, 1 + __import__('math').isqrt(p)))


def relative_precision(p, digits=100):
    n = 100
    while p**n < 10**digits:
        n += 1
    return n


@lru_cache(maxsize=None)
def teichmuller_data(p, digits):
    n = relative_precision(p, digits)
    field = Qp(p, n + 8, print_mode='terse')
    lifts = {x: field.teichmuller(x) for x in range(1, p)}
    for x, lift in lifts.items():
        assert int(lift.residue()) == x and lift**(p-1) == 1
        assert int(lift.precision_absolute()) >= n + 8
    return field, lifts


class JacobiSums(numberdb.Generator):
    table = 'T840'
    parameters = ('p', 'a', 'b')
    type = 'Qp'
    digits = 100
    rigour = 'proven'
    files = ('generate.py',)

    def enumerate(self):
        for p in range(5, 44):
            if not is_prime(p):
                continue
            exponents = [a for a in range(1, p-1) if (p-1)//gcd(a, p-1) <= 12]
            for a in exponents:
                for b in exponents:
                    if a <= b and (a+b) % (p-1):
                        yield {'p': p, 'a': a, 'b': b}

    def value(self, params, digits):
        p, a, b = (int(params[k]) for k in self.parameters)
        assert is_prime(p) and p >= 5 and 1 <= a <= b <= p-2 and (a+b) % (p-1)
        field, lifts = teichmuller_data(p, int(digits))
        result = sum((lifts[x]**(-a) * lifts[(1-x) % p]**(-b)
                      for x in range(2, p)), field(0))
        valuation = (a+b)//(p-1)
        n = relative_precision(p, int(digits))
        assert int(result.valuation()) == valuation
        assert int(result.precision_absolute()) >= n + valuation
        result = result.add_bigoh(n + valuation)
        assert int(result.precision_relative()) == n
        return result


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--publish', action='store_true')
    parser.add_argument('--verify', action='store_true')
    args = parser.parse_args()
    generator = JacobiSums()
    if args.publish:
        print(generator.publish(removing=False))
    elif args.verify:
        print(generator.verify(sample=None))
    else:
        print(generator.preview())