# pthreecheck.py -- exact P_3(N,q) for small q, by dynamic programming on the 3 row inner products of a dephased # 3-row array (columns (1, w^a, w^b), uniform), compared with Theorem 1.1: P_3 ~ h P_2^3, h = Phi_q(1). import sys from latticecheck import cyclo, reduce_mod from ptwocheck import exact as p2 def p3(q,N): P=cyclo(q); s=len(P)-1; co=[tuple(reduce_mod(e,P)) for e in range(q)] steps=[co[a]+co[b]+co[(a-b)%q] for a in range(q) for b in range(q)] dist={tuple([0]*(3*s)):1} for _ in range(N): new={} for v,c in dist.items(): for st in steps: w=tuple(x+y for x,y in zip(v,st)); new[w]=new.get(w,0)+c dist=new return dist.get(tuple([0]*(3*s)),0)/q**(2*N), sum(P) for q,Ns in ((4,(8,12,16)),): for N in Ns: a,h=p3(q,N); b=p2(q,N); print(f"q = {q}, N = {N}: P_3 / P_2^3 = {a/b**3:.4f} (Theorem 1.1: h = {h})",flush=True)