"""Exact test: for CLIMB (b=(C..1), rho=1), is R_k := G*E_k(F) - F*E_k(G) coefficientwise >= 0 in gap variables, where M=G/F is the miss probability, E_k = sum_{i<=k} p_i d/dp_i (scale the top-k block)? R_k>=0 on the chamber <=> miss probability nonincreasing in the k-th log-gap.""" import sys,time from itertools import permutations from flint import fmpz_mpoly_ctx, Ordering def run(N,C,b=None,rho=1): ctx=fmpz_mpoly_ctx.get(['x%d'%(i+1) for i in range(N)],Ordering.lex); x=ctx.gens() sub=[] for i in range(N): s=x[i] for h in range(i+1,N): s=s+x[h] sub.append(s) b=list(range(C,0,-1)) if b is None else b def I(parts): d={} for s in permutations(range(N),len(parts)): e=[0]*N for r,i in enumerate(s): e[i]+=parts[r] e=tuple(e); d[e]=d.get(e,0)+1 return ctx.from_dict(d) F=I(b)*I([rho]); G=I(b+[rho]); out=[] for k in range(1,N): E=lambda f: sum((x[i]*f.derivative(i) for i in range(1,k)), x[0]*f.derivative(0)) R=G*E(F)-F*E(G) cs=R.compose(*sub,ctx=ctx).coeffs() out.append((k,len(cs),sum(1 for c in cs if c<0))) return out if __name__=="__main__": for N in range(2,int(sys.argv[1])+1): for C in range(1,N): t=time.time(); o=run(N,C) print("N=%d C=%d:"%(N,C)," ".join("k=%d:%d terms,%d neg"%t3 for t3 in o),"[%.1fs]"%(time.time()-t),flush=True)