# holloway.py -- for each complex Hadamard matrix of order 16 in the Aalto file BH-16-4.txt (entries i^e), # decide exactly whether it is equivalent to a bistochastic matrix with entries in mu_4 = {1,i,-1,-i}. # Method: column multipliers b in mu_4^16 with b_0 = 1; the row sums of Kb are Gaussian integers of modulus 4, # hence lie in {4,4i,-4,-4i}; meet in the middle on columns 0-7 / 8-15, with exact integer keys on rows 0,1. # Output: holloway-out/part-.txt, one line per class: line number, 1 if bistochastic over mu_4, 0 if not. # Usage: /usr/bin/python3 holloway.py BH-16-4.txt WORKERS HOURS (e.g. 3 3.5, or 6 7) import sys, os, time, itertools, numpy as np from multiprocessing import Process fname=sys.argv[1]; W=int(sys.argv[2]); HOURS=float(sys.argv[3]) os.makedirs('holloway-out',exist_ok=True) U=np.array([[1,0],[0,1],[-1,0],[0,-1]]) # i^e as (re,im) L=np.array(list(itertools.product(range(4),repeat=7))); L=np.hstack([np.zeros((len(L),1),int),L]) # b_0=1 R=np.array(list(itertools.product(range(4),repeat=8))) T=[(4,0),(0,4),(-4,0),(0,-4)] def sums(E,B): # E: 16 x 8 exponents of K (block), B: n x 8 exponents of b -> re,im arrays n x 16 S=(E[None,:,:]+B[:,None,:])%4 return U[S,0].sum(2), U[S,1].sum(2) def key(a,b,c,d): return ((a+64)<<21)|((b+64)<<14)|((c+64)<<7)|(d+64) def solve(E): # returns 1 if some b exists (early exit), 0 otherwise lr,li=sums(E[:,:8],L); rr,ri=sums(E[:,8:],R) rk=key(rr[:,0],ri[:,0],rr[:,1],ri[:,1]); order=np.argsort(rk,kind='stable'); rks=rk[order] for t0 in T: for t1 in T: need=key(t0[0]-lr[:,0],t0[1]-li[:,0],t1[0]-lr[:,1],t1[1]-li[:,1]) lo=np.searchsorted(rks,need,'left'); hi=np.searchsorted(rks,need,'right'); n=hi-lo tot=int(n.sum()) if tot==0: continue ia=np.repeat(np.arange(len(L)),n) start=np.repeat(lo-np.cumsum(n)+n,n) # lo of the owning left index, minus its offset ib=order[start+np.arange(tot)] sr=lr[ia,2:]+rr[ib,2:]; si=li[ia,2:]+ri[ib,2:] ok=(((np.abs(sr)==4)&(si==0))|((sr==0)&(np.abs(si)==4))).all(1) if ok.any(): return 1 return 0 def worker(w): t0=time.time(); out=open(f'holloway-out/part-{w}.txt','a') done=set() if os.path.getsize(out.name)>0: done={int(l.split()[0]) for l in open(out.name) if l.strip()} with open(fname) as f: for ln,line in enumerate(f,1): if ln%W!=w or ln in done: continue if time.time()-t0>HOURS*3600: break E=(np.frombuffer(line[6:262].encode(),dtype=np.uint8)-48).astype(int).reshape(16,16) out.write(f"{ln} {solve(E)}\n"); out.flush() out.close() if __name__=='__main__': ps=[Process(target=worker,args=(w,)) for w in range(W)] for p in ps: p.start() for p in ps: p.join() print("holloway done, results in holloway-out/")