# dempsey.py -- few-valued circulant complex Hadamard matrices H_{ix}=h(x-i), of orders N=9 to 24, found without assuming # any symmetry. For m=2 to 5, the program searches for the vectors h with |h|=1 and |FFT(h)|^2=N such that h times some # character takes at most m values, by Gerchberg-Saxton iterations alternating with a quantization step, in which the # phases of h times the best character are pulled towards m cluster centers, and then by Gauss-Newton on the m phases of # the pattern found. The solutions are sorted into classes by the multiset of the numbers |S|, c_2 being the number of # components of the support of T_2, and for each class the program decides whether h is of multiplier type, meaning # that h(ux+t)/h(x), for some unit u not 1 and some t, is constant up to a character, as for the matrices found by # joshua.py, records the values, the zeros of the profile S on the quadruples of distinct indices, and for c_2=2 the norm # of the Jones-Wenzl piece Phi_k^(0) of T_k in the shift-invariant block, which decides wildness, up to level 4 for N<=16 # and level 3 beyond. About 6 minutes for each order. Stops after 1h50m. # Output: dempsey_output/dempsey.log, dempsey_output/dempsey.json # Usage: /usr/bin/python3 dempsey.py import numpy as np, time, json, os, math OUT="dempsey_output"; os.makedirs(OUT,exist_ok=True) LOG=open(os.path.join(OUT,"dempsey.log"),"a") def say(s): print(s,flush=True); LOG.write(s+"\n"); LOG.flush() T0=time.time(); LIMIT=110*60 def el(): return "%7.1fm"%((time.time()-T0)/60) class Block: def __init__(s,h,k,c,dt): s.N=N=len(h); s.k=k; s.c=c; s.dt=dt s.w=np.exp(2j*np.pi*c/N) s.wp=np.array([s.w**t for t in range(N)],dtype=dt) d=(np.arange(N)[:,None]-np.arange(N)[None,:])%N h=np.asarray(h,dtype=complex); hm=h[(-np.arange(N))%N] s.ops=[] for P,Q in ((h,np.conj(h)),(np.conj(hm),hm)): Pm=P[d].astype(dt); Qm=Q[d].astype(dt) K=(Qm[:,None,:]*Pm[None,:,:]) # K[b,y,z] s.ops.append((Pm,Qm,np.ascontiguousarray(K.transpose(0,2,1)))) # Kt[b,z,y] idx=np.indices((N,)*(k-1)); m=(idx[0]!=0) for j in range(k-2): m&=(idx[j]!=idx[j+1]) s.m=m.astype(np.float32 if dt==np.complex64 else np.float64) def contract(s,g,op): N,k=s.N,s.k; Pm,Qm,Kt=op G=Pm[:,0].reshape((N,)+(1,)*(k-1))*g[None] for t in range(2,k+1): a=N**(t-2); r=N**(k-t) X=np.ascontiguousarray(G.reshape(a,N,N,r).transpose(1,0,3,2)).reshape(N,a*r,N); del G Y=np.matmul(X,Kt); del X G=np.ascontiguousarray(Y.reshape(N,a,r,N).transpose(1,0,3,2)); del Y G=G.reshape((N,)*k) out=np.zeros((N,)*(k-1),dtype=s.dt); ax=tuple(range(k-1)) for z1 in range(N): out+=s.wp[z1]*np.roll(G[(-z1)%N],shift=z1,axis=ax)*Qm[:,z1].reshape((1,)*(k-2)+(N,)) return out def T(s,g): y=s.contract(g,s.ops[0]) y=np.ascontiguousarray(y.transpose(tuple(range(s.k-2,-1,-1)))) y=s.contract(y,s.ops[1]) y=np.ascontiguousarray(y.transpose(tuple(range(s.k-2,-1,-1)))) return y/s.N**(s.k+1) def P1(s,g): N,k=s.N,s.k for ax in range(k-1): g=g-g.mean(axis=ax,keepdims=True) av=np.zeros_like(g) for t in range(N): av+=s.wp[t]*np.roll(g,shift=t,axis=tuple(range(k-1))) return g-av/N def proj(s,g,tol,maxit=300): for it in range(maxit): g2=s.P1(g)*s.m ch=np.linalg.norm(g2-g)/max(np.linalg.norm(g2),1e-300); g=g2 if chabcd',H,H.conj(),H.conj(),H) def invariants(H): # the multiset of the numbers |S(a,b,c,d)|, invariant under equivalence and conjugation, and c_2 = number of connected # components of the graph on pairs (i1,i2), (j1,j2) joined when S(i1,j1,i2,j2) is nonzero N=len(H); S=profile(H); A=abs(S) key=np.round(np.sort(A.ravel()),6) adj=(A>1e-9).transpose(0,2,1,3).reshape(N*N,N*N) parent=list(range(N*N)) def find(x): while parent[x]!=x: parent[x]=parent[parent[x]]; x=parent[x] return x I,J=np.nonzero(np.triu(adj)) for i,j in zip(I.tolist(),J.tolist()): ri,rj=find(i),find(j) if ri!=rj: parent[ri]=rj return key,len({find(x) for x in range(N*N)}) def distinct_mask(N): a,b,c,d=np.indices((N,)*4); return (a!=b)&(a!=c)&(a!=d)&(b!=c)&(b!=d)&(c!=d) def kmeans_phase(z,m,rng,it=20): cen=np.exp(1j*rng.choice(np.angle(z),m,replace=False)) for _ in range(it): lab=np.argmax(np.real(np.conj(cen)[None,:]*z[:,None]),axis=1) for j in range(m): s=z[lab==j].sum() if abs(s)>1e-12: cen[j]=s/abs(s) return np.argmax(np.real(np.conj(cen)[None,:]*z[:,None]),axis=1),cen def best_character(h,m,rng): N=len(h); x=np.arange(N); best=None for c in range(N): g=h*np.exp(-2j*np.pi*c*x/N); g=g/g[0] lab,cen=kmeans_phase(g,m,rng,it=10) err=np.sum(abs(g-cen[lab])**2) if best is None or errLIMIT: say("%s time limit reached"%el()); break classes=[]; DM=distinct_mask(N); stats={} for m in range(2,6): TM=time.time(); runs=0; hits=0 while time.time()-TM<75 and time.time()-T01e-10: continue hits+=1; key,c2=invariants(circ(h)) for cl in classes: if len(cl["key"])==len(key) and np.allclose(cl["key"],key,atol=2e-6): cl["hits"]+=1; break else: classes.append({"key":key,"h":h,"c2":c2,"hits":1,"m":m}) stats[str(m)]=[runs,hits] say(" %s N=%d, at most %d values: %d runs, %d solutions, %d classes so far"%(el(),N,m,runs,hits,len(classes))) out=[]; nonmult=0 for cl in classes: h=cl["h"]; nv,c=values_up_to_characters(h); g=h*np.exp(-2j*np.pi*c*np.arange(N)/N); g=g/g[0] mt=multiplier_type(h); S=profile(circ(h)) rec={"c2":cl["c2"],"hits":cl["hits"],"values":nv,"multiplier_maps":mt[:12],"row":[[float(z.real),float(z.imag)] for z in g], "zeros_S":int(np.sum((abs(S)<1e-9)&DM)),"min_abs_S_distinct":float(abs(S)[DM].min()),"norms_block0":{}} if not mt: nonmult+=1 say(" %s N=%d class: c_2 %d, %d values, %s, zeros of S %d, min|S| %.6f, values %s"%(el(),N,cl["c2"],nv, "multiplier type %s"%mt[:3] if mt else "NOT of multiplier type",rec["zeros_S"],rec["min_abs_S_distinct"], " ".join("%.12f%+.12fi"%(z.real,z.imag) for z in sorted({complex(round(v.real,10),round(v.imag,10)) for v in g},key=lambda z:(z.real,z.imag))))) if cl["c2"]==2: for k in range(2,(4 if N<=16 else 3)+1): if time.time()-T0>LIMIT: break v=lanczos(Block(h,k,0,np.complex128),40 if N**(k-1)>=200 else 30,1e-11,seed=k*100,tag="",verbose=False)[0] rec["norms_block0"][str(k)]=v say(" %s level %d: norm of Phi_k^(0) %.6f, 4/N %.6f"%(el(),k,v,4/N)) out.append(rec) c2h={} for cl in classes: c2h[cl["c2"]]=c2h.get(cl["c2"],0)+1 say("%s N=%d: %d classes, by c_2: %s, not of multiplier type: %d"%(el(),N,len(classes),dict(sorted(c2h.items())),nonmult)) db[str(N)]={"runs_and_solutions_by_m":stats,"classes":len(classes),"by_c2":{str(a):b for a,b in c2h.items()},"not_multiplier":nonmult,"list":out} json.dump(db,open(os.path.join(OUT,"dempsey.json"),"w"),indent=1) say("%s finished"%el())