repair_checks.py

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

3908 bytes, as of the version from 2026-11-11 07:57 (current). Recorded here, not run.

"""Focused checks for T713's restored Similar tables relationships.
Python + mpmath; python repair_checks.py reads after-document.json in TMPDIR.
No generator or saved sibling values are used to compute the comparison values.
This is repair evidence, never an independent critic verdict or rigorous proof.
"""
import os,json,math,hashlib,platform
from pathlib import Path
import mpmath as mp
W=Path(os.environ.get('TMPDIR', Path(__file__).resolve().parent)); mp.mp.dps=160
raw=(W/'after-document.json').read_bytes(); doc=json.loads(raw)

def interval(text):
    mantissa,sep,exponent=text.lower().partition('e')
    places=len(mantissa.split('.',1)[1]) if '.' in mantissa else 0
    ulp=mp.mpf(10)**((int(exponent) if sep else 0)-places)
    return mp.mpf(text),ulp

def compare(text,value):
    mid,ulp=interval(text)
    allowance=max(abs(value),mp.mpf(1))*mp.mpf('1e-140')
    return bool(mp.isfinite(value) and abs(mid-value)+allowance<ulp),mp.nstr(abs(mid-value)/ulp,20)

rows=[]
def record(n,k,key,value,method,extra=None):
    text=doc['Numbers'][str(n)][str(k)][key]
    ok,error=compare(text,value)
    r={'params':{'n':n,'k':k,'x':key},'method':method,'stored':text,'computed':mp.nstr(value,150),
       'absolute_difference_ulps':error,'pass':ok}
    r.update(extra or {}); rows.append(r)

phi=(1+mp.sqrt(5))/2
endpoints={'logphi':mp.log(phi),'2logphi':2*mp.log(phi),'2logsilver':2*mp.asinh(1)}
for key,x in endpoints.items():
    record(2,0,key,mp.pi**2/6-mp.polylog(2,mp.exp(-x))-x*x/4,'dilogarithm identity')
for n in range(3,11):
    terms=[mp.mpf((-1)**j)/(mp.mpf(j)**n*math.comb(2*j,j)) for j in range(1,551)]
    factor=mp.factorial(n-2)/((-2)**(n-2))
    value=factor*mp.fsum(terms)
    # Alternating terms decrease; the next omitted term bounds the series tail.
    tail=abs(factor)/(mp.mpf(551)**n*math.comb(1102,551))
    assert tail<mp.mpf('1e-300')
    record(n,1,'2logphi',value,'alternating inverse central binomial sum, 550 terms',{'truncation_bound':mp.nstr(tail,12)})
controls={
 'Li2_zero':mp.polylog(2,0)==0,
 'Li2_half':abs(mp.polylog(2,mp.mpf(1)/2)-(mp.pi**2/12-mp.log(2)**2/2))<mp.mpf('1e-150'),
 'golden_dilog':compare(doc['Numbers']['2']['0']['2logphi'],mp.pi**2/10)[0],
 'apery_first_moment':compare(doc['Numbers']['3']['1']['2logphi'],mp.zeta(3)/5)[0]}
text=doc['Numbers']['2']['0']['2logphi']; mid,ulp=interval(text)
negatives={'nan_rejected':not compare(text,mp.nan)[0],'infinity_rejected':not compare(text,mp.inf)[0],
 'wrong_sign_rejected':not compare(text,-mp.pi**2/10)[0],'two_ulp_error_rejected':not compare(text,mid+2*ulp)[0]}
manifest=W/'repair-skill-manifest.json'
out={'scope':'Focused formula checks for restored relationships; zero numerical entries changed, no whole-table recomputation.',
 'checked_entries':len(rows),'total_entries':sum(len(xs) for ks in doc['Numbers'].values() for xs in ks.values()),
 'known_answer_control':all(controls.values()),'negative_control_rejected':all(negatives.values()),
 'controls':controls,'negative_controls':negatives,'failures':[r['params'] for r in rows if not r['pass']],
 'checks':rows,'python':platform.python_version(),'mpmath':mp.__version__,'working_decimal_digits':mp.mp.dps,
 'precision_limitations':'160-dps point evaluations and conservative 1e-140 comparison allowance are heuristic. This run does not recertify the original proven ball arithmetic; original generator, proof and checkpoints are preserved unchanged.',
 'document_file_sha256':hashlib.sha256(raw).hexdigest(),'program_sha256':hashlib.sha256(Path(__file__).read_bytes()).hexdigest(),
 'skill_manifest':str(manifest),'skill_manifest_sha256':hashlib.sha256(manifest.read_bytes()).hexdigest()}
(W/'repair-check-results.json').write_text(json.dumps(out,indent=2)+'\n')
print(json.dumps({k:v for k,v in out.items() if k not in ['checks']},indent=2))
assert not out['failures'] and out['known_answer_control'] and out['negative_control_rejected']