# arithmetic.py -- the arithmetic invariants, which live on the conjugacy class. (1) For the Fourier matrices # F_N = (w^jk), with w = e^(2 pi i/N) and j,k = 0,...,N-1, we check the Gauss formula Tr(F_N) = (1+i)(1+i^-N) sqrt(N)/2. # (2) For Butson matrices H, with entries w^E_jk, w = e^(2 pi i/q), we check that all the matrices s_m(H) = (w^(m E_jk)), # with m prime to q, are Hadamard, so that all the Galois conjugates of the eigenvalues of H have modulus sqrt(N). # (3) For the glued arrays, where the row and column spins are identified, the energy being -/sqrt(N), we compute # exactly E and E||^2, with a uniform on T^N, by averaging on the cube roots of unity, which is exact here, # and E^2 with a uniform on {-1,1}^N, by summing over all signs, and we check the formulas Tr(H), # |Tr(H)|^2 + N^2 - N, and Tr(H)^2 + Tr(H^2) + N^2 - 2N. We also check that these are invariant under conjugation by # random monomial matrices, and that the trace is not invariant under the equivalence, Tr(F_N D_b) being N for # b_k = w^(-k^2). import numpy as np, itertools, glob from math import gcd rng=np.random.default_rng(1) def fourier(N): return np.exp(2j*np.pi*np.outer(np.arange(N),np.arange(N))/N) def butson(E,q): return np.exp(2j*np.pi*np.asarray(E)/q) def glued_complex(H): N=len(H); w=np.exp(2j*np.pi*np.arange(3)/3); m1=0; m2=0; n=0 for t in itertools.product(range(3),repeat=N): a=w[list(t)]; x=np.vdot(a,H@a); m1+=x; m2+=abs(x)**2; n+=1 return m1/n, m2/n def glued_real(H): N=len(H); A=np.array(list(itertools.product([-1,1],repeat=N)),dtype=float) x=np.einsum('sj,jk,sk->s',A,H,A); return x.mean(), (x**2).mean() def monomial(N): P=np.eye(N)[rng.permutation(N)]; D=np.diag(np.exp(2j*np.pi*rng.random(N))); return P@D def r(x): return complex(round(x.real,9),round(x.imag,9)) print("(1) Gauss sums, Tr(F_N) versus (1+i)(1+i^-N) sqrt(N)/2") for N in range(1,17): t=np.trace(fourier(N)); g=(1+1j)*(1+1j**(-N))*np.sqrt(N)/2 print(f"N={N:2d} Tr(F_N)={r(t)} |Tr|^2={round(abs(t)**2,9)} agrees: {abs(t-g)<1e-9}") E6H=[[0,0,0,0,0,0],[0,2,1,1,3,3],[0,1,2,3,1,3],[0,1,3,2,3,1],[0,3,1,3,2,1],[0,3,3,1,1,2]] E6T=[[0,0,0,0,0,0],[0,0,1,1,2,2],[0,1,0,2,2,1],[0,1,2,0,1,2],[0,2,2,1,0,1],[0,2,1,2,1,0]] butsons=[(f"F_{N}",np.outer(np.arange(N),np.arange(N))%N,N) for N in range(2,13)] butsons+=[("Haagerup",E6H,4),("Tao",E6T,3)] print("(2) Weil property: all s_m(H) Hadamard, so all conjugates of the eigenvalues have modulus sqrt(N)") for name,E,q in butsons: E=np.asarray(E); N=len(E); ok=True; dev=0 for m in range(1,q): if gcd(m,q)!=1: continue K=butson(m*E%q,q); ok&=np.allclose(K@K.conj().T,N*np.eye(N)) dev=max(dev,np.max(np.abs(np.abs(np.linalg.eigvals(K))-np.sqrt(N)))) print(f"{name:9s} q={q:2d} Hadamard for all m: {ok} max | |lambda| - sqrt(N) | = {dev:.1e} Tr(H)={r(np.trace(butson(E,q)))}") print("(3) glued arrays, complex case: E = Tr(H) and E||^2 = |Tr(H)|^2 + N^2 - N") cx=[(f"F_{N}",fourier(N)) for N in range(2,8)]+[("Haagerup",butson(E6H,4)),("Tao",butson(E6T,3))] for name,H in cx: N=len(H); m1,m2=glued_complex(H); t=np.trace(H); f=abs(t)**2+N*N-N Q=monomial(N); K=Q@H@Q.conj().T; k1,k2=glued_complex(K) print(f"{name:9s} E={r(m1)} E||^2={round(m2,9)} formula={round(f,9)} agrees: {abs(m1-t)<1e-9 and abs(m2-f)<1e-8} conjugate: {abs(k1-m1)<1e-9 and abs(k2-m2)<1e-8}") print("(4) glued arrays, real case: E = Tr(H) and E^2 = Tr(H)^2 + Tr(H^2) + N^2 - 2N") for f in sorted(glob.glob('matrices/*.txt')): H=np.loadtxt(f); N=len(H) if N>16: continue m1,m2=glued_real(H); t=np.trace(H); f2=t*t+np.trace(H@H)+N*N-2*N P=np.eye(N)[rng.permutation(N)]@np.diag(rng.choice([-1,1],N)); K=P@H@P.T; k1,k2=glued_real(K) print(f"{f.split('/')[-1][:-4]:8s} Tr(H)={t:4.0f} Tr(H^2)={np.trace(H@H):5.0f} E^2={m2:7.0f} agrees: {abs(m1-t)<1e-9 and abs(m2-f2)<1e-7} conjugate: {abs(k1-m1)<1e-9 and abs(k2-m2)<1e-7}") print("(5) the trace is not an invariant of the equivalence: Tr(F_N D_b) = N, for b_k = w^(-k^2)") for N in range(2,13): w=np.exp(2j*np.pi/N); b=w**(-np.arange(N)**2) print(f"N={N:2d} |Tr(F_N)|^2={round(abs(np.trace(fourier(N)))**2,9)} Tr(F_N D_b)={r(np.trace(fourier(N)@np.diag(b)))}")