# groups16.py -- the 14 groups of order 16 (D8 being the dihedral group of order 16, while SD16, Q16, M16 are named # by their order, as usual), built from multiplication rules, with an invariant which separates them; # name(G) identifies a group given as a list of permutation tuples (or any hashable elements with a product). import itertools from collections import Counter def regular(elts,mul): """the left regular representation, as permutation tuples""" ix={e:k for k,e in enumerate(elts)} return [tuple(ix[mul(g,h)] for h in elts) for g in elts] def semi(m,n,k): # Z_m x| Z_n, b a b^-1 = a^k E=[(a,b) for a in range(m) for b in range(n)] return regular(E,lambda x,y:((x[0]+pow(k,x[1],m)*y[0])%m,(x[1]+y[1])%n)) def abelian(ns): E=list(itertools.product(*[range(n) for n in ns])) return regular(E,lambda x,y:tuple((u+v)%n for u,v,n in zip(x,y,ns))) def quat(m): # generalized quaternion of order 2m: a^m=1, b^2=a^(m/2), b a b^-1=a^-1 E=[(i,j) for i in range(m) for j in range(2)] def mul(x,y): (i,j),(k,l)=x,y if j==0: return ((i+k)%m,l) return ((i-k+(m//2)*l)%m,(j+l)%2) return regular(E,mul) def direct(A,B): E=[(x,y) for x in range(len(A)) for y in range(len(B))] return regular(E,lambda u,v:(A[u[0]][v[0]],B[u[1]][v[1]])) def g163(): # E=[(i,j,k) for i in range(4) for j in range(2) for k in range(2)] act=lambda i,j,k:(i,(j+k*i)%2) def mul(x,y): i,j=act(y[0],y[1],x[2]) return ((x[0]+i)%4,(x[1]+j)%2,(x[2]+y[2])%2) return regular(E,mul) def pauli(): # i^k X^a Z^b, with Z X = -X Z E=[(k,a,b) for k in range(4) for a in range(2) for b in range(2)] return regular(E,lambda x,y:((x[0]+y[0]+2*x[2]*y[1])%4,(x[1]+y[1])%2,(x[2]+y[2])%2)) def pmul(a,b): return tuple(a[x] for x in b) def invariant(G): G=list(G); e=tuple(range(len(G[0]))) def order(x): k=1; y=x while y!=e: y=pmul(x,y); k+=1 return k Z=[x for x in G if all(pmul(x,y)==pmul(y,x) for y in G)] sq=Counter(pmul(x,x) for x in G) cyclicZ=any(order(z)==len(Z) for z in Z) return (len(G)==len(Z),len(Z),cyclicZ,len(sq),tuple(sorted(Counter(order(x) for x in G).items())), tuple(sorted(Counter(sq.values()).items()))) D8=semi(4,2,3); Q8=quat(4) CATALOG={"Z16":abelian([16]),"Z4xZ4":abelian([4,4]),"(Z4xZ2):Z2":g163(),"Z4:Z4":semi(4,4,3),"Z8xZ2":abelian([8,2]), "M16":semi(8,2,5),"D8":semi(8,2,7),"SD16":semi(8,2,3),"Q16":quat(8),"Z4xZ2xZ2":abelian([4,2,2]), "Z2xD8":direct(abelian([2]),D8),"Z2xQ8":direct(abelian([2]),Q8),"Pauli":pauli(),"Z2^4":abelian([2,2,2,2])} KEYS={invariant(G):n for n,G in CATALOG.items()} assert len(KEYS)==14, "the invariant does not separate the 14 groups" def name(G): return KEYS.get(invariant(G),"?") if __name__=="__main__": for n,G in CATALOG.items(): print(f"{n:12s}",invariant(G)) print("the 14 groups of order 16 are separated by the invariant")