from sage.matrix.operation_table import OperationTable
def Jaccard(A,B):
XA = set([ (x,A[x]) for x in range(len(A))])
XB = set([ (x,B[x]) for x in range(len(A))])
print(XA,XB)
return QQ(len(XA.intersection(XB)))/QQ(len(XA.union(XB)))
def distJ(A,B):
return sqrt(Jaccard(A,A)+Jaccard(B,B)-2*Jaccard(A,B))
import itertools
def Jaccard(A,B):
pairs = list(itertools.combinations(range(0, len(A)), 2))
XA = set([ (A[x],A[y]) for x,y in pairs])
XB = set([ (B[x],B[y]) for x,y in pairs])
return QQ(len(XA.intersection(XB)))/QQ(len(XA.union(XB)))
def GramMatrix(finiteGroup):
G = finiteGroup
O = OperationTable(G,operator.mul,names="elements")
M = matrix([[ Jaccard(Permutation([xx+1 for xx in x]),Permutation([yy+1 for yy in y])) for x in O.table()] for y in O.table()],ring=QQ) #RDF)
return M
def regRepr(finiteGroup):
G = finiteGroup
O = OperationTable(G,operator.mul,names="elements")
#print(O.table())
ll = [ Permutation([xx +1 for xx in x]).to_matrix() for x in O.table()]
return ll
rD4 = (regRepr(DihedralGroup(4)))
#print(rD4)
GD4 = GramMatrix(DihedralGroup(4))
vecs = GD4.columns()
print(vecs)
for M in rD4:
print("--")
for v in vecs:
print(v,M*v)
print(M*v in vecs)
groups = [SymmetricGroup(2),CyclicPermutationGroup(3),CyclicPermutationGroup(4),KleinFourGroup(),CyclicPermutationGroup(5),CyclicPermutationGroup(6),SymmetricGroup(3),QuaternionGroup(),DihedralGroup(5),AlternatingGroup(4),SymmetricGroup(4),DihedralGroup(8)]
for G in groups: #G = DihedralGroup(4)
print("Group G:=")
print(G)
M = GramMatrix(G)
print("Gram-Matrix:")
print(M)
print("cholesky = ")
print(M.cholesky())
print("characteristic-polynomial of Gram-Matrix=")
print(factor(M.charpoly()))
print("Volume of G:")
print(sqrt(M.det()))