# wladimir.py -- a hunt for complex Hadamard matrices of composite order outside the Dita/wild dichotomy. A matrix which # is not wild should be of Fourier or Dita type, and in particular its quantum group should preserve a partition of the # indices into blocks, these blocks being visible on the orbitals, the connected components of the graph on the pairs of # rows (i1,i2), (j1,j2) joined when S(i1,j1,i2,j2) is nonzero, whose number is dim P_2. For N = 6, 8, 9, 10, 12 the # program finds complex Hadamard matrices from random starting points, with no symmetry assumed, by alternating # projections between the unitary group and the matrices with entries of modulus 1, polished by Levenberg-Marquardt, # sorts them into classes by the multiset of the numbers |S|, and computes for each class the defect, dim P_2, dim P_3, # and for dim P_2 > 2 the block systems, that is, the unions of orbitals which together with the diagonal are # equivalence relations with blocks of size 1 < m < N. A class with dim P_2 = 2 and dim P_3 > 5, or with dim P_2 > 2 # and no block system, would be outside the dichotomy, and is marked OUTSIDE. The profile entries below 1e-4 are # treated as zeros, since at the singular points the solutions are only accurate to about 7 digits, and each new type # of class is printed once. The time is split between the orders, 15, 25, 20, 25 and 25 minutes. # Output: wladimir_output/wladimir.log, wladimir_output/wladimir.json # Usage: /usr/bin/python3 wladimir.py import numpy as np, time, json, os, itertools OUT="wladimir_output"; os.makedirs(OUT,exist_ok=True) LOG=open(os.path.join(OUT,"wladimir.log"),"a") def say(s): print(s,flush=True); LOG.write(s+"\n"); LOG.flush() T0=time.time() def el(): return "%7.1fm"%((time.time()-T0)/60) def project(N,rng,it=3000): H=np.exp(2j*np.pi*rng.random((N,N))) for k in range(it): U,s,V=np.linalg.svd(H); H=np.sqrt(N)*U@V H=H/np.abs(H) if k%200==199 and np.abs(H@H.conj().T-N*np.eye(N)).max()<1e-6: break return H def polish(H,it=60): N=len(H); H=H/H[:,[0]]; H=H/H[[0],:] th=np.angle(H)[1:,1:].ravel() def build(th): P=np.zeros((N,N)); P[1:,1:]=th.reshape(N-1,N-1); return np.exp(1j*P) iu=np.triu_indices(N,1) for _ in range(it): H=build(th); G=H@H.conj().T; r=G[iu] res=np.concatenate([r.real,r.imag]) if np.abs(res).max()<1e-13: break J=np.zeros((len(res),(N-1)**2)) # d G_ij / d th_kl = i H_kl conj(H_jl) [k=i] - i H_il conj(H_kl) [k=j] col=0 for k in range(1,N): for l in range(1,N): dG=np.zeros((N,N),complex) dG[k,:]+=1j*H[k,l]*np.conj(H[:,l]); dG[:,k]+=-1j*H[:,l]*np.conj(H[k,l]) d=dG[iu]; J[:,col]=np.concatenate([d.real,d.imag]); col+=1 th=th+np.linalg.lstsq(J,-res,rcond=None)[0] H=build(th) return H,np.abs(H@H.conj().T-N*np.eye(N)).max() def profile(H): return np.einsum('ax,bx,cx,dx->abcd',H,H.conj(),H.conj(),H) 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 Tk(H,k): N=len(H); I=np.array(list(itertools.product(range(N),repeat=k))) A=np.ones((N**k,N**k),complex) for s in range(k): A*=np.conj(H[I[:,s]][:,I[:,s]])*H[I[:,(s+1)%k]][:,I[:,s]] return A@A.conj().T/N**(k+1) def top(T): ev=np.sort(np.linalg.eigvalsh(T))[::-1]; m=int(np.sum(ev>1-1e-6)); return m,float(ev[m]) def defect(H): N=len(H); L=np.einsum('ij,kj,kl,il->ijkl',H,H.conj(),H,H.conj()).reshape(N*N,N*N)/N return int(np.sum(np.abs(np.linalg.eigvals(L)-1)<1e-7))-(2*N-1) def orbitals(S,tol): N=S.shape[0]; adj=(np.abs(S)>tol).transpose(0,2,1,3).reshape(N*N,N*N) lab=np.arange(N*N) while True: new=np.minimum(np.where(adj,lab[None,:],N*N).min(axis=1),lab) if (new==lab).all(): break lab=new return lab.reshape(N,N) def block_systems(L,maxorb=16): N=len(L); diag={L[i,i] for i in range(N)}; off=sorted(set(L.ravel())-diag); found=set() if len(off)>maxorb: return None for r in range(1,len(off)): for sub in itertools.combinations(off,r): R=np.isin(L,list(sub))|np.eye(N,dtype=bool) if not (R==R.T).all(): continue Ri=R.astype(int) if ((Ri@Ri)>0).__eq__(R).all(): sizes={int(R[i].sum()) for i in range(N)} if len(sizes)==1: found.add(sizes.pop()) return sorted(found) if __name__=="__main__": plan=[(6,15),(8,25),(9,20),(10,25),(12,25)] say("wladimir: complex Hadamard matrices of composite order, from random starting points, N = 6, 8, 9, 10, 12") db={} try: db=json.load(open(os.path.join(OUT,"wladimir.json"))) except Exception: pass rng=np.random.default_rng(31) for N,minutes in plan: if str(N) in db and db[str(N)].get("done"): continue TN=time.time(); classes=[]; keys=[]; seen=set(); runs=0; sols=0; DM=distinct_mask(N); hist={}; outside=[] while time.time()-TN1e-11: continue sols+=1; S=profile(H); key=np.round(np.sort(np.abs(S).ravel()),6) if any(np.allclose(k,key,atol=2e-6) for k in keys): continue keys.append(key) L=orbitals(S,1e-4); p2=len(set(L.ravel())); p2b,g2=top(Tk(H,2)); p3,g3=top(Tk(H,3)); d=defect(H) A=np.abs(S); fuzzy=int(np.sum((A>1e-11)&(A<1e-4))) bs=block_systems(L) if p2>2 else [] out=p2==p2b and ((p2==2 and p3>5) or (p2>2 and bs==[])) tagh=(p2,p2b,p3,"blocks" if bs else ("many orbitals" if bs is None else "none")) hist[str(tagh)]=hist.get(str(tagh),0)+1 rec={"defect":d,"dim_P2":p2,"dim_P2_from_T2":p2b,"next_T2":g2,"dim_P3":p3,"next_T3":g3,"block_sizes":bs, "fuzzy_S":fuzzy,"zeros_S":int(np.sum((A<1e-9)&DM)),"min_abs_S_distinct":float(A[DM].min()), "rows":[[[float(z.real),float(z.imag)] for z in row] for row in H]} if out or p2>2 or len(classes)<200: classes.append(rec) if out: outside.append(rec) typ=(p2,p2b,p3,str(bs),d) if typ in seen and not out: continue seen.add(typ) say(" %s N=%d class %d: defect %d, dim P_2 %d (T_2 %d), dim P_3 %d, next eigenvalues %.6f %.6f, block sizes %s, zeros of S %d, near zeros %d%s"%( el(),N,len(keys),d,p2,p2b,p3,g2,g3,bs,rec["zeros_S"],fuzzy," OUTSIDE" if out else "")) if runs%100==0: say(" %s N=%d: %d runs, %d solutions, %d classes"%(el(),N,runs,sols,len(keys))) say("%s N=%d: %d runs, %d solutions, %d classes, by (dim P_2 from the orbitals, dim P_2 from T_2, dim P_3, blocks): %s, outside: %d"%(el(),N,runs,sols,len(keys),hist,len(outside))) db[str(N)]={"runs":runs,"solutions":sols,"classes_total":len(keys),"histogram":hist,"outside":len(outside),"done":True,"classes":classes} json.dump(db,open(os.path.join(OUT,"wladimir.json"),"w")) say("%s finished"%el())