-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.py
138 lines (109 loc) · 3.38 KB
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# import fgrouppy
# def multiplication_mod_6(a, b):
# return (a * b) % 6
def addition_mod_4(a, b):
return (a * b) % 4
def addition_mod_5(a, b):
return (a + b) % 5
def addition_mod_15(a, b):
return (a + b) % 15
def convert_permutation_to_elements(permutations):
elements = set()
for permutation in permutations:
elements.update(permutation)
return elements
def addition_v4(a, b):
if a == 'a' and b == 'b':
return 'c'
if a == 'b' and b == 'a':
return 'c'
if a == 'b' and b == 'c':
return 'a'
if a == 'c' and b == 'b':
return 'a'
if a == 'c' and b == 'a':
return 'b'
if a == 'a' and b == 'c':
return 'b'
if a == 'e' and b == 'e':
return 'e'
if a == 'e' and b == 'a':
return 'a'
if a == 'e' and b == 'b':
return 'b'
if a == 'e' and b == 'c':
return 'c'
if a == 'a' and b == 'a':
return 'e'
if a == 'b' and b == 'b':
return 'e'
if a == 'c' and b == 'c':
return 'e'
if addition_v4(b, a) != None:
return addition_v4(b, a)
return None
# Example permutation list
permutations = [[1, 2, 3], [2, 3, 1], [3, 1, 2]]
# Convert permutation list to elements
group_elements = convert_permutation_to_elements(permutations)
print("Elements of the group:", group_elements)
elements = {0, 1, 2, 3}
elements = {0, 1, 2, 3, 4}
# elements = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14}
elements = {'e', 'a', 'b', 'c'}
# Create a group
# group = Group(elements, addition_mod_5)
# group = Group(elements, addition_mod_15)
group = Group(elements, addition_v4)
# Check if it's a group
if group.is_group():
print("The given set and operation form a group.")
else:
print("The given set and operation do not form a group" + " for rule #" + str(group.why_not_group[0]) + ".")
# Find all subgroups
subgroups = group.find_subgroups()
print("Subgroups:")
for subgroup in subgroups:
print(subgroup.elements)
# Find inverse elements
print("Inverse elements:")
for element in elements:
inverse = group.inverse(element)
print(f"Inverse of {element} is {inverse}")
print("Identity element:", group.identity_element)
print("Is Cyclic: ", group.is_cyclic())
print("Is A-Cyclic: ", group.is_acyclic())
# Find order of group
order = group.get_order()
print("The order of the group is:", order)
# Find order elements
print("Inverse elements:")
for element in elements:
order = group.get_element_order(element)
print(f"Order of element {element} is {order}")
# Generate the multiplication table
multiplication_table = group.generate_multiplication_table()
# Print the multiplication list
# print("Multiplication Table:")
# for a, row in multiplication_table.items():
# for b, result in row.items():
# print(f"{a} * {b} = {result}")
# Print the multiplication table
print("Multiplication Table:")
print(group.generate_md_multiplication_table())
# Find normal subgroups
normal_subgroups = group.find_normal_subgroups()
# Print the normal subgroups
print("Normal Subgroups:")
for subgroup in normal_subgroups:
print(subgroup.elements)
# Check if the group is Abelian
if group.is_abelian():
print("The group is Abelian.")
else:
print("The group is not Abelian.")
# Print permutation list
permutations = group.to_permutation_list()
print(f"Permutation Lists:")
for permutation in permutations:
print(str(permutation))