"""Independent integer polynomial and fixed-point moment proof (standard library). No Flint/Arb, optimizer, numerical integration, or other checker is imported. """ from fractions import Fraction as F from pathlib import Path from math import comb,gcd,lcm,isqrt import json,argparse,time,hashlib if not __debug__:raise SystemExit('Refusing -O/-OO: proof assertions must be active') S=1<<180 def ceildiv(n,d): assert d>0 return -((-n)//d) def enc(x): x=F(x);return x.numerator*S//x.denominator,ceildiv(x.numerator*S,x.denominator) def interval_multiply(a,b): assert min(a)>=0 and min(b)>=0 return a[0]*b[0]//S,ceildiv(a[1]*b[1],S) def interval_power(a,k): result=(S,S) while k: if k&1:result=interval_multiply(result,a) a=interval_multiply(a,a);k>>=1 return result def pmul(a,b): result=[0]*(len(a)+len(b)-1) for i,x in enumerate(a): for j,y in enumerate(b):result[i+j]+=x*y while len(result)>1 and not result[-1]:result.pop() return result def padd(a,b): result=[0]*max(len(a),len(b)) for i,x in enumerate(a):result[i]+=x for i,x in enumerate(b):result[i]+=x while len(result)>1 and not result[-1]:result.pop() return result def scale(a,c):return [x*c for x in a] def primitive_digest(a): content=0 for x in a:content=gcd(content,abs(x)) h=hashlib.sha256() for x in a: x//=content;b=abs(x).to_bytes(max(1,(abs(x).bit_length()+7)//8),'big');h.update(bytes([x<0]));h.update(len(b).to_bytes(8,'big'));h.update(b) return h.hexdigest() def mobius_positive(p,left,right): n=len(p)-1;D=lcm(left.denominator,right.denominator);A=left.numerator*(D//left.denominator);B=right.numerator*(D//right.denominator) # (1+x)^n P((A+B*x)/(D*(1+x))) * D^n, by homogenized Horner. q=[p[-1]];dp=1 for j in range(1,n+1): dp*=D;v=p[n-j]*dp;new=[v*comb(j,k) for k in range(j+1)] for k,x in enumerate(q):new[k]+=A*x;new[k+1]+=B*x q=new assert all(x>0 for x in q),('Mobius positivity',str(left),str(right)) def main(): ap=argparse.ArgumentParser();ap.add_argument('certificate');ap.add_argument('--out');args=ap.parse_args();start=time.monotonic();path=Path(args.certificate);d=json.loads(path.read_text());c=F(d['c']);R=F(d['R']);nodes=list(map(F,d['nodes']));weights=list(map(F,d['weights'])) assert 0=2;assert all(w>0 for w in weights) and sum(weights)==R;assert nodes[0]==c*c and nodes[-1]==R and all(a=28 Delta=1-R;assert aa[0]>sum(abs(a)*Delta**j for j,a in enumerate(aa[1:],1));assert sum(abs(a)*Delta**j for j,a in enumerate(aa,1))<1 # Reconstruct K_N(sqrt(t))^2 as a ratio of INTEGER polynomials. C,D=c.numerator,c.denominator;Cn=[C**j for j in range(2*N+3)];Dn=[D**j for j in range(2*N+3)];num=[C*C,2*C*D,D*D];den=[0,1];top=4;bot=D**(2+8*N) for n in range(1,N+1): for factor in [[Dn[2*n-1],Cn[2*n-1]],[Cn[2*n+1],Dn[2*n+1]]]:num=pmul(pmul(num,factor),factor) for factor in [[Dn[2*n-2],Cn[2*n-2]],[Cn[2*n],Dn[2*n]]]:den=pmul(pmul(den,factor),factor) top*=(Dn[2*n]+Cn[2*n])**4;bot*=(Dn[2*n-1]+Cn[2*n-1])**4 common=gcd(top,bot);num=scale(num,top//common);den=scale(den,bot//common) # Expand the small lower polynomial independently by the binomial theorem. lc=[sum(((-1)**j)*aa[k-1]*comb(k,j) for k in range(max(1,j),len(aa)+1)) for j in range(len(aa)+1)] ell=1 for x in lc:ell=lcm(ell,x.denominator) LP=[int(x*ell) for x in lc] err=(1+3*c+2*c*c+(c**3+c*c)/R)*c**(2*N)/(1-c*c);assert 0=R;powers=[S]*len(T);rp=RR[1];minA=None;argA=0 for k in range(1,K1): powers=[p*t[0]//S for p,t in zip(powers,T)];rp=ceildiv(rp*RR[1],S);gap=(k+1)*sum(w[0]*p//S for w,p in zip(W,powers))-rp;assert gap>0,('A',k,F(gap,S));rel=F(gap,rp) if minA is None or rel=1 # Independently bound the derivative with respect to delta=1-t on # the tail interval: every nonconstant derivative term is bounded # below by minus its absolute coefficient times (1-t0)^power. slope_lower=aa[0] for j in range(2,len(aa)+1):slope_lower-=j*abs(aa[j-1])*(1-t0)**(j-1) assert slope_lower>0, 'tail envelope decreasing' cap=sum(a*(1-t1)**j for j,a in enumerate(aa,1));assert cap>0 tail=interval_multiply(enc(cap*(t1-t0)),interval_power(enc(t0),K2))[0];negative=sum(interval_multiply(w,interval_power(t,K2))[1] for w,t in zip(W,T));assert tail>negative,('second tail',F(tail-negative,S)) rj=[interval_power(RR,j) for j in range(len(lc))];ej=[interval_power(EE,j) for j in range(len(lc))];rp=RR;ep=EE;powers=[S]*len(T);wb=[ceildiv(w[1]*b,S) for w,b in zip(W,beta)];minB=None;argB=0 for k in range(1,K2): rp=interval_multiply(rp,RR);ep=interval_multiply(ep,EE);powers=[ceildiv(p*t[1],S) for p,t in zip(powers,T)];integ=0 for j,coef in enumerate(lc): e=interval_multiply(ep,ej[j]);r=interval_multiply(rp,rj[j]);diff=(e[0]-r[1],e[1]-r[0]);assert diff[0]>0 bound=diff[0] if coef>=0 else diff[1];integ+=(coef.numerator*bound)//(coef.denominator*(k+j+1)) gap=(k+1)*integ+rp[0]-(k+1)*sum(ceildiv(w*p,S) for w,p in zip(wb,powers));assert gap>0,('B',k,F(gap,S));rel=F(gap,rp[0]) if minB is None or rel