(Sage)
# Takes a string and turns it into a square matrix of order n
def make_matrix(string, n):
m = []
row = []
for i in range(0, n * n):
if string[i] == '\n':
continue
if string[i] == ' ':
continue
row.append(Integer(string[i]) + 1)
if len(row) == n:
m.append(row)
row = []
return matrix(m)
# Reads a file and returns a list of the matrices in the file
def fetch_matrices(file_name, n):
matrices = []
with open(file_name) as f:
L = f.readlines()
for i in L:
matrices.append(make_matrix(i, n))
return matrices
# Takes a matrix and permutates each symbol in the matrix
# with the given permutation
def permute_matrix(matrix, permutation, n):
copy = deepcopy(matrix)
for i in range(0, n):
for j in range(0 , n):
copy[i, j] = permutation[copy[i][j] - 1]
return copy
"""
Creates a determinant list with the following triples,
[Isotopy Class Representative, Permutation, Determinant]
The Isotopy class representatives come from a file that
contains all Isotopy classes.
"""
def create_determinant_list(file_name, n):
the_list = []
permu = (Permutations(n)).list()
matrices = fetch_matrices(file_name, n)
for i in range(0, len(matrices)):
for j in permu:
copy = permute_matrix(matrices[i], j, n)
the_list.append([i, j, copy.determinant()])
print(len(the_list))
return the_list
|