Group theory and Python
How do you write Python code to check if an operation * on the set {0,1, .., n-1} defined by a Cayley table is associative or not.
My code:
def is_associative_cayley_table(table):
if not is_cayley_table(table):
return False
for i in range (0,len(table)):
for j in range (0,len(table)):
for k in range (0,len(table)):
if (table[table[i][j])][k])==(table[i][(table[j][k])]):
print("Okay")
else
return False
+3
source to share
1 answer
Instead of typing "Okay"
n^3
times, you can simply return bool
.
def is_associative_cayley_table(table):
if not is_cayley_table(table):
return False
for i in range (0,len(table)):
for j in range (0,len(table)):
for k in range (0,len(table)):
if (table[table[i][j])][k])!=(table[i][(table[j][k])]):
return False
return true
In addition, there is no algorithm for checking the associativity of the set yet.
You have to use brute force.
The best you can do is use the Light Associativity Test , which does not improve the worst-case execution time O(n^3)
. It just makes things easier in some cases.
+1
source to share