stored_check.py

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

2603 bytes, as of the version from 2026-11-15 23:03 (current). Recorded here, not run.

"""Verify T718's actual stored intervals against saved independent 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 key is needed only while this table remains a private draft. It is sent
only to NumberDB's authenticated API and never printed or stored.
"""
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 main():
    key=sys.stdin.read().strip()
    if '=' in key and key.split('=',1)[0].isidentifier():
        key=key.split('=',1)[1].strip().strip('\"\'')
    client=Client(api_key=key or None,timeout=60)
    doc=numberdb.table('T718',client=client)
    stored=_stored_entries(doc)
    saved=json.loads(Path(__file__).with_name('theta-checkpoints.json').read_text())
    assert set(stored)=={f"{row['D']},{n}" for row in saved for n in range(1,21)}
    ctx.prec=512
    failures=[];checked=0;mindigits=10000
    for row in saved:
        for n,data in enumerate(row['values'],1):
            text=stored[f"{row['D']},{n}"]
            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,365) and x>low and x<high
            if not okay:failures.append({'D':row['D'],'n':n,'stored':text,'theta':str(x)})
            else:checked+=1
            mindigits=min(mindigits,digits_of(text))
    first=saved[0];centre,radius=_claim(stored[f"{first['D']},1"])
    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.transform_controls()['known_answer_control']
    out={'checked_entries':checked,'total_entries':len(stored),'failures':failures,
         'minimum_stored_significant_digits':mindigits,
         'comparison':'entire independent theta enclosure inside exact stored decimal interval',
         'known_answer_control':known,'negative_control_rejected':negative}
    print('READBACK '+json.dumps(out),flush=True)
    assert not failures and checked==520 and mindigits>=100 and known and negative

if __name__=='__main__':main()