back to table · edit · history · where entries came from · files · download
948 bytes, as of the version from 2026-12-02 03:41 (current). Recorded here, not run.
import json,sys
from pathlib import Path
from fractions import Fraction
from decimal import Decimal
import mpmath as mp
p=Path(__file__).with_name('document.json');d=json.loads(p.read_text())
ns={};exec(compile(d['Programs']['mpmath-example']['code'],'Programs/mpmath-example','exec'),ns)
fail=[];rows=[]
for r,row in d['Numbers'].items():
v=ns['watts'](Fraction(r));c=Decimal(row['number']);u=Fraction(10)**c.as_tuple().exponent
low=Fraction(c)-u;high=Fraction(c)+u
conv=lambda z:mp.mpf(z.numerator)/z.denominator
ok=conv(low)<v<conv(high)
rows.append({'r':r,'contained':bool(ok)})
if not ok:fail.append(r)
ratios=sorted({Fraction(a,b) for a in range(1,9) for b in range(1,a+1)})
assert list(d['Numbers'])==[str(r) for r in ratios]
print(json.dumps({'table':'T856','program':'document.json Programs/mpmath-example','checked_entries':len(rows),'enumeration_matches':True,'failures':fail,'entries':rows},indent=2))
if fail:raise SystemExit(1)