back to table · edit · history · where entries came from · files · download
5312 bytes, as of the version from 2026-10-24 22:26 (current). Recorded here, not run.
"""Reproduce T470 and check its prose repair -- https://numberdb.org/T470.
Run with SageMath after installing numberdb:
sage -pip install numberdb
sage -python check_repair.py
A draft requires NUMBERDB_API_KEY, or pipe its owner's key to stdin.
This script reads NumberDB, generates all 54 values in their existing range,
and checks them. It never writes or offers a draft. The generator's 100-digit
precision and 80 guard bits are reproduced from the table's Programs section.
The ellipse bounds must be finite, narrower than 1e-110 relative radius, and
strictly inside each stored last-place interval. Three known closed forms
are checked independently at 600 bits. Integer harmonic values in the linked
T247 are verified against exact sums. No replacement values are submitted.
"""
import json
import os
import sys
from decimal import Decimal
from urllib.request import build_opener, ProxyHandler, Request
import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.complex_arb import ComplexBallField
from sage.rings.real_arb import RealBallField
DIGITS = 100
GUARD_BITS = 80
def generate(region, n):
"""Generate the existing ratio using exact arithmetic or certified Arb."""
if region == 'equilateral-triangle':
return 1-QQ(2)/(n+1)*sum(QQ(1)/k for k in range(1,n+1))
if region == 'unit-square':
s=sum((1-QQ(1)/2**k)/k for k in range(1,n+2))
return 1-QQ(8)/(3*(n+1))*(s-QQ(1)/((n+1)*2**(n+1)))
assert region == 'unit-disk'
C=ComplexBallField(numberdb.bits(DIGITS, losing=GUARD_BITS))
pi=C.pi()
def integrand(u, analytic):
s=(pi*u).sin()
c=(pi*u).cos()
return s**4*(u-s*c/pi)**(n-1)
answer=1-C(8*n)/3*C.integral(integrand,0,1)
assert answer.real().is_finite() and answer.imag().is_finite()
assert answer.real()>0 and answer.real()<1
assert answer.imag()>-1 and answer.imag()<1 and answer.imag().contains_zero()
return answer.real()
def exact_decimal(s):
t=Decimal(s).as_tuple()
coefficient=int(''.join(map(str,t.digits))) * (-1 if t.sign else 1)
return QQ(coefficient)*QQ(10)**t.exponent
def interval(s):
center=exact_decimal(s)
ulp=QQ(10)**Decimal(s).as_tuple().exponent
return center-ulp, center+ulp
def number(row):
return row['number'] if isinstance(row,dict) else row
def fetch(tid, key):
headers={'Authorization':'Bearer '+key} if key else {}
opener=build_opener(ProxyHandler({}))
with opener.open(Request('https://numberdb.org/api/table?id='+tid,headers=headers),timeout=60) as r:
result=json.load(r)
assert 'error' not in result, result.get('error')
return result
def main():
key=os.environ.get('NUMBERDB_API_KEY') or (sys.stdin.read().strip() if not sys.stdin.isatty() else '')
doc=fetch('T470',key)
harmonic=fetch('T247',key)
assert list(doc['Parameters']) == ['region','n']
assert list(doc['Numbers']) == ['equilateral-triangle','unit-square','unit-disk']
assert doc['Display properties']['number-header'] == '$v_K(n)$'
R=RealBallField(600)
pi=R.pi()
closed={3:35/(48*pi**2),4:35/(24*pi**2),5:175/(72*pi**2)-23023/(6912*pi**4)}
# Start with an independently known normalization control.
control=generate('unit-disk',3)
assert control>0 and control<1 and R(control.rad())<R('1e-110')
assert control.overlaps(closed[3])
assert generate('equilateral-triangle',3)==QQ(1)/12
assert generate('unit-square',3)==QQ(11)/144
print('Known normalization controls: triangle 1/12; parallelogram 11/144; ellipse 35/(48*pi^2): PASS',flush=True)
maximum_radius=R(0)
for region,rows in doc['Numbers'].items():
assert list(rows)==[str(n) for n in range(3,21)]
for label,row in rows.items():
n=int(label)
s=number(row)
got=generate(region,n)
if region!='unit-disk':
assert got==QQ(s),(region,n)
else:
assert len(Decimal(s).as_tuple().digits)==DIGITS
lo,hi=interval(s)
assert got>0 and got<1
relative=R(got.rad())/abs(R(got.center()))
assert relative<R('1e-110')
maximum_radius=max(maximum_radius,relative)
assert got>R(lo) and got<R(hi),(region,n)
if n in closed:
assert closed[n]>0 and closed[n]<1 and R(closed[n].rad())<R('1e-170')
assert closed[n]>R(lo) and closed[n]<R(hi)
print(region+': all 18 stored entries verified',flush=True)
for n in range(5):
assert QQ(number(harmonic['Numbers'][str(n)])) == sum(QQ(1)/k for k in range(1,n+1))
print('T247: every stored nonnegative-integer harmonic value (0..4) agrees with the finite sum',flush=True)
print('All 18 decimal strings have 100 significant digits; all 3 ellipse closed forms enclosed',flush=True)
print('Maximum recomputed relative radius:',maximum_radius,flush=True)
# An affine area factor cancels in the normalized ratio.
q=QQ(1)/12
assert (5*q)/5==q and 5*q!=q
print('Area scaling control: area 1 gives 1/12; area 5 gives 5/12; both ratios are 1/12',flush=True)
print('PASS: 54 entries checked; no numbers written',flush=True)
if __name__=='__main__':
main()