# indexthree.py -- the circulant complex Hadamard matrices of prime order p = 1(3) coming from the cyclic p-roots of # simple index 3 of Bjorck, with first row h(0)=1, h(x)=x_j for x in the j-th coset of the subgroup of cubes. Starting # from the double precision solutions of ali.py, we refine them by Newton to 600 digits, and find by integer relations # (LLL) the minimal polynomial f of u=x_0+1/x_0, and expressions u_j=g_j(u) of u_j=x_j+1/x_j, and s_0 s_j=k_j(u) of the # products of s_j=x_j-1/x_j. Then, in exact arithmetic in K=Q[u]/(f)[s]/(s^2-u^2+4), with x_0=(u+s)/2 and # x_j=(g_j+s_j)/2, s_j=k_j s/(u^2-4), and complex conjugation s->-s, we check that x_j conj(x_j)=1, and that the rows are # orthogonal. We check that f is irreducible, from its factorization patterns modulo small primes, and that u_1=g_1(u), # u_2=g_1(u_1), u=g_1(u_2). Finally, for each prime q dividing p-4, we compute the multiplicity m of the root -2 of f # modulo q, which is the number of roots of f in an algebraic closure of Q_q which are integral and congruent to -2, # and, via the idempotent e of Z_q[u]/(f) attached to these roots, obtained by Hensel lifting, the characteristic # polynomials of g_j(u)+2 on them, whose Newton polygons give the number of these roots t with g_j(t) congruent to -2. # If some root t has this property for j=1,2, an embedding sending u to t gives a prime above q where all u_j are -2, # and so all x_j are -1, and the matrix reduces there to 2I-J, with p=4 modulo q. When the leading coefficient of f is # divisible by q, we use instead z=1/(u-c), with f(c) prime to q. When all this fails, we look for the primes q<400 # where f has the root 2-p, as needed for a reduction to J+(lambda-1)I, by factoring f(2-p). The precision of the q-adic # computations is certified, the margin being printed. We also give an interval isolating u among the roots of f, by # Sturm sequences, and the sign of Im(x_0), which determine the class, and we identify it numerically with one of the 2 # unimodular solutions c^(1), c^(2) of Bjorck and Haagerup, up to rotation and reversal of the cosets. # Usage: python3 indexthree.py import json, os, sys, time from decimal import Decimal as D, getcontext from fractions import Fraction as Fr getcontext().prec=600 class C: __slots__=('r','i') def __init__(s,r,i=D(0)): s.r=D(r); s.i=D(i) def __add__(a,b): return C(a.r+b.r,a.i+b.i) def __sub__(a,b): return C(a.r-b.r,a.i-b.i) def __mul__(a,b): return C(a.r*b.r-a.i*b.i,a.r*b.i+a.i*b.r) def inv(a): n=a.r*a.r+a.i*a.i; return C(a.r/n,-a.i/n) def __truediv__(a,b): return a*b.inv() def abs(a): return (a.r*a.r+a.i*a.i).sqrt() ZERO=C(0); ONE=C(1) def primroot(p): return next(g for g in range(2,p) if len({pow(g,k,p) for k in range(p-1)})==p-1) def setup(p,d): g=primroot(p); idx={pow(g,k,p):k%d for k in range(p-1)} return idx,[pow(g,k,p) for k in range(d)] def newton(x,p,d): idx,reps=setup(p,d) for it in range(80): h=[ONE]+[x[idx[t]] for t in range(1,p)]; hi=[v.inv() for v in h]; f=[]; J=[] for s in reps: tot=ZERO; row=[ZERO]*d for t in range(p): u=(t+s)%p; term=h[u]*hi[t]; tot=tot+term if u: row[idx[u]]=row[idx[u]]+hi[t] if t: row[idx[t]]=row[idx[t]]-term*hi[t] f.append(tot); J.append(row) res=max(v.abs() for v in f) if resd[l+1]: q=(2*lam[k][l]+d[l+1])//(2*d[l+1]); b[k]=[x-q*y for x,y in zip(b[k],b[l])]; lam[k][l]-=q*d[l+1] for i in range(l): lam[k][i]-=q*lam[l][i] def swap(k,kmax): b[k],b[k-1]=b[k-1],b[k] for j in range(k-1): lam[k][j],lam[k-1][j]=lam[k-1][j],lam[k][j] L=lam[k][k-1]; Bv=(d[k-1]*d[k+1]+L*L)//d[k] for i in range(k+1,kmax+1): t=lam[i][k]; lam[i][k]=(d[k+1]*lam[i][k-1]-L*t)//d[k]; lam[i][k-1]=(Bv*t+L*lam[i][k])//d[k+1] d[k]=Bv d[1]=dot(b[0],b[0]); k=1; kmax=0 while kkmax: kmax=k for j in range(k+1): u=dot(b[k],b[j]) for i in range(j): u=(d[i+1]*u-lam[k][i]*lam[j][i])//d[i] if j=len(b): c=a[-1]*ib%l; sh=len(a)-len(b) for i,y in enumerate(b): a[sh+i]=(a[sh+i]-c*y)%l fl_trim(a) return a def fl_mul(a,b,l): r=[0]*(len(a)+len(b)-1) if a and b else [] for i,x in enumerate(a): for j,y in enumerate(b): r[i+j]=(r[i+j]+x*y)%l return fl_trim(r) def fl_gcd(a,b,l): a=fl_trim([x%l for x in a]); b=fl_trim([x%l for x in b]) while b: a,b=b,fl_mod(a,b,l) return a def fl_powmod(a,e,m,l): r=[1]; a=fl_mod(a,m,l) while e: if e&1: r=fl_mod(fl_mul(r,a,l),m,l) a=fl_mod(fl_mul(a,a,l),m,l); e>>=1 return r def fl_deriv(a,l): return fl_trim([i*a[i]%l for i in range(1,len(a))]) def fl_div(a,b,l): a=a[:]; ib=pow(b[-1],-1,l); q=[0]*(len(a)-len(b)+1) while len(a)>=len(b): c=a[-1]*ib%l; sh=len(a)-len(b); q[sh]=c for i,y in enumerate(b): a[sh+i]=(a[sh+i]-c*y)%l fl_trim(a) return fl_trim(q) def degree_pattern(f,l): # degrees of the irreducible factors of f modulo l, by distinct degree factorization (None if not squarefree) g=fl_trim([c%l for c in f]) if len(g)!=len(f) or len(fl_gcd(g,fl_deriv(g,l),l))>1: return None pat=[]; h=[0,1]; k=0 while len(g)>1: k+=1 if len(g)-1<2*k: pat.append(len(g)-1); break h=fl_powmod(h,l,g,l); hm=(h+[0,0])[:max(2,len(h))]; hm[1]=(hm[1]-1)%l t=fl_gcd(g,fl_trim(hm),l) if len(t)>1: pat+=[k]*((len(t)-1)//k); g=fl_div(g,t,l); h=fl_mod(h,g,l) return pat def irreducible(f): n=len(f)-1; possible=set(range(1,n)) for l in [x for x in range(5,400) if all(x%y for y in range(2,x))]: pat=degree_pattern(f,l) if pat is None: continue sums={0} for k in pat: sums|={s+k for s in sums} possible&=sums if not possible: return True return False # q-adic test: characteristic polynomials of g_j(u)+2 on the roots of f congruent to root modulo q, where the g_j are # the coordinates u_0,u_1,u_2 written as polynomials in the variable of f def qadic(f,gs,q,root=-2,add=2,K=90): n=len(f)-1; Q=q**K; lead=f[n]; root%=q if lead%q==0: return None il=pow(lead,-1,Q); fm=[c*il%Q for c in f] def zmod(r): # reduce an integer polynomial modulo fm and Q r=[x%Q for x in r]+[0]*max(0,n-len(r)) for k in range(len(r)-1,n-1,-1): c=r[k] if c: for j in range(n+1): r[k-n+j]=(r[k-n+j]-c*fm[j])%Q return r[:n] def zmul(a,b): r=[0]*(len(a)+len(b)-1) for i,x in enumerate(a): if x: for j,y in enumerate(b): r[i+j]+=x*y return zmod(r) # multiplicity m of the root -2 modulo q, and cofactor c g=[x%q for x in f]; m=0 while len(g)>1 and sum(c*pow(root,i,q) for i,c in enumerate(g))%q==0: r=[0]*(len(g)-1); acc=0 for i in range(len(g)-1,0,-1): acc=(acc*root+g[i])%q; r[i-1]=acc g=r; m+=1 if m==0: return 0,None,None # b with b c = 1 modulo (u+2)^m, over F_q, by linear algebra, then e0 = b c w=[1] for _ in range(m): w=fl_mul(w,[(-root)%q,1],q) if m=0 and i<=n: s-=fm[n-i]*ps[k-i] ps.append(s%Q) tr=lambda z: sum(z[i]*ps[i] for i in range(n))%Q out=[]; margins=[] vq=lambda x: 10**6 if x==0 else (lambda n,d: (lambda f: f(f,n)-f(f,d))(lambda f,t: 0 if t%q else 1+f(f,t//q)))(x.numerator,x.denominator) for gj in gs: den=1 for c in gj: den=den*c.denominator//__import__('math').gcd(den,c.denominator) Y=[int(c*den) for c in gj]; Y[0]+=add*den; P=[]; z=e[:] for k in range(1,m+1): z=zmul(z,Y); P.append(Fr(tr(z),den**k)) el=[Fr(1)] for k in range(1,m+1): el.append(sum((-1)**(i-1)*el[k-i]*P[i-1] for i in range(1,k+1))/k) # the characteristic polynomial of g_j(u)+2 on the roots in question has coefficients (-1)^k el[k] of Y^(m-k), # and the number of its roots of positive valuation is the smallest power of Y of minimal valuation # el[k] is known modulo q^(K-v_q(k!)-k v_q(den)), by the Newton identities applied to the integral power sums # tr(z), known modulo q^K, so the valuations below this bound are exact, and the leftmost minimum is certified # when the minimal valuation is smaller than all these bounds, the difference being the margin vs=[vq(el[m-i]) for i in range(m+1)] vden=vq(Fr(den)); prec=[K-sum(vq(Fr(j)) for j in range(1,k+1))-k*vden for k in range(1,m+1)] margin=min(prec)-min(vs); margins.append(margin) if margin<=0: return "precision" out.append(min(i for i in range(m+1) if vs[i]==min(vs))) return m,out,min(margins) def verdict(m,n,ok,cyc): # m roots congruent to -2, ok[j] of them with u_j congruent to -2 as well, so at least ok[1]+ok[2]-m with all of # them; when g_1 permutes the roots in cycles of length 3, with g_2=g_1(g_1), a good root gives a cycle of 3 good # roots, mapped to good roots by g_1, so ok[1]<3 excludes this both=ok[1]+ok[2]-m return "root -2 of multiplicity %d/%d, with u_1, u_2 = -2 for %d, %d of them, all u_j=-2 at a prime above q: %s"%( m,n,ok[1],ok[2],"True" if both>0 else ("False" if min(ok[1:])==0 or cyc and min(ok[1:])<3 else "undecided")) def factor(n): out=[]; d=2 while d*d<=n: e=0 while n%d==0: n//=d; e+=1 if e: out.append((d,e)) d+=1 if n>1: out.append((n,1)) return out def sturm_count(f,a,b): # number of roots of the squarefree polynomial f in (a,b], by the Sturm sequence, in exact arithmetic def prem(x,y): x=x[:] while len(x)>=len(y) and any(x): c=x[-1]/y[-1]; sh=len(x)-len(y) for i,t in enumerate(y): x[sh+i]-=c*t x.pop() while x and x[-1]==0: x.pop() return x seq=[[Fr(c) for c in f],[Fr(i*c) for i,c in enumerate(f)][1:]] while len(seq[-1])>1: r=prem(seq[-2],seq[-1]) if not r: break seq.append([-c for c in r]) def changes(x): vals=[sum(c*x**i for i,c in enumerate(P)) for P in seq]; vals=[v for v in vals if v!=0] return sum(1 for s,t in zip(vals,vals[1:]) if (s>0)!=(t>0)) return changes(a)-changes(b) def bjorck_haagerup(p): # the 2 unimodular solutions c^(1), c^(2) of Bjorck and Haagerup, in double precision, with 4p = A^2+27B^2, # A = 1(3), B > 0, u = sqrt(p), v = sqrt(p+4A+16), theta = arccos(A/2sqrt(p))/3 import math, cmath B=next(b for b in range(1,p) if 4*p-27*b*b>=0 and int(round(math.sqrt(4*p-27*b*b)))**2==4*p-27*b*b) A=int(round(math.sqrt(4*p-27*B*B))); A=A if A%3==1 else -A u=math.sqrt(p); v=math.sqrt(p+4*A+16); th=math.acos(A/(2*u))/3; s3=math.sqrt(3); r4=math.sqrt(p-4); D=p*p-3*p-A sq=cmath.sqrt; d2=u*u+u*v+2 al=[0.5*(p*A-2*p-2*A)/D+1.5j*s3*u*r4*B/D, -0.5*(u*u-u*v-4)/d2+0.5j*u*sq(4+u-v)*sq(4-u+v)/d2] be=[-0.5*u*(p-4)*(A+2)/D-1.5j*s3*r4*(p-2)*B/D, (A+2)*u/d2+0.25j*(u*u+u*v+4)*sq(4+u-v)*sq(4-u+v)/d2] ga=[-1.5*s3*u*(p-4)*B/D+0.5j*r4*(p*A-2*p-2*A)/D, 3*s3*B*u/d2+0.25j*(u*u-u*v-4)*sq(u+v+4)*sq(u+v-4)/d2] return [[al[i]+be[i]*math.cos(th-2*math.pi*j/3)+ga[i]*math.sin(th-2*math.pi*j/3) for j in range(3)] for i in (0,1)] def primes(a,b): return [n for n in range(a,b) if n>1 and all(n%m for m in range(2,int(n**.5)+1))] db=json.load(open('ali_output/ali.json')) for p in [p for p in primes(7,128) if p%3==1]: idx,reps=setup(p,3) for ci,r in enumerate(db["%d,3"%p]["classes"]): t0=time.time() x,res=newton([C(D(repr(r["row"][s][0])),D(repr(r["row"][s][1]))) for s in reps],p,3) u=[(v+v.inv()).r for v in x]; sv=[(v-v.inv()).i for v in x] # s_j = i sv_j f=None for n in (1,2,3,6): c=relation([u[0]**k for k in range(n+1)]) if c: f=c if c[-1]>0 else [-t for t in c]; break if f is None: print("p=%d class %d: no minimal polynomial of degree at most 6 found"%(p,ci+1)); continue n=len(f)-1; F=[Fr(c) for c in f] if n==1: print("p=%d class %d (dim P_2 %d): u is rational, %s"%(p,ci+1,r["dim_P2"],f)); continue pw=[u[0]**k for k in range(n)] g=[[Fr(0),Fr(1)]+[Fr(0)]*(n-2)]; kk=[None] for j in (1,2): c=relation(pw+[u[j]]); g.append([Fr(-a,c[-1]) for a in c[:n]]) c=relation(pw+[-sv[0]*sv[j]]); kk.append([Fr(-a,c[-1]) for a in c[:n]]) one=[Fr(1)]+[Fr(0)]*(n-1); uu=g[0]; s2=padd(pmul(uu,uu,F),psc(one,-4)); is2=pinv(s2,F) # K elements are pairs (a,b) = a+b s, with s^2=s2 kmul=lambda X,Y: (padd(pmul(X[0],Y[0],F),pmul(pmul(X[1],Y[1],F),s2,F)),padd(pmul(X[0],Y[1],F),pmul(X[1],Y[0],F))) kz=lambda X: not any(X[0]) and not any(X[1]) conj=lambda X: (X[0],psc(X[1],-1)) xs=[(psc(uu,Fr(1,2)),psc(one,Fr(1,2)))] for j in (1,2): xs.append((psc(g[j],Fr(1,2)),psc(pmul(kk[j],is2,F),Fr(1,2)))) unim=all(kz((padd(kmul(X,conj(X))[0],psc(one,-1)),kmul(X,conj(X))[1])) for X in xs) hK=[(one,[Fr(0)]*n)]+[xs[idx[y]] for y in range(1,p)] orth=True for sh in reps: tot=([Fr(0)]*n,[Fr(0)]*n) for y in range(p): pr=kmul(hK[(y+sh)%p],conj(hK[y])); tot=(padd(tot[0],pr[0]),padd(tot[1],pr[1])) orth=orth and kz(tot) fg=[] for j in (1,2): acc=[Fr(0)]*n; pwj=one for c in F: acc=padd(acc,psc(pwj,c)); pwj=pmul(pwj,g[j],F) fg.append(not any(acc)) # g_1 permutes the roots of f cyclically, with g_2=g_1(g_1) and g_1(g_2)=u def comp(P,X): acc=[Fr(0)]*n; pwx=one for c in P: acc=padd(acc,psc(pwx,c)); pwx=pmul(pwx,X,F) return acc cyc=comp(g[1],g[1])==g[2] and comp(g[1],g[2])==g[0] # numerical match of the exact expressions with the refined solution ev=lambda P: sum(D(c.numerator)/D(c.denominator)*u[0]**i for i,c in enumerate(P)) err=max(abs(ev(g[j])-u[j])+abs(ev(kk[j])+sv[0]*sv[j]) for j in (1,2)) irr=irreducible(f) qs=[q for q in primes(3,p) if (p-4)%q==0] red=[] for q in qs: out=qadic(f,g,q) if out is None: # z=1/(u-c), with f(c) prime to q: F(z)=z^n f(c+1/z) has a leading coefficient prime to q, the roots # of f which are integral at a prime above q and congruent to -2 there correspond to the roots of F # congruent to 1/(-2-c), and the coordinates become G_j(z)=g_j(c+1/z) in Q[z]/(F) c=next(c for c in range(q) if c!=q-2 and sum(a*c**i for i,a in enumerate(f))%q) Fz=[Fr(0)]*(n+1) for k,a in enumerate(f): t=[Fr(1)] for _ in range(k): t=[x+y for x,y in zip(t+[Fr(0)],[Fr(0)]+[c*v for v in t])] # (1+cz)^k for i,v in enumerate(t): Fz[i+n-k]+=a*v Fi=[int(v) for v in Fz]; zi=pinv([Fr(0),Fr(1)]+[Fr(0)]*(n-2),Fz); uz=padd([Fr(c)]+[Fr(0)]*(n-1),zi) G=[] for gj in g: acc=[Fr(0)]*n; pwz=[Fr(1)]+[Fr(0)]*(n-1) for a in gj: acc=padd(acc,psc(pwz,a)); pwz=pmul(pwz,uz,Fz) G.append(acc) out=qadic(Fi,G,q,root=pow((-2-c)%q,-1,q)) if out is None or out=="precision": red.append("q=%d: no test"%q); continue m,ok,mg=out if m==0: red.append("q=%d: no root -2"%q); continue red.append("q=%d: via z=1/(u-%d), %s, precision margin %d"%(q,c,verdict(m,n,ok,cyc),mg)); continue if out=="precision": red.append("q=%d: no test"%q); continue m,ok,mg=out if m==0: red.append("q=%d: no root -2"%q); continue red.append("q=%d: %s, precision margin %d"%(q,verdict(m,n,ok,cyc),mg)) print("p=%d class %d (dim P_2 %d): f=%s, irreducible: %s, u_j roots of f: %s, cyclic: %s, x_j conj(x_j)=1: %s, rows orthogonal: %s, numerical error %.0e (%.0fs)"%( p,ci+1,r["dim_P2"],f,irr,all(fg),cyc,unim,orth,float(err),time.time()-t0)) print(" "+"; ".join(red),flush=True) # the branch: u_0 is the unique root of f in an interval of length 10^-12, and the sign of Im(x_0) E12=10**12; a=Fr(int((u[0]*E12).to_integral_value())-1,E12); b=a+Fr(2,E12) assert sturm_count(f,a,b)==1 # identification with the solutions of Bjorck and Haagerup, up to rotation and reversal of the cosets ours=[float(t) for t in u]; best=None for i,c in enumerate(bjorck_haagerup(p)): for sh in range(3): for o in (1,-1): e=max(abs(ours[j]-2*c[(sh+o*j)%3].real) for j in range(3)) if best is None or e" if sv[0]>0 else "<",best[1],best[0]),flush=True) if not any("prime above q: True" in t for t in red): # no reduction to 2I-J: look for a reduction to J+(lambda-1)I, lambda+1/lambda=2-p, at a prime not dividing p, # which requires a root of f congruent to 2-p modulo q # the u_j being distinct roots of f, they can all reduce to 2-p at a prime above q only if 2-p is a multiple # root of f modulo q, when q does not divide the leading coefficient v=sum(a*(2-p)**i for i,a in enumerate(f)); fac=factor(abs(v)) dv=sum(i*a*(2-p)**(i-1) for i,a in enumerate(f) if i) st=["%d^%d"%(q,e) if e>1 else "%d"%q for q,e in fac] simple=[q for q,e in fac if f[-1]%q and dv%q] other=[q for q,e in fac if q not in simple] print(" no reduction to 2I-J; f(2-p) = %s, 2-p is a simple root of f modulo %s, and the other prime divisors are %s"%( " ".join(st),simple,other))