generate.py

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

2460 bytes, as of the version from 2026-12-02 04:01 (current). Recorded here, not run.

"""Reproduce Porter's constant in NumberDB T886.

Install SageMath, then run:
    sage -pip install numberdb
    sage -python generate.py
    sage -python generate.py --publish
The default verifies all stored entries; --publish fills only this existing
private draft when authorized. Configure a NumberDB key for draft access.

There are no input parameters: enumerate one empty mapping. The value counts
the initial zero in a canonical rational simple continued fraction, whose last
partial quotient is at least 2. Use natural logarithms and the fixed-denominator
mean, not an average over all denominators below a bound.

Ustinov (2008), Izvestiya: Mathematics 72(5), p. 1024, gives
 C_P = log(2)/zeta(2)*(3*log(2)+4*gamma-4*zeta'(2)/zeta(2)-2)-1/2.
DOI: 10.1070/IM2008v072n05ABEH002427.
Sage RealBall.zetaderiv(1) evaluates the derivative with Arb; every constant,
logarithm and subsequent operation carries an enclosure. At 100 requested
significant digits, 512 working bits give a final radius below 10^-150;
check-evidence.json records exact outward endpoints and containment in the
serialized 100-digit interval. The guard grows for larger requests.
"""
import os
import sys
import numberdb.sage as numberdb
from sage.rings.real_arb import RealBallField
from sage.rings.rational_field import QQ


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

    def enumerate(self):
        yield {}

    def value(self, params, digits):
        if params:
            raise ValueError("Porter's constant has no parameters")
        R = RealBallField(max(512, numberdb.bits(digits, losing=128)))
        log2 = R(2).log()
        zeta2 = R(2).zeta()
        derivative = R(2).zetaderiv(1)
        result = log2 / zeta2 * (
            3 * log2 + 4 * R.euler_constant() - 4 * derivative / zeta2 - 2
        ) - R(1) / 2
        if not result.is_finite() or not (0 < result.rad().exact_rational() < QQ(1) / 10 ** (digits + 20)):
            raise ArithmeticError('Nonfinite or insufficiently narrow enclosure')
        return result


if __name__ == '__main__':
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        numberdb.configure(api_key=sys.stdin.read().strip())
    generator = PorterConstant()
    if '--publish' in sys.argv or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(generator.publish())
    else:
        print(generator.verify(sample=None))