generate.py

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

1759 bytes, as of the version from 2026-12-02 03:19 (current). Recorded here, not run.

"""T908: Gelfond constant.

Install numberdb into Sage, then run:
    sage -pip install numberdb
    sage -python generate.py
    NUMBERDB_API_KEY=... sage -python generate.py --publish

The default command verifies all stored values and never writes. The explicit
--publish option fills the assigned table; it does not offer or publish a draft.
No parameters are sampled: enumerate() yields one empty mapping and value()
returns the positive real number exp(pi) itself. Sage's Arb-backed real balls
enclose both pi and its exponential. At 100 requested significant digits the
working precision is 512 bits, measured to retain 509 relative accuracy bits.
For higher requested precision the working field grows with a 96-bit guard.
"""

import argparse
import os
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField


class GelfondConstant(numberdb.Generator):
    table = 'T908'
    parameters = ()
    type = 'R'
    digits = 100
    rigour = 'proven'

    def enumerate(self):
        yield {}

    def value(self, params, digits):
        if params:
            raise ValueError('Gelfond constant has no parameters')
        field = RealBallField(max(512, numberdb.bits(digits, losing=96)))
        result = field.pi().exp()
        if not result.is_finite() or result.accuracy() < numberdb.bits(digits):
            raise ArithmeticError('Insufficient finite enclosure accuracy')
        return result


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument('--publish', action='store_true')
    options = parser.parse_args()
    generator = GelfondConstant()
    if options.publish:
        print(generator.publish())
    else:
        print(generator.verify(sample=None))