# twist.py -- explicit bistochastic forms of a cocyclic Hadamard matrix H = (psi(g,h)), read from cocycle.json. # (1) If psi = d(phi) on G, the matrix conj(phi(gh)) is a group-developed bistochastic form. # (2) For each subgroup G0 of index 2 on which psi = d(phi0), extend phi0 by phi(xt) = psi(x,t) phi0(x), x in G0, # put f = conj(phi), S0 = sum of f over G0, S1 = sum over G - G0. Then |S0|^2 + |S1|^2 = N, and the column # multipliers f * (1 on G0, w on G - G0), with w = i S0 conj(S1)/|S0 S1| or its negative, give bistochastic forms. # The trivializations are searched with values in mu_N, which suffices. For each form we record the order of w as a # root of unity (0 if it is not one, up to order 1000) and whether all entries lie in some mu_n, n <= 1000. # Only the first cocyclic structure of each type (group, coboundary or not) in the json file is treated. import numpy as np, json, sys, itertools from collections import Counter H=np.loadtxt(sys.argv[1]); N=len(H) data=json.load(open(sys.argv[2] if len(sys.argv)>2 else 'cocycle.json')) from groups import name_table def rootorder(z,nmax=1000): t=(np.angle(z)/(2*np.pi))%1 for n in range(1,nmax+1): if abs(t*n-round(t*n))<1e-7: return n return 0 seen_types=set() for C in data: if (C.get('group'),C['z_in_commutator']) in seen_types: continue seen_types.add((C.get('group'),C['z_in_commutator'])) rl,cl,mult,psi=C['rows'],C['cols'],np.array(C['mult']),np.array(C['psi'],float) Mx=H[np.ix_(rl,cl)]; cs=Mx[0,:] gname=name_table(mult.tolist()) def gen(S): S=set(S)|{0} while True: T=S|{int(mult[a][b]) for a in S for b in S} if T==S: return frozenset(S) S=T def trivializations(G0): G0=sorted(G0) gens=next(list(c) for r in (1,2,3) for c in itertools.combinations([a for a in G0 if a],r) if gen(c)==frozenset(G0)) zN=np.exp(2j*np.pi/N); sols=[] for vals in itertools.product(range(N),repeat=len(gens)): phi={0:1+0j}; fr=[0] while fr: new=[] for x in fr: for g,v in zip(gens,vals): y=int(mult[x][g]) if y not in phi: phi[y]=phi[x]*zN**v/psi[x,g]; new.append(y) fr=new if all(abs(psi[x,y]-phi[x]*phi[y]/phi[int(mult[x][y])])<1e-9 for x in G0 for y in G0): sols.append(phi) return sols print(f"\n=== G = {gname}, z in [E,E]: {C['z_in_commutator']}") full=trivializations(range(N)) if full: orders=Counter() for phi in full: f=np.array([np.conj(phi[h]) for h in range(N)]) B=np.array([[f[mult[g][h]] for h in range(N)] for g in range(N)]) assert np.allclose(B.sum(0),B.sum(0)[0]) and np.allclose(abs(B.sum(1)),np.sqrt(N)) n=np.lcm.reduce([rootorder(x) for x in f]); orders[(int(n),complex(np.round(B.sum(1)[0],6)))]+=1 print(f" psi is a coboundary over T: {len(full)} group-developed forms conj(phi(gh)); (entries in mu_n, row sum):",dict(orders)) subs={gen([a,b]) for a in range(N) for b in range(N)} subs=sorted([K for K in subs if len(K)==N//2],key=sorted) for G0 in subs: sols=trivializations(G0) G0s=sorted(G0); G1=[h for h in range(N) if h not in G0]; t=G1[0] sub=[[G0s.index(int(mult[a][b])) for b in G0s] for a in G0s] if not sols: print(f" G0 = {name_table(sub)}: psi is not a coboundary on G0"); continue stats=Counter() for phi0 in sols: phi=dict(phi0) for x in G0: phi[int(mult[x][t])]=psi[x,t]*phi0[x] f=np.array([np.conj(phi[h]) for h in range(N)]) S0=f[G0s].sum(); S1=f[G1].sum() assert abs(abs(S0)**2+abs(S1)**2-N)<1e-8 ws=[1j*S0*np.conj(S1)/abs(S0*S1),-1j*S0*np.conj(S1)/abs(S0*S1)] if abs(S0*S1)>1e-9 else [np.exp(0.3j)] for w in ws: beta=f*np.where(np.isin(np.arange(N),G0s),1,w) assert np.allclose(abs(psi@beta),np.sqrt(N)) b=np.zeros(N,complex); b[cl]=cs*beta; assert np.allclose(abs(H@b),np.sqrt(N)) s=H@b; a=np.conj(s/abs(s)); B=a[:,None]*H*b[None,:]; B=B/B[0,0] n=np.lcm.reduce([rootorder(x) for x in B.flatten()]) if all(rootorder(x) for x in B.flatten()) else 0 stats[(round(abs(S0)**2,4),rootorder(w) if abs(S0*S1)>1e-9 else 'free',int(n))]+=1 print(f" G0 = {name_table(sub)}: {len(sols)} trivializations; forms by (|S0|^2, order of w, entries in mu_n or 0):") for k,v in sorted(stats.items(),key=str): print(f" {k}: {v}")