# circulant.py -- circulant Hadamard matrices H_{ix}=h(x-i): the Fourier form of the profile (Proposition 5.14), and the # decomposition of the Jones transfer matrices T_k=N^{-k-1}AA^* over the characters t->w^{ct} of the cyclic shift # (Theorem 5.15). The vectors of the block c are the functions f on Z_N^k with f(i+t)=w^{ct}f(i), stored by their values # on the words starting with 0, and T_k is applied by contracting the cycle i_1,x_1,...,i_k,x_k one vertex at a time, # at a cost of order N^{k+1}. The Jones-Wenzl piece Phi_k^{(c)} is T_k on the vectors of the block c whose leg sums vanish # and which vanish on the words with 2 equal adjacent letters, the projection onto these vectors being computed by # alternating projections, and its norm is computed by Lanczos, with full reorthogonalization. Output for BF_6, levels # 2 to 6, with the checks against the full matrices T_k at the levels 2 to 4. # Usage: python3 circulant.py import numpy as np, itertools, time def bf6(): s3=np.sqrt(3); a=(1-s3+1j*np.sqrt(2*s3))/2 return np.array([1,1j*a,-a,-1j,-np.conj(a),1j*np.conj(a)]) def circ(h): N=len(h); return np.array([[h[(x-i)%N] for x in range(N)] for i in range(N)]) def contract(g,P,Q,c,N,k): # out(y) = sum_z prod_s P(y_s-z_s)Q(y_s-z_{s+1}) g(z), for functions in the block c, in reduced form w=np.exp(2j*np.pi*c/N); d=(np.arange(N)[:,None]-np.arange(N)[None,:])%N Pm=P[d]; Qm=Q[d]; K=Qm[:,None,:]*Pm[None,:,:] G=Pm[:,0].reshape((N,)+(1,)*(k-1))*g[None] for t in range(2,k+1): G=np.einsum('abzr,byz->abyr',G.reshape(N**(t-2),N,N,N**(k-t)),K,optimize=True).reshape((N,)*k) out=np.zeros((N,)*(k-1),dtype=G.dtype) for z1 in range(N): out+=(w**z1)*np.roll(G,shift=z1,axis=tuple(range(k)))[0]*Qm[:,z1].reshape((1,)*(k-2)+(N,)) return out def rev(g): return np.transpose(g,tuple(range(g.ndim-1,-1,-1))) class Block: def __init__(s,h,k,c): s.h=np.asarray(h,dtype=complex); s.N=len(h); s.k=k; s.c=c; s.w=np.exp(2j*np.pi*c/s.N) def Astar(s,g): return contract(g,s.h,np.conj(s.h),s.c,s.N,s.k) def A(s,g): hm=s.h[(-np.arange(s.N))%s.N]; return rev(contract(rev(g),np.conj(hm),hm,s.c,s.N,s.k)) def T(s,g): return s.A(s.Astar(g))/s.N**(s.k+1) def full(s,g): N,k=s.N,s.k; idx=np.indices((N,)*k).reshape(k,-1); i1=idx[0] return ((s.w**i1)*g[tuple((idx[1:]-i1)%N)]).reshape((N,)*k) def P1(s,g): N,k=s.N,s.k for ax in range(k-1): g=g-g.mean(axis=ax,keepdims=True) return g-sum((s.w**t)*np.roll(g,shift=t,axis=tuple(range(k-1))) for t in range(N))/N def mask(s): idx=np.indices((s.N,)*(s.k-1)); m=(idx[0]!=0) for j in range(s.k-2): m&=(idx[j]!=idx[j+1]) return m def proj(B,g,m,tol=1e-13,maxit=1000): for it in range(maxit): g2=B.P1(g)*m if np.linalg.norm(g2-g)<=tol*max(np.linalg.norm(g),1e-300): return g2 g=g2 return g def phinorm(B,nv=60,seed=0): rng=np.random.default_rng(seed); m=B.mask(); sh=m.shape v=proj(B,rng.normal(size=sh)+1j*rng.normal(size=sh),m); V=[v/np.linalg.norm(v)] for j in range(min(nv,int(np.prod(sh))-1)): w=proj(B,B.T(V[-1]),m) for rep in range(2): for u in V: w=w-np.vdot(u,w)*u nb=np.linalg.norm(w) if nb<1e-10: break V.append(w/nb) Vm=np.array([u.ravel() for u in V]); TV=np.array([proj(B,B.T(u),m).ravel() for u in V]) M=Vm.conj()@TV.T; return np.linalg.eigvalsh((M+M.conj().T)/2).max() def Tfull(H,k): N=len(H); idx=np.indices((N,)*(2*k)).reshape(2*k,-1); i=idx[:k]; x=idx[k:] val=np.ones(idx.shape[1],dtype=complex) for s in range(k): val*=np.conj(H[i[s],x[s]])*H[i[(s+1)%k],x[s]] A=val.reshape(N**k,N**k); return A@A.conj().T/N**(k+1) if __name__=="__main__": h=bf6(); N=6; H=circ(h); w=np.exp(2j*np.pi/N) print("BF_6: Hadamard error %.1e"%abs(H@H.conj().T-N*np.eye(N)).max()) lam=np.array([sum(h[t]*w**(k*t) for t in range(N)) for k in range(N)]) print("eigenvalues |lambda_k|^2:",np.round(abs(lam)**2,12)) S=lambda a,b,c,d: sum(H[a,y]*np.conj(H[b,y])*np.conj(H[c,y])*H[d,y] for y in range(N)) SF=lambda a,b,c,d: sum(lam[k]*np.conj(lam[l])*np.conj(lam[m])*lam[(l+m-k)%N]*w**(k*a-l*b-m*c+((l+m-k)%N)*d) for k in range(N) for l in range(N) for m in range(N))/N**3 print("Fourier form of the profile, max error %.1e"%max(abs(S(*q)-SF(*q)) for q in itertools.product(range(N),repeat=4))) rng=np.random.default_rng(0) for k in (2,3,4): T=Tfull(H,k); err=0 for c in range(N): B=Block(h,k,c); g=rng.normal(size=(N,)*(k-1))+1j*rng.normal(size=(N,)*(k-1)) err=max(err,abs(B.full(B.T(g))-(T@B.full(g).ravel()).reshape((N,)*k)).max()) print("level %d: blocks versus the full T_k, max error %.1e"%(k,err)) print("norms of the blocks Phi_k^(c), c=0,...,5:") for k in range(2,7): t=time.time(); row=[phinorm(Block(h,k,c)) for c in range(N)] print("k=%d "%k+" ".join("%.8f"%x for x in row)+" max %.8f %.0fs"%(max(row),time.time()-t),flush=True)