back to table · edit · history · where entries came from · files · download
5411 bytes, as of the version from 2026-12-01 00:41 (current). Recorded here, not run.
"""Exact rational-series check, independent of Arb and its logarithm routine.
Run with ordinary Python: python independent_check.py [--document stored.json].
No network, Sage, floating-point logarithm, or generator imports are used.
Endpoint interval arithmetic propagates every input error.
For 1<=y<=2 put z=(y-1)/(y+1), so 0<=z<=1/3. Integrating the
geometric series for 2/(1-z*z) gives log(y)=2 sum z^(2j+1)/(2j+1).
The omitted nonnegative tail is at most
2*z^(2J+1)/((2J+1)*(1-z*z)). Range reduction x=2^m*y is exact.
For negative m the log(2) interval reverses under multiplication by m.
Logs of intervals use endpoint monotonicity. Q(u) is assembled by general
interval multiplication/subtraction, so dependency only widens the bounds.
"""
import argparse
from fractions import Fraction as F
from pathlib import Path
import json
import re
import time
J = 180
SCALE = 2**600
def outward(a):
"""Exact dyadic outward rounding bounds intermediate denominator growth."""
low=(a[0]*SCALE).__floor__()
high=(a[1]*SCALE).__ceil__()
return (F(low,SCALE),F(high,SCALE))
def add(a,b): return (a[0]+b[0],a[1]+b[1])
def neg(a): return (-a[1],-a[0])
def sub(a,b): return add(a,neg(b))
def mul(a,b):
p=[x*y for x in a for y in b]
return (min(p),max(p))
def reciprocal(a):
assert 0<a[0]<=a[1]
return (1/a[1],1/a[0])
def log_reduced(y):
assert F(1)<=y<=F(2)
z=(y-1)/(y+1); z2=z*z; term=z; total=F(0)
for j in range(J):
total += term/(2*j+1)
term *= z2
tail=2*term/((2*J+1)*(1-z2))
return outward((2*total,2*total+tail))
LOG2=log_reduced(F(2))
def log_rational(x):
x=F(x); assert x>0
m=0
while x<1: x*=2; m-=1
while x>=2: x/=2; m+=1
return outward(add(log_reduced(x),mul((F(m),F(m)),LOG2)))
def log_interval(x):
assert 0<x[0]<=x[1]
return (log_rational(x[0])[0],log_rational(x[1])[1])
def q_interval(u):
return add(sub(mul(u,log_interval(u)),u),(F(1),F(1)))
def decimal_interval(text):
text=str(text).strip()
if text.startswith('[') and text.endswith(']'):
a,b=text[1:-1].split(','); return F(a),F(b)
if '+/-' in text:
a,b=text.split('+/-'); return F(a)-F(b),F(a)+F(b)
assert re.fullmatch(r'-?\d+\.\d+(?:[eE][+-]?\d+)?',text)
decimal,_,exponent=text.lower().partition('e')
places=len(decimal.split('.')[1]); exp=int(exponent or '0')
ulp=F(10)**(exp-places); center=F(text)
return (center-ulp,center+ulp)
def contains(outer,inner): return outer[0]<=inner[0]<=inner[1]<=outer[1]
def run(value):
started=time.perf_counter()
u=reciprocal(LOG2); checked=q_interval(u); stored=decimal_interval(value)
prefix=decimal_interval('0.086071332055934206887573')
known=q_interval((F(1),F(1))) == (F(0),F(0))
known=known and contains(log_rational(F(1)),(F(0),F(0))) and contains(prefix,checked)
# Nonzero control: integral log(t) dt from 1 to 2 = 2 log(2)-1.
known=known and contains(q_interval((F(2),F(2))),sub(mul((F(2),F(2)),LOG2),(F(1),F(1))))
assert F(0)<checked[1]-checked[0]<F(1,10**140)
assert F(0)<stored[1]-stored[0]<=F(1,10**100)
# Wrong sign, missing additive 1, and replacing both natural logs by log_2.
# log_2(2)=1 and log_2(1)=0, so the latter erroneous expression is 0.
wrong=[neg(checked),sub(checked,(F(1),F(1))),(F(0),F(0))]
rejected=all(not contains(stored,x) for x in wrong)
failures=[]
if not contains(stored,checked): failures.append('Rational-series enclosure outside stored interval')
if not known: failures.append('Known-answer control failed')
if not rejected: failures.append('Negative control accepted')
def pair(a): return [str(a[0]),str(a[1])]
return dict(checked_entries=1,total_entries=1,failures=failures,
known_answer_control=known,negative_control_rejected=rejected,
source='Koukoulopoulos arXiv:0809.1072v6 introduction pp.1–2',
method='Python Fraction; bounded atanh series; Q(1/log(2))',
series_terms=J,stored_value=value,stored_interval=pair(stored),
enclosure=pair(checked),enclosure_width=str(checked[1]-checked[0]),
stored_width=str(stored[1]-stored[0]),
controls=['Q(1)=0','log(1)=0','Q(2)=2 log(2)-1','external 23-significant-digit prefix',
'wrong sign rejected','missing 1 rejected','base-2 logarithms rejected'],
elapsed_seconds=time.perf_counter()-started)
if __name__=='__main__':
parser=argparse.ArgumentParser(description=__doc__)
parser.add_argument('--document',type=Path)
parser.add_argument('--value',default=None)
parser.add_argument('--output',type=Path,default=Path('check-results.json'))
args=parser.parse_args()
if args.document:
doc=json.loads(args.document.read_text()); rows=doc['Numbers']
assert not doc.get('Parameters') and len(rows)==1
entry=rows[0]
if isinstance(entry,dict):
assert entry.get('params',{})=={}
value=entry['number']
else:
assert isinstance(entry,str)
value=entry
else:
value=args.value or Path('computed.txt').read_text().strip()
result=run(value)
args.output.write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps({k:result[k] for k in ['checked_entries','failures','known_answer_control','negative_control_rejected','elapsed_seconds']}))
raise SystemExit(bool(result['failures']))