"""Exact scalar reconstruction of Liu ยง6 at its rational boundary. The new arbitrary-unitary ordinary theorem is GRANTED by this scalar script. No analytic theorem, Lean endpoint or official record is proved by these numbers. """ from fractions import Fraction as F from math import comb,gcd,lcm from pathlib import Path import hashlib,json import sympy as sy q=sy.Rational d,x=sy.symbols('delta x') B=q(8733821,10**7); b=q(499781491,5*10**9) ell=q(11,3)-4*B; lx=(1-b-ell)/2; ly=(1+b-ell)/2; h=(1+b+3*ell)/2 T=2*ly-h; C0=-q(1,4)+b/6+5*ell/4; stock=q(21,100); p=q(1124661,250000); theta0=d*x/p md=(q(5,6)-d*x)/(q(5,2)-d-2*d*x);rd=2*md;td=3*md;Fd=x+2*(1-x)*md;Rd=1-d*Fd cc=2/p;D=3-(1+2*cc)*x;P=(2-2*cc*x)*(1-x);J=(q(5,6)-d)*D+d*P Rs=1-d+(q(5,6)-d)*d*P/(2*J) def E(R):return C0+d/2+d*x*(ell+(h/2-ly)/p)-3*h*(1-R)/4 def S(R):return (3*R+1)/4+theta0/2-q(17,50) def N(R):return (3*R+1)/4-theta0/2 def Dsh(R):return R+(q(1,2)-theta0)*q(3,40)-N(R) JN=q(5,2)-5/p;GN=d*x*JN*T/10;GL=theta0*(q(7,10)*h-ly);GR=(d/2-theta0)*(ly-q(53,100)*h) Dmain=(F(11,50),F(13,20),F(6,25),F(1,2));Omega=(F(1,8),F(5,6),F(0),F(1,2)) comps=[(F(1,8),F(5,6),F(0),F(6,25)),(F(1,8),F(11,50),F(6,25),F(1,2)),(F(13,20),F(5,6),F(6,25),F(1,2))] def frac(v):return F(int(v.p),int(v.q)) def coefficients(poly): terms={ij:frac(c) for ij,c in sy.Poly(poly,d,x).terms()};den=lcm(*(v.denominator for v in terms.values())) terms={ij:int(v*den) for ij,v in terms.items()};gg=gcd(*(abs(v) for v in terms.values())) or 1 return {ij:F(v//gg) for ij,v in terms.items() if v} def bernstein(c,box): na=max(i for i,j in c);nb=max(j for i,j in c);a,b,u,v=box;pw={} for (i,j),val in c.items(): for k in range(i+1): for n in range(j+1): ij=(k,n);pw[ij]=pw.get(ij,F(0))+val*comb(i,k)*a**(i-k)*(b-a)**k*comb(j,n)*u**(j-n)*(v-u)**n return [sum((pw.get((k,n),F(0))*F(comb(i,k),comb(na,k))*F(comb(j,n),comb(nb,n)) for k in range(i+1) for n in range(j+1)),F(0)) for i in range(na+1) for j in range(nb+1)] def halves(box,axis): a,b,u,v=box return ((a,(a+b)/2,u,v),((a+b)/2,b,u,v)) if axis==0 else ((a,b,u,(u+v)/2),(a,b,(u+v)/2,v)) def prove(c,box,depth=0): vals=bernstein(c,box) if min(vals)>0:return {'min':str(min(vals))} a,b,u,v=box;mid=sum((val*((a+b)/2)**i*((u+v)/2)**j for (i,j),val in c.items()),F(0)) if mid<=0 or depth>=28:raise ValueError((box,mid,depth)) ll,rr=halves(box,depth%2) return {'axis':depth%2,'left':prove(c,ll,depth+1),'right':prove(c,rr,depth+1)} def leaves(tree):return 1 if 'min' in tree else leaves(tree['left'])+leaves(tree['right']) cert=[] def positive(name,expr,box=Dmain): num,den=sy.fraction(sy.cancel(expr));pt={d:q((box[0]+box[1])/2),x:q((box[2]+box[3])/2)} if den.subs(pt)<0:num,den=-num,-den rec={'name':name,'box':[str(v) for v in box]} for part,poly in [('numerator',num),('denominator',den)]: c=coefficients(poly);tree=prove(c,box) rec[part]={'coefficients':[[i,j,str(v)] for (i,j),v in sorted(c.items())],'tree':tree,'leaves':leaves(tree)} cert.append(rec) for name,expr in [ ('left numerator gain>1e-8',GL-E(Rd)-q(1,10**8)), ('middle numerator gain>1e-8',GN-E(Rd)-q(1,10**8)), ('right numerator gain>1e-8',GR-E(Rd)-q(1,10**8)), ('main reference slope>1/5',S(Rd)-q(1,5)),('main reference slope<1',1-S(Rd)), ('main reference exponent<1/250',q(1,250)-E(Rd)), ('main reference stock',(p-2*d*x)*stock-Rd), ('short-source saving>1e-5',-E(Rd)-h*Dsh(Rd)-q(1,10**5)), ('short-source slope positive',S(Rd)+Dsh(Rd)),('short-source slope<2',2-S(Rd)-Dsh(Rd)), ('detector md>7/20',md-q(7,20)),('detector md<49/100',q(49,100)-md), ('detector rd>3/5',rd-q(3,5)),('detector rd<1',1-rd), ('detector td>1',td-1),('detector td<3/2',q(3,2)-td), ('detector upper m endpoint stronger',q(49,50)+x/50-Fd), ('numerator saving bound',q(1,50)-d*x*JN*q(2,5)/10), ]:positive(name,expr) for name,expr in [('old denominator positive',J),('old reference slope positive',S(Rs)),('old reference slope<1',1-S(Rs)),('old reference stock',(p-2*d*x)*stock-Rs)]:positive(name,expr,Omega) for i,box in enumerate(comps):positive('complement reference saving>1e-5 '+str(i),-E(Rs)-q(1,10**5),box) m0=1-ly/h;Qsm=ell*(q(1,2)+2*ell/h)-11*h/54 const={ 'b':b,'ell>1/6':ell-q(1,6),'ell<1/5':q(1,5)-ell,'lx>ell':lx-ell,'Gram':ly-ell-11*b/6, 'p1 ell>3/4':p*ell-q(3,4),'T':T,'ly<1/2':q(1,2)-ly,'principal B>.87':B-q(87,100), 'stock top buffered':ell/(h+q(1,10**9))-stock,'shortened stock<2/9':q(2,9)-ell/(h-q(1,40)), 'm0>.30':m0-q(3,10),'m0<.47':q(47,100)-m0,'ly/h>.57':ly/h-q(57,100),'ly/h<.59':q(59,100)-ly/h, 'small amplitude coefficient':-Qsm,'small amplitude margin':-q(1,250)-C0-(1-h)/16, 'floor margin':-q(1,1000)-C0-(q(1,2)+3*ell/2)/50, 'small rows margin':-q(1,20)-13*h/75+ly/2-q(1,50), 'principal h/600':h/600,'principal ly/20':ly/20, 'reference theta0<.073':q(73,1000)-q(13,40)/p, 'scale slope>.1':q(1,5)-q(73,1000)*q(37,40)-q(1,50)-q(1,10), } assert all(v>0 for v in const.values()) assert sy.cancel(q(11,12)-ell/4-B)==0 assert sy.cancel(Rd-q(1,6)-(q(5,6)-d)*td)==0 out={'status':'PASS_EXACT_SCALAR_ONLY_WITH_NEW_TWO_BACKGROUND_MOMENT_GRANTED','theta':str(B), 'geometry':{k:str(v) for k,v in [('b',b),('ell',ell),('h',h),('lx',lx),('ly',ly),('T',T),('m0',m0)]}, 'detector_prime_coefficient':'2','reference_prime_coefficient':str(p),'certificates':cert, 'positive_constants':{k:str(v) for k,v in const.items()}, 'analytic_moment_proved_by_script':False,'complete_analytic_endpoint_proved_by_script':False,'Lean_endpoint':False,'tracker_admission':False, 'imported_scalar_source':'Liu2611.00082v1 Section6; independently reconstructed rational functions and certificates', 'new_source_requirement':'Full coefficient-two ordinary moment for same-background(psi,psi), not merely mixed(1,psi).'} path=Path(__file__).with_name('complete-certificate.json');path.write_text(json.dumps(out,indent=2)+'\n') print(json.dumps({'status':out['status'],'theta':str(B),'conditions':len(cert),'leaves':sum(z[k]['leaves'] for z in cert for k in ['numerator','denominator']),'constants':len(const),'sha256':hashlib.sha256(path.read_bytes()).hexdigest()}))