generate.py

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

3049 bytes, as of the version from 2026-12-01 00:22 (current). Recorded here, not run.

"""Reproduce NumberDB T879: logarithmic denominator exponents.

Requires SageMath with real Arb and numberdb:
    sage -pip install numberdb
    sage -python generate.py              # compute; no writes
    sage -python generate.py --verify     # check every stored entry
    sage -python generate.py --publish    # fill an authorized target only

For each integer dimension d>=2 this computes Q((d-1)/log(d)), where
Q(u)=u*log(u)-u+1 and every logarithm is natural. The default enumeration
is every d=2,...,100. Dimension 100 is a finite reference budget, not a
mathematical boundary. No continuous parameters are selected.

Arb balls propagate the exact integer input through both logarithms and
all arithmetic. At 100 significant digits 512 working bits are used;
o rounded intermediate argument is imported. independent_check.py uses
an independently implemented, rigorously bounded rational log series.
Credentials and session provenance are supplied by the caller.
"""
import argparse
import os
import numberdb.sage as numberdb
from numberdb._write import to_text
from sage.rings.integer_ring import ZZ
from sage.rings.real_arb import RealBallField


class MultiplicationExponents(numberdb.Generator):
    table = 'T879'
    parameters = ('d',)
    type = 'R'
    digits = 100
    rigour = 'proven'

    def enumerate(self):
        for d in range(2, 101):
            yield {'d': d}

    def value(self, params, digits):
        if set(params) != {'d'}:
            raise ValueError('Exactly one dimension d is required.')
        raw = params['d']
        if isinstance(raw, (float, bool)):
            raise ValueError('Dimension must be an exact integer.')
        d = ZZ(raw)
        if str(d) != str(raw) or d < 2:
            raise ValueError('The dimension is an integer d>=2.')
        field = RealBallField(max(512, numberdb.bits(digits, losing=160)))
        u = field(d-1) / field(d).log()
        result = u*u.log() - u + 1
        if not result.is_finite() or result.rad() <= 0:
            raise ArithmeticError('Expected a finite nonzero-width ball.')
        if result.accuracy() < numberdb.bits(digits, losing=10):
            raise ArithmeticError('Insufficient relative accuracy.')
        return result


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    actions = parser.add_mutually_exclusive_group()
    actions.add_argument('--publish', action='store_true')
    actions.add_argument('--verify', action='store_true')
    opts = parser.parse_args()
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        import sys
        os.environ['NUMBERDB_API_KEY'] = sys.stdin.read().strip()
    gen = MultiplicationExponents()
    if opts.publish or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(gen.publish(message=os.environ.get('NUMBERDB_EDIT_MESSAGE', ''), removing=False))
    elif opts.verify:
        print(gen.verify(sample=None))
    else:
        for params in gen.enumerate():
            print(params['d'], to_text(gen.value(params,gen.digits),gen.digits))