identities.py

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

1585 bytes, as of the version from 2026-11-18 08:37 (current). Recorded here, not run.

import json,math,itertools
import mpmath as mp
from collections import defaultdict
steps=list(itertools.product((-1,1), repeat=3));counts={(0,0,0):1};moments={}
for n in range(1,5):
 nxt=defaultdict(int)
 for a,c in counts.items():
  for b in steps:nxt[tuple(a[i]+b[i] for i in range(3))]+=c
 counts=nxt; moments[n]=counts.get((0,0,0),0)
assert moments=={1:0,2:8,3:0,4:216}
mp.mp.dps=150
# Direct defining-quantity derivative via nearby elliptic integrals; this uses
# a finite difference and is numerical evidence, not a universal proof.
def M(k):
 a=(1-mp.sqrt(1-64/k**2))/2
 def f(u):
  if not u:return mp.mpf(1)/4
  return ((2*mp.ellipk(u)/mp.pi)**2-1)*(1-2*u)/(2*u*(1-u))
 return mp.log(k)-mp.quad(f,[0,a/2,a])
checks=[]
for k in [9,10,12,16,24,32]:
 k=mp.mpf(k); h=mp.mpf('1e-35');a=(1-mp.sqrt(1-64/k**2))/2
 W=(2*mp.ellipk(a)/mp.pi)**2
 derivative=k*(M(k+h)-M(k-h))/(2*h)
 e=abs(W-derivative)
 assert e<mp.mpf('1e-65')
 checks.append({'k':int(k),'error':str(e),'h':'1e-35'})
# Nonzero known answer and deliberate invalid stored-interval controls.
def accept(value,expected,ulp):
 return bool(mp.isfinite(value) and mp.isfinite(expected) and ulp>0 and ulp<mp.mpf('1e-90') and abs(value-expected)<=ulp)
v=M(mp.mpf(9));ulp=mp.mpf('1e-99')
controls={'known_nonzero':accept(v,v,ulp),'corrupted_value_rejected':not accept(v+mp.mpf('1e-96'),v,ulp),'nan_rejected':not accept(mp.nan,v,ulp),'vacuous_interval_rejected':not accept(v,v,mp.mpf('1e5'))}
assert all(controls.values())
print('RESULT '+json.dumps({'closed_walk_moments':moments,'derivative_checks':checks,'controls':controls}))