"""Independently replay the exterior proof. Requires only Python's standard library. The supplied tree selects split axes and integer trial polynomials. This program constructs the six initial boxes itself, checks both children of every split, and establishes each strict test with exact fractions and integer square roots. Dirichlet energies are computed by signed triangles in physical coordinates. """ from collections import Counter, defaultdict from fractions import Fraction as F from itertools import product from math import ceil, comb, floor, isqrt import argparse import json from pathlib import Path GRID=2**32 ROOT_SCALE=2**56 class I: """Closed rational intervals. Endpoints are exact until a rational sqrt enclosure.""" __slots__=('lo','hi') def __init__(self,lo,hi=None): self.lo=lo; self.hi=lo if hi is None else hi def __add__(x,y): if isinstance(y,I): return I(x.lo+y.lo,x.hi+y.hi) return I(x.lo+y,x.hi+y) __radd__=__add__ def __neg__(x): return I(-x.hi,-x.lo) def __sub__(x,y): return x+(-y) def __rsub__(x,y): return -x+y def __mul__(x,y): if not isinstance(y,I): return I(x.lo*y,x.hi*y) if y>=0 else I(x.hi*y,x.lo*y) vals=(x.lo*y.lo,x.lo*y.hi,x.hi*y.lo,x.hi*y.hi) return I(min(vals),max(vals)) __rmul__=__mul__ def square(x): return I(max(0,x.lo,-x.hi)**2,max(x.hi,-x.lo)**2) def absmin(x): return max(0,x.lo,-x.hi) def sqrt(x): if x.lo<0: raise ArithmeticError('negative squared length') def lower(t): # floor(sqrt(t)*ROOT_SCALE) for t >= 0. return isqrt(t.numerator*ROOT_SCALE**2//t.denominator) return I(F(lower(x.lo),ROOT_SCALE),F(lower(x.hi)+1,ROOT_SCALE)) def dyad(l,h): return (floor(F(l)*GRID),ceil(F(h)*GRID)) def root_boxes(): a,c=dyad('0','0.21'),dyad('0','0.045') return [(a,c,dyad(l,h),dyad(v,w)) for l,h,v,w in [('0.40','1.21','-1','1'),('0','0.40','0.60','1'), ('0','0.40','-1','-0.60'),('0.20','0.40','-0.60','0.60'), ('0','0.20','0.28','0.60'),('0','0.20','-0.60','-0.28')]] def parts(box,axis): lo,hi=box[axis]; mid=(lo+hi)//2 if not lodelta.hi if modes=='a': _,r,s,center=node; b=g=0 else: _,r,s,b,g,center=node if r==s==b==g==0: return False center=F(center,GRID) E90=30*energy3(r,s,b,g,box,rng) f=L=0; weighted=I(0) for m,d,_ in edge_geometry(u,v,t): X,Y=m; x,y=d length=(x.square()+y.square()).sqrt() def qform(U,V): return b*(U.square()-V.square())+2*g*U*V e0=r*X+s*Y+qform(X,Y)-center e1=r*x+s*y+2*((b*X+g*Y)*x+(g*X-b*Y)*y) e2=qform(x,y); h=3*e0+e2 variance45=5*h.square()+15*e1.square()+4*e2.square() f+=(length*(11*variance45-E90)).lo L+=length.lo; weighted+=length*h return f>0 and f*L>55*weighted.square().hi def replay(node,box,counts): check_types(node) if type(node[0]) is int: for child,part in zip(node[1:],parts(box,node[0])): replay(child,part,counts) elif accepts(node,box): counts[node[0]]+=1 else: raise ArithmeticError(('invalid leaf',node,box)) if __name__=='__main__': parser=argparse.ArgumentParser() parser.add_argument('file',type=Path,nargs='?',default=Path(__file__).with_name('exterior-tree.json')) tree=json.loads(parser.parse_args().file.read_text(encoding='ascii')) boxes=root_boxes() if len(tree)!=len(boxes): raise ValueError('six root certificates required') full=Counter() for n,(root,box) in enumerate(zip(tree,boxes),1): seen=Counter(); replay(root,box,seen); full.update(seen) print('Region',n,'verified',sum(seen.values()),'leaves',dict(sorted(seen.items())),flush=True) print('All six regions verified.',sum(full.values()),'leaves',dict(sorted(full.items())))