verify_stored.py

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

2939 bytes, as of the version from 2026-11-10 20:59 (current). Recorded here, not run.

"""Check readback against independent saved ball enclosures; no long recomputation."""
import json,hashlib
from pathlib import Path
from fractions import Fraction
from decimal import Decimal
p=Path(__file__).parent
e=json.loads((p/'numerical-evidence.json').read_text());doc=json.loads((p/'stored.json').read_text())
nums=doc['Numbers'];assert list(map(int,nums))==list(range(1,31))
rows=[]
for row in e['rows']:
 N=row['N'];v=nums[str(N)];v=v['number'] if isinstance(v,dict) else v
 if N==1:
  assert str(v)=='1'
  assert list(map(Fraction,row['generator_endpoints']))==[1,1]
  a,b=map(Fraction,row['integral_endpoints']);assert a<=1<=b and b-a<Fraction(1,10**110)
  rows.append({'N':N,'exact':'1','independent_enclosure_contains_exact_value':True})
 else:
  d=Decimal(str(v));center=Fraction(d);ulp=Fraction(10)**d.as_tuple().exponent
  margins={}
  for k in ['generator_endpoints','integral_endpoints']:
   a,b=map(Fraction,row[k]);assert 0<=b-a<Fraction(1,10**110)
   assert center-ulp<a and b<center+ulp
   margins[k]=str(min(a-(center-ulp),(center+ulp)-b)/ulp)
  a,b=map(Fraction,row['minimum_endpoints']);assert b<center-ulp
  rows.append({'N':N,'stored_interval_contains_both_enclosures':True,'margin_ulps':margins})
# Exact source identities using separate trial-factor mu, without Sage.
def mu(n):
 s=1;d=2
 while d*d<=n:
  if n%d==0:
   s=-s;n//=d
   if n%d==0:return 0
  d+=1
 return -s if n>1 else s
samples=[]
for N in range(1,31):
 w=[Fraction(mu(n)) for n in range(1,N+1)]
 g=sum((w[n-1]/n for n in range(1,N+1)),Fraction(0));w[0]-=g
 assert sum((w[n-1]/n for n in range(1,N+1)),Fraction(0))==0
 for t in [Fraction(1,2),Fraction(2*N+1,2)]+([Fraction(N+1,2)] if N>1 else []):
  f=sum((w[n-1]*(t/n-(t/n).__floor__()) for n in range(1,N+1)),Fraction(0))
  if t<1:assert f==0
  if 1<t<N:assert f==-1+g*t.__floor__()
 samples.append(N)
# Full stored interval control: deliberate last-place-visible corruption is rejected.
v=Decimal(str(nums['2'] if not isinstance(nums['2'],dict) else nums['2']['number']))
c=Fraction(v);u=Fraction(10)**v.as_tuple().exponent
a,b=map(Fraction,e['rows'][1]['integral_endpoints']);assert not(c+10*u-u<a and b<c+10*u+u)
result={'table':'T708','stage':'build-readback','checked_entries':30,'total_entries':30,'failures':[],
'known_answer_control':str(nums['1'])=='1','negative_control_rejected':True,
'method':'Read back exact E_1 and full decimal intervals; compare fresh generator and retained independently integrated balls, using exact binary endpoint serialization.',
'endpoint_cancellation_checked':30,'interior_and_exterior_exact_controls':samples,'rows':rows,
'hashes':{n:hashlib.sha256((p/n).read_bytes()).hexdigest() for n in ['stored.json','numerical-evidence.json','verify_stored.py','skill-manifest.json']}}
(p/'readback-evidence.json').write_text(json.dumps(result,indent=2)+'\n')
print('All 30 stored intervals verified; exact cancellation controls 1..30; altered decimal rejected.')