# Exercise 8.32#

from itertools import permutations, product
from pprint import pformat

from numpy import zeros
from sympy.combinatorics.generators import symmetric
from IPython.display import Markdown

def display_symmetric(n: int):
perms = list(symmetric(n))
perm_dict = dict()
for i, perm in enumerate(perms):
perm_dict[i] = perm
inv_perms = {v: k for k, v in perm_dict.items()}

display(Markdown(f'**n = {n}**'))
print(pformat(perm_dict))

exp_table        = zeros([len(perms), len(perms)], dtype=int)
conjugacy_table2 = zeros([len(perms), len(perms)], dtype=int)
for i, j in product(range(len(perms)), repeat=2):
a = perms[i]
b = perms[j]
exp_table[i, j]        = inv_perms[a ^ b]
conjugacy_table2[i, j] = inv_perms[b * a * ~b]

display(Markdown('<br/>exp_table'))
print(exp_table)

display(Markdown('<br/>conjugacy_table2'))
print(conjugacy_table2)

[display_symmetric(n) for n in range(3,4)];


n = 3

{0: Permutation(2),
1: Permutation(1, 2),
2: Permutation(2)(0, 1),
3: Permutation(0, 1, 2),
4: Permutation(0, 2, 1),
5: Permutation(0, 2)}


exp_table

[[0 0 0 0 0 0]
[1 1 5 5 2 2]
[2 5 2 1 5 1]
[3 4 4 3 3 4]
[4 3 3 4 4 3]
[5 2 1 2 1 5]]


conjugacy_table2

[[0 0 0 0 0 0]
[1 1 5 2 5 2]
[2 5 2 5 1 1]
[3 4 4 3 3 4]
[4 3 3 4 4 3]
[5 2 1 1 2 5]]