generate.py

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

3627 bytes, as of the version from 2026-10-28 15:38 (current). Recorded here, not run.

"""Hardy Z-function derivatives at Riemann zeta zeros -- numberdb.org/T584.

Run with SageMath (exact tested versions are in numerical-evidence.json):
    sage -pip install numberdb
    sage -python generate.py                 # verify the stored draft/table
    sage -python checks.py                   # independent checks, no writes

Download hardy_arb.pyx beside this file. Sage compiles this small bridge to
FLINT on first use; a working Sage Cython compiler is required. To send values
to an authorized draft, set NUMBERDB_API_KEY and NUMBERDB_FILL_DRAFT=1.
This does not offer, review or publish the draft.

FLINT isolates the nth zeta zero and evaluates the Taylor jet of Hardy Z on
its entire enclosing ball. Multiplication by k! produces actual derivatives.
All signs are retained. The 160-bit guard is assessed in numerical-evidence.json.
The phase convention, selection and cutoff rationale are in argument-selection.md.
"""
import os
import sys
from functools import lru_cache
from math import factorial
from pathlib import Path
import numberdb.sage as numberdb
from sage.misc.cython import cython_import
from sage.rings.rational_field import QQ

WORKING_GUARD = 160
ZERO_INDICES = tuple(range(1, 101)) + (6709, 6710)
DERIVATIVE_ORDERS = (1, 2, 3)

@lru_cache(maxsize=1)
def bridge():
    return cython_import(str(Path(__file__).with_name('hardy_arb.pyx')))

@lru_cache(maxsize=None)
def compute_zero(n, digits):
    prec = numberdb.bits(digits, losing=WORKING_GUARD)
    rho = bridge().zero(int(n), prec)
    assert rho.real() == QQ(1) / 2
    gamma = rho.imag()
    assert gamma.is_finite() and gamma > 0
    coefficients = bridge().jet(gamma, 4, prec)
    assert (coefficients[0].real().is_finite() and coefficients[0].imag().is_finite()) and coefficients[0].contains_zero()
    derivatives = []
    for k in DERIVATIVE_ORDERS:
        coefficient = coefficients[k]
        assert (coefficient.real().is_finite() and coefficient.imag().is_finite()) and coefficient.imag().contains_zero()
        value = coefficient.real() * factorial(k)
        assert value.accuracy() >= numberdb.bits(digits) + 24
        derivatives.append(value)
    # Nonzero Z' on the root enclosure also certifies simplicity there.
    assert not derivatives[0].contains_zero()
    return gamma, tuple(derivatives)

class HardyZDerivatives(numberdb.Generator):
    table = 'T584'
    parameters = ('n', 'k')
    type = 'R'
    digits = 100
    rigour = 'proven'
    files = ('generate.py', 'hardy_arb.pyx', 'checks.py', 'check.py',
             'argument-selection.md', 'numerical-evidence.json', 'skill-manifest.json')

    def enumerate(self):
        for n in ZERO_INDICES:
            for k in DERIVATIVE_ORDERS:
                yield {'n': str(n), 'k': str(k)}

    def value(self, params, digits):
        n, k = int(params['n']), int(params['k'])
        if k not in DERIVATIVE_ORDERS:
            raise ValueError('This implementation supports derivative orders 1, 2, 3')
        return compute_zero(n, digits)[1][k-1]

if __name__ == '__main__':
    if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
        key = sys.stdin.read().strip()
        if '=' in key: key = key.split('=', 1)[1].strip().strip('\"\'')
        os.environ['NUMBERDB_API_KEY'] = key
    generator = HardyZDerivatives()
    if os.environ.get('NUMBERDB_FILL_DRAFT') == '1' or os.environ.get('NUMBERDB_PUBLISH') == '1':
        print(generator.publish(message='Store 306 certified signed Hardy Z derivatives with reproducible checks'))
    else:
        report = generator.verify(sample=None)
        print(report)
        sys.exit(0 if report.ok else 1)