Xiorume-Kai-Delta / code /verify.py
PureOne's picture
Upload Xiorume KAI Delta research dataset release
c1c9129 verified
Raw History Blame Contribute Delete
6.4 kB
"""Reproducible finite checks for Xiorume Kappa.
These checks verify formulas and finite instances of inequalities. They do not
replace the analytic all-orders proof in the manuscript.
Run: python3 verify.py
"""
from fractions import Fraction
import json
import math
from pathlib import Path
import numpy as np
def partitions(n, minimum=1):
if n == 0:
yield ()
for first in range(minimum, n + 1):
for rest in partitions(n - first, first):
yield (first,) + rest
def theta(n, y):
b = -1 / np.tan(np.pi / (2*n))
return (n-1)*np.pi + 2*n*np.arctan(y+b)
def g(n, x, y):
rho = 1 + .5*np.tanh(x)
a = theta(n, y)
return np.array([rho*np.cos(a)-1, rho*np.sin(a)])
def jac(n, x, y):
b = -1 / np.tan(np.pi/(2*n))
rho = 1+.5*np.tanh(x)
rp = .5/np.cosh(x)**2
a = theta(n,y)
ap = 2*n/(1+(y+b)**2)
return np.array([[rp*np.cos(a), -rho*np.sin(a)*ap],
[rp*np.sin(a), rho*np.cos(a)*ap]])
def run():
result = {"purpose":"formula and finite-instance verification; not a proof checker"}
count = 0
worst = Fraction(0)
for k in range(2,17):
for parts in partitions(k):
if len(parts) < 2:
continue
ratio = sum(Fraction(1,3**(k-size)) for size in parts)
assert ratio <= Fraction(len(parts), 3**(len(parts)-1)) < 1
worst = max(worst, ratio)
count += 1
result['partition_checks']={"count":count,"max_order":16,
"maximum_deficit_ratio":str(worst),"passed":True}
roots = []
for n in range(2,13):
b = -1/np.tan(np.pi/(2*n))
ys = [np.tan((2*np.pi*j-(n-1)*np.pi)/(2*n))-b for j in range(n)]
residual = max(float(np.linalg.norm(g(n,0,y))) for y in ys)
assert residual < 1e-11
assert all(np.linalg.det(jac(n,0,y)) > 0 for y in ys)
roots.append({"N":n,"zero_count":len(ys),"max_residual":residual})
result['root_checks']=roots
rng=np.random.default_rng(52816)
det_min=1e10
inverse_error=0
for _ in range(200):
n=int(rng.integers(2,9))
x,y=rng.uniform(-4,4,2)
J=jac(n,x,y)
det=float(np.linalg.det(J))
assert det>0
det_min=min(det_min,det)
inverse_error=max(inverse_error,float(np.linalg.norm(J@np.linalg.inv(J)-np.eye(2))))
result['jacobian_checks']={"samples":200,"minimum_det":det_min,
"maximum_inverse_residual":inverse_error,"passed":True}
threshold=[]
for m in range(1,25):
expected=(m+1)//2
actual=next(k for k in range(m+1) if 2*k-m > -1)
assert expected==actual
threshold.append({"pole":m,"minimum_jet_order":actual})
result['threshold_checks']=threshold
weight_checks=0
max_error=0.
for a in [.25,.5,2.,3.]:
for t in [.08,.12,.18]:
sigma=t/(1-t*math.log(a))
source=math.exp(1/t)
target=math.exp(1/sigma)
relative=abs(a*target/source-1)
max_error=max(max_error,relative)
assert relative<1e-12
for m in range(1,13):
delta=m+.4*m*(m-1)
assert abs((a*delta)*target/(delta*source)-1)<1e-12
weight_checks+=1
result['weight_reparameterization']={'checks':weight_checks,
'maximum_relative_error':max_error,'passed':True}
normalized=[]
for c in [Fraction(0),Fraction(1,4),Fraction(1,2),Fraction(1)]:
seq=tuple(Fraction(m)+c*m*(m-1) for m in range(1,9))
assert all(seq[i+1]>seq[i] for i in range(len(seq)-1))
normalized.append(tuple(x/seq[0] for x in seq))
assert len(set(normalized))==4
result['weight_moduli_examples']={'distinct_normalized_sequences':4,'passed':True}
radial=[]
for c in range(1,9):
for k in range(1,5):
for offset in [-1,0,1]:
for q in [0,1,2]:
p=2*k+c+offset
power=2*k+c-p
converges=(power>0 or (power==0 and q>1))
expected=(offset<0 or (offset==0 and q>1))
assert converges==expected
radial.append((c,k,p,q,converges))
result['codimension_log_thresholds']={'cases':len(radial),'passed':True}
gs=lambda x:x-math.sin(x)+math.sqrt(math.pi)/2*math.erf(x)
derivative=lambda x:1-math.cos(x)+math.exp(-x*x)
for x in np.linspace(-20,20,2001):
assert derivative(float(x))>0
assert abs(gs(float(x))-x)<=1+math.sqrt(math.pi)/2+1e-12
logs=[(2*math.pi*n)**2 for n in range(1,11)]
assert all(logs[j+1]>logs[j] for j in range(9))
result['homeomorphism_inverse_counterexample']={
'positive_derivative_samples':2001,
'inverse_jacobian_log_at_2pi_n':logs,
'inverse_values_evaluated_in_log_domain':True,'passed':True}
result['closed_form_critical_integrals']={
'integral_1_to_infinity_u^-2':1,
'integral_1_to_infinity_u^-1':'diverges',
'role':'critical logarithmic threshold; analytic identities, not numerical quadrature'}
hyp_error=0.
for _ in range(100):
c=float(np.exp(rng.uniform(-5,5)))
dc=float(rng.normal())
dq=rng.normal(size=4)
y=2/c**.5
dy=-dc/c**1.5
intrinsic=(dc/c)**2+c*float(dq@dq)
upper=4*(dy*dy+float(dq@dq))/(y*y)
hyp_error=max(hyp_error,abs(intrinsic-upper)/max(intrinsic,1))
assert np.isclose(intrinsic,upper,rtol=1e-12)
y1=float(np.exp(rng.uniform(-3,3)))
y2=float(np.exp(rng.uniform(-3,3)))
vertical=2*math.acosh(1+(y2-y1)**2/(2*y1*y2))
assert np.isclose(vertical,2*abs(math.log(y2/y1)),rtol=1e-10,atol=1e-10)
result['hyperbolic_pullback']={'random_vectors':100,
'max_relative_error':hyp_error,'vertical_distance_identity_passed':True}
result['all_checks_passed']=True
dest=Path(__file__).resolve().parents[1] / 'metadata' / 'Verification.json'
dest.parent.mkdir(parents=True, exist_ok=True)
dest.write_text(json.dumps(result,indent=2)+'\n')
print(json.dumps({"passed":True,"partition_checks":count,
"N_values":11,"jacobian_samples":200,"pole_values":24,
"weight_checks":weight_checks,"radial_cases":len(radial),
"inverse_derivative_samples":2001}))
if __name__=='__main__':
run()