Download research/code/verify_adjacent_boundary.py from PureOne/Nhoryun-Omega-III: direct link, hf CLI and curl.
- Browser
- Download file 6.67 kB
-
https://huggingface.co/datasets/PureOne/Nhoryun-Omega-III/resolve/main/research/code/verify_adjacent_boundary.py
- Command line
-
hf download hf://datasets/PureOne/Nhoryun-Omega-III/research/code/verify_adjacent_boundary.py
-
curl -L -o verify_adjacent_boundary.py https://huggingface.co/datasets/PureOne/Nhoryun-Omega-III/resolve/main/research/code/verify_adjacent_boundary.py
6.67 kB
| #!/usr/bin/env python3 | |
| """Exact algebraic isolation and certificate audit for adjacent concavity. | |
| All assertions use fractions. Polynomial coefficient identities, Taylor interval | |
| bounds, and degree-certified matrix identities justify the arithmetic reported. | |
| The written theorem supplies the logical all-function conclusions. | |
| """ | |
| from fractions import Fraction as F | |
| from math import comb | |
| from itertools import product | |
| from pathlib import Path | |
| import argparse | |
| import json | |
| def trim(p): | |
| p=list(p) | |
| while len(p)>1 and p[-1]==0:p.pop() | |
| return p | |
| def add(p,q): | |
| r=[F(0)]*max(len(p),len(q)) | |
| for i,a in enumerate(p):r[i]+=a | |
| for i,a in enumerate(q):r[i]+=a | |
| return trim(r) | |
| def scale(p,a):return trim([a*x for x in p]) | |
| def mul(p,q): | |
| r=[F(0)]*(len(p)+len(q)-1) | |
| for i,a in enumerate(p): | |
| for j,b in enumerate(q):r[i+j]+=a*b | |
| return trim(r) | |
| def power(p,k): | |
| z=[F(1)] | |
| for _ in range(k):z=mul(z,p) | |
| return z | |
| def val(p,x): | |
| y=F(0) | |
| for a in reversed(p):y=y*x+a | |
| return y | |
| def taylor(p,c): | |
| return [sum((p[j]*comb(j,k)*c**(j-k) for j in range(k,len(p))),F(0)) for k in range(len(p))] | |
| def bounds(p,l,u): | |
| c=(l+u)/2;w=(u-l)/2;q=taylor(p,c) | |
| e=sum((abs(q[k])*w**k for k in range(1,len(q))),F(0)) | |
| return q[0]-e,q[0]+e | |
| def discriminant_identity(): | |
| a=list(map(F,[8,-4]));b=list(map(F,[-44,-20,25])) | |
| c=list(map(F,[-48,168,-84]));d=list(map(F,[36,-72,36])) | |
| disc=mul(power(b,2),power(c,2)) | |
| disc=add(disc,scale(mul(a,power(c,3)),F(-4))) | |
| disc=add(disc,scale(mul(power(b,3),d),F(-4))) | |
| disc=add(disc,scale(mul(power(a,2),power(d,2)),F(-27))) | |
| disc=add(disc,scale(mul(mul(a,b),mul(c,d)),F(18))) | |
| P=list(map(F,[-33536,126080,-224304,235672,-175306,97161,-33602,5000])) | |
| assert disc==scale(mul(list(map(F,[-2,1])),P),F(432)) | |
| H=add(power(b,2),scale(mul(a,c),F(-3))) | |
| N=add(scale(mul(a,d),F(9)),scale(mul(b,c),F(-1))) | |
| # r=N/(2H). These denominator-cleared identities hold coefficientwise. | |
| Dr_num=add(add(scale(mul(a,power(N,2)),F(3)),scale(mul(mul(b,N),H),F(4))),scale(mul(c,power(H,2)),F(4))) | |
| assert Dr_num==scale(mul(a,disc),F(-9)) | |
| D_num=add(add(mul(a,power(N,3)),scale(mul(mul(b,power(N,2)),H),F(2))), | |
| add(scale(mul(mul(c,N),power(H,2)),F(4)),scale(mul(d,power(H,3)),F(8)))) | |
| factor=add(add(scale(mul(power(a,2),d),F(27)),scale(mul(mul(a,b),c),F(-9))),scale(power(b,3),F(2))) | |
| assert D_num==scale(mul(factor,disc),F(-1)) | |
| return P | |
| def root_isolation(P): | |
| l=F(1863425364,10**9);u=F(1863425365,10**9) | |
| assert -F(340,10**9)<val(P,l)<-F(339,10**9) | |
| assert F(594,10**9)<val(P,u)<F(595,10**9) | |
| c=(l+u)/2;w=(u-l)/2;q=taylor(P,c) | |
| err=sum((k*abs(q[k])*w**(k-1) for k in range(2,len(q))),F(0)) | |
| assert 933<q[1]<934 and err<F(1,100000) | |
| numerator=list(map(F,[240,-24,3024,-3588,1050])) | |
| denominator=list(map(F,[3088,-2848,2232,-2008,625])) | |
| nl,nu=bounds(numerator,l,u);dl,du=bounds(denominator,l,u) | |
| assert dl>0 | |
| rl,ru=nl/du,nu/dl | |
| assert F(187988820,10**8)<rl<ru<F(187988824,10**8) | |
| assert F(18798882025,10**10)<rl and ru<F(18798882351,10**10) | |
| # A is increasing in both arguments on this rectangle. | |
| def A(r,h):return (r*(h+2)-6*(h-1))/(6*r*(2-h)) | |
| alo=A(F(187988820,10**8),l);ahi=A(F(187988824,10**8),u) | |
| assert F(13517,10000)<alo<ahi<F(6759,5000) | |
| assert F(135170122,10**8)<alo and ahi<F(135170131,10**8) | |
| # Positive extension matrix has a positive 2-by-2 determinant. | |
| for r in [F(187,100),F(189,100)]:assert -25*r*r+84*r-36>33 | |
| ll,uu=l,u | |
| for _ in range(70): | |
| mid=(ll+uu)/2 | |
| if val(P,mid)<0:ll=mid | |
| else:uu=mid | |
| return {'isolating_interval':[str(l),str(u)], | |
| 'P_endpoint_values':[str(val(P,l)),str(val(P,u))], | |
| 'P_derivative_lower_bound':str(q[1]-err), | |
| 'r_enclosure':[str(rl),str(ru)], | |
| 'A_enclosure':[str(alo),str(ahi)], | |
| 'h_display':float((ll+uu)/2), | |
| 'all_exact_checks_passed':True} | |
| def zero(n):return [[F(0) for _ in range(n)]for _ in range(n)] | |
| def outer(a,b):return [[x*y for y in b]for x in a] | |
| def madd(A,B,c=F(1)): | |
| return [[x+c*y for x,y in zip(ar,br)]for ar,br in zip(A,B)] | |
| def sym(A):return [[(A[i][j]+A[j][i])/2 for j in range(len(A))]for i in range(len(A))] | |
| def det3(A): | |
| return (A[0][0]*(A[1][1]*A[2][2]-A[1][2]*A[2][1]) | |
| -A[0][1]*(A[1][0]*A[2][2]-A[1][2]*A[2][0]) | |
| +A[0][2]*(A[1][0]*A[2][1]-A[1][1]*A[2][0])) | |
| def matrix_and_certificate(): | |
| eye=[[F(i==j)for j in range(4)]for i in range(4)] | |
| ds=[[eye[i+1][j]-eye[i][j]for j in range(4)]for i in range(3)] | |
| count=0 | |
| for r,h in product(map(F,[1,2,3,4]),[F(1),F(3,2),F(7,4)]): | |
| M=[[r*(1-h/2),r*(h+2)/12-(h-1)/2,F(0)], | |
| [r*(h+2)/12-(h-1)/2,r*(h+1)/3-h+F(1,2),r/6], | |
| [F(0),r/6,F(1,2)]] | |
| D=4*(2-h)*r**3+(25*h*h-20*h-44)*r*r+(-84*h*h+168*h-48)*r+36*(h-1)**2 | |
| assert -288*det3(M)==D | |
| x=[[(-h if j<i else F(0))for j in range(4)]for i in range(4)] | |
| weights={(0,1):5*r/3-1,(0,2):1-r/6,(2,0):r/2,(3,1):r/3,(3,2):1-r/3} | |
| fcoefs=[F(0)]*4;mat=zero(4) | |
| for (i,j),lam in weights.items(): | |
| fcoefs[i]+=lam;fcoefs[j]-=lam | |
| dx=[x[i][z]-x[j][z]for z in range(4)] | |
| dg=[eye[i][z]-eye[j][z]for z in range(4)] | |
| Imat=madd(sym(outer(eye[j],dx)),outer(dg,dg),F(1,2)) | |
| mat=madd(mat,Imat,lam) | |
| assert fcoefs==[r,1-2*r,r-2,F(1)] | |
| Qmat=zero(4) | |
| for i in range(3): | |
| for j in range(3):Qmat=madd(Qmat,outer(ds[i],ds[j]),M[i][j]) | |
| assert mat==Qmat | |
| count+=1 | |
| # Certificate entries have bidegree <=(1,1) in(r,h); det <=(3,2). | |
| # Thus the 4-by-3 exact grid proves both polynomial identities. | |
| return {'exact_identity_grid_cases':count,'determinant_degrees':[3,2], | |
| 'certificate_degrees':[1,1],'all_exact_checks_passed':True} | |
| def run(): | |
| P=discriminant_identity() | |
| return {'certificate':'sharp adjacent-concavity algebraic boundary', | |
| 'arithmetic':'fractions.Fraction', | |
| 'coefficientwise_discriminant_and_repeated_root_identities':True, | |
| 'root_isolation':root_isolation(P), | |
| 'matrix_and_certificate':matrix_and_certificate(), | |
| 'external_replication':False,'proof_assistant_formalization':False, | |
| 'all_exact_checks_passed':True} | |
| if __name__=='__main__': | |
| parser=argparse.ArgumentParser();parser.add_argument('--output',type=Path) | |
| args=parser.parse_args();result=run();out=json.dumps(result,indent=2)+'\n' | |
| if args.output: | |
| args.output.parent.mkdir(parents=True,exist_ok=True);args.output.write_text(out) | |
| print(out) | |