offline.py

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

4820 bytes, as of the version from 2026-11-18 12:45 (current). Recorded here, not run.

import numberdb.sage as numberdb
from sage.rings.rational_field import QQ
from sage.rings.complex_arb import ComplexBallField
from sage.rings.real_arb import RealBallField
import sys,json,hashlib,inspect,importlib.metadata
from collections import Counter,deque
from pathlib import Path
from generate import CubicResistance,coefficients,origin
from derive import canon,valid,dist,steps
import dry_run
assert dry_run.main([str(Path(__file__).resolve().parent/'generate.py')])==0
G=CubicResistance();rows=list(G.enumerate());assert Counter(p['lattice'] for p in rows)==dict(sc=22,bcc=29,fcc=36)
# Exhaustive graph-ball check independent of the closed-form distance tests.
for L in ['sc','bcc','fcc']:
 seen={(0,0,0):0};todo=deque(seen)
 while todo:
  t=todo.popleft()
  if seen[t]==6:continue
  for s in steps(L):
   u=tuple(t[i]+s[i] for i in range(3))
   if u not in seen:seen[u]=seen[t]+1;todo.append(u)
 actual={canon(t) for t in seen if t!=(0,0,0)}
 expect={tuple(p[k] for k in ('l','m','n')) for p in rows if p['lattice']==L}
 assert actual==expect
 for t in seen:assert dist(L,canon(t))==seen[t]
# Exact harmonic identities at ALL selected rows, including cutoff rows;
# helpers are uniquely determined by the same equations up to coordinate 8.
for p in rows:
 L=p['lattice'];t=tuple(p[k] for k in ('l','m','n'));C=coefficients(L);q=len(steps(L));co=C[t]
 for j in range(3):assert q*co[j]==sum(C[canon(tuple(t[i]+s[i] for i in range(3)))][j] for s in steps(L))
# Independent elliptic expressions for the origin constants, parameter m=k^2.
for L in ['sc','bcc','fcc']:
 C=ComplexBallField(650);pi=C.pi()
 if L=='sc':k=(2-C(3).sqrt())*(C(3).sqrt()-C(2).sqrt());h=4/pi**2*(18+12*C(2).sqrt()-10*C(3).sqrt()-7*C(6).sqrt())*(k*k).elliptic_k()**2
 elif L=='bcc':h=4/pi**2*C(QQ(1)/2).elliptic_k()**2
 else:k=(C(3).sqrt()-1)/(2*C(2).sqrt());h=C(3).sqrt()/pi**2*(k*k).elliptic_k()**2
 assert h.imag().contains_zero() and h.real().overlaps(origin(L,100))
 assert h.real().is_finite() and h.real().rad().exact_rational()<QQ(10)**(-150)
# All BCC coefficient triples are separately transcribed from Asad et al.
# Table 1, arXiv:1302.4376, p.8, where the tabulated quantity is 4*r here.
bcc_source={
 '111':['0','0','1'],'200':['1','-4','0'],'220':['0','16','0'],'222':['-3','-36','8'],
 '311':['2','-8','-1'],'331':['-4','80','1'],'333':['-18','-504','63'],
 '400':['8/9','0','0'],'420':['25/9','-36','0'],'422':['104/9','16','-16'],
 '440':['-112/9','256','0'],'442':['-407/9','444','32'],'444':['-360/9','-5376','448'],
 '511':['-2/9','8','1'],'531':['120/9','-224','-1'],'533':['810/9','920','-191'],
 '551':['-652/9','1392','1'],'553':['-4266/9','1192','575'],'555':['7650/9','-48840','2369'],
 '600':['1','-36/25','0'],'620':['-16/9','1296/25','0'],'622':['-155/9','444/25','24'],
 '640':['409/9','-21316/25','0'],'642':['1112/9','-42224/25','-48'],'644':['5481/9','379804/25','-1952'],
 '660':['-288','138384/25','0'],'662':['-5147/9','249596/25','72'],
 '664':['-165600/36','-563056/25','8048'],'666':['169317/9','-9083844/25','216']}
for key,v in bcc_source.items():
 t=tuple(map(int,key));a,b,c=coefficients('bcc')[t];assert (1-a,-b,-c)==tuple(map(QQ,v)),(key,(1-a,-b,-c),v)
assert len(bcc_source)==29
# Controls require nonzero known results and deliberately wrong cases.
for L,t,q in [('sc',(1,0,0),3),('bcc',(1,1,1),4),('fcc',(1,1,0),6)]:
 p=dict(zip(G.parameters,(L,*t)));assert G.value(p,100)==QQ(1)/q
 assert G.value(p,100)!=QQ(2)/q
for L,t in [('bcc',(1,0,0)),('fcc',(1,1,1))]:
 try:G.value(dict(zip(G.parameters,(L,*t))),100)
 except ValueError:pass
 else:raise AssertionError('Wrong parity accepted')
assert len(steps('bcc'))==8 and len(steps('fcc'))==12
assert set(steps('bcc'))!=set(steps('bcc')+steps('sc'))
assert QQ(2)/len(steps('bcc')+steps('sc')) != QQ(1)/4
# The modulus and parameter really differ at the nontrivial FCC origin.
C=ComplexBallField(650);k=(C(3).sqrt()-1)/(2*C(2).sqrt());wrong=C(3).sqrt()/C.pi()**2*k.elliptic_k()**2
assert not wrong.real().overlaps(origin('fcc',100))
vals=[];minbits=10000
for p in rows:
 v=G.value(p,100);r={'params':p,'number':str(v),'native_type':type(v).__name__}
 if hasattr(v,'rad'):
  r['radius']=str(v.rad());r['accuracy_bits']=int((QQ(1)/v.rad().exact_rational()).floor()).bit_length()-1;minbits=min(minbits,r['accuracy_bits'])
 vals.append(r)
print('OFFLINE_RESULT',json.dumps({'table':'T751','entries':87,'counts':dict(Counter(p['lattice'] for p in rows)),'bfs_verified':True,'harmonicity_checked_entries':87,'bcc_external_formula_checks':29,'gamma_elliptic_controls':3,'known_answer_control':True,'negative_control_rejected':True,'minimum_absolute_accuracy_bits':minbits,'values':vals,'versions':{x:importlib.metadata.version(x) for x in ['numberdb','numpy','scipy','mpmath']},'skill_manifest':'../20261118T114154Z-build-skills/manifest.json'}),flush=True)