# circwild.py -- the circulant matrices C_8 and C_10 found by fury.py are wild (Theorem 5.16). Exact arithmetic: # C_8 has first row (1,z,z,-1,z,1,1,-1), z=(-1-2i sqrt2)/3, entries in Q(i sqrt2), and we compute the valuations of the # profile S at the prime P=(i sqrt2) above 2, which is the 2-adic valuation of the norm. C_10 has first row # (1,a,1,-i,ia,a,ia,a,ia,-i), a=(sqrt5+2i)/3, entries in Q(i,sqrt5), with ring of integers Z[i,f], f=(1+sqrt5)/2, and we # reduce sigma=S/10 modulo the prime P=(1+i), with residue field F_4, via i->1 and f->w, w^2=w+1. In both cases sigma # is integral at P, equal to -1 modulo P on the quadruples of distinct indices, and to 0 modulo P on the restricted # quadruples with a=d or b=c but not both, which is the affine condition of Theorem 5.10 with X=Y=1. Also, the circulant # matrix C_7C with first row (1,A,B,C,C,B,A), from the cyclic 7-roots of simple index 3 (Theorem 5.18): the field is # K=Q(u)(s), with f(u)=0, f=u^6-12u^5+18u^4+64u^3-96u^2-45u+43, and s^2=u^2-4, with A=(u+s)/2, and B, C given by the # expressions of 2Re(B), 2Re(C), Im(A)Im(B), Im(A)Im(C) as polynomials in u, which were found by integer relations # (LLL) from a solution computed at 120 digits. We check exactly that the Hadamard equations hold, that 2Re(B), 2Re(C) # are roots of f, and that f=(u-1)^6 modulo 3, so that the entries are -1 modulo any prime above 3. # Finally, the circulant matrices C_14 and C_15 (Theorem 5.17), with entries 1,z,z^2 in Q(sqrt(-7)) and Q(sqrt(-15)), whose # profile is affine with X=Y=-1 at the prime above 7, respectively above 5, which ramify and divide N: the local ring is # Z_p[sqrt(-d)], and sigma=S/N is integral there, with residue r modulo P for sigma=r+s sqrt(-d). # Usage: python3 circwild.py from fractions import Fraction as Fr from collections import Counter import itertools, numpy as np class Q2: # a + b sqrt(-2) def __init__(s,a,b=0): s.a=Fr(a); s.b=Fr(b) def __add__(x,y): return Q2(x.a+y.a,x.b+y.b) def __neg__(x): return Q2(-x.a,-x.b) def __mul__(x,y): return Q2(x.a*y.a-2*x.b*y.b,x.a*y.b+x.b*y.a) def conj(x): return Q2(x.a,-x.b) def norm(x): return x.a*x.a+2*x.b*x.b def __eq__(x,y): return x.a==y.a and x.b==y.b def num(x): return complex(float(x.a),float(x.b)*2**.5) class K: # c0 + c1 i + c2 f + c3 if, f=(1+sqrt5)/2, f^2=f+1 def __init__(s,c): s.c=tuple(Fr(x) for x in c) def __add__(a,b): return K([x+y for x,y in zip(a.c,b.c)]) def __neg__(a): return K([-x for x in a.c]) def __mul__(a,b): m=lambda p,q: (p[0]*q[0]+p[1]*q[1],p[0]*q[1]+p[1]*q[0]+p[1]*q[1]) A0=(a.c[0],a.c[2]); A1=(a.c[1],a.c[3]); B0=(b.c[0],b.c[2]); B1=(b.c[1],b.c[3]) r0=m(A0,B0); r1=m(A1,B1); s0=m(A0,B1); s1=m(A1,B0) return K([r0[0]-r1[0],s0[0]+s1[0],r0[1]-r1[1],s0[1]+s1[1]]) def conj(a): return K([a.c[0],-a.c[1],a.c[2],-a.c[3]]) def __eq__(x,y): return x.c==y.c def num(a): f=(1+5**.5)/2; return complex(float(a.c[0])+float(a.c[2])*f,float(a.c[1])+float(a.c[3])*f) def circ(h): N=len(h); return [[h[(x-i)%N] for x in range(N)] for i in range(N)] def profile(H,a,b,c,d,zero): t=zero for y in range(len(H)): t=t+H[a][y]*H[b][y].conj()*H[c][y].conj()*H[d][y] return t def hadamard(H,zero,scal): N=len(H) for i in range(N): for j in range(N): s=zero for y in range(N): s=s+H[i][y]*H[j][y].conj() if not s==scal(N if i==j else 0): return False return True def kind(q): a,b,c,d=q if len(set(q))==4: return "distinct" if (a==d)!=(b==c): return "a=d or b=c" return "other" # C_8 z=Q2(Fr(-1,3),Fr(-2,3)); one=Q2(1) h8=[one,z,z,-one,z,one,one,-one]; H8=circ(h8) print("C_8: entries unimodular:",all(x.norm()==1 for x in h8),", Hadamard:",hadamard(H8,Q2(0),Q2), ", z=pi'/pi with pi=1+sqrt(-2):",z*Q2(1,1)==Q2(1,-1)) def v2(x): n=x.norm() if n==0: return 99 v=0; p,q=n.numerator,n.denominator while p%2==0: p//=2; v+=1 while q%2==0: q//=2; v-=1 return v cnt=Counter() for q in itertools.product(range(8),repeat=4): if q[0]==q[2] or q[1]==q[3]: continue cnt[(kind(q),v2(profile(H8,*q,Q2(0))))]+=1 print(" valuations v_P(S) on the restricted quadruples, by type:",sorted(cnt.items())) # C_10 o=K([1,0,0,0]); I=K([0,1,0,0]); a=K([Fr(-1,3),Fr(2,3),Fr(2,3),0]) # (sqrt5+2i)/3, sqrt5=2f-1 h10=[o,a,o,-I,I*a,a,I*a,a,I*a,-I]; H10=circ(h10) nrm=lambda x: (x*x.conj()) print("C_10: entries unimodular:",all(nrm(x)==o for x in h10),", Hadamard:",hadamard(H10,K([0]*4),lambda n:K([n,0,0,0])), ", numerically:",np.allclose(np.abs(np.fft.fft([x.num() for x in h10]))**2,10)) def res4(x): # reduction modulo P=(1+i) to F_4={0,1,w,w^2}, encoded 0,1,2,3; None if not integral at P if any(c.denominator%2==0 for c in x.c): return None r=[(c.numerator*pow(c.denominator,-1,2))%2 for c in x.c] a0=(r[0]+r[1])%2; a1=(r[2]+r[3])%2 return a0+2*a1 cnt=Counter(); tenth=K([Fr(1,10),0,0,0]) for q in itertools.product(range(10),repeat=4): if q[0]==q[2] or q[1]==q[3]: continue cnt[(kind(q),res4(profile(H10,*q,K([0]*4))*tenth))]+=1 print(" residues of sigma=S/10 modulo P (0,1,w,w^2 = 0,1,2,3, None = not integral), by type:",sorted(cnt.items(),key=str)) # C_7C, exact arithmetic in K = Q[u]/(f) [s]/(s^2-u^2+4) f=[43,-45,-96,64,18,-12,1] def pmod(r): r=list(r)+[Fr(0)]*max(0,6-len(r)) for k in range(len(r)-1,5,-1): c=r[k] if c: for j in range(7): r[k-6+j]-=c*f[j] return r[:6] def pmul(a,b): r=[Fr(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 pmod(r) padd=lambda a,b: [x+y for x,y in zip(a,b)] psc=lambda a,c: [x*c for x in a] pone=[Fr(1)]+[Fr(0)]*5; pu=[Fr(0),Fr(1)]+[Fr(0)]*4 def ppow(a,k): r=pone for _ in range(k): r=pmul(r,a) return r def poly(cs,den): r=[Fr(0)]*6 for k,c in enumerate(cs): r=padd(r,psc(ppow(pu,k),Fr(c,den))) return r def pinv(a): cols=[] for j in range(6): e=[Fr(0)]*6; e[j]=Fr(1); cols.append(pmul(a,e)) M=[[cols[j][i] for j in range(6)]+[Fr(1 if i==0 else 0)] for i in range(6)] for c in range(6): piv=next(r for r in range(c,6) if M[r][c]!=0); M[c],M[piv]=M[piv],M[c] pv=M[c][c]; M[c]=[x/pv for x in M[c]] for r in range(6): if r!=c and M[r][c]!=0: fac=M[r][c]; M[r]=[x-fac*y for x,y in zip(M[r],M[c])] return [M[i][6] for i in range(6)] fof=lambda x: [sum(c for c in col) for col in zip(*[psc(ppow(x,k),Fr(c)) for k,c in enumerate(f)])] v=poly([-2,-38,18,8,-1,0],21); w=poly([95,65,-70,-50,25,-2],63) pab=poly([164,236,-238,-20,52,-5],-252); pac=poly([-238,107,143,-32,-8,1],252) g=padd(pmul(pu,pu),psc(pone,-4)); c4=pinv(psc(g,-1)) kmul=lambda x,y: (padd(pmul(x[0],y[0]),pmul(pmul(x[1],y[1]),g)),padd(pmul(x[0],y[1]),pmul(x[1],y[0]))) def kadd(*xs): r=([Fr(0)]*6,[Fr(0)]*6) for x in xs: r=(padd(r[0],x[0]),padd(r[1],x[1])) return r kc=lambda c: (psc(pone,Fr(c)),[Fr(0)]*6) kz=lambda x: all(c==0 for c in x[0]+x[1]) h=Fr(1,2); tB=pmul(psc(pab,4),c4); tC=pmul(psc(pac,4),c4) A=(psc(pu,h),psc(pone,h)); Ab=(psc(pu,h),psc(pone,-h)) B=(psc(v,h),psc(tB,h)); Bb=(psc(v,h),psc(tB,-h)); C=(psc(w,h),psc(tC,h)); Cb=(psc(w,h),psc(tC,-h)) r1=kadd(A,Ab,kmul(B,Ab),kmul(A,Bb),kmul(C,Bb),kmul(B,Cb),kc(1)) r2=kadd(B,Bb,kmul(C,Ab),kmul(A,Cb),kmul(C,Bb),kmul(B,Cb),kc(1)) r3=kadd(C,Cb,kmul(C,Ab),kmul(A,Cb),kmul(A,Bb),kmul(B,Ab),kc(1)) print("C_7C: A Abar=B Bbar=C Cbar=1:",all(kz(kadd(kmul(X,Y),kc(-1))) for X,Y in ((A,Ab),(B,Bb),(C,Cb))), ", Hadamard equations:",kz(r1) and kz(r2) and kz(r3),", f(2ReB)=f(2ReC)=0:",not any(fof(v)) and not any(fof(w))) binom=[1,-6,15,-20,15,-6,1] print(" f modulo 3:",[c%3 for c in f],", (u-1)^6 modulo 3:",[c%3 for c in binom]) ur=[r.real for r in np.roots(f[::-1]) if abs(r.imag)<1e-12]; ur=min(ur,key=lambda x:abs(x+0.778)) ev=lambda p: sum(float(c)*ur**k for k,c in enumerate(p)); sv=-2j*np.sqrt(1-(ur/2)**2) kev=lambda x: ev(x[0])+ev(x[1])*sv row=[1,kev(A),kev(B),kev(C),kev(C),kev(B),kev(A)] Hn=np.array([[row[(j-i)%7] for j in range(7)] for i in range(7)]) print(" numerical embedding: A,B,C =",", ".join("%.12f%+.12fi"%(z.real,z.imag) for z in row[1:4]), ", Hadamard error %.1e"%abs(Hn@Hn.conj().T-7*np.eye(7)).max()) # C_14 and C_15, affine with X=Y=-1 at the ramified prime P above p=7, 5, dividing N class Qd: d=7 def __init__(s,r,t=0): s.r=Fr(r); s.s=Fr(t) def __add__(a,b): return Qd(a.r+b.r,a.s+b.s) def __neg__(a): return Qd(-a.r,-a.s) def __mul__(a,b): return Qd(a.r*b.r-Qd.d*a.s*b.s,a.r*b.s+a.s*b.r) def conj(a): return Qd(a.r,-a.s) def __eq__(a,b): return a.r==b.r and a.s==b.s def vpr(x,p): if x==0: return 99 v=0; n,dd=x.numerator,x.denominator while n%p==0: n//=p; v+=1 while dd%p==0: dd//=p; v-=1 return v for name,d,p,z,pat in [("C_14",7,7,(Fr(-3,4),Fr(-1,4)),[0,0,1,2,1,2,2,1,1,0,2,0,2,2]), ("C_15",15,5,(Fr(-1,4),Fr(1,4)),[0,0,0,0,1,2,2,0,2,1,0,0,2,0,1])]: Qd.d=d; zz=Qd(*z); vals=[Qd(1),zz,zz*zz]; h=[vals[t] for t in pat]; N=len(h); H=circ(h) had=hadamard(H,Qd(0),Qd) res=Counter() for q in itertools.product(range(N),repeat=4): if q[0]==q[2] or q[1]==q[3]: continue s=profile(H,*q,Qd(0)); x=Qd(s.r/N,s.s/N) if vpr(x.r,p)<0 or vpr(x.s,p)<0: res[(kind(q),"not integral")]+=1; continue res[(kind(q),int(x.r.numerator*pow(x.r.denominator,-1,p))%p)]+=1 print("%s: first row values 1,z,z^2 with z=%s%s sqrt(-%d), pattern %s, Hadamard: %s"%(name,z[0],("+%s"%z[1]) if z[1]>0 else z[1],d,pat,had)) print(" residues of sigma=S/%d modulo the prime above %d, by type:"%(N,p),sorted(res.items(),key=str))