stored_check.py

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

2626 bytes, as of the version from 2026-11-15 20:42 (current). Recorded here, not run.

"""Check T719's stored intervals against independently computed theta balls.

Install Sage, numberdb and python-flint. Download this file, theta_check.py
and theta-checkpoints.json from the same revision, then run:
    cat /private/path/to/your-key | sage -python stored_check.py
The private-draft key is used only for NumberDB's authenticated API.
The independently computed balls must fit wholly in the stored decimal
intervals, and must be finite and sufficiently narrow before comparison.
"""
import sys,json
from pathlib import Path
from fractions import Fraction
import numberdb.sage as numberdb
from numberdb import Client
from numberdb._generate import _stored_entries
from numberdb._compare import _claim,digits_of
from flint import arb,ctx
import theta_check


def run(client):
    doc=numberdb.table('T719',client=client)
    stored=_stored_entries(doc)
    saved=json.loads(Path(__file__).with_name('theta-checkpoints.json').read_text())
    assert set(stored)=={f"{row['D']},{m}" for row in saved for m in range(21)}
    ctx.prec=640;failures=[];checked=0;mindigits=10000
    for row in saved:
        for m,data in enumerate(row['values']):
            text=stored[f"{row['D']},{m}"]
            centre,radius=_claim(text);C,R=Fraction(centre),Fraction(radius)
            lo,hi=C-R,C+R;x=theta_check.decode(data)
            low=arb(lo.numerator)/lo.denominator;high=arb(hi.numerator)/hi.denominator
            okay=theta_check.narrow(x,390) and x>low and x<high
            if not okay:failures.append({'D':row['D'],'m':m,'stored':text,'theta':str(x)})
            else:checked+=1
            mindigits=min(mindigits,digits_of(text))
    first=saved[0];centre,radius=_claim(stored[f"{first['D']},0"])
    upper=Fraction(centre)+Fraction(radius)
    shifted=theta_check.decode(first['values'][0])+arb(10)**-60
    negative=bool(shifted>arb(upper.numerator)/upper.denominator)
    known=theta_check.controls()['known_answer_control']
    out={'checked_entries':checked,'total_entries':len(stored),'failures':failures,
         'minimum_stored_significant_digits':mindigits,
         'comparison':'entire independent theta ball inside exact stored decimal interval',
         'known_answer_control':known,'negative_control_rejected':negative}
    assert not failures and checked==546 and mindigits>=100 and known and negative
    return out


def main():
    key=sys.stdin.read().strip()
    if '=' in key and key.split('=',1)[0].isidentifier():key=key.split('=',1)[1].strip().strip('"\'')
    print('READBACK '+json.dumps(run(Client(api_key=key or None,timeout=60))),flush=True)

if __name__=='__main__':main()