repair-checks-20261028.py

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

3614 bytes, as of the version from 2026-10-28 21:43 (current). Recorded here, not run.

"""Check the T591 prose repair and retained values -- numberdb.org/T591.

Run alongside the unchanged generate.py:
    sage -python repair_checks.py
For a private draft set NUMBERDB_API_KEY, or set NUMBERDB_KEY_FROM_STDIN=1
and pipe the key on stdin. No write, offer, review or publication is performed.
The archived table-before.json and critical-table.json are optional offline inputs.
"""
import os, sys, json, time, hashlib
from pathlib import Path
import numberdb.sage as numberdb
from sage.rings.integer_ring import ZZ
from sage.rings.rational_field import QQ
from sage.rings.real_mpfi import RealIntervalField
from sage.rings.real_arb import RealBallField
from sage.env import SAGE_VERSION
from generate import partition_polynomial, rectangles, FisherZeros, R, b

if os.environ.get('NUMBERDB_KEY_FROM_STDIN') == '1':
    token=sys.stdin.read().strip()
    if '=' in token and token.split('=',1)[0].strip().isidentifier():
        token=token.split('=',1)[1].strip().strip('\"\'')
    os.environ['NUMBERDB_API_KEY']=token

start=time.monotonic()
def document(filename, tid):
    path=Path(__file__).parent/filename
    return json.loads(path.read_text()) if path.exists() else numberdb.table(tid)

def explicit_cuts(m,n):
    edges=[]
    for i in range(m):
        for j in range(n):
            v=i*n+j
            if i+1<m: edges.append((v,v+n))
            if j+1<n: edges.append((v,v+1))
    assert len(edges)==2*m*n-m-n
    counts=[0]*(len(edges)+1)
    for mask in range(1 << (m*n)):
        d=sum(((mask>>u)^(mask>>v))&1 for u,v in edges)
        # The energy sum is E-2*d for every individual spin assignment.
        spin_sum=sum((1-2*((mask>>u)&1))*(1-2*((mask>>v)&1)) for u,v in edges)
        assert spin_sum==len(edges)-2*d
        counts[d]+=1
    return R(counts)

control=explicit_cuts(2,2)
assert control==2*(1+6*b**2+b**4)
print('Known-answer four-cycle control passed.',flush=True)
checked=[]
for m,n in rectangles():
    if m*n<=16:
        p=explicit_cuts(m,n)
        assert p==partition_polynomial(m,n)
        assert p(0)==2 and p(1)==2**(m*n)
        checked.append([m,n])
print('Direct subset enumeration and termwise normalization passed:',checked,flush=True)

# The linked critical-coupling entry must contain the claimed formula's
# entire ball, rather than merely overlap it. Its decimal means +/- one ULP.
critical=document('critical-table.json','Critical_couplings_of_the_Ising_model_on_lattices')
s=critical['Numbers']['square']['coupling']['number']
q=QQ(int(s.replace('.',''),10)) / ZZ(10)**len(s.split('.')[1])
ulp=QQ(1)/ZZ(10)**len(s.split('.')[1])
RB=RealBallField(600); RI=RealIntervalField(650)
k=(RB(1)+RB(2).sqrt()).log()/2
assert k.is_finite() and RB(k.rad())<RB(10)**(-170)
assert RI(q-ulp)<RI(k) and RI(k)<RI(q+ulp)
assert ((-2*k).exp()-(RB(2).sqrt()-1)).contains_zero()
print('Linked square critical coupling agrees with its formula and b_c=sqrt(2)-1.',flush=True)
report=FisherZeros().verify(sample=None)
print(report,flush=True)
assert report.ok
print(json.dumps({'table':'T591','skill_manifest':'agents/runs/20261028T213717Z-repair-skills/manifest.json','skill_local_sha256':'e37efb7e2ededf6c1d7134c673f152f648f26e0267c556aebdf3ec65765d8b4c','skill_live_sha256':'e37efb7e2ededf6c1d7134c673f152f648f26e0267c556aebdf3ec65765d8b4c','sage':SAGE_VERSION,'direct_enumeration_rectangles':checked,'termwise_energy_identity':True,'critical_link_formula_contained':True,'all_stored_values_generator_verified':True,'generator_sha256':hashlib.sha256((Path(__file__).parent/'generate.py').read_bytes()).hexdigest(),'seconds':time.monotonic()-start},indent=2),flush=True)