# ztab.py -- writes ztab.h: the coordinates of zeta_m^e, e = 0..m-1, in the power basis of Z[zeta_m], # for the values of m used by butson8.c (computed by reduction modulo the cyclotomic polynomial). def cyclo(m): def polydiv(a,b): a=a[:]; q=[0]*(len(a)-len(b)+1) for i in range(len(a)-len(b),-1,-1): c=a[i+len(b)-1]//b[-1]; q[i]=c for j in range(len(b)): a[i+j]-=c*b[j] assert all(x==0 for x in a[:len(b)-1]); return q p=[-1]+[0]*(m-1)+[1] for d in range(1,m): if m%d==0: p=polydiv(p,cyclo(d)) return p def table(m): P=cyclo(m); phi=len(P)-1; rows=[]; cur=[1]+[0]*(phi-1) for e in range(m): rows.append(cur[:]); nxt=[0]+cur; top=nxt[phi]; nxt=nxt[:phi] for j in range(phi): nxt[j]-=top*P[j] cur=nxt return phi,rows with open('ztab.h','w') as f: for m in [4,8,12,16,20,24,40]: phi,rows=table(m) f.write(f"static const int PHI_{m}={phi};\nstatic const int Z_{m}[{m}][{phi}]={{"+",".join("{"+",".join(map(str,r))+"}" for r in rows)+"};\n")