# formclasses.py -- reads the forms found by poirier.py (poirier-out/forms-.txt, phases in units of 1e-6 turn), # refines them by the alternating iteration, checks the Jacobian rank, and sorts them into classes according to the # moduli of the row and column sums of B^2 and B^3 (entrywise powers), B being the bistochastic matrix D_a H D_b. # Writes formclasses.txt: one line per class, with its size, the number of forms seen by 1, 2, 3 workers, and a representative. import numpy as np from collections import Counter H=np.loadtxt('had163.txt') sets=[set(l.strip() for l in open(f'poirier-out/forms-{w}.txt')) for w in range(3)] U=list(sets[0]|sets[1]|sets[2]) mult=np.array([sum(k in s for s in sets) for k in U]) P=np.array([[int(x) for x in l.split()] for l in U],float)*2*np.pi/1e6 b=np.exp(1j*P) for it in range(200): u=H@b.T; u=u/abs(u); b=(H.T@u).T; b=b/abs(b) s=(H@b.T).T; a=np.conj(s/abs(s)); B=a[:,:,None]*H[None]*b[:,None,:] B2=B*B; B3=B2*B F=np.round(np.concatenate([np.sort(abs(B2.sum(2)),1),np.sort(abs(B2.sum(1)),1),np.sort(abs(B3.sum(2)),1),np.sort(abs(B3.sum(1)),1)],1),5) keys=[r.tobytes() for r in F]; cnt=Counter(keys) order=sorted(cnt,key=lambda k:-cnt[k]); lab=np.array([order.index(k) for k in keys]) J=2*np.real(np.conj(s)[:,:,None]*1j*H[None,:,:]*b[:,None,:]); sv=np.linalg.svd(J,compute_uv=False) Om=abs(B.sum((1,2))) out=open('formclasses.txt','w') for c in range(len(order)): m=lab==c out.write(f"class {c} size {m.sum()} seen123 {[(mult[m]==t).sum() for t in (1,2,3)]} rep {' '.join(str(int(round((np.angle(x/b[m][0][0])/(2*np.pi))%1*1e6))) for x in b[m][0])}\n") print(f"class {c}: size {m.sum():6d} seen by 1/2/3 workers {[(mult[m]==t).sum() for t in (1,2,3)]} sv15 {sv[m,14].min():.4f} |B2 rowsums| {np.round(np.sort(abs(B2[m][0].sum(1))),3)[[0,-1]]} phases rational? {np.round(np.angle(b[m][0]/b[m][0][0])/(2*np.pi)*16,4)}")