generate.py

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

3869 bytes, as of the version from 2026-10-25 19:33 (current). Recorded here, not run.

"""Landau–Kolmogorov constants on the real line -- numberdb.org/T500.

Run with SageMath or passagemath and the numberdb client installed:
    sage -pip install numberdb
    sage -python generate.py             # verify every stored entry
    sage -python checks.py               # independent local checks, no key
    sage -python generate.py --fill      # write entries with NUMBERDB_API_KEY

A draft also needs its owner's key for verification. The --fill option writes
entries to the existing table; it does not publish or offer the draft.

Convention: the optimal L-infinity constant on the entire real line, with
1 <= k < n, in ||f^(k)|| <= C(n,k) ||f||^(1-k/n) ||f^(n)||^(k/n).
The complete triangle 2 <= n <= 20 covers low and moderate derivative orders.
Kolmogorov's formula is C(n,k) = K_(n-k) / K_n^((n-k)/n).
Favard constants are evaluated by Riemann and Hurwitz zeta in Arb, never by
truncating their slowly convergent defining series. All divisions entering
exponents are rational. The 64 guard bits give a 397-bit computation at 100
requested digits; checks.py measures the actual enclosure widths over the
whole range. Exact Euler-spline arithmetic independently proves that none of
these 190 entries is rational, so each is stored as a certified decimal.
"""
import os
import sys
from functools import lru_cache

import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.real_arb import RealBallField

WORKING_GUARD = 64
MAX_N = 20


@lru_cache(maxsize=None)
def favard(r, precision):
    if r < 0:
        raise ValueError('The Favard index must be nonnegative.')
    R = RealBallField(precision)
    if r == 0:
        return R(1)
    s = r + 1
    if r % 2:
        series = (1 - R(2)**(-s)) * R(s).zeta()
    else:
        series = R(4)**(-s) * (
            R(s).zeta(R(QQ(1)/4)) - R(s).zeta(R(QQ(3)/4)))
    return 4 * series / R.pi()


def constant(n, k, digits=100):
    n, k = int(n), int(k)
    if not 1 <= k < n:
        raise ValueError('The indices must satisfy 1 <= k < n.')
    precision = numberdb.bits(digits, losing=WORKING_GUARD)
    return favard(n-k, precision) / favard(n, precision)**(QQ(n-k)/n)


class LandauKolmogorov(numberdb.Generator):
    table = 'T500'
    parameters = ('n', 'k')
    type = 'R'
    digits = 100
    rigour = 'proven'
    files = ('generate.py', 'checks.py', 'check.py', 'euler-controls.json', 'preflight.json')

    def enumerate(self, max_n=MAX_N):
        for n in range(2, max_n + 1):
            for k in range(1, n):
                yield {'n': n, 'k': k}

    def value(self, params, digits):
        n, k = int(params['n']), int(params['k'])
        result = constant(n, k, digits)
        comments = {
            (2, 1): r'$C(2,1)=\sqrt{2}$, the sharp real-line Landau inequality.',
            (3, 1): r'$C(3,1)=(9/8)^{1/3}$. Its decimal expansion is CITE{OEIS}.',
            (3, 2): r'$C(3,2)=3^{1/3}$.',
            (4, 1): r'$C(4,1)=(512/375)^{1/4}$.',
            (4, 2): r'$C(4,2)=\sqrt{6/5}$.',
            (4, 3): r'$C(4,3)=(24/5)^{1/4}$.',
        }
        return {'number': result, 'comment': comments[(n, k)]} if (n, k) in comments else result


def configure_from_stdin():
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        token = sys.stdin.read().strip()
        if '=' in token and token.split('=', 1)[0].isupper():
            token = token.split('=', 1)[1].strip().strip('\'"')
        numberdb.configure(api_key=token)


if __name__ == '__main__':
    configure_from_stdin()
    generator = LandauKolmogorov()
    if '--fill' in sys.argv or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(generator.publish(message='Fill 190 certified constants, independently checked using exact Euler splines.'))
    else:
        report = generator.verify(sample=None)
        print(report)
        sys.exit(0 if report.ok else 1)