# twistforms.py -- classes 8 and 9 of the bistochastic forms of had16.3: decomposition b_j = zeta^{k_j} w^{eps_j}, # exact verification in Z[zeta_16] of |P_i|^2+|Q_i|^2 = 16 and Q_i conj(P_i) = +-a for all rows, w = +-i conj(a)/|a|, # and the exact check that -conj(a)/a is not a 16-th root of unity. Also checks the factorizations used in the paper. import numpy as np, json H=np.loadtxt('had163.txt').astype(int) reps=[l.split(' rep ')[1].split() for l in open('../macs/poirier-out/formclasses.txt')] R1=np.nonzero(H[:,0]+H[:,1])[0]; R2=np.nonzero(H[:,0]-H[:,1])[0] print("Dita row groups:",R1.tolist(),R2.tolist()) for c in (8,9): b=np.exp(2j*np.pi*np.array([int(x) for x in reps[c]])/1e6) for it in range(3000): u=H@b; u=u/abs(u); b=H.T@u; b=b/abs(b) s=H@b; a=4/s # row multipliers so that row sums are 4 B=a[:,None]*H*b[None,:] tb=(np.angle(b/b[0])/(2*np.pi)*16)%16; ta=(np.angle(a*b[0])/(2*np.pi)*16)%16 fb=np.round(tb%1,6); fa=np.round(ta%1,6) print(f"\nclass {c}: column phases frac parts {sorted(set(fb))}, row {sorted(set(fa))}") cs=[np.nonzero(np.isclose(fb,v,atol=1e-5))[0].tolist() for v in sorted(set(fb))] rs=[np.nonzero(np.isclose(fa,v,atol=1e-5))[0].tolist() for v in sorted(set(fa))] print(" column split:",cs,"\n row split:",rs) np.save(f'b{c}.npy',b) import numpy as np from math import gcd H=np.loadtxt('had163.txt').astype(int) z=np.exp(2j*np.pi/16) def ev(v,k=1): return sum(int(v[e])*z**(k*e) for e in range(8)) # element of Z[zeta16] as int vector, zeta^8=-1 def mono(e): v=np.zeros(8,int); e%=16; v[e%8]=1 if e<8 else -1; return v def mul(p,q): r=np.zeros(16,int) for i in range(8): for j in range(8): r[i+j]+=p[i]*q[j] return r[:8]-r[8:] def conj(p): # zeta^e -> zeta^-e = -zeta^(8-e) r=np.zeros(8,int); r[0]=p[0] for e in range(1,8): r[8-e]-=p[e] return r for c in (8,9): b=np.load(f'b{c}.npy'); b=b/b[0] t=(np.angle(b)/(2*np.pi)*16)%16; f=t%1; tw=f>0.5 # twisted columns w=np.mean(b[tw]/z**np.round(t[tw]-f[tw]).astype(int)) # the common twist k=np.where(tw,np.round(t-f),np.round(t)).astype(int)%16 assert np.allclose(b,np.where(tw,w,1)*z**k) print(f"class {c}: w = exp(2 pi i * {np.angle(w)/(2*np.pi):.15f}), column exponents k = {k.tolist()}, twisted cols = {np.nonzero(tw)[0].tolist()}") quads=set() for i in range(16): P=sum(H[i,j]*mono(k[j]) for j in range(16) if not tw[j]); Q=sum(H[i,j]*mono(k[j]) for j in range(16) if tw[j]) A=mul(Q,conj(P)); Bc=mul(P,conj(P))+mul(Q,conj(Q)); Bc[0]-=16; C=conj(A) assert abs(ev(A)*w*w+ev(Bc)*w+ev(C))<1e-10 quads.add((tuple(A),tuple(Bc))) print(" distinct quadratics a w^2 + b w + conj(a) = 0 over the 16 rows:",len(quads)) for A,Bc in sorted(quads)[:4]: print(" a =",A," b =",Bc) # norm down to Q: product over sigma_k, k odd A,Bc=map(np.array,sorted(quads)[0]); C=conj(A) poly=np.array([1+0j]) for kk in (1,3,5,7,9,11,13,15): poly=np.convolve(poly,[ev(A,kk),ev(Bc,kk),ev(C,kk)]) pi=np.round(poly.real).astype(np.int64); print(" integer poly (deg 16) max coeff err", np.abs(poly-pi).max(), "\n coeffs", pi.tolist()) g=0 for x in pi: g=gcd(g,int(x)) print(" content",g) # root-of-unity test: phi(n)<=16 -> n<=60 bad=[n for n in range(1,61) if abs(w**n-1)<1e-8]; print(" n<=60 with w^n=1:",bad, " min |w^n-1| =",min(abs(w**n-1) for n in range(1,61))) np.save(f'w{c}.npy',np.array([w])); np.save(f'k{c}.npy',k); np.save(f'tw{c}.npy',tw) print() for c in (8,9): b=np.load(f'b{c}.npy'); b=b/b[0]; w=np.load(f'w{c}.npy')[0]; k=np.load(f'k{c}.npy'); tw=np.load(f'tw{c}.npy') Ps=[];Qs=[];As=[] for i in range(16): P=sum(H[i,j]*mono(k[j]) for j in range(16) if not tw[j]); Q=sum(H[i,j]*mono(k[j]) for j in range(16) if tw[j]) Ps.append(P);Qs.append(Q);As.append(mul(Q,conj(P))) nP=[mul(P,conj(P)) for P in Ps]; nQ=[mul(Q,conj(Q)) for Q in Qs] print(f"class {c}: |P_i|^2 values {sorted(set(tuple(x) for x in nP))}") print(f" |Q_i|^2 values {sorted(set(tuple(x) for x in nQ))}") a=As[0]; # exact test: is -conj(a)/a in mu_16 ? <=> conj(a) = -zeta^m a for some m hits=[m for m in range(16) if np.array_equal(conj(a), -mul(mono(m),a))] print(" a =",a.tolist()," -conj(a)/a in mu_16 for m in",hits, " |a|^2 =",mul(a,conj(a)).tolist(), "numerically",abs(ev(a))**2) print(" w vs i*conj(a)/|a|:", w, 1j*np.conj(ev(a))/abs(ev(a))) x=4/np.array([ev(P)+w*ev(Q) for P,Q in zip(Ps,Qs)]) print(" row multipliers x_i/x_0 phases (units 2pi/16):",np.round((np.angle(x/x[0])/(2*np.pi)*16)%16,6).tolist()) # the arithmetic facts used in the paper, in Z[sqrt2] written as pairs (x,y) = x+y sqrt2 def m2(p,q): return (p[0]*q[0]+2*p[1]*q[1], p[0]*q[1]+p[1]*q[0]) print("\n(1+sqrt2)(5-2sqrt2) sqrt2 =", m2(m2((1,1),(5,-2)),(0,1)), " (should be 6+sqrt2 = (6,1))") print("(5+2sqrt2)(5-2sqrt2) =", m2((5,2),(5,-2)), " (should be 17)", " 17 mod 16 =", 17%16)