# Python de symmetric group 3

import

``````%matplotlib inline
import numpy as np
import math
from sympy import *
from sympy.combinatorics import *

init_printing(pretty_print=False)
``````

# function

``````def plusone(x):
add_one = [(i > 0) * (list(x)[i - 1] + 1) for i in range(1 + len(list(x)))]
#(i > 0) is a step function.

n = 4
def plusone_list(x):
return plusone(x)

def plusone_multi(list_of_permutations):
return [plusone(list_of_permutations[i]) for i in range(len(list_of_permutations))]

def list_multi(list_of_permutations):
return [list(list_of_permutations[i]) for i in range(len(list_of_permutations))]

def sgn(x):
return x.signature()
``````

# Normal without unparalleled sorting

Let's display it without any sort without dividing it into conjugates.

## display

``````Symn_perm = SymmetricGroup(n)._elements
plusone_multi(Symn_perm)
'''
[(4), (1 2 3 4), (1 3)(2 4), (1 4), (2 3 4), (1 2 4 3), (4)(1 3 2), (1 4 2 3), (2 4 3), (4)(1 2), (1 3 4), (1 4 3 2),
(3 4), (4)(1 2 3), (1 3 2 4), (1 4 3), (4)(2 3), (1 2 4), (1 3 4 2), (1 4)(2 3), (2 4), (1 2)(3 4), (4)(1 3), (1 4 2)]
'''
``````
``````Symn_list = list_multi(plusone_multi(Symn_perm))
Symn_list, len(Symn_list)
'''
([[0, 1, 2, 3, 4], [0, 2, 3, 4, 1], [0, 3, 4, 1, 2], [0, 4, 2, 3, 1], [0, 1, 3, 4, 2], [0, 2, 4, 1, 3], [0, 3, 1, 2, 4], [0, 4, 3, 1, 2], [0, 1, 4, 2, 3], [0, 2, 1, 3, 4], [0, 3, 2, 4, 1], [0, 4, 1, 2, 3],
[0, 1, 2, 4, 3], [0, 2, 3, 1, 4], [0, 3, 4, 2, 1], [0, 4, 2, 1, 3], [0, 1, 3, 2, 4], [0, 2, 4, 3, 1], [0, 3, 1, 4, 2], [0, 4, 3, 2, 1], [0, 1, 4, 3, 2], [0, 2, 1, 4, 3], [0, 3, 2, 1, 4], [0, 4, 1, 3, 2]], 24)
'''
``````

## Function to determine each element

``````def discriminate_perm(x):
for i in range(len(Symn_perm)):
if x == Symn_perm[i] or x == plusone(Symn_perm[i]):
return 'g' + str(i)
elif x == Symn_list[i] or x == list(plusone(Symn_list[i])):
return 'g' + str(i)

[ [discriminate_perm(Symn_perm[i]), plusone(Symn_perm[i]), sgn(Symn_perm[i] ) ]
for i in range(len(Symn_perm))]

'''
[['g0', Permutation(4), 1],
['g1', Permutation(1, 2, 3, 4), -1],
['g2', Permutation(1, 3)(2, 4), 1],
['g3', Permutation(1, 4), -1],
['g4', Permutation(2, 3, 4), 1],
['g5', Permutation(1, 2, 4, 3), -1],
['g6', Permutation(4)(1, 3, 2), 1],
['g7', Permutation(1, 4, 2, 3), -1],
['g8', Permutation(2, 4, 3), 1],
['g9', Permutation(4)(1, 2), -1],
['g10', Permutation(1, 3, 4), 1],
['g11', Permutation(1, 4, 3, 2), -1],
['g12', Permutation(3, 4), -1],
['g13', Permutation(4)(1, 2, 3), 1],
['g14', Permutation(1, 3, 2, 4), -1],
['g15', Permutation(1, 4, 3), 1],
['g16', Permutation(4)(2, 3), -1],
['g17', Permutation(1, 2, 4), 1],
['g18', Permutation(1, 3, 4, 2), -1],
['g19', Permutation(1, 4)(2, 3), 1],
['g20', Permutation(2, 4), -1],
['g21', Permutation(1, 2)(3, 4), 1],
['g22', Permutation(4)(1, 3), -1],
['g23', Permutation(1, 4, 2), 1]]
'''
``````

# Divide into conjugates

## display

If you print line by line, you can see what you are doing.

``````conjc = SymmetricGroup(n).conjugacy_classes()
conjc_list = [list(conjc[i]) for i in range(len(conjc))] #not for i in range(n)!!!

Symn_conj = [ conjc_list[i][j]  for i in range(len(conjc)) for j in range(len(conjc_list[i]))]
len(Symn_conj), plusone_multi(Symn_conj)

'''
(24, [(4), (1 4 2 3), (1 2 3 4), (1 3 2 4), (1 2 4 3), (1 4 3 2), (1 3 4 2), (1 4)(2 3), (1 3)(2 4), (1 2)(3 4), (2 4), (4)(1 3), (3 4), (4)(1 2), (1 4), (4)(2 3), (1 4 2), (1 2 4), (1 3 4), (1 4 3), (2 4 3), (2 3 4), (4)(1 3 2), (4)(1 2 3)])
'''
The result is long, but I stopped breaking lines

``````
• The order in the conjugate class was changed between 12/17 and 12/20, but the part for 12/20 is displayed. Perhaps it was updated and the program was rewritten internally (but as of 12/20, the last update of sympy.combinatorics was 12/12. The cause is unknown).
``````[ list_multi( plusone_multi (conjc_list[i] )) for i in range(n)]
'''
[[[0, 1, 2, 3, 4]], [[0, 4, 3, 1, 2], [0, 2, 3, 4, 1], [0, 3, 4, 2, 1], [0, 2, 4, 1, 3], [0, 4, 1, 2, 3], [0, 3, 1, 4, 2]], [[0, 4, 3, 2, 1], [0, 3, 4, 1, 2], [0, 2, 1, 4, 3]], [[0, 1, 4, 3, 2], [0, 3, 2, 1, 4], [0, 1, 2, 4, 3], [0, 2, 1, 3, 4], [0, 4, 2, 3, 1], [0, 1, 3, 2, 4]]]
'''
``````

## Function to determine each element

``````def discriminate_conj(x):
for i in range(len(Symn_conj)):
if x == Symn_conj[i] or x == plusone(Symn_conj[i]):
return 'g' + str(i)
elif x == Symn_conj[i] or x == list(plusone(Symn_conj[i])):
return 'g' + str(i)

[ [discriminate_conj(Symn_conj[i]), plusone(Symn_conj[i]), sgn(Symn_conj[i] ) ]
for i in range(len(Symn_conj))]

'''
[['g0', Permutation(4), 1],
['g1', Permutation(1, 4, 2, 3), -1],
['g2', Permutation(1, 2, 3, 4), -1],
['g3', Permutation(1, 3, 2, 4), -1],
['g4', Permutation(1, 2, 4, 3), -1],
['g5', Permutation(1, 4, 3, 2), -1],
['g6', Permutation(1, 3, 4, 2), -1],
['g7', Permutation(1, 4)(2, 3), 1],
['g8', Permutation(1, 3)(2, 4), 1],
['g9', Permutation(1, 2)(3, 4), 1],
['g10', Permutation(2, 4), -1],
['g11', Permutation(4)(1, 3), -1],
['g12', Permutation(3, 4), -1],
['g13', Permutation(4)(1, 2), -1],
['g14', Permutation(1, 4), -1],
['g15', Permutation(4)(2, 3), -1],
['g16', Permutation(1, 4, 2), 1],
['g17', Permutation(1, 2, 4), 1],
['g18', Permutation(1, 3, 4), 1],
['g19', Permutation(1, 4, 3), 1],
['g20', Permutation(2, 4, 3), 1],
['g21', Permutation(2, 3, 4), 1],
['g22', Permutation(4)(1, 3, 2), 1],
['g23', Permutation(4)(1, 2, 3), 1]]
'''
``````

# Further sort by determinant so that alternating groups appear

The Klein four-group has already appeared, but the alternating group is difficult to see, so sort by a determinant from here.

## First sort

``````
def sortsgn(perms):
sortedlist = [perms[k] for k in range(len(perms))]
for i in range(len(perms)):
for j in range(i, 0 ,-1):
if sgn(sortedlist[j - 1]) < sgn(sortedlist[j]):
sortedlist[j - 1], sortedlist[j] = sortedlist[j], sortedlist[j - 1]
return sortedlist

Symn_conj_sort = sortsgn(Symn_conj)
[ [discriminate_conj(Symn_conj_sort[i]), plusone(Symn_conj_sort[i]), sgn(Symn_conj_sort[i] ) ]
for i in range(len(Symn_conj_sort))]
'''

[['g0', Permutation(4), 1],
['g7', Permutation(1, 4)(2, 3), 1],
['g8', Permutation(1, 3)(2, 4), 1],
['g9', Permutation(1, 2)(3, 4), 1],
['g16', Permutation(1, 4, 2), 1],
['g17', Permutation(1, 2, 4), 1],
['g18', Permutation(1, 3, 4), 1],
['g19', Permutation(1, 4, 3), 1],
['g20', Permutation(2, 4, 3), 1],
['g21', Permutation(2, 3, 4), 1],
['g22', Permutation(4)(1, 3, 2), 1],
['g23', Permutation(4)(1, 2, 3), 1],
['g1', Permutation(1, 4, 2, 3), -1],
['g2', Permutation(1, 2, 3, 4), -1],
['g3', Permutation(1, 3, 2, 4), -1],
['g4', Permutation(1, 2, 4, 3), -1],
['g5', Permutation(1, 4, 3, 2), -1],
['g6', Permutation(1, 3, 4, 2), -1],
['g10', Permutation(2, 4), -1],
['g11', Permutation(4)(1, 3), -1],
['g12', Permutation(3, 4), -1],
['g13', Permutation(4)(1, 2), -1],
['g14', Permutation(1, 4), -1],
['g15', Permutation(4)(2, 3), -1]]
'''
``````

## Functions that determine in this order

Rewrite the discriminating functions in the order after sorting.

``````def discriminate_conj_sort(x):
for i in range(len(Symn_conj_sort)):
if x == Symn_conj_sort[i] or x == plusone(Symn_conj_sort[i]):
return 'g' + str(i)
elif x == Symn_conj_sort[i] or x == list(plusone(Symn_conj_sort[i])):
return 'g' + str(i)

[ [discriminate_conj_sort(Symn_conj_sort[i]), plusone(Symn_conj_sort[i]), sgn(Symn_conj_sort[i] ) ]
for i in range(len(Symn_conj_sort))]

'''

[['g0', Permutation(4), 1],
['g1', Permutation(1, 4)(2, 3), 1],
['g2', Permutation(1, 3)(2, 4), 1],
['g3', Permutation(1, 2)(3, 4), 1],
['g4', Permutation(1, 4, 2), 1],
['g5', Permutation(1, 2, 4), 1],
['g6', Permutation(1, 3, 4), 1],
['g7', Permutation(1, 4, 3), 1],
['g8', Permutation(2, 4, 3), 1],
['g9', Permutation(2, 3, 4), 1],
['g10', Permutation(4)(1, 3, 2), 1],
['g11', Permutation(4)(1, 2, 3), 1],
['g12', Permutation(1, 4, 2, 3), -1],
['g13', Permutation(1, 2, 3, 4), -1],
['g14', Permutation(1, 3, 2, 4), -1],
['g15', Permutation(1, 2, 4, 3), -1],
['g16', Permutation(1, 4, 3, 2), -1],
['g17', Permutation(1, 3, 4, 2), -1],
['g18', Permutation(2, 4), -1],
['g19', Permutation(4)(1, 3), -1],
['g20', Permutation(3, 4), -1],
['g21', Permutation(4)(1, 2), -1],
['g22', Permutation(1, 4), -1],
['g23', Permutation(4)(2, 3), -1]]
'''

``````

If you devise this, you can also write a group table (1 min for 5th order, 3.3 h for 6th order). the end.

# Afterword

Isn't Python the only language that can handle symmetric groups so simply? Even if you search for "symmetric group programming language", only Wolfram and his Egison (it seems that Einstein's abbreviation notation can be used in a language made by Japanese) will be hit. Wolfram has few examples (and the paid version is not cheap), and Egison is too new and it is unclear whether it is possible to perform calculations even if it is investigated.

While calculating the symmetric group with Python, I was impressed by calling conjugate classes with a single command, freely converting types, and performing operations.

The symmetric group that appears in the math girl "Galois theory", will you feel nostalgic if you understand it again using Python, or will you feel like taking a step into an open world?

As can be seen from Cayley's theorem that any finite group is isomorphic to a subgroup of a symmetric group, the peaks of the symmetric group are rich, beautiful, blue and deep. I hope this article will help you to see the magnificent view from the summit.

Recommended Posts