ZTWHHH commited on
Commit
9d82aab
·
verified ·
1 Parent(s): 9e46023

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/__init__.cpython-310.pyc +0 -0
  2. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/coset_table.cpython-310.pyc +0 -0
  3. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/fp_groups.cpython-310.pyc +0 -0
  4. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/free_groups.cpython-310.pyc +0 -0
  5. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/galois.cpython-310.pyc +0 -0
  6. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/generators.cpython-310.pyc +0 -0
  7. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/graycode.cpython-310.pyc +0 -0
  8. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/group_constructs.cpython-310.pyc +0 -0
  9. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/group_numbers.cpython-310.pyc +0 -0
  10. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/homomorphisms.cpython-310.pyc +0 -0
  11. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/named_groups.cpython-310.pyc +0 -0
  12. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/partitions.cpython-310.pyc +0 -0
  13. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/pc_groups.cpython-310.pyc +0 -0
  14. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/permutations.cpython-310.pyc +0 -0
  15. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/polyhedron.cpython-310.pyc +0 -0
  16. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/prufer.cpython-310.pyc +0 -0
  17. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/rewritingsystem.cpython-310.pyc +0 -0
  18. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/rewritingsystem_fsm.cpython-310.pyc +0 -0
  19. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/schur_number.cpython-310.pyc +0 -0
  20. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/subsets.cpython-310.pyc +0 -0
  21. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/tensor_can.cpython-310.pyc +0 -0
  22. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/testutil.cpython-310.pyc +0 -0
  23. pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/util.cpython-310.pyc +0 -0
  24. pllava/lib/python3.10/site-packages/sympy/combinatorics/coset_table.py +1255 -0
  25. pllava/lib/python3.10/site-packages/sympy/combinatorics/generators.py +302 -0
  26. pllava/lib/python3.10/site-packages/sympy/combinatorics/group_constructs.py +61 -0
  27. pllava/lib/python3.10/site-packages/sympy/combinatorics/named_groups.py +332 -0
  28. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__init__.py +0 -0
  29. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_coset_table.cpython-310.pyc +0 -0
  30. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_fp_groups.cpython-310.pyc +0 -0
  31. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_free_groups.cpython-310.pyc +0 -0
  32. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_galois.cpython-310.pyc +0 -0
  33. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_generators.cpython-310.pyc +0 -0
  34. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_graycode.cpython-310.pyc +0 -0
  35. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_group_constructs.cpython-310.pyc +0 -0
  36. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_homomorphisms.cpython-310.pyc +0 -0
  37. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_partitions.cpython-310.pyc +0 -0
  38. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_pc_groups.cpython-310.pyc +0 -0
  39. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_perm_groups.cpython-310.pyc +0 -0
  40. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_permutations.cpython-310.pyc +0 -0
  41. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_rewriting.cpython-310.pyc +0 -0
  42. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_subsets.cpython-310.pyc +0 -0
  43. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_tensor_can.cpython-310.pyc +0 -0
  44. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_testutil.cpython-310.pyc +0 -0
  45. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_util.cpython-310.pyc +0 -0
  46. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_fp_groups.py +257 -0
  47. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_generators.py +105 -0
  48. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_graycode.py +72 -0
  49. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_homomorphisms.py +114 -0
  50. pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_perm_groups.py +1243 -0
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (1.6 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/coset_table.cpython-310.pyc ADDED
Binary file (34.4 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/fp_groups.cpython-310.pyc ADDED
Binary file (38.1 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/free_groups.cpython-310.pyc ADDED
Binary file (38.7 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/galois.cpython-310.pyc ADDED
Binary file (17.2 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/generators.cpython-310.pyc ADDED
Binary file (8.27 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/graycode.cpython-310.pyc ADDED
Binary file (11.7 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/group_constructs.cpython-310.pyc ADDED
Binary file (2.12 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/group_numbers.cpython-310.pyc ADDED
Binary file (9.53 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/homomorphisms.cpython-310.pyc ADDED
Binary file (16.5 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/named_groups.cpython-310.pyc ADDED
Binary file (8.13 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/partitions.cpython-310.pyc ADDED
Binary file (21.9 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/pc_groups.cpython-310.pyc ADDED
Binary file (20 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/permutations.cpython-310.pyc ADDED
Binary file (90 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/polyhedron.cpython-310.pyc ADDED
Binary file (33.6 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/prufer.cpython-310.pyc ADDED
Binary file (12 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/rewritingsystem.cpython-310.pyc ADDED
Binary file (11 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/rewritingsystem_fsm.cpython-310.pyc ADDED
Binary file (2.99 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/schur_number.cpython-310.pyc ADDED
Binary file (4.99 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/subsets.cpython-310.pyc ADDED
Binary file (15.9 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/tensor_can.cpython-310.pyc ADDED
Binary file (38 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/testutil.cpython-310.pyc ADDED
Binary file (9.88 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/__pycache__/util.cpython-310.pyc ADDED
Binary file (14.6 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/coset_table.py ADDED
@@ -0,0 +1,1255 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics.free_groups import free_group
2
+ from sympy.printing.defaults import DefaultPrinting
3
+
4
+ from itertools import chain, product
5
+ from bisect import bisect_left
6
+
7
+
8
+ ###############################################################################
9
+ # COSET TABLE #
10
+ ###############################################################################
11
+
12
+ class CosetTable(DefaultPrinting):
13
+ # coset_table: Mathematically a coset table
14
+ # represented using a list of lists
15
+ # alpha: Mathematically a coset (precisely, a live coset)
16
+ # represented by an integer between i with 1 <= i <= n
17
+ # alpha in c
18
+ # x: Mathematically an element of "A" (set of generators and
19
+ # their inverses), represented using "FpGroupElement"
20
+ # fp_grp: Finitely Presented Group with < X|R > as presentation.
21
+ # H: subgroup of fp_grp.
22
+ # NOTE: We start with H as being only a list of words in generators
23
+ # of "fp_grp". Since `.subgroup` method has not been implemented.
24
+
25
+ r"""
26
+
27
+ Properties
28
+ ==========
29
+
30
+ [1] `0 \in \Omega` and `\tau(1) = \epsilon`
31
+ [2] `\alpha^x = \beta \Leftrightarrow \beta^{x^{-1}} = \alpha`
32
+ [3] If `\alpha^x = \beta`, then `H \tau(\alpha)x = H \tau(\beta)`
33
+ [4] `\forall \alpha \in \Omega, 1^{\tau(\alpha)} = \alpha`
34
+
35
+ References
36
+ ==========
37
+
38
+ .. [1] Holt, D., Eick, B., O'Brien, E.
39
+ "Handbook of Computational Group Theory"
40
+
41
+ .. [2] John J. Cannon; Lucien A. Dimino; George Havas; Jane M. Watson
42
+ Mathematics of Computation, Vol. 27, No. 123. (Jul., 1973), pp. 463-490.
43
+ "Implementation and Analysis of the Todd-Coxeter Algorithm"
44
+
45
+ """
46
+ # default limit for the number of cosets allowed in a
47
+ # coset enumeration.
48
+ coset_table_max_limit = 4096000
49
+ # limit for the current instance
50
+ coset_table_limit = None
51
+ # maximum size of deduction stack above or equal to
52
+ # which it is emptied
53
+ max_stack_size = 100
54
+
55
+ def __init__(self, fp_grp, subgroup, max_cosets=None):
56
+ if not max_cosets:
57
+ max_cosets = CosetTable.coset_table_max_limit
58
+ self.fp_group = fp_grp
59
+ self.subgroup = subgroup
60
+ self.coset_table_limit = max_cosets
61
+ # "p" is setup independent of Omega and n
62
+ self.p = [0]
63
+ # a list of the form `[gen_1, gen_1^{-1}, ... , gen_k, gen_k^{-1}]`
64
+ self.A = list(chain.from_iterable((gen, gen**-1) \
65
+ for gen in self.fp_group.generators))
66
+ #P[alpha, x] Only defined when alpha^x is defined.
67
+ self.P = [[None]*len(self.A)]
68
+ # the mathematical coset table which is a list of lists
69
+ self.table = [[None]*len(self.A)]
70
+ self.A_dict = {x: self.A.index(x) for x in self.A}
71
+ self.A_dict_inv = {}
72
+ for x, index in self.A_dict.items():
73
+ if index % 2 == 0:
74
+ self.A_dict_inv[x] = self.A_dict[x] + 1
75
+ else:
76
+ self.A_dict_inv[x] = self.A_dict[x] - 1
77
+ # used in the coset-table based method of coset enumeration. Each of
78
+ # the element is called a "deduction" which is the form (alpha, x) whenever
79
+ # a value is assigned to alpha^x during a definition or "deduction process"
80
+ self.deduction_stack = []
81
+ # Attributes for modified methods.
82
+ H = self.subgroup
83
+ self._grp = free_group(', ' .join(["a_%d" % i for i in range(len(H))]))[0]
84
+ self.P = [[None]*len(self.A)]
85
+ self.p_p = {}
86
+
87
+ @property
88
+ def omega(self):
89
+ """Set of live cosets. """
90
+ return [coset for coset in range(len(self.p)) if self.p[coset] == coset]
91
+
92
+ def copy(self):
93
+ """
94
+ Return a shallow copy of Coset Table instance ``self``.
95
+
96
+ """
97
+ self_copy = self.__class__(self.fp_group, self.subgroup)
98
+ self_copy.table = [list(perm_rep) for perm_rep in self.table]
99
+ self_copy.p = list(self.p)
100
+ self_copy.deduction_stack = list(self.deduction_stack)
101
+ return self_copy
102
+
103
+ def __str__(self):
104
+ return "Coset Table on %s with %s as subgroup generators" \
105
+ % (self.fp_group, self.subgroup)
106
+
107
+ __repr__ = __str__
108
+
109
+ @property
110
+ def n(self):
111
+ """The number `n` represents the length of the sublist containing the
112
+ live cosets.
113
+
114
+ """
115
+ if not self.table:
116
+ return 0
117
+ return max(self.omega) + 1
118
+
119
+ # Pg. 152 [1]
120
+ def is_complete(self):
121
+ r"""
122
+ The coset table is called complete if it has no undefined entries
123
+ on the live cosets; that is, `\alpha^x` is defined for all
124
+ `\alpha \in \Omega` and `x \in A`.
125
+
126
+ """
127
+ return not any(None in self.table[coset] for coset in self.omega)
128
+
129
+ # Pg. 153 [1]
130
+ def define(self, alpha, x, modified=False):
131
+ r"""
132
+ This routine is used in the relator-based strategy of Todd-Coxeter
133
+ algorithm if some `\alpha^x` is undefined. We check whether there is
134
+ space available for defining a new coset. If there is enough space
135
+ then we remedy this by adjoining a new coset `\beta` to `\Omega`
136
+ (i.e to set of live cosets) and put that equal to `\alpha^x`, then
137
+ make an assignment satisfying Property[1]. If there is not enough space
138
+ then we halt the Coset Table creation. The maximum amount of space that
139
+ can be used by Coset Table can be manipulated using the class variable
140
+ ``CosetTable.coset_table_max_limit``.
141
+
142
+ See Also
143
+ ========
144
+
145
+ define_c
146
+
147
+ """
148
+ A = self.A
149
+ table = self.table
150
+ len_table = len(table)
151
+ if len_table >= self.coset_table_limit:
152
+ # abort the further generation of cosets
153
+ raise ValueError("the coset enumeration has defined more than "
154
+ "%s cosets. Try with a greater value max number of cosets "
155
+ % self.coset_table_limit)
156
+ table.append([None]*len(A))
157
+ self.P.append([None]*len(self.A))
158
+ # beta is the new coset generated
159
+ beta = len_table
160
+ self.p.append(beta)
161
+ table[alpha][self.A_dict[x]] = beta
162
+ table[beta][self.A_dict_inv[x]] = alpha
163
+ # P[alpha][x] = epsilon, P[beta][x**-1] = epsilon
164
+ if modified:
165
+ self.P[alpha][self.A_dict[x]] = self._grp.identity
166
+ self.P[beta][self.A_dict_inv[x]] = self._grp.identity
167
+ self.p_p[beta] = self._grp.identity
168
+
169
+ def define_c(self, alpha, x):
170
+ r"""
171
+ A variation of ``define`` routine, described on Pg. 165 [1], used in
172
+ the coset table-based strategy of Todd-Coxeter algorithm. It differs
173
+ from ``define`` routine in that for each definition it also adds the
174
+ tuple `(\alpha, x)` to the deduction stack.
175
+
176
+ See Also
177
+ ========
178
+
179
+ define
180
+
181
+ """
182
+ A = self.A
183
+ table = self.table
184
+ len_table = len(table)
185
+ if len_table >= self.coset_table_limit:
186
+ # abort the further generation of cosets
187
+ raise ValueError("the coset enumeration has defined more than "
188
+ "%s cosets. Try with a greater value max number of cosets "
189
+ % self.coset_table_limit)
190
+ table.append([None]*len(A))
191
+ # beta is the new coset generated
192
+ beta = len_table
193
+ self.p.append(beta)
194
+ table[alpha][self.A_dict[x]] = beta
195
+ table[beta][self.A_dict_inv[x]] = alpha
196
+ # append to deduction stack
197
+ self.deduction_stack.append((alpha, x))
198
+
199
+ def scan_c(self, alpha, word):
200
+ """
201
+ A variation of ``scan`` routine, described on pg. 165 of [1], which
202
+ puts at tuple, whenever a deduction occurs, to deduction stack.
203
+
204
+ See Also
205
+ ========
206
+
207
+ scan, scan_check, scan_and_fill, scan_and_fill_c
208
+
209
+ """
210
+ # alpha is an integer representing a "coset"
211
+ # since scanning can be in two cases
212
+ # 1. for alpha=0 and w in Y (i.e generating set of H)
213
+ # 2. alpha in Omega (set of live cosets), w in R (relators)
214
+ A_dict = self.A_dict
215
+ A_dict_inv = self.A_dict_inv
216
+ table = self.table
217
+ f = alpha
218
+ i = 0
219
+ r = len(word)
220
+ b = alpha
221
+ j = r - 1
222
+ # list of union of generators and their inverses
223
+ while i <= j and table[f][A_dict[word[i]]] is not None:
224
+ f = table[f][A_dict[word[i]]]
225
+ i += 1
226
+ if i > j:
227
+ if f != b:
228
+ self.coincidence_c(f, b)
229
+ return
230
+ while j >= i and table[b][A_dict_inv[word[j]]] is not None:
231
+ b = table[b][A_dict_inv[word[j]]]
232
+ j -= 1
233
+ if j < i:
234
+ # we have an incorrect completed scan with coincidence f ~ b
235
+ # run the "coincidence" routine
236
+ self.coincidence_c(f, b)
237
+ elif j == i:
238
+ # deduction process
239
+ table[f][A_dict[word[i]]] = b
240
+ table[b][A_dict_inv[word[i]]] = f
241
+ self.deduction_stack.append((f, word[i]))
242
+ # otherwise scan is incomplete and yields no information
243
+
244
+ # alpha, beta coincide, i.e. alpha, beta represent the pair of cosets where
245
+ # coincidence occurs
246
+ def coincidence_c(self, alpha, beta):
247
+ """
248
+ A variation of ``coincidence`` routine used in the coset-table based
249
+ method of coset enumeration. The only difference being on addition of
250
+ a new coset in coset table(i.e new coset introduction), then it is
251
+ appended to ``deduction_stack``.
252
+
253
+ See Also
254
+ ========
255
+
256
+ coincidence
257
+
258
+ """
259
+ A_dict = self.A_dict
260
+ A_dict_inv = self.A_dict_inv
261
+ table = self.table
262
+ # behaves as a queue
263
+ q = []
264
+ self.merge(alpha, beta, q)
265
+ while len(q) > 0:
266
+ gamma = q.pop(0)
267
+ for x in A_dict:
268
+ delta = table[gamma][A_dict[x]]
269
+ if delta is not None:
270
+ table[delta][A_dict_inv[x]] = None
271
+ # only line of difference from ``coincidence`` routine
272
+ self.deduction_stack.append((delta, x**-1))
273
+ mu = self.rep(gamma)
274
+ nu = self.rep(delta)
275
+ if table[mu][A_dict[x]] is not None:
276
+ self.merge(nu, table[mu][A_dict[x]], q)
277
+ elif table[nu][A_dict_inv[x]] is not None:
278
+ self.merge(mu, table[nu][A_dict_inv[x]], q)
279
+ else:
280
+ table[mu][A_dict[x]] = nu
281
+ table[nu][A_dict_inv[x]] = mu
282
+
283
+ def scan(self, alpha, word, y=None, fill=False, modified=False):
284
+ r"""
285
+ ``scan`` performs a scanning process on the input ``word``.
286
+ It first locates the largest prefix ``s`` of ``word`` for which
287
+ `\alpha^s` is defined (i.e is not ``None``), ``s`` may be empty. Let
288
+ ``word=sv``, let ``t`` be the longest suffix of ``v`` for which
289
+ `\alpha^{t^{-1}}` is defined, and let ``v=ut``. Then three
290
+ possibilities are there:
291
+
292
+ 1. If ``t=v``, then we say that the scan completes, and if, in addition
293
+ `\alpha^s = \alpha^{t^{-1}}`, then we say that the scan completes
294
+ correctly.
295
+
296
+ 2. It can also happen that scan does not complete, but `|u|=1`; that
297
+ is, the word ``u`` consists of a single generator `x \in A`. In that
298
+ case, if `\alpha^s = \beta` and `\alpha^{t^{-1}} = \gamma`, then we can
299
+ set `\beta^x = \gamma` and `\gamma^{x^{-1}} = \beta`. These assignments
300
+ are known as deductions and enable the scan to complete correctly.
301
+
302
+ 3. See ``coicidence`` routine for explanation of third condition.
303
+
304
+ Notes
305
+ =====
306
+
307
+ The code for the procedure of scanning `\alpha \in \Omega`
308
+ under `w \in A*` is defined on pg. 155 [1]
309
+
310
+ See Also
311
+ ========
312
+
313
+ scan_c, scan_check, scan_and_fill, scan_and_fill_c
314
+
315
+ Scan and Fill
316
+ =============
317
+
318
+ Performed when the default argument fill=True.
319
+
320
+ Modified Scan
321
+ =============
322
+
323
+ Performed when the default argument modified=True
324
+
325
+ """
326
+ # alpha is an integer representing a "coset"
327
+ # since scanning can be in two cases
328
+ # 1. for alpha=0 and w in Y (i.e generating set of H)
329
+ # 2. alpha in Omega (set of live cosets), w in R (relators)
330
+ A_dict = self.A_dict
331
+ A_dict_inv = self.A_dict_inv
332
+ table = self.table
333
+ f = alpha
334
+ i = 0
335
+ r = len(word)
336
+ b = alpha
337
+ j = r - 1
338
+ b_p = y
339
+ if modified:
340
+ f_p = self._grp.identity
341
+ flag = 0
342
+ while fill or flag == 0:
343
+ flag = 1
344
+ while i <= j and table[f][A_dict[word[i]]] is not None:
345
+ if modified:
346
+ f_p = f_p*self.P[f][A_dict[word[i]]]
347
+ f = table[f][A_dict[word[i]]]
348
+ i += 1
349
+ if i > j:
350
+ if f != b:
351
+ if modified:
352
+ self.modified_coincidence(f, b, f_p**-1*y)
353
+ else:
354
+ self.coincidence(f, b)
355
+ return
356
+ while j >= i and table[b][A_dict_inv[word[j]]] is not None:
357
+ if modified:
358
+ b_p = b_p*self.P[b][self.A_dict_inv[word[j]]]
359
+ b = table[b][A_dict_inv[word[j]]]
360
+ j -= 1
361
+ if j < i:
362
+ # we have an incorrect completed scan with coincidence f ~ b
363
+ # run the "coincidence" routine
364
+ if modified:
365
+ self.modified_coincidence(f, b, f_p**-1*b_p)
366
+ else:
367
+ self.coincidence(f, b)
368
+ elif j == i:
369
+ # deduction process
370
+ table[f][A_dict[word[i]]] = b
371
+ table[b][A_dict_inv[word[i]]] = f
372
+ if modified:
373
+ self.P[f][self.A_dict[word[i]]] = f_p**-1*b_p
374
+ self.P[b][self.A_dict_inv[word[i]]] = b_p**-1*f_p
375
+ return
376
+ elif fill:
377
+ self.define(f, word[i], modified=modified)
378
+ # otherwise scan is incomplete and yields no information
379
+
380
+ # used in the low-index subgroups algorithm
381
+ def scan_check(self, alpha, word):
382
+ r"""
383
+ Another version of ``scan`` routine, described on, it checks whether
384
+ `\alpha` scans correctly under `word`, it is a straightforward
385
+ modification of ``scan``. ``scan_check`` returns ``False`` (rather than
386
+ calling ``coincidence``) if the scan completes incorrectly; otherwise
387
+ it returns ``True``.
388
+
389
+ See Also
390
+ ========
391
+
392
+ scan, scan_c, scan_and_fill, scan_and_fill_c
393
+
394
+ """
395
+ # alpha is an integer representing a "coset"
396
+ # since scanning can be in two cases
397
+ # 1. for alpha=0 and w in Y (i.e generating set of H)
398
+ # 2. alpha in Omega (set of live cosets), w in R (relators)
399
+ A_dict = self.A_dict
400
+ A_dict_inv = self.A_dict_inv
401
+ table = self.table
402
+ f = alpha
403
+ i = 0
404
+ r = len(word)
405
+ b = alpha
406
+ j = r - 1
407
+ while i <= j and table[f][A_dict[word[i]]] is not None:
408
+ f = table[f][A_dict[word[i]]]
409
+ i += 1
410
+ if i > j:
411
+ return f == b
412
+ while j >= i and table[b][A_dict_inv[word[j]]] is not None:
413
+ b = table[b][A_dict_inv[word[j]]]
414
+ j -= 1
415
+ if j < i:
416
+ # we have an incorrect completed scan with coincidence f ~ b
417
+ # return False, instead of calling coincidence routine
418
+ return False
419
+ elif j == i:
420
+ # deduction process
421
+ table[f][A_dict[word[i]]] = b
422
+ table[b][A_dict_inv[word[i]]] = f
423
+ return True
424
+
425
+ def merge(self, k, lamda, q, w=None, modified=False):
426
+ """
427
+ Merge two classes with representatives ``k`` and ``lamda``, described
428
+ on Pg. 157 [1] (for pseudocode), start by putting ``p[k] = lamda``.
429
+ It is more efficient to choose the new representative from the larger
430
+ of the two classes being merged, i.e larger among ``k`` and ``lamda``.
431
+ procedure ``merge`` performs the merging operation, adds the deleted
432
+ class representative to the queue ``q``.
433
+
434
+ Parameters
435
+ ==========
436
+
437
+ 'k', 'lamda' being the two class representatives to be merged.
438
+
439
+ Notes
440
+ =====
441
+
442
+ Pg. 86-87 [1] contains a description of this method.
443
+
444
+ See Also
445
+ ========
446
+
447
+ coincidence, rep
448
+
449
+ """
450
+ p = self.p
451
+ rep = self.rep
452
+ phi = rep(k, modified=modified)
453
+ psi = rep(lamda, modified=modified)
454
+ if phi != psi:
455
+ mu = min(phi, psi)
456
+ v = max(phi, psi)
457
+ p[v] = mu
458
+ if modified:
459
+ if v == phi:
460
+ self.p_p[phi] = self.p_p[k]**-1*w*self.p_p[lamda]
461
+ else:
462
+ self.p_p[psi] = self.p_p[lamda]**-1*w**-1*self.p_p[k]
463
+ q.append(v)
464
+
465
+ def rep(self, k, modified=False):
466
+ r"""
467
+ Parameters
468
+ ==========
469
+
470
+ `k \in [0 \ldots n-1]`, as for ``self`` only array ``p`` is used
471
+
472
+ Returns
473
+ =======
474
+
475
+ Representative of the class containing ``k``.
476
+
477
+ Returns the representative of `\sim` class containing ``k``, it also
478
+ makes some modification to array ``p`` of ``self`` to ease further
479
+ computations, described on Pg. 157 [1].
480
+
481
+ The information on classes under `\sim` is stored in array `p` of
482
+ ``self`` argument, which will always satisfy the property:
483
+
484
+ `p[\alpha] \sim \alpha` and `p[\alpha]=\alpha \iff \alpha=rep(\alpha)`
485
+ `\forall \in [0 \ldots n-1]`.
486
+
487
+ So, for `\alpha \in [0 \ldots n-1]`, we find `rep(self, \alpha)` by
488
+ continually replacing `\alpha` by `p[\alpha]` until it becomes
489
+ constant (i.e satisfies `p[\alpha] = \alpha`):w
490
+
491
+ To increase the efficiency of later ``rep`` calculations, whenever we
492
+ find `rep(self, \alpha)=\beta`, we set
493
+ `p[\gamma] = \beta \forall \gamma \in p-chain` from `\alpha` to `\beta`
494
+
495
+ Notes
496
+ =====
497
+
498
+ ``rep`` routine is also described on Pg. 85-87 [1] in Atkinson's
499
+ algorithm, this results from the fact that ``coincidence`` routine
500
+ introduces functionality similar to that introduced by the
501
+ ``minimal_block`` routine on Pg. 85-87 [1].
502
+
503
+ See Also
504
+ ========
505
+
506
+ coincidence, merge
507
+
508
+ """
509
+ p = self.p
510
+ lamda = k
511
+ rho = p[lamda]
512
+ if modified:
513
+ s = p[:]
514
+ while rho != lamda:
515
+ if modified:
516
+ s[rho] = lamda
517
+ lamda = rho
518
+ rho = p[lamda]
519
+ if modified:
520
+ rho = s[lamda]
521
+ while rho != k:
522
+ mu = rho
523
+ rho = s[mu]
524
+ p[rho] = lamda
525
+ self.p_p[rho] = self.p_p[rho]*self.p_p[mu]
526
+ else:
527
+ mu = k
528
+ rho = p[mu]
529
+ while rho != lamda:
530
+ p[mu] = lamda
531
+ mu = rho
532
+ rho = p[mu]
533
+ return lamda
534
+
535
+ # alpha, beta coincide, i.e. alpha, beta represent the pair of cosets
536
+ # where coincidence occurs
537
+ def coincidence(self, alpha, beta, w=None, modified=False):
538
+ r"""
539
+ The third situation described in ``scan`` routine is handled by this
540
+ routine, described on Pg. 156-161 [1].
541
+
542
+ The unfortunate situation when the scan completes but not correctly,
543
+ then ``coincidence`` routine is run. i.e when for some `i` with
544
+ `1 \le i \le r+1`, we have `w=st` with `s = x_1 x_2 \dots x_{i-1}`,
545
+ `t = x_i x_{i+1} \dots x_r`, and `\beta = \alpha^s` and
546
+ `\gamma = \alpha^{t-1}` are defined but unequal. This means that
547
+ `\beta` and `\gamma` represent the same coset of `H` in `G`. Described
548
+ on Pg. 156 [1]. ``rep``
549
+
550
+ See Also
551
+ ========
552
+
553
+ scan
554
+
555
+ """
556
+ A_dict = self.A_dict
557
+ A_dict_inv = self.A_dict_inv
558
+ table = self.table
559
+ # behaves as a queue
560
+ q = []
561
+ if modified:
562
+ self.modified_merge(alpha, beta, w, q)
563
+ else:
564
+ self.merge(alpha, beta, q)
565
+ while len(q) > 0:
566
+ gamma = q.pop(0)
567
+ for x in A_dict:
568
+ delta = table[gamma][A_dict[x]]
569
+ if delta is not None:
570
+ table[delta][A_dict_inv[x]] = None
571
+ mu = self.rep(gamma, modified=modified)
572
+ nu = self.rep(delta, modified=modified)
573
+ if table[mu][A_dict[x]] is not None:
574
+ if modified:
575
+ v = self.p_p[delta]**-1*self.P[gamma][self.A_dict[x]]**-1
576
+ v = v*self.p_p[gamma]*self.P[mu][self.A_dict[x]]
577
+ self.modified_merge(nu, table[mu][self.A_dict[x]], v, q)
578
+ else:
579
+ self.merge(nu, table[mu][A_dict[x]], q)
580
+ elif table[nu][A_dict_inv[x]] is not None:
581
+ if modified:
582
+ v = self.p_p[gamma]**-1*self.P[gamma][self.A_dict[x]]
583
+ v = v*self.p_p[delta]*self.P[mu][self.A_dict_inv[x]]
584
+ self.modified_merge(mu, table[nu][self.A_dict_inv[x]], v, q)
585
+ else:
586
+ self.merge(mu, table[nu][A_dict_inv[x]], q)
587
+ else:
588
+ table[mu][A_dict[x]] = nu
589
+ table[nu][A_dict_inv[x]] = mu
590
+ if modified:
591
+ v = self.p_p[gamma]**-1*self.P[gamma][self.A_dict[x]]*self.p_p[delta]
592
+ self.P[mu][self.A_dict[x]] = v
593
+ self.P[nu][self.A_dict_inv[x]] = v**-1
594
+
595
+ # method used in the HLT strategy
596
+ def scan_and_fill(self, alpha, word):
597
+ """
598
+ A modified version of ``scan`` routine used in the relator-based
599
+ method of coset enumeration, described on pg. 162-163 [1], which
600
+ follows the idea that whenever the procedure is called and the scan
601
+ is incomplete then it makes new definitions to enable the scan to
602
+ complete; i.e it fills in the gaps in the scan of the relator or
603
+ subgroup generator.
604
+
605
+ """
606
+ self.scan(alpha, word, fill=True)
607
+
608
+ def scan_and_fill_c(self, alpha, word):
609
+ """
610
+ A modified version of ``scan`` routine, described on Pg. 165 second
611
+ para. [1], with modification similar to that of ``scan_anf_fill`` the
612
+ only difference being it calls the coincidence procedure used in the
613
+ coset-table based method i.e. the routine ``coincidence_c`` is used.
614
+
615
+ See Also
616
+ ========
617
+
618
+ scan, scan_and_fill
619
+
620
+ """
621
+ A_dict = self.A_dict
622
+ A_dict_inv = self.A_dict_inv
623
+ table = self.table
624
+ r = len(word)
625
+ f = alpha
626
+ i = 0
627
+ b = alpha
628
+ j = r - 1
629
+ # loop until it has filled the alpha row in the table.
630
+ while True:
631
+ # do the forward scanning
632
+ while i <= j and table[f][A_dict[word[i]]] is not None:
633
+ f = table[f][A_dict[word[i]]]
634
+ i += 1
635
+ if i > j:
636
+ if f != b:
637
+ self.coincidence_c(f, b)
638
+ return
639
+ # forward scan was incomplete, scan backwards
640
+ while j >= i and table[b][A_dict_inv[word[j]]] is not None:
641
+ b = table[b][A_dict_inv[word[j]]]
642
+ j -= 1
643
+ if j < i:
644
+ self.coincidence_c(f, b)
645
+ elif j == i:
646
+ table[f][A_dict[word[i]]] = b
647
+ table[b][A_dict_inv[word[i]]] = f
648
+ self.deduction_stack.append((f, word[i]))
649
+ else:
650
+ self.define_c(f, word[i])
651
+
652
+ # method used in the HLT strategy
653
+ def look_ahead(self):
654
+ """
655
+ When combined with the HLT method this is known as HLT+Lookahead
656
+ method of coset enumeration, described on pg. 164 [1]. Whenever
657
+ ``define`` aborts due to lack of space available this procedure is
658
+ executed. This routine helps in recovering space resulting from
659
+ "coincidence" of cosets.
660
+
661
+ """
662
+ R = self.fp_group.relators
663
+ p = self.p
664
+ # complete scan all relators under all cosets(obviously live)
665
+ # without making new definitions
666
+ for beta in self.omega:
667
+ for w in R:
668
+ self.scan(beta, w)
669
+ if p[beta] < beta:
670
+ break
671
+
672
+ # Pg. 166
673
+ def process_deductions(self, R_c_x, R_c_x_inv):
674
+ """
675
+ Processes the deductions that have been pushed onto ``deduction_stack``,
676
+ described on Pg. 166 [1] and is used in coset-table based enumeration.
677
+
678
+ See Also
679
+ ========
680
+
681
+ deduction_stack
682
+
683
+ """
684
+ p = self.p
685
+ table = self.table
686
+ while len(self.deduction_stack) > 0:
687
+ if len(self.deduction_stack) >= CosetTable.max_stack_size:
688
+ self.look_ahead()
689
+ del self.deduction_stack[:]
690
+ continue
691
+ else:
692
+ alpha, x = self.deduction_stack.pop()
693
+ if p[alpha] == alpha:
694
+ for w in R_c_x:
695
+ self.scan_c(alpha, w)
696
+ if p[alpha] < alpha:
697
+ break
698
+ beta = table[alpha][self.A_dict[x]]
699
+ if beta is not None and p[beta] == beta:
700
+ for w in R_c_x_inv:
701
+ self.scan_c(beta, w)
702
+ if p[beta] < beta:
703
+ break
704
+
705
+ def process_deductions_check(self, R_c_x, R_c_x_inv):
706
+ """
707
+ A variation of ``process_deductions``, this calls ``scan_check``
708
+ wherever ``process_deductions`` calls ``scan``, described on Pg. [1].
709
+
710
+ See Also
711
+ ========
712
+
713
+ process_deductions
714
+
715
+ """
716
+ table = self.table
717
+ while len(self.deduction_stack) > 0:
718
+ alpha, x = self.deduction_stack.pop()
719
+ for w in R_c_x:
720
+ if not self.scan_check(alpha, w):
721
+ return False
722
+ beta = table[alpha][self.A_dict[x]]
723
+ if beta is not None:
724
+ for w in R_c_x_inv:
725
+ if not self.scan_check(beta, w):
726
+ return False
727
+ return True
728
+
729
+ def switch(self, beta, gamma):
730
+ r"""Switch the elements `\beta, \gamma \in \Omega` of ``self``, used
731
+ by the ``standardize`` procedure, described on Pg. 167 [1].
732
+
733
+ See Also
734
+ ========
735
+
736
+ standardize
737
+
738
+ """
739
+ A = self.A
740
+ A_dict = self.A_dict
741
+ table = self.table
742
+ for x in A:
743
+ z = table[gamma][A_dict[x]]
744
+ table[gamma][A_dict[x]] = table[beta][A_dict[x]]
745
+ table[beta][A_dict[x]] = z
746
+ for alpha in range(len(self.p)):
747
+ if self.p[alpha] == alpha:
748
+ if table[alpha][A_dict[x]] == beta:
749
+ table[alpha][A_dict[x]] = gamma
750
+ elif table[alpha][A_dict[x]] == gamma:
751
+ table[alpha][A_dict[x]] = beta
752
+
753
+ def standardize(self):
754
+ r"""
755
+ A coset table is standardized if when running through the cosets and
756
+ within each coset through the generator images (ignoring generator
757
+ inverses), the cosets appear in order of the integers
758
+ `0, 1, \dots, n`. "Standardize" reorders the elements of `\Omega`
759
+ such that, if we scan the coset table first by elements of `\Omega`
760
+ and then by elements of A, then the cosets occur in ascending order.
761
+ ``standardize()`` is used at the end of an enumeration to permute the
762
+ cosets so that they occur in some sort of standard order.
763
+
764
+ Notes
765
+ =====
766
+
767
+ procedure is described on pg. 167-168 [1], it also makes use of the
768
+ ``switch`` routine to replace by smaller integer value.
769
+
770
+ Examples
771
+ ========
772
+
773
+ >>> from sympy.combinatorics import free_group
774
+ >>> from sympy.combinatorics.fp_groups import FpGroup, coset_enumeration_r
775
+ >>> F, x, y = free_group("x, y")
776
+
777
+ # Example 5.3 from [1]
778
+ >>> f = FpGroup(F, [x**2*y**2, x**3*y**5])
779
+ >>> C = coset_enumeration_r(f, [])
780
+ >>> C.compress()
781
+ >>> C.table
782
+ [[1, 3, 1, 3], [2, 0, 2, 0], [3, 1, 3, 1], [0, 2, 0, 2]]
783
+ >>> C.standardize()
784
+ >>> C.table
785
+ [[1, 2, 1, 2], [3, 0, 3, 0], [0, 3, 0, 3], [2, 1, 2, 1]]
786
+
787
+ """
788
+ A = self.A
789
+ A_dict = self.A_dict
790
+ gamma = 1
791
+ for alpha, x in product(range(self.n), A):
792
+ beta = self.table[alpha][A_dict[x]]
793
+ if beta >= gamma:
794
+ if beta > gamma:
795
+ self.switch(gamma, beta)
796
+ gamma += 1
797
+ if gamma == self.n:
798
+ return
799
+
800
+ # Compression of a Coset Table
801
+ def compress(self):
802
+ """Removes the non-live cosets from the coset table, described on
803
+ pg. 167 [1].
804
+
805
+ """
806
+ gamma = -1
807
+ A = self.A
808
+ A_dict = self.A_dict
809
+ A_dict_inv = self.A_dict_inv
810
+ table = self.table
811
+ chi = tuple([i for i in range(len(self.p)) if self.p[i] != i])
812
+ for alpha in self.omega:
813
+ gamma += 1
814
+ if gamma != alpha:
815
+ # replace alpha by gamma in coset table
816
+ for x in A:
817
+ beta = table[alpha][A_dict[x]]
818
+ table[gamma][A_dict[x]] = beta
819
+ table[beta][A_dict_inv[x]] == gamma
820
+ # all the cosets in the table are live cosets
821
+ self.p = list(range(gamma + 1))
822
+ # delete the useless columns
823
+ del table[len(self.p):]
824
+ # re-define values
825
+ for row in table:
826
+ for j in range(len(self.A)):
827
+ row[j] -= bisect_left(chi, row[j])
828
+
829
+ def conjugates(self, R):
830
+ R_c = list(chain.from_iterable((rel.cyclic_conjugates(), \
831
+ (rel**-1).cyclic_conjugates()) for rel in R))
832
+ R_set = set()
833
+ for conjugate in R_c:
834
+ R_set = R_set.union(conjugate)
835
+ R_c_list = []
836
+ for x in self.A:
837
+ r = {word for word in R_set if word[0] == x}
838
+ R_c_list.append(r)
839
+ R_set.difference_update(r)
840
+ return R_c_list
841
+
842
+ def coset_representative(self, coset):
843
+ '''
844
+ Compute the coset representative of a given coset.
845
+
846
+ Examples
847
+ ========
848
+
849
+ >>> from sympy.combinatorics import free_group
850
+ >>> from sympy.combinatorics.fp_groups import FpGroup, coset_enumeration_r
851
+ >>> F, x, y = free_group("x, y")
852
+ >>> f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
853
+ >>> C = coset_enumeration_r(f, [x])
854
+ >>> C.compress()
855
+ >>> C.table
856
+ [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1]]
857
+ >>> C.coset_representative(0)
858
+ <identity>
859
+ >>> C.coset_representative(1)
860
+ y
861
+ >>> C.coset_representative(2)
862
+ y**-1
863
+
864
+ '''
865
+ for x in self.A:
866
+ gamma = self.table[coset][self.A_dict[x]]
867
+ if coset == 0:
868
+ return self.fp_group.identity
869
+ if gamma < coset:
870
+ return self.coset_representative(gamma)*x**-1
871
+
872
+ ##############################
873
+ # Modified Methods #
874
+ ##############################
875
+
876
+ def modified_define(self, alpha, x):
877
+ r"""
878
+ Define a function p_p from from [1..n] to A* as
879
+ an additional component of the modified coset table.
880
+
881
+ Parameters
882
+ ==========
883
+
884
+ \alpha \in \Omega
885
+ x \in A*
886
+
887
+ See Also
888
+ ========
889
+
890
+ define
891
+
892
+ """
893
+ self.define(alpha, x, modified=True)
894
+
895
+ def modified_scan(self, alpha, w, y, fill=False):
896
+ r"""
897
+ Parameters
898
+ ==========
899
+ \alpha \in \Omega
900
+ w \in A*
901
+ y \in (YUY^-1)
902
+ fill -- `modified_scan_and_fill` when set to True.
903
+
904
+ See Also
905
+ ========
906
+
907
+ scan
908
+ """
909
+ self.scan(alpha, w, y=y, fill=fill, modified=True)
910
+
911
+ def modified_scan_and_fill(self, alpha, w, y):
912
+ self.modified_scan(alpha, w, y, fill=True)
913
+
914
+ def modified_merge(self, k, lamda, w, q):
915
+ r"""
916
+ Parameters
917
+ ==========
918
+
919
+ 'k', 'lamda' -- the two class representatives to be merged.
920
+ q -- queue of length l of elements to be deleted from `\Omega` *.
921
+ w -- Word in (YUY^-1)
922
+
923
+ See Also
924
+ ========
925
+
926
+ merge
927
+ """
928
+ self.merge(k, lamda, q, w=w, modified=True)
929
+
930
+ def modified_rep(self, k):
931
+ r"""
932
+ Parameters
933
+ ==========
934
+
935
+ `k \in [0 \ldots n-1]`
936
+
937
+ See Also
938
+ ========
939
+
940
+ rep
941
+ """
942
+ self.rep(k, modified=True)
943
+
944
+ def modified_coincidence(self, alpha, beta, w):
945
+ r"""
946
+ Parameters
947
+ ==========
948
+
949
+ A coincident pair `\alpha, \beta \in \Omega, w \in Y \cup Y^{-1}`
950
+
951
+ See Also
952
+ ========
953
+
954
+ coincidence
955
+
956
+ """
957
+ self.coincidence(alpha, beta, w=w, modified=True)
958
+
959
+ ###############################################################################
960
+ # COSET ENUMERATION #
961
+ ###############################################################################
962
+
963
+ # relator-based method
964
+ def coset_enumeration_r(fp_grp, Y, max_cosets=None, draft=None,
965
+ incomplete=False, modified=False):
966
+ """
967
+ This is easier of the two implemented methods of coset enumeration.
968
+ and is often called the HLT method, after Hazelgrove, Leech, Trotter
969
+ The idea is that we make use of ``scan_and_fill`` makes new definitions
970
+ whenever the scan is incomplete to enable the scan to complete; this way
971
+ we fill in the gaps in the scan of the relator or subgroup generator,
972
+ that's why the name relator-based method.
973
+
974
+ An instance of `CosetTable` for `fp_grp` can be passed as the keyword
975
+ argument `draft` in which case the coset enumeration will start with
976
+ that instance and attempt to complete it.
977
+
978
+ When `incomplete` is `True` and the function is unable to complete for
979
+ some reason, the partially complete table will be returned.
980
+
981
+ # TODO: complete the docstring
982
+
983
+ See Also
984
+ ========
985
+
986
+ scan_and_fill,
987
+
988
+ Examples
989
+ ========
990
+
991
+ >>> from sympy.combinatorics.free_groups import free_group
992
+ >>> from sympy.combinatorics.fp_groups import FpGroup, coset_enumeration_r
993
+ >>> F, x, y = free_group("x, y")
994
+
995
+ # Example 5.1 from [1]
996
+ >>> f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
997
+ >>> C = coset_enumeration_r(f, [x])
998
+ >>> for i in range(len(C.p)):
999
+ ... if C.p[i] == i:
1000
+ ... print(C.table[i])
1001
+ [0, 0, 1, 2]
1002
+ [1, 1, 2, 0]
1003
+ [2, 2, 0, 1]
1004
+ >>> C.p
1005
+ [0, 1, 2, 1, 1]
1006
+
1007
+ # Example from exercises Q2 [1]
1008
+ >>> f = FpGroup(F, [x**2*y**2, y**-1*x*y*x**-3])
1009
+ >>> C = coset_enumeration_r(f, [])
1010
+ >>> C.compress(); C.standardize()
1011
+ >>> C.table
1012
+ [[1, 2, 3, 4],
1013
+ [5, 0, 6, 7],
1014
+ [0, 5, 7, 6],
1015
+ [7, 6, 5, 0],
1016
+ [6, 7, 0, 5],
1017
+ [2, 1, 4, 3],
1018
+ [3, 4, 2, 1],
1019
+ [4, 3, 1, 2]]
1020
+
1021
+ # Example 5.2
1022
+ >>> f = FpGroup(F, [x**2, y**3, (x*y)**3])
1023
+ >>> Y = [x*y]
1024
+ >>> C = coset_enumeration_r(f, Y)
1025
+ >>> for i in range(len(C.p)):
1026
+ ... if C.p[i] == i:
1027
+ ... print(C.table[i])
1028
+ [1, 1, 2, 1]
1029
+ [0, 0, 0, 2]
1030
+ [3, 3, 1, 0]
1031
+ [2, 2, 3, 3]
1032
+
1033
+ # Example 5.3
1034
+ >>> f = FpGroup(F, [x**2*y**2, x**3*y**5])
1035
+ >>> Y = []
1036
+ >>> C = coset_enumeration_r(f, Y)
1037
+ >>> for i in range(len(C.p)):
1038
+ ... if C.p[i] == i:
1039
+ ... print(C.table[i])
1040
+ [1, 3, 1, 3]
1041
+ [2, 0, 2, 0]
1042
+ [3, 1, 3, 1]
1043
+ [0, 2, 0, 2]
1044
+
1045
+ # Example 5.4
1046
+ >>> F, a, b, c, d, e = free_group("a, b, c, d, e")
1047
+ >>> f = FpGroup(F, [a*b*c**-1, b*c*d**-1, c*d*e**-1, d*e*a**-1, e*a*b**-1])
1048
+ >>> Y = [a]
1049
+ >>> C = coset_enumeration_r(f, Y)
1050
+ >>> for i in range(len(C.p)):
1051
+ ... if C.p[i] == i:
1052
+ ... print(C.table[i])
1053
+ [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
1054
+
1055
+ # example of "compress" method
1056
+ >>> C.compress()
1057
+ >>> C.table
1058
+ [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
1059
+
1060
+ # Exercises Pg. 161, Q2.
1061
+ >>> F, x, y = free_group("x, y")
1062
+ >>> f = FpGroup(F, [x**2*y**2, y**-1*x*y*x**-3])
1063
+ >>> Y = []
1064
+ >>> C = coset_enumeration_r(f, Y)
1065
+ >>> C.compress()
1066
+ >>> C.standardize()
1067
+ >>> C.table
1068
+ [[1, 2, 3, 4],
1069
+ [5, 0, 6, 7],
1070
+ [0, 5, 7, 6],
1071
+ [7, 6, 5, 0],
1072
+ [6, 7, 0, 5],
1073
+ [2, 1, 4, 3],
1074
+ [3, 4, 2, 1],
1075
+ [4, 3, 1, 2]]
1076
+
1077
+ # John J. Cannon; Lucien A. Dimino; George Havas; Jane M. Watson
1078
+ # Mathematics of Computation, Vol. 27, No. 123. (Jul., 1973), pp. 463-490
1079
+ # from 1973chwd.pdf
1080
+ # Table 1. Ex. 1
1081
+ >>> F, r, s, t = free_group("r, s, t")
1082
+ >>> E1 = FpGroup(F, [t**-1*r*t*r**-2, r**-1*s*r*s**-2, s**-1*t*s*t**-2])
1083
+ >>> C = coset_enumeration_r(E1, [r])
1084
+ >>> for i in range(len(C.p)):
1085
+ ... if C.p[i] == i:
1086
+ ... print(C.table[i])
1087
+ [0, 0, 0, 0, 0, 0]
1088
+
1089
+ Ex. 2
1090
+ >>> F, a, b = free_group("a, b")
1091
+ >>> Cox = FpGroup(F, [a**6, b**6, (a*b)**2, (a**2*b**2)**2, (a**3*b**3)**5])
1092
+ >>> C = coset_enumeration_r(Cox, [a])
1093
+ >>> index = 0
1094
+ >>> for i in range(len(C.p)):
1095
+ ... if C.p[i] == i:
1096
+ ... index += 1
1097
+ >>> index
1098
+ 500
1099
+
1100
+ # Ex. 3
1101
+ >>> F, a, b = free_group("a, b")
1102
+ >>> B_2_4 = FpGroup(F, [a**4, b**4, (a*b)**4, (a**-1*b)**4, (a**2*b)**4, \
1103
+ (a*b**2)**4, (a**2*b**2)**4, (a**-1*b*a*b)**4, (a*b**-1*a*b)**4])
1104
+ >>> C = coset_enumeration_r(B_2_4, [a])
1105
+ >>> index = 0
1106
+ >>> for i in range(len(C.p)):
1107
+ ... if C.p[i] == i:
1108
+ ... index += 1
1109
+ >>> index
1110
+ 1024
1111
+
1112
+ References
1113
+ ==========
1114
+
1115
+ .. [1] Holt, D., Eick, B., O'Brien, E.
1116
+ "Handbook of computational group theory"
1117
+
1118
+ """
1119
+ # 1. Initialize a coset table C for < X|R >
1120
+ C = CosetTable(fp_grp, Y, max_cosets=max_cosets)
1121
+ # Define coset table methods.
1122
+ if modified:
1123
+ _scan_and_fill = C.modified_scan_and_fill
1124
+ _define = C.modified_define
1125
+ else:
1126
+ _scan_and_fill = C.scan_and_fill
1127
+ _define = C.define
1128
+ if draft:
1129
+ C.table = draft.table[:]
1130
+ C.p = draft.p[:]
1131
+ R = fp_grp.relators
1132
+ A_dict = C.A_dict
1133
+ p = C.p
1134
+ for i in range(len(Y)):
1135
+ if modified:
1136
+ _scan_and_fill(0, Y[i], C._grp.generators[i])
1137
+ else:
1138
+ _scan_and_fill(0, Y[i])
1139
+ alpha = 0
1140
+ while alpha < C.n:
1141
+ if p[alpha] == alpha:
1142
+ try:
1143
+ for w in R:
1144
+ if modified:
1145
+ _scan_and_fill(alpha, w, C._grp.identity)
1146
+ else:
1147
+ _scan_and_fill(alpha, w)
1148
+ # if alpha was eliminated during the scan then break
1149
+ if p[alpha] < alpha:
1150
+ break
1151
+ if p[alpha] == alpha:
1152
+ for x in A_dict:
1153
+ if C.table[alpha][A_dict[x]] is None:
1154
+ _define(alpha, x)
1155
+ except ValueError as e:
1156
+ if incomplete:
1157
+ return C
1158
+ raise e
1159
+ alpha += 1
1160
+ return C
1161
+
1162
+ def modified_coset_enumeration_r(fp_grp, Y, max_cosets=None, draft=None,
1163
+ incomplete=False):
1164
+ r"""
1165
+ Introduce a new set of symbols y \in Y that correspond to the
1166
+ generators of the subgroup. Store the elements of Y as a
1167
+ word P[\alpha, x] and compute the coset table similar to that of
1168
+ the regular coset enumeration methods.
1169
+
1170
+ Examples
1171
+ ========
1172
+
1173
+ >>> from sympy.combinatorics.free_groups import free_group
1174
+ >>> from sympy.combinatorics.fp_groups import FpGroup
1175
+ >>> from sympy.combinatorics.coset_table import modified_coset_enumeration_r
1176
+ >>> F, x, y = free_group("x, y")
1177
+ >>> f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
1178
+ >>> C = modified_coset_enumeration_r(f, [x])
1179
+ >>> C.table
1180
+ [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1], [None, 1, None, None], [1, 3, None, None]]
1181
+
1182
+ See Also
1183
+ ========
1184
+
1185
+ coset_enumertation_r
1186
+
1187
+ References
1188
+ ==========
1189
+
1190
+ .. [1] Holt, D., Eick, B., O'Brien, E.,
1191
+ "Handbook of Computational Group Theory",
1192
+ Section 5.3.2
1193
+ """
1194
+ return coset_enumeration_r(fp_grp, Y, max_cosets=max_cosets, draft=draft,
1195
+ incomplete=incomplete, modified=True)
1196
+
1197
+ # Pg. 166
1198
+ # coset-table based method
1199
+ def coset_enumeration_c(fp_grp, Y, max_cosets=None, draft=None,
1200
+ incomplete=False):
1201
+ """
1202
+ >>> from sympy.combinatorics.free_groups import free_group
1203
+ >>> from sympy.combinatorics.fp_groups import FpGroup, coset_enumeration_c
1204
+ >>> F, x, y = free_group("x, y")
1205
+ >>> f = FpGroup(F, [x**3, y**3, x**-1*y**-1*x*y])
1206
+ >>> C = coset_enumeration_c(f, [x])
1207
+ >>> C.table
1208
+ [[0, 0, 1, 2], [1, 1, 2, 0], [2, 2, 0, 1]]
1209
+
1210
+ """
1211
+ # Initialize a coset table C for < X|R >
1212
+ X = fp_grp.generators
1213
+ R = fp_grp.relators
1214
+ C = CosetTable(fp_grp, Y, max_cosets=max_cosets)
1215
+ if draft:
1216
+ C.table = draft.table[:]
1217
+ C.p = draft.p[:]
1218
+ C.deduction_stack = draft.deduction_stack
1219
+ for alpha, x in product(range(len(C.table)), X):
1220
+ if C.table[alpha][C.A_dict[x]] is not None:
1221
+ C.deduction_stack.append((alpha, x))
1222
+ A = C.A
1223
+ # replace all the elements by cyclic reductions
1224
+ R_cyc_red = [rel.identity_cyclic_reduction() for rel in R]
1225
+ R_c = list(chain.from_iterable((rel.cyclic_conjugates(), (rel**-1).cyclic_conjugates()) \
1226
+ for rel in R_cyc_red))
1227
+ R_set = set()
1228
+ for conjugate in R_c:
1229
+ R_set = R_set.union(conjugate)
1230
+ # a list of subsets of R_c whose words start with "x".
1231
+ R_c_list = []
1232
+ for x in C.A:
1233
+ r = {word for word in R_set if word[0] == x}
1234
+ R_c_list.append(r)
1235
+ R_set.difference_update(r)
1236
+ for w in Y:
1237
+ C.scan_and_fill_c(0, w)
1238
+ for x in A:
1239
+ C.process_deductions(R_c_list[C.A_dict[x]], R_c_list[C.A_dict_inv[x]])
1240
+ alpha = 0
1241
+ while alpha < len(C.table):
1242
+ if C.p[alpha] == alpha:
1243
+ try:
1244
+ for x in C.A:
1245
+ if C.p[alpha] != alpha:
1246
+ break
1247
+ if C.table[alpha][C.A_dict[x]] is None:
1248
+ C.define_c(alpha, x)
1249
+ C.process_deductions(R_c_list[C.A_dict[x]], R_c_list[C.A_dict_inv[x]])
1250
+ except ValueError as e:
1251
+ if incomplete:
1252
+ return C
1253
+ raise e
1254
+ alpha += 1
1255
+ return C
pllava/lib/python3.10/site-packages/sympy/combinatorics/generators.py ADDED
@@ -0,0 +1,302 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics.permutations import Permutation
2
+ from sympy.core.symbol import symbols
3
+ from sympy.matrices import Matrix
4
+ from sympy.utilities.iterables import variations, rotate_left
5
+
6
+
7
+ def symmetric(n):
8
+ """
9
+ Generates the symmetric group of order n, Sn.
10
+
11
+ Examples
12
+ ========
13
+
14
+ >>> from sympy.combinatorics.generators import symmetric
15
+ >>> list(symmetric(3))
16
+ [(2), (1 2), (2)(0 1), (0 1 2), (0 2 1), (0 2)]
17
+ """
18
+ for perm in variations(range(n), n):
19
+ yield Permutation(perm)
20
+
21
+
22
+ def cyclic(n):
23
+ """
24
+ Generates the cyclic group of order n, Cn.
25
+
26
+ Examples
27
+ ========
28
+
29
+ >>> from sympy.combinatorics.generators import cyclic
30
+ >>> list(cyclic(5))
31
+ [(4), (0 1 2 3 4), (0 2 4 1 3),
32
+ (0 3 1 4 2), (0 4 3 2 1)]
33
+
34
+ See Also
35
+ ========
36
+
37
+ dihedral
38
+ """
39
+ gen = list(range(n))
40
+ for i in range(n):
41
+ yield Permutation(gen)
42
+ gen = rotate_left(gen, 1)
43
+
44
+
45
+ def alternating(n):
46
+ """
47
+ Generates the alternating group of order n, An.
48
+
49
+ Examples
50
+ ========
51
+
52
+ >>> from sympy.combinatorics.generators import alternating
53
+ >>> list(alternating(3))
54
+ [(2), (0 1 2), (0 2 1)]
55
+ """
56
+ for perm in variations(range(n), n):
57
+ p = Permutation(perm)
58
+ if p.is_even:
59
+ yield p
60
+
61
+
62
+ def dihedral(n):
63
+ """
64
+ Generates the dihedral group of order 2n, Dn.
65
+
66
+ The result is given as a subgroup of Sn, except for the special cases n=1
67
+ (the group S2) and n=2 (the Klein 4-group) where that's not possible
68
+ and embeddings in S2 and S4 respectively are given.
69
+
70
+ Examples
71
+ ========
72
+
73
+ >>> from sympy.combinatorics.generators import dihedral
74
+ >>> list(dihedral(3))
75
+ [(2), (0 2), (0 1 2), (1 2), (0 2 1), (2)(0 1)]
76
+
77
+ See Also
78
+ ========
79
+
80
+ cyclic
81
+ """
82
+ if n == 1:
83
+ yield Permutation([0, 1])
84
+ yield Permutation([1, 0])
85
+ elif n == 2:
86
+ yield Permutation([0, 1, 2, 3])
87
+ yield Permutation([1, 0, 3, 2])
88
+ yield Permutation([2, 3, 0, 1])
89
+ yield Permutation([3, 2, 1, 0])
90
+ else:
91
+ gen = list(range(n))
92
+ for i in range(n):
93
+ yield Permutation(gen)
94
+ yield Permutation(gen[::-1])
95
+ gen = rotate_left(gen, 1)
96
+
97
+
98
+ def rubik_cube_generators():
99
+ """Return the permutations of the 3x3 Rubik's cube, see
100
+ https://www.gap-system.org/Doc/Examples/rubik.html
101
+ """
102
+ a = [
103
+ [(1, 3, 8, 6), (2, 5, 7, 4), (9, 33, 25, 17), (10, 34, 26, 18),
104
+ (11, 35, 27, 19)],
105
+ [(9, 11, 16, 14), (10, 13, 15, 12), (1, 17, 41, 40), (4, 20, 44, 37),
106
+ (6, 22, 46, 35)],
107
+ [(17, 19, 24, 22), (18, 21, 23, 20), (6, 25, 43, 16), (7, 28, 42, 13),
108
+ (8, 30, 41, 11)],
109
+ [(25, 27, 32, 30), (26, 29, 31, 28), (3, 38, 43, 19), (5, 36, 45, 21),
110
+ (8, 33, 48, 24)],
111
+ [(33, 35, 40, 38), (34, 37, 39, 36), (3, 9, 46, 32), (2, 12, 47, 29),
112
+ (1, 14, 48, 27)],
113
+ [(41, 43, 48, 46), (42, 45, 47, 44), (14, 22, 30, 38),
114
+ (15, 23, 31, 39), (16, 24, 32, 40)]
115
+ ]
116
+ return [Permutation([[i - 1 for i in xi] for xi in x], size=48) for x in a]
117
+
118
+
119
+ def rubik(n):
120
+ """Return permutations for an nxn Rubik's cube.
121
+
122
+ Permutations returned are for rotation of each of the slice
123
+ from the face up to the last face for each of the 3 sides (in this order):
124
+ front, right and bottom. Hence, the first n - 1 permutations are for the
125
+ slices from the front.
126
+ """
127
+
128
+ if n < 2:
129
+ raise ValueError('dimension of cube must be > 1')
130
+
131
+ # 1-based reference to rows and columns in Matrix
132
+ def getr(f, i):
133
+ return faces[f].col(n - i)
134
+
135
+ def getl(f, i):
136
+ return faces[f].col(i - 1)
137
+
138
+ def getu(f, i):
139
+ return faces[f].row(i - 1)
140
+
141
+ def getd(f, i):
142
+ return faces[f].row(n - i)
143
+
144
+ def setr(f, i, s):
145
+ faces[f][:, n - i] = Matrix(n, 1, s)
146
+
147
+ def setl(f, i, s):
148
+ faces[f][:, i - 1] = Matrix(n, 1, s)
149
+
150
+ def setu(f, i, s):
151
+ faces[f][i - 1, :] = Matrix(1, n, s)
152
+
153
+ def setd(f, i, s):
154
+ faces[f][n - i, :] = Matrix(1, n, s)
155
+
156
+ # motion of a single face
157
+ def cw(F, r=1):
158
+ for _ in range(r):
159
+ face = faces[F]
160
+ rv = []
161
+ for c in range(n):
162
+ for r in range(n - 1, -1, -1):
163
+ rv.append(face[r, c])
164
+ faces[F] = Matrix(n, n, rv)
165
+
166
+ def ccw(F):
167
+ cw(F, 3)
168
+
169
+ # motion of plane i from the F side;
170
+ # fcw(0) moves the F face, fcw(1) moves the plane
171
+ # just behind the front face, etc...
172
+ def fcw(i, r=1):
173
+ for _ in range(r):
174
+ if i == 0:
175
+ cw(F)
176
+ i += 1
177
+ temp = getr(L, i)
178
+ setr(L, i, list(getu(D, i)))
179
+ setu(D, i, list(reversed(getl(R, i))))
180
+ setl(R, i, list(getd(U, i)))
181
+ setd(U, i, list(reversed(temp)))
182
+ i -= 1
183
+
184
+ def fccw(i):
185
+ fcw(i, 3)
186
+
187
+ # motion of the entire cube from the F side
188
+ def FCW(r=1):
189
+ for _ in range(r):
190
+ cw(F)
191
+ ccw(B)
192
+ cw(U)
193
+ t = faces[U]
194
+ cw(L)
195
+ faces[U] = faces[L]
196
+ cw(D)
197
+ faces[L] = faces[D]
198
+ cw(R)
199
+ faces[D] = faces[R]
200
+ faces[R] = t
201
+
202
+ def FCCW():
203
+ FCW(3)
204
+
205
+ # motion of the entire cube from the U side
206
+ def UCW(r=1):
207
+ for _ in range(r):
208
+ cw(U)
209
+ ccw(D)
210
+ t = faces[F]
211
+ faces[F] = faces[R]
212
+ faces[R] = faces[B]
213
+ faces[B] = faces[L]
214
+ faces[L] = t
215
+
216
+ def UCCW():
217
+ UCW(3)
218
+
219
+ # defining the permutations for the cube
220
+
221
+ U, F, R, B, L, D = names = symbols('U, F, R, B, L, D')
222
+
223
+ # the faces are represented by nxn matrices
224
+ faces = {}
225
+ count = 0
226
+ for fi in range(6):
227
+ f = []
228
+ for a in range(n**2):
229
+ f.append(count)
230
+ count += 1
231
+ faces[names[fi]] = Matrix(n, n, f)
232
+
233
+ # this will either return the value of the current permutation
234
+ # (show != 1) or else append the permutation to the group, g
235
+ def perm(show=0):
236
+ # add perm to the list of perms
237
+ p = []
238
+ for f in names:
239
+ p.extend(faces[f])
240
+ if show:
241
+ return p
242
+ g.append(Permutation(p))
243
+
244
+ g = [] # container for the group's permutations
245
+ I = list(range(6*n**2)) # the identity permutation used for checking
246
+
247
+ # define permutations corresponding to cw rotations of the planes
248
+ # up TO the last plane from that direction; by not including the
249
+ # last plane, the orientation of the cube is maintained.
250
+
251
+ # F slices
252
+ for i in range(n - 1):
253
+ fcw(i)
254
+ perm()
255
+ fccw(i) # restore
256
+ assert perm(1) == I
257
+
258
+ # R slices
259
+ # bring R to front
260
+ UCW()
261
+ for i in range(n - 1):
262
+ fcw(i)
263
+ # put it back in place
264
+ UCCW()
265
+ # record
266
+ perm()
267
+ # restore
268
+ # bring face to front
269
+ UCW()
270
+ fccw(i)
271
+ # restore
272
+ UCCW()
273
+ assert perm(1) == I
274
+
275
+ # D slices
276
+ # bring up bottom
277
+ FCW()
278
+ UCCW()
279
+ FCCW()
280
+ for i in range(n - 1):
281
+ # turn strip
282
+ fcw(i)
283
+ # put bottom back on the bottom
284
+ FCW()
285
+ UCW()
286
+ FCCW()
287
+ # record
288
+ perm()
289
+ # restore
290
+ # bring up bottom
291
+ FCW()
292
+ UCCW()
293
+ FCCW()
294
+ # turn strip
295
+ fccw(i)
296
+ # put bottom back on the bottom
297
+ FCW()
298
+ UCW()
299
+ FCCW()
300
+ assert perm(1) == I
301
+
302
+ return g
pllava/lib/python3.10/site-packages/sympy/combinatorics/group_constructs.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics.perm_groups import PermutationGroup
2
+ from sympy.combinatorics.permutations import Permutation
3
+ from sympy.utilities.iterables import uniq
4
+
5
+ _af_new = Permutation._af_new
6
+
7
+
8
+ def DirectProduct(*groups):
9
+ """
10
+ Returns the direct product of several groups as a permutation group.
11
+
12
+ Explanation
13
+ ===========
14
+
15
+ This is implemented much like the __mul__ procedure for taking the direct
16
+ product of two permutation groups, but the idea of shifting the
17
+ generators is realized in the case of an arbitrary number of groups.
18
+ A call to DirectProduct(G1, G2, ..., Gn) is generally expected to be faster
19
+ than a call to G1*G2*...*Gn (and thus the need for this algorithm).
20
+
21
+ Examples
22
+ ========
23
+
24
+ >>> from sympy.combinatorics.group_constructs import DirectProduct
25
+ >>> from sympy.combinatorics.named_groups import CyclicGroup
26
+ >>> C = CyclicGroup(4)
27
+ >>> G = DirectProduct(C, C, C)
28
+ >>> G.order()
29
+ 64
30
+
31
+ See Also
32
+ ========
33
+
34
+ sympy.combinatorics.perm_groups.PermutationGroup.__mul__
35
+
36
+ """
37
+ degrees = []
38
+ gens_count = []
39
+ total_degree = 0
40
+ total_gens = 0
41
+ for group in groups:
42
+ current_deg = group.degree
43
+ current_num_gens = len(group.generators)
44
+ degrees.append(current_deg)
45
+ total_degree += current_deg
46
+ gens_count.append(current_num_gens)
47
+ total_gens += current_num_gens
48
+ array_gens = []
49
+ for i in range(total_gens):
50
+ array_gens.append(list(range(total_degree)))
51
+ current_gen = 0
52
+ current_deg = 0
53
+ for i in range(len(gens_count)):
54
+ for j in range(current_gen, current_gen + gens_count[i]):
55
+ gen = ((groups[i].generators)[j - current_gen]).array_form
56
+ array_gens[j][current_deg:current_deg + degrees[i]] = \
57
+ [x + current_deg for x in gen]
58
+ current_gen += gens_count[i]
59
+ current_deg += degrees[i]
60
+ perm_gens = list(uniq([_af_new(list(a)) for a in array_gens]))
61
+ return PermutationGroup(perm_gens, dups=False)
pllava/lib/python3.10/site-packages/sympy/combinatorics/named_groups.py ADDED
@@ -0,0 +1,332 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics.group_constructs import DirectProduct
2
+ from sympy.combinatorics.perm_groups import PermutationGroup
3
+ from sympy.combinatorics.permutations import Permutation
4
+
5
+ _af_new = Permutation._af_new
6
+
7
+
8
+ def AbelianGroup(*cyclic_orders):
9
+ """
10
+ Returns the direct product of cyclic groups with the given orders.
11
+
12
+ Explanation
13
+ ===========
14
+
15
+ According to the structure theorem for finite abelian groups ([1]),
16
+ every finite abelian group can be written as the direct product of
17
+ finitely many cyclic groups.
18
+
19
+ Examples
20
+ ========
21
+
22
+ >>> from sympy.combinatorics.named_groups import AbelianGroup
23
+ >>> AbelianGroup(3, 4)
24
+ PermutationGroup([
25
+ (6)(0 1 2),
26
+ (3 4 5 6)])
27
+ >>> _.is_group
28
+ True
29
+
30
+ See Also
31
+ ========
32
+
33
+ DirectProduct
34
+
35
+ References
36
+ ==========
37
+
38
+ .. [1] https://groupprops.subwiki.org/wiki/Structure_theorem_for_finitely_generated_abelian_groups
39
+
40
+ """
41
+ groups = []
42
+ degree = 0
43
+ order = 1
44
+ for size in cyclic_orders:
45
+ degree += size
46
+ order *= size
47
+ groups.append(CyclicGroup(size))
48
+ G = DirectProduct(*groups)
49
+ G._is_abelian = True
50
+ G._degree = degree
51
+ G._order = order
52
+
53
+ return G
54
+
55
+
56
+ def AlternatingGroup(n):
57
+ """
58
+ Generates the alternating group on ``n`` elements as a permutation group.
59
+
60
+ Explanation
61
+ ===========
62
+
63
+ For ``n > 2``, the generators taken are ``(0 1 2), (0 1 2 ... n-1)`` for
64
+ ``n`` odd
65
+ and ``(0 1 2), (1 2 ... n-1)`` for ``n`` even (See [1], p.31, ex.6.9.).
66
+ After the group is generated, some of its basic properties are set.
67
+ The cases ``n = 1, 2`` are handled separately.
68
+
69
+ Examples
70
+ ========
71
+
72
+ >>> from sympy.combinatorics.named_groups import AlternatingGroup
73
+ >>> G = AlternatingGroup(4)
74
+ >>> G.is_group
75
+ True
76
+ >>> a = list(G.generate_dimino())
77
+ >>> len(a)
78
+ 12
79
+ >>> all(perm.is_even for perm in a)
80
+ True
81
+
82
+ See Also
83
+ ========
84
+
85
+ SymmetricGroup, CyclicGroup, DihedralGroup
86
+
87
+ References
88
+ ==========
89
+
90
+ .. [1] Armstrong, M. "Groups and Symmetry"
91
+
92
+ """
93
+ # small cases are special
94
+ if n in (1, 2):
95
+ return PermutationGroup([Permutation([0])])
96
+
97
+ a = list(range(n))
98
+ a[0], a[1], a[2] = a[1], a[2], a[0]
99
+ gen1 = a
100
+ if n % 2:
101
+ a = list(range(1, n))
102
+ a.append(0)
103
+ gen2 = a
104
+ else:
105
+ a = list(range(2, n))
106
+ a.append(1)
107
+ a.insert(0, 0)
108
+ gen2 = a
109
+ gens = [gen1, gen2]
110
+ if gen1 == gen2:
111
+ gens = gens[:1]
112
+ G = PermutationGroup([_af_new(a) for a in gens], dups=False)
113
+
114
+ set_alternating_group_properties(G, n, n)
115
+ G._is_alt = True
116
+ return G
117
+
118
+
119
+ def set_alternating_group_properties(G, n, degree):
120
+ """Set known properties of an alternating group. """
121
+ if n < 4:
122
+ G._is_abelian = True
123
+ G._is_nilpotent = True
124
+ else:
125
+ G._is_abelian = False
126
+ G._is_nilpotent = False
127
+ if n < 5:
128
+ G._is_solvable = True
129
+ else:
130
+ G._is_solvable = False
131
+ G._degree = degree
132
+ G._is_transitive = True
133
+ G._is_dihedral = False
134
+
135
+
136
+ def CyclicGroup(n):
137
+ """
138
+ Generates the cyclic group of order ``n`` as a permutation group.
139
+
140
+ Explanation
141
+ ===========
142
+
143
+ The generator taken is the ``n``-cycle ``(0 1 2 ... n-1)``
144
+ (in cycle notation). After the group is generated, some of its basic
145
+ properties are set.
146
+
147
+ Examples
148
+ ========
149
+
150
+ >>> from sympy.combinatorics.named_groups import CyclicGroup
151
+ >>> G = CyclicGroup(6)
152
+ >>> G.is_group
153
+ True
154
+ >>> G.order()
155
+ 6
156
+ >>> list(G.generate_schreier_sims(af=True))
157
+ [[0, 1, 2, 3, 4, 5], [1, 2, 3, 4, 5, 0], [2, 3, 4, 5, 0, 1],
158
+ [3, 4, 5, 0, 1, 2], [4, 5, 0, 1, 2, 3], [5, 0, 1, 2, 3, 4]]
159
+
160
+ See Also
161
+ ========
162
+
163
+ SymmetricGroup, DihedralGroup, AlternatingGroup
164
+
165
+ """
166
+ a = list(range(1, n))
167
+ a.append(0)
168
+ gen = _af_new(a)
169
+ G = PermutationGroup([gen])
170
+
171
+ G._is_abelian = True
172
+ G._is_nilpotent = True
173
+ G._is_solvable = True
174
+ G._degree = n
175
+ G._is_transitive = True
176
+ G._order = n
177
+ G._is_dihedral = (n == 2)
178
+ return G
179
+
180
+
181
+ def DihedralGroup(n):
182
+ r"""
183
+ Generates the dihedral group `D_n` as a permutation group.
184
+
185
+ Explanation
186
+ ===========
187
+
188
+ The dihedral group `D_n` is the group of symmetries of the regular
189
+ ``n``-gon. The generators taken are the ``n``-cycle ``a = (0 1 2 ... n-1)``
190
+ (a rotation of the ``n``-gon) and ``b = (0 n-1)(1 n-2)...``
191
+ (a reflection of the ``n``-gon) in cycle rotation. It is easy to see that
192
+ these satisfy ``a**n = b**2 = 1`` and ``bab = ~a`` so they indeed generate
193
+ `D_n` (See [1]). After the group is generated, some of its basic properties
194
+ are set.
195
+
196
+ Examples
197
+ ========
198
+
199
+ >>> from sympy.combinatorics.named_groups import DihedralGroup
200
+ >>> G = DihedralGroup(5)
201
+ >>> G.is_group
202
+ True
203
+ >>> a = list(G.generate_dimino())
204
+ >>> [perm.cyclic_form for perm in a]
205
+ [[], [[0, 1, 2, 3, 4]], [[0, 2, 4, 1, 3]],
206
+ [[0, 3, 1, 4, 2]], [[0, 4, 3, 2, 1]], [[0, 4], [1, 3]],
207
+ [[1, 4], [2, 3]], [[0, 1], [2, 4]], [[0, 2], [3, 4]],
208
+ [[0, 3], [1, 2]]]
209
+
210
+ See Also
211
+ ========
212
+
213
+ SymmetricGroup, CyclicGroup, AlternatingGroup
214
+
215
+ References
216
+ ==========
217
+
218
+ .. [1] https://en.wikipedia.org/wiki/Dihedral_group
219
+
220
+ """
221
+ # small cases are special
222
+ if n == 1:
223
+ return PermutationGroup([Permutation([1, 0])])
224
+ if n == 2:
225
+ return PermutationGroup([Permutation([1, 0, 3, 2]),
226
+ Permutation([2, 3, 0, 1]), Permutation([3, 2, 1, 0])])
227
+
228
+ a = list(range(1, n))
229
+ a.append(0)
230
+ gen1 = _af_new(a)
231
+ a = list(range(n))
232
+ a.reverse()
233
+ gen2 = _af_new(a)
234
+ G = PermutationGroup([gen1, gen2])
235
+ # if n is a power of 2, group is nilpotent
236
+ if n & (n-1) == 0:
237
+ G._is_nilpotent = True
238
+ else:
239
+ G._is_nilpotent = False
240
+ G._is_dihedral = True
241
+ G._is_abelian = False
242
+ G._is_solvable = True
243
+ G._degree = n
244
+ G._is_transitive = True
245
+ G._order = 2*n
246
+ return G
247
+
248
+
249
+ def SymmetricGroup(n):
250
+ """
251
+ Generates the symmetric group on ``n`` elements as a permutation group.
252
+
253
+ Explanation
254
+ ===========
255
+
256
+ The generators taken are the ``n``-cycle
257
+ ``(0 1 2 ... n-1)`` and the transposition ``(0 1)`` (in cycle notation).
258
+ (See [1]). After the group is generated, some of its basic properties
259
+ are set.
260
+
261
+ Examples
262
+ ========
263
+
264
+ >>> from sympy.combinatorics.named_groups import SymmetricGroup
265
+ >>> G = SymmetricGroup(4)
266
+ >>> G.is_group
267
+ True
268
+ >>> G.order()
269
+ 24
270
+ >>> list(G.generate_schreier_sims(af=True))
271
+ [[0, 1, 2, 3], [1, 2, 3, 0], [2, 3, 0, 1], [3, 1, 2, 0], [0, 2, 3, 1],
272
+ [1, 3, 0, 2], [2, 0, 1, 3], [3, 2, 0, 1], [0, 3, 1, 2], [1, 0, 2, 3],
273
+ [2, 1, 3, 0], [3, 0, 1, 2], [0, 1, 3, 2], [1, 2, 0, 3], [2, 3, 1, 0],
274
+ [3, 1, 0, 2], [0, 2, 1, 3], [1, 3, 2, 0], [2, 0, 3, 1], [3, 2, 1, 0],
275
+ [0, 3, 2, 1], [1, 0, 3, 2], [2, 1, 0, 3], [3, 0, 2, 1]]
276
+
277
+ See Also
278
+ ========
279
+
280
+ CyclicGroup, DihedralGroup, AlternatingGroup
281
+
282
+ References
283
+ ==========
284
+
285
+ .. [1] https://en.wikipedia.org/wiki/Symmetric_group#Generators_and_relations
286
+
287
+ """
288
+ if n == 1:
289
+ G = PermutationGroup([Permutation([0])])
290
+ elif n == 2:
291
+ G = PermutationGroup([Permutation([1, 0])])
292
+ else:
293
+ a = list(range(1, n))
294
+ a.append(0)
295
+ gen1 = _af_new(a)
296
+ a = list(range(n))
297
+ a[0], a[1] = a[1], a[0]
298
+ gen2 = _af_new(a)
299
+ G = PermutationGroup([gen1, gen2])
300
+ set_symmetric_group_properties(G, n, n)
301
+ G._is_sym = True
302
+ return G
303
+
304
+
305
+ def set_symmetric_group_properties(G, n, degree):
306
+ """Set known properties of a symmetric group. """
307
+ if n < 3:
308
+ G._is_abelian = True
309
+ G._is_nilpotent = True
310
+ else:
311
+ G._is_abelian = False
312
+ G._is_nilpotent = False
313
+ if n < 5:
314
+ G._is_solvable = True
315
+ else:
316
+ G._is_solvable = False
317
+ G._degree = degree
318
+ G._is_transitive = True
319
+ G._is_dihedral = (n in [2, 3]) # cf Landau's func and Stirling's approx
320
+
321
+
322
+ def RubikGroup(n):
323
+ """Return a group of Rubik's cube generators
324
+
325
+ >>> from sympy.combinatorics.named_groups import RubikGroup
326
+ >>> RubikGroup(2).is_group
327
+ True
328
+ """
329
+ from sympy.combinatorics.generators import rubik
330
+ if n <= 1:
331
+ raise ValueError("Invalid cube. n has to be greater than 1")
332
+ return PermutationGroup(rubik(n))
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__init__.py ADDED
File without changes
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_coset_table.cpython-310.pyc ADDED
Binary file (28.4 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_fp_groups.cpython-310.pyc ADDED
Binary file (9.28 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_free_groups.cpython-310.pyc ADDED
Binary file (8.19 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_galois.cpython-310.pyc ADDED
Binary file (2.33 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_generators.cpython-310.pyc ADDED
Binary file (3.58 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_graycode.cpython-310.pyc ADDED
Binary file (3.39 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_group_constructs.cpython-310.pyc ADDED
Binary file (710 Bytes). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_homomorphisms.cpython-310.pyc ADDED
Binary file (3.32 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_partitions.cpython-310.pyc ADDED
Binary file (5.26 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_pc_groups.cpython-310.pyc ADDED
Binary file (2.22 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_perm_groups.cpython-310.pyc ADDED
Binary file (36.2 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_permutations.cpython-310.pyc ADDED
Binary file (21.7 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_rewriting.cpython-310.pyc ADDED
Binary file (1.9 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_subsets.cpython-310.pyc ADDED
Binary file (2.69 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_tensor_can.cpython-310.pyc ADDED
Binary file (15.4 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_testutil.cpython-310.pyc ADDED
Binary file (2 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/__pycache__/test_util.cpython-310.pyc ADDED
Binary file (4.11 kB). View file
 
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_fp_groups.py ADDED
@@ -0,0 +1,257 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.singleton import S
2
+ from sympy.combinatorics.fp_groups import (FpGroup, low_index_subgroups,
3
+ reidemeister_presentation, FpSubgroup,
4
+ simplify_presentation)
5
+ from sympy.combinatorics.free_groups import (free_group, FreeGroup)
6
+
7
+ from sympy.testing.pytest import slow
8
+
9
+ """
10
+ References
11
+ ==========
12
+
13
+ [1] Holt, D., Eick, B., O'Brien, E.
14
+ "Handbook of Computational Group Theory"
15
+
16
+ [2] John J. Cannon; Lucien A. Dimino; George Havas; Jane M. Watson
17
+ Mathematics of Computation, Vol. 27, No. 123. (Jul., 1973), pp. 463-490.
18
+ "Implementation and Analysis of the Todd-Coxeter Algorithm"
19
+
20
+ [3] PROC. SECOND INTERNAT. CONF. THEORY OF GROUPS, CANBERRA 1973,
21
+ pp. 347-356. "A Reidemeister-Schreier program" by George Havas.
22
+ http://staff.itee.uq.edu.au/havas/1973cdhw.pdf
23
+
24
+ """
25
+
26
+ def test_low_index_subgroups():
27
+ F, x, y = free_group("x, y")
28
+
29
+ # Example 5.10 from [1] Pg. 194
30
+ f = FpGroup(F, [x**2, y**3, (x*y)**4])
31
+ L = low_index_subgroups(f, 4)
32
+ t1 = [[[0, 0, 0, 0]],
33
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 3, 3]],
34
+ [[0, 0, 1, 2], [2, 2, 2, 0], [1, 1, 0, 1]],
35
+ [[1, 1, 0, 0], [0, 0, 1, 1]]]
36
+ for i in range(len(t1)):
37
+ assert L[i].table == t1[i]
38
+
39
+ f = FpGroup(F, [x**2, y**3, (x*y)**7])
40
+ L = low_index_subgroups(f, 15)
41
+ t2 = [[[0, 0, 0, 0]],
42
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5],
43
+ [4, 4, 5, 3], [6, 6, 3, 4], [5, 5, 6, 6]],
44
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5],
45
+ [6, 6, 5, 3], [5, 5, 3, 4], [4, 4, 6, 6]],
46
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5],
47
+ [6, 6, 5, 3], [7, 7, 3, 4], [4, 4, 8, 9], [5, 5, 10, 11],
48
+ [11, 11, 9, 6], [9, 9, 6, 8], [12, 12, 11, 7], [8, 8, 7, 10],
49
+ [10, 10, 13, 14], [14, 14, 14, 12], [13, 13, 12, 13]],
50
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5],
51
+ [6, 6, 5, 3], [7, 7, 3, 4], [4, 4, 8, 9], [5, 5, 10, 11],
52
+ [11, 11, 9, 6], [12, 12, 6, 8], [10, 10, 11, 7], [8, 8, 7, 10],
53
+ [9, 9, 13, 14], [14, 14, 14, 12], [13, 13, 12, 13]],
54
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5],
55
+ [6, 6, 5, 3], [7, 7, 3, 4], [4, 4, 8, 9], [5, 5, 10, 11],
56
+ [11, 11, 9, 6], [12, 12, 6, 8], [13, 13, 11, 7], [8, 8, 7, 10],
57
+ [9, 9, 12, 12], [10, 10, 13, 13]],
58
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 3, 3], [2, 2, 5, 6]
59
+ , [7, 7, 6, 4], [8, 8, 4, 5], [5, 5, 8, 9], [6, 6, 9, 7],
60
+ [10, 10, 7, 8], [9, 9, 11, 12], [11, 11, 12, 10], [13, 13, 10, 11],
61
+ [12, 12, 13, 13]],
62
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 3, 3], [2, 2, 5, 6]
63
+ , [7, 7, 6, 4], [8, 8, 4, 5], [5, 5, 8, 9], [6, 6, 9, 7],
64
+ [10, 10, 7, 8], [9, 9, 11, 12], [13, 13, 12, 10], [12, 12, 10, 11],
65
+ [11, 11, 13, 13]],
66
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 4, 4]
67
+ , [7, 7, 6, 3], [8, 8, 3, 5], [5, 5, 8, 9], [6, 6, 9, 7],
68
+ [10, 10, 7, 8], [9, 9, 11, 12], [13, 13, 12, 10], [12, 12, 10, 11],
69
+ [11, 11, 13, 13]],
70
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
71
+ , [5, 5, 6, 3], [9, 9, 3, 5], [10, 10, 8, 4], [8, 8, 4, 7],
72
+ [6, 6, 10, 11], [7, 7, 11, 9], [12, 12, 9, 10], [11, 11, 13, 14],
73
+ [14, 14, 14, 12], [13, 13, 12, 13]],
74
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
75
+ , [6, 6, 6, 3], [5, 5, 3, 5], [8, 8, 8, 4], [7, 7, 4, 7]],
76
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
77
+ , [9, 9, 6, 3], [6, 6, 3, 5], [10, 10, 8, 4], [11, 11, 4, 7],
78
+ [5, 5, 10, 12], [7, 7, 12, 9], [8, 8, 11, 11], [13, 13, 9, 10],
79
+ [12, 12, 13, 13]],
80
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
81
+ , [9, 9, 6, 3], [6, 6, 3, 5], [10, 10, 8, 4], [11, 11, 4, 7],
82
+ [5, 5, 12, 11], [7, 7, 10, 10], [8, 8, 9, 12], [13, 13, 11, 9],
83
+ [12, 12, 13, 13]],
84
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
85
+ , [9, 9, 6, 3], [10, 10, 3, 5], [7, 7, 8, 4], [11, 11, 4, 7],
86
+ [5, 5, 9, 9], [6, 6, 11, 12], [8, 8, 12, 10], [13, 13, 10, 11],
87
+ [12, 12, 13, 13]],
88
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
89
+ , [9, 9, 6, 3], [10, 10, 3, 5], [7, 7, 8, 4], [11, 11, 4, 7],
90
+ [5, 5, 12, 11], [6, 6, 10, 10], [8, 8, 9, 12], [13, 13, 11, 9],
91
+ [12, 12, 13, 13]],
92
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8]
93
+ , [9, 9, 6, 3], [10, 10, 3, 5], [11, 11, 8, 4], [12, 12, 4, 7],
94
+ [5, 5, 9, 9], [6, 6, 12, 13], [7, 7, 11, 11], [8, 8, 13, 10],
95
+ [13, 13, 10, 12]],
96
+ [[1, 1, 0, 0], [0, 0, 2, 3], [4, 4, 3, 1], [5, 5, 1, 2], [2, 2, 4, 4]
97
+ , [3, 3, 6, 7], [7, 7, 7, 5], [6, 6, 5, 6]]]
98
+ for i in range(len(t2)):
99
+ assert L[i].table == t2[i]
100
+
101
+ f = FpGroup(F, [x**2, y**3, (x*y)**7])
102
+ L = low_index_subgroups(f, 10, [x])
103
+ t3 = [[[0, 0, 0, 0]],
104
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5], [4, 4, 5, 3],
105
+ [6, 6, 3, 4], [5, 5, 6, 6]],
106
+ [[0, 0, 1, 2], [1, 1, 2, 0], [3, 3, 0, 1], [2, 2, 4, 5], [6, 6, 5, 3],
107
+ [5, 5, 3, 4], [4, 4, 6, 6]],
108
+ [[0, 0, 1, 2], [3, 3, 2, 0], [4, 4, 0, 1], [1, 1, 5, 6], [2, 2, 7, 8],
109
+ [6, 6, 6, 3], [5, 5, 3, 5], [8, 8, 8, 4], [7, 7, 4, 7]]]
110
+ for i in range(len(t3)):
111
+ assert L[i].table == t3[i]
112
+
113
+
114
+ def test_subgroup_presentations():
115
+ F, x, y = free_group("x, y")
116
+ f = FpGroup(F, [x**3, y**5, (x*y)**2])
117
+ H = [x*y, x**-1*y**-1*x*y*x]
118
+ p1 = reidemeister_presentation(f, H)
119
+ assert str(p1) == "((y_1, y_2), (y_1**2, y_2**3, y_2*y_1*y_2*y_1*y_2*y_1))"
120
+
121
+ H = f.subgroup(H)
122
+ assert (H.generators, H.relators) == p1
123
+
124
+ f = FpGroup(F, [x**3, y**3, (x*y)**3])
125
+ H = [x*y, x*y**-1]
126
+ p2 = reidemeister_presentation(f, H)
127
+ assert str(p2) == "((x_0, y_0), (x_0**3, y_0**3, x_0*y_0*x_0*y_0*x_0*y_0))"
128
+
129
+ f = FpGroup(F, [x**2*y**2, y**-1*x*y*x**-3])
130
+ H = [x]
131
+ p3 = reidemeister_presentation(f, H)
132
+ assert str(p3) == "((x_0,), (x_0**4,))"
133
+
134
+ f = FpGroup(F, [x**3*y**-3, (x*y)**3, (x*y**-1)**2])
135
+ H = [x]
136
+ p4 = reidemeister_presentation(f, H)
137
+ assert str(p4) == "((x_0,), (x_0**6,))"
138
+
139
+ # this presentation can be improved, the most simplified form
140
+ # of presentation is <a, b | a^11, b^2, (a*b)^3, (a^4*b*a^-5*b)^2>
141
+ # See [2] Pg 474 group PSL_2(11)
142
+ # This is the group PSL_2(11)
143
+ F, a, b, c = free_group("a, b, c")
144
+ f = FpGroup(F, [a**11, b**5, c**4, (b*c**2)**2, (a*b*c)**3, (a**4*c**2)**3, b**2*c**-1*b**-1*c, a**4*b**-1*a**-1*b])
145
+ H = [a, b, c**2]
146
+ gens, rels = reidemeister_presentation(f, H)
147
+ assert str(gens) == "(b_1, c_3)"
148
+ assert len(rels) == 18
149
+
150
+
151
+ @slow
152
+ def test_order():
153
+ F, x, y = free_group("x, y")
154
+ f = FpGroup(F, [x**4, y**2, x*y*x**-1*y])
155
+ assert f.order() == 8
156
+
157
+ f = FpGroup(F, [x*y*x**-1*y**-1, y**2])
158
+ assert f.order() is S.Infinity
159
+
160
+ F, a, b, c = free_group("a, b, c")
161
+ f = FpGroup(F, [a**250, b**2, c*b*c**-1*b, c**4, c**-1*a**-1*c*a, a**-1*b**-1*a*b])
162
+ assert f.order() == 2000
163
+
164
+ F, x = free_group("x")
165
+ f = FpGroup(F, [])
166
+ assert f.order() is S.Infinity
167
+
168
+ f = FpGroup(free_group('')[0], [])
169
+ assert f.order() == 1
170
+
171
+ def test_fp_subgroup():
172
+ def _test_subgroup(K, T, S):
173
+ _gens = T(K.generators)
174
+ assert all(elem in S for elem in _gens)
175
+ assert T.is_injective()
176
+ assert T.image().order() == S.order()
177
+ F, x, y = free_group("x, y")
178
+ f = FpGroup(F, [x**4, y**2, x*y*x**-1*y])
179
+ S = FpSubgroup(f, [x*y])
180
+ assert (x*y)**-3 in S
181
+ K, T = f.subgroup([x*y], homomorphism=True)
182
+ assert T(K.generators) == [y*x**-1]
183
+ _test_subgroup(K, T, S)
184
+
185
+ S = FpSubgroup(f, [x**-1*y*x])
186
+ assert x**-1*y**4*x in S
187
+ assert x**-1*y**4*x**2 not in S
188
+ K, T = f.subgroup([x**-1*y*x], homomorphism=True)
189
+ assert T(K.generators[0]**3) == y**3
190
+ _test_subgroup(K, T, S)
191
+
192
+ f = FpGroup(F, [x**3, y**5, (x*y)**2])
193
+ H = [x*y, x**-1*y**-1*x*y*x]
194
+ K, T = f.subgroup(H, homomorphism=True)
195
+ S = FpSubgroup(f, H)
196
+ _test_subgroup(K, T, S)
197
+
198
+ def test_permutation_methods():
199
+ F, x, y = free_group("x, y")
200
+ # DihedralGroup(8)
201
+ G = FpGroup(F, [x**2, y**8, x*y*x**-1*y])
202
+ T = G._to_perm_group()[1]
203
+ assert T.is_isomorphism()
204
+ assert G.center() == [y**4]
205
+
206
+ # DiheadralGroup(4)
207
+ G = FpGroup(F, [x**2, y**4, x*y*x**-1*y])
208
+ S = FpSubgroup(G, G.normal_closure([x]))
209
+ assert x in S
210
+ assert y**-1*x*y in S
211
+
212
+ # Z_5xZ_4
213
+ G = FpGroup(F, [x*y*x**-1*y**-1, y**5, x**4])
214
+ assert G.is_abelian
215
+ assert G.is_solvable
216
+
217
+ # AlternatingGroup(5)
218
+ G = FpGroup(F, [x**3, y**2, (x*y)**5])
219
+ assert not G.is_solvable
220
+
221
+ # AlternatingGroup(4)
222
+ G = FpGroup(F, [x**3, y**2, (x*y)**3])
223
+ assert len(G.derived_series()) == 3
224
+ S = FpSubgroup(G, G.derived_subgroup())
225
+ assert S.order() == 4
226
+
227
+
228
+ def test_simplify_presentation():
229
+ # ref #16083
230
+ G = simplify_presentation(FpGroup(FreeGroup([]), []))
231
+ assert not G.generators
232
+ assert not G.relators
233
+
234
+ # CyclicGroup(3)
235
+ # The second generator in <x, y | x^2, x^5, y^3> is trivial due to relators {x^2, x^5}
236
+ F, x, y = free_group("x, y")
237
+ G = simplify_presentation(FpGroup(F, [x**2, x**5, y**3]))
238
+ assert x in G.relators
239
+
240
+ def test_cyclic():
241
+ F, x, y = free_group("x, y")
242
+ f = FpGroup(F, [x*y, x**-1*y**-1*x*y*x])
243
+ assert f.is_cyclic
244
+ f = FpGroup(F, [x*y, x*y**-1])
245
+ assert f.is_cyclic
246
+ f = FpGroup(F, [x**4, y**2, x*y*x**-1*y])
247
+ assert not f.is_cyclic
248
+
249
+
250
+ def test_abelian_invariants():
251
+ F, x, y = free_group("x, y")
252
+ f = FpGroup(F, [x*y, x**-1*y**-1*x*y*x])
253
+ assert f.abelian_invariants() == []
254
+ f = FpGroup(F, [x*y, x*y**-1])
255
+ assert f.abelian_invariants() == [2]
256
+ f = FpGroup(F, [x**4, y**2, x*y*x**-1*y])
257
+ assert f.abelian_invariants() == [2, 4]
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_generators.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics.generators import symmetric, cyclic, alternating, \
2
+ dihedral, rubik
3
+ from sympy.combinatorics.permutations import Permutation
4
+ from sympy.testing.pytest import raises
5
+
6
+ def test_generators():
7
+
8
+ assert list(cyclic(6)) == [
9
+ Permutation([0, 1, 2, 3, 4, 5]),
10
+ Permutation([1, 2, 3, 4, 5, 0]),
11
+ Permutation([2, 3, 4, 5, 0, 1]),
12
+ Permutation([3, 4, 5, 0, 1, 2]),
13
+ Permutation([4, 5, 0, 1, 2, 3]),
14
+ Permutation([5, 0, 1, 2, 3, 4])]
15
+
16
+ assert list(cyclic(10)) == [
17
+ Permutation([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]),
18
+ Permutation([1, 2, 3, 4, 5, 6, 7, 8, 9, 0]),
19
+ Permutation([2, 3, 4, 5, 6, 7, 8, 9, 0, 1]),
20
+ Permutation([3, 4, 5, 6, 7, 8, 9, 0, 1, 2]),
21
+ Permutation([4, 5, 6, 7, 8, 9, 0, 1, 2, 3]),
22
+ Permutation([5, 6, 7, 8, 9, 0, 1, 2, 3, 4]),
23
+ Permutation([6, 7, 8, 9, 0, 1, 2, 3, 4, 5]),
24
+ Permutation([7, 8, 9, 0, 1, 2, 3, 4, 5, 6]),
25
+ Permutation([8, 9, 0, 1, 2, 3, 4, 5, 6, 7]),
26
+ Permutation([9, 0, 1, 2, 3, 4, 5, 6, 7, 8])]
27
+
28
+ assert list(alternating(4)) == [
29
+ Permutation([0, 1, 2, 3]),
30
+ Permutation([0, 2, 3, 1]),
31
+ Permutation([0, 3, 1, 2]),
32
+ Permutation([1, 0, 3, 2]),
33
+ Permutation([1, 2, 0, 3]),
34
+ Permutation([1, 3, 2, 0]),
35
+ Permutation([2, 0, 1, 3]),
36
+ Permutation([2, 1, 3, 0]),
37
+ Permutation([2, 3, 0, 1]),
38
+ Permutation([3, 0, 2, 1]),
39
+ Permutation([3, 1, 0, 2]),
40
+ Permutation([3, 2, 1, 0])]
41
+
42
+ assert list(symmetric(3)) == [
43
+ Permutation([0, 1, 2]),
44
+ Permutation([0, 2, 1]),
45
+ Permutation([1, 0, 2]),
46
+ Permutation([1, 2, 0]),
47
+ Permutation([2, 0, 1]),
48
+ Permutation([2, 1, 0])]
49
+
50
+ assert list(symmetric(4)) == [
51
+ Permutation([0, 1, 2, 3]),
52
+ Permutation([0, 1, 3, 2]),
53
+ Permutation([0, 2, 1, 3]),
54
+ Permutation([0, 2, 3, 1]),
55
+ Permutation([0, 3, 1, 2]),
56
+ Permutation([0, 3, 2, 1]),
57
+ Permutation([1, 0, 2, 3]),
58
+ Permutation([1, 0, 3, 2]),
59
+ Permutation([1, 2, 0, 3]),
60
+ Permutation([1, 2, 3, 0]),
61
+ Permutation([1, 3, 0, 2]),
62
+ Permutation([1, 3, 2, 0]),
63
+ Permutation([2, 0, 1, 3]),
64
+ Permutation([2, 0, 3, 1]),
65
+ Permutation([2, 1, 0, 3]),
66
+ Permutation([2, 1, 3, 0]),
67
+ Permutation([2, 3, 0, 1]),
68
+ Permutation([2, 3, 1, 0]),
69
+ Permutation([3, 0, 1, 2]),
70
+ Permutation([3, 0, 2, 1]),
71
+ Permutation([3, 1, 0, 2]),
72
+ Permutation([3, 1, 2, 0]),
73
+ Permutation([3, 2, 0, 1]),
74
+ Permutation([3, 2, 1, 0])]
75
+
76
+ assert list(dihedral(1)) == [
77
+ Permutation([0, 1]), Permutation([1, 0])]
78
+
79
+ assert list(dihedral(2)) == [
80
+ Permutation([0, 1, 2, 3]),
81
+ Permutation([1, 0, 3, 2]),
82
+ Permutation([2, 3, 0, 1]),
83
+ Permutation([3, 2, 1, 0])]
84
+
85
+ assert list(dihedral(3)) == [
86
+ Permutation([0, 1, 2]),
87
+ Permutation([2, 1, 0]),
88
+ Permutation([1, 2, 0]),
89
+ Permutation([0, 2, 1]),
90
+ Permutation([2, 0, 1]),
91
+ Permutation([1, 0, 2])]
92
+
93
+ assert list(dihedral(5)) == [
94
+ Permutation([0, 1, 2, 3, 4]),
95
+ Permutation([4, 3, 2, 1, 0]),
96
+ Permutation([1, 2, 3, 4, 0]),
97
+ Permutation([0, 4, 3, 2, 1]),
98
+ Permutation([2, 3, 4, 0, 1]),
99
+ Permutation([1, 0, 4, 3, 2]),
100
+ Permutation([3, 4, 0, 1, 2]),
101
+ Permutation([2, 1, 0, 4, 3]),
102
+ Permutation([4, 0, 1, 2, 3]),
103
+ Permutation([3, 2, 1, 0, 4])]
104
+
105
+ raises(ValueError, lambda: rubik(1))
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_graycode.py ADDED
@@ -0,0 +1,72 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics.graycode import (GrayCode, bin_to_gray,
2
+ random_bitstring, get_subset_from_bitstring, graycode_subsets,
3
+ gray_to_bin)
4
+ from sympy.testing.pytest import raises
5
+
6
+ def test_graycode():
7
+ g = GrayCode(2)
8
+ got = []
9
+ for i in g.generate_gray():
10
+ if i.startswith('0'):
11
+ g.skip()
12
+ got.append(i)
13
+ assert got == '00 11 10'.split()
14
+ a = GrayCode(6)
15
+ assert a.current == '0'*6
16
+ assert a.rank == 0
17
+ assert len(list(a.generate_gray())) == 64
18
+ codes = ['011001', '011011', '011010',
19
+ '011110', '011111', '011101', '011100', '010100', '010101', '010111',
20
+ '010110', '010010', '010011', '010001', '010000', '110000', '110001',
21
+ '110011', '110010', '110110', '110111', '110101', '110100', '111100',
22
+ '111101', '111111', '111110', '111010', '111011', '111001', '111000',
23
+ '101000', '101001', '101011', '101010', '101110', '101111', '101101',
24
+ '101100', '100100', '100101', '100111', '100110', '100010', '100011',
25
+ '100001', '100000']
26
+ assert list(a.generate_gray(start='011001')) == codes
27
+ assert list(
28
+ a.generate_gray(rank=GrayCode(6, start='011001').rank)) == codes
29
+ assert a.next().current == '000001'
30
+ assert a.next(2).current == '000011'
31
+ assert a.next(-1).current == '100000'
32
+
33
+ a = GrayCode(5, start='10010')
34
+ assert a.rank == 28
35
+ a = GrayCode(6, start='101000')
36
+ assert a.rank == 48
37
+
38
+ assert GrayCode(6, rank=4).current == '000110'
39
+ assert GrayCode(6, rank=4).rank == 4
40
+ assert [GrayCode(4, start=s).rank for s in
41
+ GrayCode(4).generate_gray()] == [0, 1, 2, 3, 4, 5, 6, 7, 8,
42
+ 9, 10, 11, 12, 13, 14, 15]
43
+ a = GrayCode(15, rank=15)
44
+ assert a.current == '000000000001000'
45
+
46
+ assert bin_to_gray('111') == '100'
47
+
48
+ a = random_bitstring(5)
49
+ assert type(a) is str
50
+ assert len(a) == 5
51
+ assert all(i in ['0', '1'] for i in a)
52
+
53
+ assert get_subset_from_bitstring(
54
+ ['a', 'b', 'c', 'd'], '0011') == ['c', 'd']
55
+ assert get_subset_from_bitstring('abcd', '1001') == ['a', 'd']
56
+ assert list(graycode_subsets(['a', 'b', 'c'])) == \
57
+ [[], ['c'], ['b', 'c'], ['b'], ['a', 'b'], ['a', 'b', 'c'],
58
+ ['a', 'c'], ['a']]
59
+
60
+ raises(ValueError, lambda: GrayCode(0))
61
+ raises(ValueError, lambda: GrayCode(2.2))
62
+ raises(ValueError, lambda: GrayCode(2, start=[1, 1, 0]))
63
+ raises(ValueError, lambda: GrayCode(2, rank=2.5))
64
+ raises(ValueError, lambda: get_subset_from_bitstring(['c', 'a', 'c'], '1100'))
65
+ raises(ValueError, lambda: list(GrayCode(3).generate_gray(start="1111")))
66
+
67
+
68
+ def test_live_issue_117():
69
+ assert bin_to_gray('0100') == '0110'
70
+ assert bin_to_gray('0101') == '0111'
71
+ for bits in ('0100', '0101'):
72
+ assert gray_to_bin(bin_to_gray(bits)) == bits
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_homomorphisms.py ADDED
@@ -0,0 +1,114 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.combinatorics import Permutation
2
+ from sympy.combinatorics.perm_groups import PermutationGroup
3
+ from sympy.combinatorics.homomorphisms import homomorphism, group_isomorphism, is_isomorphic
4
+ from sympy.combinatorics.free_groups import free_group
5
+ from sympy.combinatorics.fp_groups import FpGroup
6
+ from sympy.combinatorics.named_groups import AlternatingGroup, DihedralGroup, CyclicGroup
7
+ from sympy.testing.pytest import raises
8
+
9
+ def test_homomorphism():
10
+ # FpGroup -> PermutationGroup
11
+ F, a, b = free_group("a, b")
12
+ G = FpGroup(F, [a**3, b**3, (a*b)**2])
13
+
14
+ c = Permutation(3)(0, 1, 2)
15
+ d = Permutation(3)(1, 2, 3)
16
+ A = AlternatingGroup(4)
17
+ T = homomorphism(G, A, [a, b], [c, d])
18
+ assert T(a*b**2*a**-1) == c*d**2*c**-1
19
+ assert T.is_isomorphism()
20
+ assert T(T.invert(Permutation(3)(0, 2, 3))) == Permutation(3)(0, 2, 3)
21
+
22
+ T = homomorphism(G, AlternatingGroup(4), G.generators)
23
+ assert T.is_trivial()
24
+ assert T.kernel().order() == G.order()
25
+
26
+ E, e = free_group("e")
27
+ G = FpGroup(E, [e**8])
28
+ P = PermutationGroup([Permutation(0, 1, 2, 3), Permutation(0, 2)])
29
+ T = homomorphism(G, P, [e], [Permutation(0, 1, 2, 3)])
30
+ assert T.image().order() == 4
31
+ assert T(T.invert(Permutation(0, 2)(1, 3))) == Permutation(0, 2)(1, 3)
32
+
33
+ T = homomorphism(E, AlternatingGroup(4), E.generators, [c])
34
+ assert T.invert(c**2) == e**-1 #order(c) == 3 so c**2 == c**-1
35
+
36
+ # FreeGroup -> FreeGroup
37
+ T = homomorphism(F, E, [a], [e])
38
+ assert T(a**-2*b**4*a**2).is_identity
39
+
40
+ # FreeGroup -> FpGroup
41
+ G = FpGroup(F, [a*b*a**-1*b**-1])
42
+ T = homomorphism(F, G, F.generators, G.generators)
43
+ assert T.invert(a**-1*b**-1*a**2) == a*b**-1
44
+
45
+ # PermutationGroup -> PermutationGroup
46
+ D = DihedralGroup(8)
47
+ p = Permutation(0, 1, 2, 3, 4, 5, 6, 7)
48
+ P = PermutationGroup(p)
49
+ T = homomorphism(P, D, [p], [p])
50
+ assert T.is_injective()
51
+ assert not T.is_isomorphism()
52
+ assert T.invert(p**3) == p**3
53
+
54
+ T2 = homomorphism(F, P, [F.generators[0]], P.generators)
55
+ T = T.compose(T2)
56
+ assert T.domain == F
57
+ assert T.codomain == D
58
+ assert T(a*b) == p
59
+
60
+ D3 = DihedralGroup(3)
61
+ T = homomorphism(D3, D3, D3.generators, D3.generators)
62
+ assert T.is_isomorphism()
63
+
64
+
65
+ def test_isomorphisms():
66
+
67
+ F, a, b = free_group("a, b")
68
+ E, c, d = free_group("c, d")
69
+ # Infinite groups with differently ordered relators.
70
+ G = FpGroup(F, [a**2, b**3])
71
+ H = FpGroup(F, [b**3, a**2])
72
+ assert is_isomorphic(G, H)
73
+
74
+ # Trivial Case
75
+ # FpGroup -> FpGroup
76
+ H = FpGroup(F, [a**3, b**3, (a*b)**2])
77
+ F, c, d = free_group("c, d")
78
+ G = FpGroup(F, [c**3, d**3, (c*d)**2])
79
+ check, T = group_isomorphism(G, H)
80
+ assert check
81
+ assert T(c**3*d**2) == a**3*b**2
82
+
83
+ # FpGroup -> PermutationGroup
84
+ # FpGroup is converted to the equivalent isomorphic group.
85
+ F, a, b = free_group("a, b")
86
+ G = FpGroup(F, [a**3, b**3, (a*b)**2])
87
+ H = AlternatingGroup(4)
88
+ check, T = group_isomorphism(G, H)
89
+ assert check
90
+ assert T(b*a*b**-1*a**-1*b**-1) == Permutation(0, 2, 3)
91
+ assert T(b*a*b*a**-1*b**-1) == Permutation(0, 3, 2)
92
+
93
+ # PermutationGroup -> PermutationGroup
94
+ D = DihedralGroup(8)
95
+ p = Permutation(0, 1, 2, 3, 4, 5, 6, 7)
96
+ P = PermutationGroup(p)
97
+ assert not is_isomorphic(D, P)
98
+
99
+ A = CyclicGroup(5)
100
+ B = CyclicGroup(7)
101
+ assert not is_isomorphic(A, B)
102
+
103
+ # Two groups of the same prime order are isomorphic to each other.
104
+ G = FpGroup(F, [a, b**5])
105
+ H = CyclicGroup(5)
106
+ assert G.order() == H.order()
107
+ assert is_isomorphic(G, H)
108
+
109
+
110
+ def test_check_homomorphism():
111
+ a = Permutation(1,2,3,4)
112
+ b = Permutation(1,3)
113
+ G = PermutationGroup([a, b])
114
+ raises(ValueError, lambda: homomorphism(G, G, [a], [a]))
pllava/lib/python3.10/site-packages/sympy/combinatorics/tests/test_perm_groups.py ADDED
@@ -0,0 +1,1243 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from sympy.core.containers import Tuple
2
+ from sympy.combinatorics.generators import rubik_cube_generators
3
+ from sympy.combinatorics.homomorphisms import is_isomorphic
4
+ from sympy.combinatorics.named_groups import SymmetricGroup, CyclicGroup,\
5
+ DihedralGroup, AlternatingGroup, AbelianGroup, RubikGroup
6
+ from sympy.combinatorics.perm_groups import (PermutationGroup,
7
+ _orbit_transversal, Coset, SymmetricPermutationGroup)
8
+ from sympy.combinatorics.permutations import Permutation
9
+ from sympy.combinatorics.polyhedron import tetrahedron as Tetra, cube
10
+ from sympy.combinatorics.testutil import _verify_bsgs, _verify_centralizer,\
11
+ _verify_normal_closure
12
+ from sympy.testing.pytest import skip, XFAIL, slow
13
+
14
+ rmul = Permutation.rmul
15
+
16
+
17
+ def test_has():
18
+ a = Permutation([1, 0])
19
+ G = PermutationGroup([a])
20
+ assert G.is_abelian
21
+ a = Permutation([2, 0, 1])
22
+ b = Permutation([2, 1, 0])
23
+ G = PermutationGroup([a, b])
24
+ assert not G.is_abelian
25
+
26
+ G = PermutationGroup([a])
27
+ assert G.has(a)
28
+ assert not G.has(b)
29
+
30
+ a = Permutation([2, 0, 1, 3, 4, 5])
31
+ b = Permutation([0, 2, 1, 3, 4])
32
+ assert PermutationGroup(a, b).degree == \
33
+ PermutationGroup(a, b).degree == 6
34
+
35
+ g = PermutationGroup(Permutation(0, 2, 1))
36
+ assert Tuple(1, g).has(g)
37
+
38
+
39
+ def test_generate():
40
+ a = Permutation([1, 0])
41
+ g = list(PermutationGroup([a]).generate())
42
+ assert g == [Permutation([0, 1]), Permutation([1, 0])]
43
+ assert len(list(PermutationGroup(Permutation((0, 1))).generate())) == 1
44
+ g = PermutationGroup([a]).generate(method='dimino')
45
+ assert list(g) == [Permutation([0, 1]), Permutation([1, 0])]
46
+ a = Permutation([2, 0, 1])
47
+ b = Permutation([2, 1, 0])
48
+ G = PermutationGroup([a, b])
49
+ g = G.generate()
50
+ v1 = [p.array_form for p in list(g)]
51
+ v1.sort()
52
+ assert v1 == [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0,
53
+ 1], [2, 1, 0]]
54
+ v2 = list(G.generate(method='dimino', af=True))
55
+ assert v1 == sorted(v2)
56
+ a = Permutation([2, 0, 1, 3, 4, 5])
57
+ b = Permutation([2, 1, 3, 4, 5, 0])
58
+ g = PermutationGroup([a, b]).generate(af=True)
59
+ assert len(list(g)) == 360
60
+
61
+
62
+ def test_order():
63
+ a = Permutation([2, 0, 1, 3, 4, 5, 6, 7, 8, 9])
64
+ b = Permutation([2, 1, 3, 4, 5, 6, 7, 8, 9, 0])
65
+ g = PermutationGroup([a, b])
66
+ assert g.order() == 1814400
67
+ assert PermutationGroup().order() == 1
68
+
69
+
70
+ def test_equality():
71
+ p_1 = Permutation(0, 1, 3)
72
+ p_2 = Permutation(0, 2, 3)
73
+ p_3 = Permutation(0, 1, 2)
74
+ p_4 = Permutation(0, 1, 3)
75
+ g_1 = PermutationGroup(p_1, p_2)
76
+ g_2 = PermutationGroup(p_3, p_4)
77
+ g_3 = PermutationGroup(p_2, p_1)
78
+ g_4 = PermutationGroup(p_1, p_2)
79
+
80
+ assert g_1 != g_2
81
+ assert g_1.generators != g_2.generators
82
+ assert g_1.equals(g_2)
83
+ assert g_1 != g_3
84
+ assert g_1.equals(g_3)
85
+ assert g_1 == g_4
86
+
87
+
88
+ def test_stabilizer():
89
+ S = SymmetricGroup(2)
90
+ H = S.stabilizer(0)
91
+ assert H.generators == [Permutation(1)]
92
+ a = Permutation([2, 0, 1, 3, 4, 5])
93
+ b = Permutation([2, 1, 3, 4, 5, 0])
94
+ G = PermutationGroup([a, b])
95
+ G0 = G.stabilizer(0)
96
+ assert G0.order() == 60
97
+
98
+ gens_cube = [[1, 3, 5, 7, 0, 2, 4, 6], [1, 3, 0, 2, 5, 7, 4, 6]]
99
+ gens = [Permutation(p) for p in gens_cube]
100
+ G = PermutationGroup(gens)
101
+ G2 = G.stabilizer(2)
102
+ assert G2.order() == 6
103
+ G2_1 = G2.stabilizer(1)
104
+ v = list(G2_1.generate(af=True))
105
+ assert v == [[0, 1, 2, 3, 4, 5, 6, 7], [3, 1, 2, 0, 7, 5, 6, 4]]
106
+
107
+ gens = (
108
+ (1, 2, 0, 4, 5, 3, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19),
109
+ (0, 1, 2, 3, 4, 5, 19, 6, 8, 9, 10, 11, 12, 13, 14,
110
+ 15, 16, 7, 17, 18),
111
+ (0, 1, 2, 3, 4, 5, 6, 7, 9, 18, 16, 11, 12, 13, 14, 15, 8, 17, 10, 19))
112
+ gens = [Permutation(p) for p in gens]
113
+ G = PermutationGroup(gens)
114
+ G2 = G.stabilizer(2)
115
+ assert G2.order() == 181440
116
+ S = SymmetricGroup(3)
117
+ assert [G.order() for G in S.basic_stabilizers] == [6, 2]
118
+
119
+
120
+ def test_center():
121
+ # the center of the dihedral group D_n is of order 2 for even n
122
+ for i in (4, 6, 10):
123
+ D = DihedralGroup(i)
124
+ assert (D.center()).order() == 2
125
+ # the center of the dihedral group D_n is of order 1 for odd n>2
126
+ for i in (3, 5, 7):
127
+ D = DihedralGroup(i)
128
+ assert (D.center()).order() == 1
129
+ # the center of an abelian group is the group itself
130
+ for i in (2, 3, 5):
131
+ for j in (1, 5, 7):
132
+ for k in (1, 1, 11):
133
+ G = AbelianGroup(i, j, k)
134
+ assert G.center().is_subgroup(G)
135
+ # the center of a nonabelian simple group is trivial
136
+ for i in(1, 5, 9):
137
+ A = AlternatingGroup(i)
138
+ assert (A.center()).order() == 1
139
+ # brute-force verifications
140
+ D = DihedralGroup(5)
141
+ A = AlternatingGroup(3)
142
+ C = CyclicGroup(4)
143
+ G.is_subgroup(D*A*C)
144
+ assert _verify_centralizer(G, G)
145
+
146
+
147
+ def test_centralizer():
148
+ # the centralizer of the trivial group is the entire group
149
+ S = SymmetricGroup(2)
150
+ assert S.centralizer(Permutation(list(range(2)))).is_subgroup(S)
151
+ A = AlternatingGroup(5)
152
+ assert A.centralizer(Permutation(list(range(5)))).is_subgroup(A)
153
+ # a centralizer in the trivial group is the trivial group itself
154
+ triv = PermutationGroup([Permutation([0, 1, 2, 3])])
155
+ D = DihedralGroup(4)
156
+ assert triv.centralizer(D).is_subgroup(triv)
157
+ # brute-force verifications for centralizers of groups
158
+ for i in (4, 5, 6):
159
+ S = SymmetricGroup(i)
160
+ A = AlternatingGroup(i)
161
+ C = CyclicGroup(i)
162
+ D = DihedralGroup(i)
163
+ for gp in (S, A, C, D):
164
+ for gp2 in (S, A, C, D):
165
+ if not gp2.is_subgroup(gp):
166
+ assert _verify_centralizer(gp, gp2)
167
+ # verify the centralizer for all elements of several groups
168
+ S = SymmetricGroup(5)
169
+ elements = list(S.generate_dimino())
170
+ for element in elements:
171
+ assert _verify_centralizer(S, element)
172
+ A = AlternatingGroup(5)
173
+ elements = list(A.generate_dimino())
174
+ for element in elements:
175
+ assert _verify_centralizer(A, element)
176
+ D = DihedralGroup(7)
177
+ elements = list(D.generate_dimino())
178
+ for element in elements:
179
+ assert _verify_centralizer(D, element)
180
+ # verify centralizers of small groups within small groups
181
+ small = []
182
+ for i in (1, 2, 3):
183
+ small.append(SymmetricGroup(i))
184
+ small.append(AlternatingGroup(i))
185
+ small.append(DihedralGroup(i))
186
+ small.append(CyclicGroup(i))
187
+ for gp in small:
188
+ for gp2 in small:
189
+ if gp.degree == gp2.degree:
190
+ assert _verify_centralizer(gp, gp2)
191
+
192
+
193
+ def test_coset_rank():
194
+ gens_cube = [[1, 3, 5, 7, 0, 2, 4, 6], [1, 3, 0, 2, 5, 7, 4, 6]]
195
+ gens = [Permutation(p) for p in gens_cube]
196
+ G = PermutationGroup(gens)
197
+ i = 0
198
+ for h in G.generate(af=True):
199
+ rk = G.coset_rank(h)
200
+ assert rk == i
201
+ h1 = G.coset_unrank(rk, af=True)
202
+ assert h == h1
203
+ i += 1
204
+ assert G.coset_unrank(48) is None
205
+ assert G.coset_unrank(G.coset_rank(gens[0])) == gens[0]
206
+
207
+
208
+ def test_coset_factor():
209
+ a = Permutation([0, 2, 1])
210
+ G = PermutationGroup([a])
211
+ c = Permutation([2, 1, 0])
212
+ assert not G.coset_factor(c)
213
+ assert G.coset_rank(c) is None
214
+
215
+ a = Permutation([2, 0, 1, 3, 4, 5])
216
+ b = Permutation([2, 1, 3, 4, 5, 0])
217
+ g = PermutationGroup([a, b])
218
+ assert g.order() == 360
219
+ d = Permutation([1, 0, 2, 3, 4, 5])
220
+ assert not g.coset_factor(d.array_form)
221
+ assert not g.contains(d)
222
+ assert Permutation(2) in G
223
+ c = Permutation([1, 0, 2, 3, 5, 4])
224
+ v = g.coset_factor(c, True)
225
+ tr = g.basic_transversals
226
+ p = Permutation.rmul(*[tr[i][v[i]] for i in range(len(g.base))])
227
+ assert p == c
228
+ v = g.coset_factor(c)
229
+ p = Permutation.rmul(*v)
230
+ assert p == c
231
+ assert g.contains(c)
232
+ G = PermutationGroup([Permutation([2, 1, 0])])
233
+ p = Permutation([1, 0, 2])
234
+ assert G.coset_factor(p) == []
235
+
236
+
237
+ def test_orbits():
238
+ a = Permutation([2, 0, 1])
239
+ b = Permutation([2, 1, 0])
240
+ g = PermutationGroup([a, b])
241
+ assert g.orbit(0) == {0, 1, 2}
242
+ assert g.orbits() == [{0, 1, 2}]
243
+ assert g.is_transitive() and g.is_transitive(strict=False)
244
+ assert g.orbit_transversal(0) == \
245
+ [Permutation(
246
+ [0, 1, 2]), Permutation([2, 0, 1]), Permutation([1, 2, 0])]
247
+ assert g.orbit_transversal(0, True) == \
248
+ [(0, Permutation([0, 1, 2])), (2, Permutation([2, 0, 1])),
249
+ (1, Permutation([1, 2, 0]))]
250
+
251
+ G = DihedralGroup(6)
252
+ transversal, slps = _orbit_transversal(G.degree, G.generators, 0, True, slp=True)
253
+ for i, t in transversal:
254
+ slp = slps[i]
255
+ w = G.identity
256
+ for s in slp:
257
+ w = G.generators[s]*w
258
+ assert w == t
259
+
260
+ a = Permutation(list(range(1, 100)) + [0])
261
+ G = PermutationGroup([a])
262
+ assert [min(o) for o in G.orbits()] == [0]
263
+ G = PermutationGroup(rubik_cube_generators())
264
+ assert [min(o) for o in G.orbits()] == [0, 1]
265
+ assert not G.is_transitive() and not G.is_transitive(strict=False)
266
+ G = PermutationGroup([Permutation(0, 1, 3), Permutation(3)(0, 1)])
267
+ assert not G.is_transitive() and G.is_transitive(strict=False)
268
+ assert PermutationGroup(
269
+ Permutation(3)).is_transitive(strict=False) is False
270
+
271
+
272
+ def test_is_normal():
273
+ gens_s5 = [Permutation(p) for p in [[1, 2, 3, 4, 0], [2, 1, 4, 0, 3]]]
274
+ G1 = PermutationGroup(gens_s5)
275
+ assert G1.order() == 120
276
+ gens_a5 = [Permutation(p) for p in [[1, 0, 3, 2, 4], [2, 1, 4, 3, 0]]]
277
+ G2 = PermutationGroup(gens_a5)
278
+ assert G2.order() == 60
279
+ assert G2.is_normal(G1)
280
+ gens3 = [Permutation(p) for p in [[2, 1, 3, 0, 4], [1, 2, 0, 3, 4]]]
281
+ G3 = PermutationGroup(gens3)
282
+ assert not G3.is_normal(G1)
283
+ assert G3.order() == 12
284
+ G4 = G1.normal_closure(G3.generators)
285
+ assert G4.order() == 60
286
+ gens5 = [Permutation(p) for p in [[1, 2, 3, 0, 4], [1, 2, 0, 3, 4]]]
287
+ G5 = PermutationGroup(gens5)
288
+ assert G5.order() == 24
289
+ G6 = G1.normal_closure(G5.generators)
290
+ assert G6.order() == 120
291
+ assert G1.is_subgroup(G6)
292
+ assert not G1.is_subgroup(G4)
293
+ assert G2.is_subgroup(G4)
294
+ I5 = PermutationGroup(Permutation(4))
295
+ assert I5.is_normal(G5)
296
+ assert I5.is_normal(G6, strict=False)
297
+ p1 = Permutation([1, 0, 2, 3, 4])
298
+ p2 = Permutation([0, 1, 2, 4, 3])
299
+ p3 = Permutation([3, 4, 2, 1, 0])
300
+ id_ = Permutation([0, 1, 2, 3, 4])
301
+ H = PermutationGroup([p1, p3])
302
+ H_n1 = PermutationGroup([p1, p2])
303
+ H_n2_1 = PermutationGroup(p1)
304
+ H_n2_2 = PermutationGroup(p2)
305
+ H_id = PermutationGroup(id_)
306
+ assert H_n1.is_normal(H)
307
+ assert H_n2_1.is_normal(H_n1)
308
+ assert H_n2_2.is_normal(H_n1)
309
+ assert H_id.is_normal(H_n2_1)
310
+ assert H_id.is_normal(H_n1)
311
+ assert H_id.is_normal(H)
312
+ assert not H_n2_1.is_normal(H)
313
+ assert not H_n2_2.is_normal(H)
314
+
315
+
316
+ def test_eq():
317
+ a = [[1, 2, 0, 3, 4, 5], [1, 0, 2, 3, 4, 5], [2, 1, 0, 3, 4, 5], [
318
+ 1, 2, 0, 3, 4, 5]]
319
+ a = [Permutation(p) for p in a + [[1, 2, 3, 4, 5, 0]]]
320
+ g = Permutation([1, 2, 3, 4, 5, 0])
321
+ G1, G2, G3 = [PermutationGroup(x) for x in [a[:2], a[2:4], [g, g**2]]]
322
+ assert G1.order() == G2.order() == G3.order() == 6
323
+ assert G1.is_subgroup(G2)
324
+ assert not G1.is_subgroup(G3)
325
+ G4 = PermutationGroup([Permutation([0, 1])])
326
+ assert not G1.is_subgroup(G4)
327
+ assert G4.is_subgroup(G1, 0)
328
+ assert PermutationGroup(g, g).is_subgroup(PermutationGroup(g))
329
+ assert SymmetricGroup(3).is_subgroup(SymmetricGroup(4), 0)
330
+ assert SymmetricGroup(3).is_subgroup(SymmetricGroup(3)*CyclicGroup(5), 0)
331
+ assert not CyclicGroup(5).is_subgroup(SymmetricGroup(3)*CyclicGroup(5), 0)
332
+ assert CyclicGroup(3).is_subgroup(SymmetricGroup(3)*CyclicGroup(5), 0)
333
+
334
+
335
+ def test_derived_subgroup():
336
+ a = Permutation([1, 0, 2, 4, 3])
337
+ b = Permutation([0, 1, 3, 2, 4])
338
+ G = PermutationGroup([a, b])
339
+ C = G.derived_subgroup()
340
+ assert C.order() == 3
341
+ assert C.is_normal(G)
342
+ assert C.is_subgroup(G, 0)
343
+ assert not G.is_subgroup(C, 0)
344
+ gens_cube = [[1, 3, 5, 7, 0, 2, 4, 6], [1, 3, 0, 2, 5, 7, 4, 6]]
345
+ gens = [Permutation(p) for p in gens_cube]
346
+ G = PermutationGroup(gens)
347
+ C = G.derived_subgroup()
348
+ assert C.order() == 12
349
+
350
+
351
+ def test_is_solvable():
352
+ a = Permutation([1, 2, 0])
353
+ b = Permutation([1, 0, 2])
354
+ G = PermutationGroup([a, b])
355
+ assert G.is_solvable
356
+ G = PermutationGroup([a])
357
+ assert G.is_solvable
358
+ a = Permutation([1, 2, 3, 4, 0])
359
+ b = Permutation([1, 0, 2, 3, 4])
360
+ G = PermutationGroup([a, b])
361
+ assert not G.is_solvable
362
+ P = SymmetricGroup(10)
363
+ S = P.sylow_subgroup(3)
364
+ assert S.is_solvable
365
+
366
+ def test_rubik1():
367
+ gens = rubik_cube_generators()
368
+ gens1 = [gens[-1]] + [p**2 for p in gens[1:]]
369
+ G1 = PermutationGroup(gens1)
370
+ assert G1.order() == 19508428800
371
+ gens2 = [p**2 for p in gens]
372
+ G2 = PermutationGroup(gens2)
373
+ assert G2.order() == 663552
374
+ assert G2.is_subgroup(G1, 0)
375
+ C1 = G1.derived_subgroup()
376
+ assert C1.order() == 4877107200
377
+ assert C1.is_subgroup(G1, 0)
378
+ assert not G2.is_subgroup(C1, 0)
379
+
380
+ G = RubikGroup(2)
381
+ assert G.order() == 3674160
382
+
383
+
384
+ @XFAIL
385
+ def test_rubik():
386
+ skip('takes too much time')
387
+ G = PermutationGroup(rubik_cube_generators())
388
+ assert G.order() == 43252003274489856000
389
+ G1 = PermutationGroup(G[:3])
390
+ assert G1.order() == 170659735142400
391
+ assert not G1.is_normal(G)
392
+ G2 = G.normal_closure(G1.generators)
393
+ assert G2.is_subgroup(G)
394
+
395
+
396
+ def test_direct_product():
397
+ C = CyclicGroup(4)
398
+ D = DihedralGroup(4)
399
+ G = C*C*C
400
+ assert G.order() == 64
401
+ assert G.degree == 12
402
+ assert len(G.orbits()) == 3
403
+ assert G.is_abelian is True
404
+ H = D*C
405
+ assert H.order() == 32
406
+ assert H.is_abelian is False
407
+
408
+
409
+ def test_orbit_rep():
410
+ G = DihedralGroup(6)
411
+ assert G.orbit_rep(1, 3) in [Permutation([2, 3, 4, 5, 0, 1]),
412
+ Permutation([4, 3, 2, 1, 0, 5])]
413
+ H = CyclicGroup(4)*G
414
+ assert H.orbit_rep(1, 5) is False
415
+
416
+
417
+ def test_schreier_vector():
418
+ G = CyclicGroup(50)
419
+ v = [0]*50
420
+ v[23] = -1
421
+ assert G.schreier_vector(23) == v
422
+ H = DihedralGroup(8)
423
+ assert H.schreier_vector(2) == [0, 1, -1, 0, 0, 1, 0, 0]
424
+ L = SymmetricGroup(4)
425
+ assert L.schreier_vector(1) == [1, -1, 0, 0]
426
+
427
+
428
+ def test_random_pr():
429
+ D = DihedralGroup(6)
430
+ r = 11
431
+ n = 3
432
+ _random_prec_n = {}
433
+ _random_prec_n[0] = {'s': 7, 't': 3, 'x': 2, 'e': -1}
434
+ _random_prec_n[1] = {'s': 5, 't': 5, 'x': 1, 'e': -1}
435
+ _random_prec_n[2] = {'s': 3, 't': 4, 'x': 2, 'e': 1}
436
+ D._random_pr_init(r, n, _random_prec_n=_random_prec_n)
437
+ assert D._random_gens[11] == [0, 1, 2, 3, 4, 5]
438
+ _random_prec = {'s': 2, 't': 9, 'x': 1, 'e': -1}
439
+ assert D.random_pr(_random_prec=_random_prec) == \
440
+ Permutation([0, 5, 4, 3, 2, 1])
441
+
442
+
443
+ def test_is_alt_sym():
444
+ G = DihedralGroup(10)
445
+ assert G.is_alt_sym() is False
446
+ assert G._eval_is_alt_sym_naive() is False
447
+ assert G._eval_is_alt_sym_naive(only_alt=True) is False
448
+ assert G._eval_is_alt_sym_naive(only_sym=True) is False
449
+
450
+ S = SymmetricGroup(10)
451
+ assert S._eval_is_alt_sym_naive() is True
452
+ assert S._eval_is_alt_sym_naive(only_alt=True) is False
453
+ assert S._eval_is_alt_sym_naive(only_sym=True) is True
454
+
455
+ N_eps = 10
456
+ _random_prec = {'N_eps': N_eps,
457
+ 0: Permutation([[2], [1, 4], [0, 6, 7, 8, 9, 3, 5]]),
458
+ 1: Permutation([[1, 8, 7, 6, 3, 5, 2, 9], [0, 4]]),
459
+ 2: Permutation([[5, 8], [4, 7], [0, 1, 2, 3, 6, 9]]),
460
+ 3: Permutation([[3], [0, 8, 2, 7, 4, 1, 6, 9, 5]]),
461
+ 4: Permutation([[8], [4, 7, 9], [3, 6], [0, 5, 1, 2]]),
462
+ 5: Permutation([[6], [0, 2, 4, 5, 1, 8, 3, 9, 7]]),
463
+ 6: Permutation([[6, 9, 8], [4, 5], [1, 3, 7], [0, 2]]),
464
+ 7: Permutation([[4], [0, 2, 9, 1, 3, 8, 6, 5, 7]]),
465
+ 8: Permutation([[1, 5, 6, 3], [0, 2, 7, 8, 4, 9]]),
466
+ 9: Permutation([[8], [6, 7], [2, 3, 4, 5], [0, 1, 9]])}
467
+ assert S.is_alt_sym(_random_prec=_random_prec) is True
468
+
469
+ A = AlternatingGroup(10)
470
+ assert A._eval_is_alt_sym_naive() is True
471
+ assert A._eval_is_alt_sym_naive(only_alt=True) is True
472
+ assert A._eval_is_alt_sym_naive(only_sym=True) is False
473
+
474
+ _random_prec = {'N_eps': N_eps,
475
+ 0: Permutation([[1, 6, 4, 2, 7, 8, 5, 9, 3], [0]]),
476
+ 1: Permutation([[1], [0, 5, 8, 4, 9, 2, 3, 6, 7]]),
477
+ 2: Permutation([[1, 9, 8, 3, 2, 5], [0, 6, 7, 4]]),
478
+ 3: Permutation([[6, 8, 9], [4, 5], [1, 3, 7, 2], [0]]),
479
+ 4: Permutation([[8], [5], [4], [2, 6, 9, 3], [1], [0, 7]]),
480
+ 5: Permutation([[3, 6], [0, 8, 1, 7, 5, 9, 4, 2]]),
481
+ 6: Permutation([[5], [2, 9], [1, 8, 3], [0, 4, 7, 6]]),
482
+ 7: Permutation([[1, 8, 4, 7, 2, 3], [0, 6, 9, 5]]),
483
+ 8: Permutation([[5, 8, 7], [3], [1, 4, 2, 6], [0, 9]]),
484
+ 9: Permutation([[4, 9, 6], [3, 8], [1, 2], [0, 5, 7]])}
485
+ assert A.is_alt_sym(_random_prec=_random_prec) is False
486
+
487
+ G = PermutationGroup(
488
+ Permutation(1, 3, size=8)(0, 2, 4, 6),
489
+ Permutation(5, 7, size=8)(0, 2, 4, 6))
490
+ assert G.is_alt_sym() is False
491
+
492
+ # Tests for monte-carlo c_n parameter setting, and which guarantees
493
+ # to give False.
494
+ G = DihedralGroup(10)
495
+ assert G._eval_is_alt_sym_monte_carlo() is False
496
+ G = DihedralGroup(20)
497
+ assert G._eval_is_alt_sym_monte_carlo() is False
498
+
499
+ # A dry-running test to check if it looks up for the updated cache.
500
+ G = DihedralGroup(6)
501
+ G.is_alt_sym()
502
+ assert G.is_alt_sym() is False
503
+
504
+
505
+ def test_minimal_block():
506
+ D = DihedralGroup(6)
507
+ block_system = D.minimal_block([0, 3])
508
+ for i in range(3):
509
+ assert block_system[i] == block_system[i + 3]
510
+ S = SymmetricGroup(6)
511
+ assert S.minimal_block([0, 1]) == [0, 0, 0, 0, 0, 0]
512
+
513
+ assert Tetra.pgroup.minimal_block([0, 1]) == [0, 0, 0, 0]
514
+
515
+ P1 = PermutationGroup(Permutation(1, 5)(2, 4), Permutation(0, 1, 2, 3, 4, 5))
516
+ P2 = PermutationGroup(Permutation(0, 1, 2, 3, 4, 5), Permutation(1, 5)(2, 4))
517
+ assert P1.minimal_block([0, 2]) == [0, 1, 0, 1, 0, 1]
518
+ assert P2.minimal_block([0, 2]) == [0, 1, 0, 1, 0, 1]
519
+
520
+
521
+ def test_minimal_blocks():
522
+ P = PermutationGroup(Permutation(1, 5)(2, 4), Permutation(0, 1, 2, 3, 4, 5))
523
+ assert P.minimal_blocks() == [[0, 1, 0, 1, 0, 1], [0, 1, 2, 0, 1, 2]]
524
+
525
+ P = SymmetricGroup(5)
526
+ assert P.minimal_blocks() == [[0]*5]
527
+
528
+ P = PermutationGroup(Permutation(0, 3))
529
+ assert P.minimal_blocks() is False
530
+
531
+
532
+ def test_max_div():
533
+ S = SymmetricGroup(10)
534
+ assert S.max_div == 5
535
+
536
+
537
+ def test_is_primitive():
538
+ S = SymmetricGroup(5)
539
+ assert S.is_primitive() is True
540
+ C = CyclicGroup(7)
541
+ assert C.is_primitive() is True
542
+
543
+ a = Permutation(0, 1, 2, size=6)
544
+ b = Permutation(3, 4, 5, size=6)
545
+ G = PermutationGroup(a, b)
546
+ assert G.is_primitive() is False
547
+
548
+
549
+ def test_random_stab():
550
+ S = SymmetricGroup(5)
551
+ _random_el = Permutation([1, 3, 2, 0, 4])
552
+ _random_prec = {'rand': _random_el}
553
+ g = S.random_stab(2, _random_prec=_random_prec)
554
+ assert g == Permutation([1, 3, 2, 0, 4])
555
+ h = S.random_stab(1)
556
+ assert h(1) == 1
557
+
558
+
559
+ def test_transitivity_degree():
560
+ perm = Permutation([1, 2, 0])
561
+ C = PermutationGroup([perm])
562
+ assert C.transitivity_degree == 1
563
+ gen1 = Permutation([1, 2, 0, 3, 4])
564
+ gen2 = Permutation([1, 2, 3, 4, 0])
565
+ # alternating group of degree 5
566
+ Alt = PermutationGroup([gen1, gen2])
567
+ assert Alt.transitivity_degree == 3
568
+
569
+
570
+ def test_schreier_sims_random():
571
+ assert sorted(Tetra.pgroup.base) == [0, 1]
572
+
573
+ S = SymmetricGroup(3)
574
+ base = [0, 1]
575
+ strong_gens = [Permutation([1, 2, 0]), Permutation([1, 0, 2]),
576
+ Permutation([0, 2, 1])]
577
+ assert S.schreier_sims_random(base, strong_gens, 5) == (base, strong_gens)
578
+ D = DihedralGroup(3)
579
+ _random_prec = {'g': [Permutation([2, 0, 1]), Permutation([1, 2, 0]),
580
+ Permutation([1, 0, 2])]}
581
+ base = [0, 1]
582
+ strong_gens = [Permutation([1, 2, 0]), Permutation([2, 1, 0]),
583
+ Permutation([0, 2, 1])]
584
+ assert D.schreier_sims_random([], D.generators, 2,
585
+ _random_prec=_random_prec) == (base, strong_gens)
586
+
587
+
588
+ def test_baseswap():
589
+ S = SymmetricGroup(4)
590
+ S.schreier_sims()
591
+ base = S.base
592
+ strong_gens = S.strong_gens
593
+ assert base == [0, 1, 2]
594
+ deterministic = S.baseswap(base, strong_gens, 1, randomized=False)
595
+ randomized = S.baseswap(base, strong_gens, 1)
596
+ assert deterministic[0] == [0, 2, 1]
597
+ assert _verify_bsgs(S, deterministic[0], deterministic[1]) is True
598
+ assert randomized[0] == [0, 2, 1]
599
+ assert _verify_bsgs(S, randomized[0], randomized[1]) is True
600
+
601
+
602
+ def test_schreier_sims_incremental():
603
+ identity = Permutation([0, 1, 2, 3, 4])
604
+ TrivialGroup = PermutationGroup([identity])
605
+ base, strong_gens = TrivialGroup.schreier_sims_incremental(base=[0, 1, 2])
606
+ assert _verify_bsgs(TrivialGroup, base, strong_gens) is True
607
+ S = SymmetricGroup(5)
608
+ base, strong_gens = S.schreier_sims_incremental(base=[0, 1, 2])
609
+ assert _verify_bsgs(S, base, strong_gens) is True
610
+ D = DihedralGroup(2)
611
+ base, strong_gens = D.schreier_sims_incremental(base=[1])
612
+ assert _verify_bsgs(D, base, strong_gens) is True
613
+ A = AlternatingGroup(7)
614
+ gens = A.generators[:]
615
+ gen0 = gens[0]
616
+ gen1 = gens[1]
617
+ gen1 = rmul(gen1, ~gen0)
618
+ gen0 = rmul(gen0, gen1)
619
+ gen1 = rmul(gen0, gen1)
620
+ base, strong_gens = A.schreier_sims_incremental(base=[0, 1], gens=gens)
621
+ assert _verify_bsgs(A, base, strong_gens) is True
622
+ C = CyclicGroup(11)
623
+ gen = C.generators[0]
624
+ base, strong_gens = C.schreier_sims_incremental(gens=[gen**3])
625
+ assert _verify_bsgs(C, base, strong_gens) is True
626
+
627
+
628
+ def _subgroup_search(i, j, k):
629
+ prop_true = lambda x: True
630
+ prop_fix_points = lambda x: [x(point) for point in points] == points
631
+ prop_comm_g = lambda x: rmul(x, g) == rmul(g, x)
632
+ prop_even = lambda x: x.is_even
633
+ for i in range(i, j, k):
634
+ S = SymmetricGroup(i)
635
+ A = AlternatingGroup(i)
636
+ C = CyclicGroup(i)
637
+ Sym = S.subgroup_search(prop_true)
638
+ assert Sym.is_subgroup(S)
639
+ Alt = S.subgroup_search(prop_even)
640
+ assert Alt.is_subgroup(A)
641
+ Sym = S.subgroup_search(prop_true, init_subgroup=C)
642
+ assert Sym.is_subgroup(S)
643
+ points = [7]
644
+ assert S.stabilizer(7).is_subgroup(S.subgroup_search(prop_fix_points))
645
+ points = [3, 4]
646
+ assert S.stabilizer(3).stabilizer(4).is_subgroup(
647
+ S.subgroup_search(prop_fix_points))
648
+ points = [3, 5]
649
+ fix35 = A.subgroup_search(prop_fix_points)
650
+ points = [5]
651
+ fix5 = A.subgroup_search(prop_fix_points)
652
+ assert A.subgroup_search(prop_fix_points, init_subgroup=fix35
653
+ ).is_subgroup(fix5)
654
+ base, strong_gens = A.schreier_sims_incremental()
655
+ g = A.generators[0]
656
+ comm_g = \
657
+ A.subgroup_search(prop_comm_g, base=base, strong_gens=strong_gens)
658
+ assert _verify_bsgs(comm_g, base, comm_g.generators) is True
659
+ assert [prop_comm_g(gen) is True for gen in comm_g.generators]
660
+
661
+
662
+ def test_subgroup_search():
663
+ _subgroup_search(10, 15, 2)
664
+
665
+
666
+ @XFAIL
667
+ def test_subgroup_search2():
668
+ skip('takes too much time')
669
+ _subgroup_search(16, 17, 1)
670
+
671
+
672
+ def test_normal_closure():
673
+ # the normal closure of the trivial group is trivial
674
+ S = SymmetricGroup(3)
675
+ identity = Permutation([0, 1, 2])
676
+ closure = S.normal_closure(identity)
677
+ assert closure.is_trivial
678
+ # the normal closure of the entire group is the entire group
679
+ A = AlternatingGroup(4)
680
+ assert A.normal_closure(A).is_subgroup(A)
681
+ # brute-force verifications for subgroups
682
+ for i in (3, 4, 5):
683
+ S = SymmetricGroup(i)
684
+ A = AlternatingGroup(i)
685
+ D = DihedralGroup(i)
686
+ C = CyclicGroup(i)
687
+ for gp in (A, D, C):
688
+ assert _verify_normal_closure(S, gp)
689
+ # brute-force verifications for all elements of a group
690
+ S = SymmetricGroup(5)
691
+ elements = list(S.generate_dimino())
692
+ for element in elements:
693
+ assert _verify_normal_closure(S, element)
694
+ # small groups
695
+ small = []
696
+ for i in (1, 2, 3):
697
+ small.append(SymmetricGroup(i))
698
+ small.append(AlternatingGroup(i))
699
+ small.append(DihedralGroup(i))
700
+ small.append(CyclicGroup(i))
701
+ for gp in small:
702
+ for gp2 in small:
703
+ if gp2.is_subgroup(gp, 0) and gp2.degree == gp.degree:
704
+ assert _verify_normal_closure(gp, gp2)
705
+
706
+
707
+ def test_derived_series():
708
+ # the derived series of the trivial group consists only of the trivial group
709
+ triv = PermutationGroup([Permutation([0, 1, 2])])
710
+ assert triv.derived_series()[0].is_subgroup(triv)
711
+ # the derived series for a simple group consists only of the group itself
712
+ for i in (5, 6, 7):
713
+ A = AlternatingGroup(i)
714
+ assert A.derived_series()[0].is_subgroup(A)
715
+ # the derived series for S_4 is S_4 > A_4 > K_4 > triv
716
+ S = SymmetricGroup(4)
717
+ series = S.derived_series()
718
+ assert series[1].is_subgroup(AlternatingGroup(4))
719
+ assert series[2].is_subgroup(DihedralGroup(2))
720
+ assert series[3].is_trivial
721
+
722
+
723
+ def test_lower_central_series():
724
+ # the lower central series of the trivial group consists of the trivial
725
+ # group
726
+ triv = PermutationGroup([Permutation([0, 1, 2])])
727
+ assert triv.lower_central_series()[0].is_subgroup(triv)
728
+ # the lower central series of a simple group consists of the group itself
729
+ for i in (5, 6, 7):
730
+ A = AlternatingGroup(i)
731
+ assert A.lower_central_series()[0].is_subgroup(A)
732
+ # GAP-verified example
733
+ S = SymmetricGroup(6)
734
+ series = S.lower_central_series()
735
+ assert len(series) == 2
736
+ assert series[1].is_subgroup(AlternatingGroup(6))
737
+
738
+
739
+ def test_commutator():
740
+ # the commutator of the trivial group and the trivial group is trivial
741
+ S = SymmetricGroup(3)
742
+ triv = PermutationGroup([Permutation([0, 1, 2])])
743
+ assert S.commutator(triv, triv).is_subgroup(triv)
744
+ # the commutator of the trivial group and any other group is again trivial
745
+ A = AlternatingGroup(3)
746
+ assert S.commutator(triv, A).is_subgroup(triv)
747
+ # the commutator is commutative
748
+ for i in (3, 4, 5):
749
+ S = SymmetricGroup(i)
750
+ A = AlternatingGroup(i)
751
+ D = DihedralGroup(i)
752
+ assert S.commutator(A, D).is_subgroup(S.commutator(D, A))
753
+ # the commutator of an abelian group is trivial
754
+ S = SymmetricGroup(7)
755
+ A1 = AbelianGroup(2, 5)
756
+ A2 = AbelianGroup(3, 4)
757
+ triv = PermutationGroup([Permutation([0, 1, 2, 3, 4, 5, 6])])
758
+ assert S.commutator(A1, A1).is_subgroup(triv)
759
+ assert S.commutator(A2, A2).is_subgroup(triv)
760
+ # examples calculated by hand
761
+ S = SymmetricGroup(3)
762
+ A = AlternatingGroup(3)
763
+ assert S.commutator(A, S).is_subgroup(A)
764
+
765
+
766
+ def test_is_nilpotent():
767
+ # every abelian group is nilpotent
768
+ for i in (1, 2, 3):
769
+ C = CyclicGroup(i)
770
+ Ab = AbelianGroup(i, i + 2)
771
+ assert C.is_nilpotent
772
+ assert Ab.is_nilpotent
773
+ Ab = AbelianGroup(5, 7, 10)
774
+ assert Ab.is_nilpotent
775
+ # A_5 is not solvable and thus not nilpotent
776
+ assert AlternatingGroup(5).is_nilpotent is False
777
+
778
+
779
+ def test_is_trivial():
780
+ for i in range(5):
781
+ triv = PermutationGroup([Permutation(list(range(i)))])
782
+ assert triv.is_trivial
783
+
784
+
785
+ def test_pointwise_stabilizer():
786
+ S = SymmetricGroup(2)
787
+ stab = S.pointwise_stabilizer([0])
788
+ assert stab.generators == [Permutation(1)]
789
+ S = SymmetricGroup(5)
790
+ points = []
791
+ stab = S
792
+ for point in (2, 0, 3, 4, 1):
793
+ stab = stab.stabilizer(point)
794
+ points.append(point)
795
+ assert S.pointwise_stabilizer(points).is_subgroup(stab)
796
+
797
+
798
+ def test_make_perm():
799
+ assert cube.pgroup.make_perm(5, seed=list(range(5))) == \
800
+ Permutation([4, 7, 6, 5, 0, 3, 2, 1])
801
+ assert cube.pgroup.make_perm(7, seed=list(range(7))) == \
802
+ Permutation([6, 7, 3, 2, 5, 4, 0, 1])
803
+
804
+
805
+ def test_elements():
806
+ from sympy.sets.sets import FiniteSet
807
+
808
+ p = Permutation(2, 3)
809
+ assert set(PermutationGroup(p).elements) == {Permutation(3), Permutation(2, 3)}
810
+ assert FiniteSet(*PermutationGroup(p).elements) \
811
+ == FiniteSet(Permutation(2, 3), Permutation(3))
812
+
813
+
814
+ def test_is_group():
815
+ assert PermutationGroup(Permutation(1,2), Permutation(2,4)).is_group is True
816
+ assert SymmetricGroup(4).is_group is True
817
+
818
+
819
+ def test_PermutationGroup():
820
+ assert PermutationGroup() == PermutationGroup(Permutation())
821
+ assert (PermutationGroup() == 0) is False
822
+
823
+
824
+ def test_coset_transvesal():
825
+ G = AlternatingGroup(5)
826
+ H = PermutationGroup(Permutation(0,1,2),Permutation(1,2)(3,4))
827
+ assert G.coset_transversal(H) == \
828
+ [Permutation(4), Permutation(2, 3, 4), Permutation(2, 4, 3),
829
+ Permutation(1, 2, 4), Permutation(4)(1, 2, 3), Permutation(1, 3)(2, 4),
830
+ Permutation(0, 1, 2, 3, 4), Permutation(0, 1, 2, 4, 3),
831
+ Permutation(0, 1, 3, 2, 4), Permutation(0, 2, 4, 1, 3)]
832
+
833
+
834
+ def test_coset_table():
835
+ G = PermutationGroup(Permutation(0,1,2,3), Permutation(0,1,2),
836
+ Permutation(0,4,2,7), Permutation(5,6), Permutation(0,7));
837
+ H = PermutationGroup(Permutation(0,1,2,3), Permutation(0,7))
838
+ assert G.coset_table(H) == \
839
+ [[0, 0, 0, 0, 1, 2, 3, 3, 0, 0], [4, 5, 2, 5, 6, 0, 7, 7, 1, 1],
840
+ [5, 4, 5, 1, 0, 6, 8, 8, 6, 6], [3, 3, 3, 3, 7, 8, 0, 0, 3, 3],
841
+ [2, 1, 4, 4, 4, 4, 9, 9, 4, 4], [1, 2, 1, 2, 5, 5, 10, 10, 5, 5],
842
+ [6, 6, 6, 6, 2, 1, 11, 11, 2, 2], [9, 10, 8, 10, 11, 3, 1, 1, 7, 7],
843
+ [10, 9, 10, 7, 3, 11, 2, 2, 11, 11], [8, 7, 9, 9, 9, 9, 4, 4, 9, 9],
844
+ [7, 8, 7, 8, 10, 10, 5, 5, 10, 10], [11, 11, 11, 11, 8, 7, 6, 6, 8, 8]]
845
+
846
+
847
+ def test_subgroup():
848
+ G = PermutationGroup(Permutation(0,1,2), Permutation(0,2,3))
849
+ H = G.subgroup([Permutation(0,1,3)])
850
+ assert H.is_subgroup(G)
851
+
852
+
853
+ def test_generator_product():
854
+ G = SymmetricGroup(5)
855
+ p = Permutation(0, 2, 3)(1, 4)
856
+ gens = G.generator_product(p)
857
+ assert all(g in G.strong_gens for g in gens)
858
+ w = G.identity
859
+ for g in gens:
860
+ w = g*w
861
+ assert w == p
862
+
863
+
864
+ def test_sylow_subgroup():
865
+ P = PermutationGroup(Permutation(1, 5)(2, 4), Permutation(0, 1, 2, 3, 4, 5))
866
+ S = P.sylow_subgroup(2)
867
+ assert S.order() == 4
868
+
869
+ P = DihedralGroup(12)
870
+ S = P.sylow_subgroup(3)
871
+ assert S.order() == 3
872
+
873
+ P = PermutationGroup(
874
+ Permutation(1, 5)(2, 4), Permutation(0, 1, 2, 3, 4, 5), Permutation(0, 2))
875
+ S = P.sylow_subgroup(3)
876
+ assert S.order() == 9
877
+ S = P.sylow_subgroup(2)
878
+ assert S.order() == 8
879
+
880
+ P = SymmetricGroup(10)
881
+ S = P.sylow_subgroup(2)
882
+ assert S.order() == 256
883
+ S = P.sylow_subgroup(3)
884
+ assert S.order() == 81
885
+ S = P.sylow_subgroup(5)
886
+ assert S.order() == 25
887
+
888
+ # the length of the lower central series
889
+ # of a p-Sylow subgroup of Sym(n) grows with
890
+ # the highest exponent exp of p such
891
+ # that n >= p**exp
892
+ exp = 1
893
+ length = 0
894
+ for i in range(2, 9):
895
+ P = SymmetricGroup(i)
896
+ S = P.sylow_subgroup(2)
897
+ ls = S.lower_central_series()
898
+ if i // 2**exp > 0:
899
+ # length increases with exponent
900
+ assert len(ls) > length
901
+ length = len(ls)
902
+ exp += 1
903
+ else:
904
+ assert len(ls) == length
905
+
906
+ G = SymmetricGroup(100)
907
+ S = G.sylow_subgroup(3)
908
+ assert G.order() % S.order() == 0
909
+ assert G.order()/S.order() % 3 > 0
910
+
911
+ G = AlternatingGroup(100)
912
+ S = G.sylow_subgroup(2)
913
+ assert G.order() % S.order() == 0
914
+ assert G.order()/S.order() % 2 > 0
915
+
916
+ G = DihedralGroup(18)
917
+ S = G.sylow_subgroup(p=2)
918
+ assert S.order() == 4
919
+
920
+ G = DihedralGroup(50)
921
+ S = G.sylow_subgroup(p=2)
922
+ assert S.order() == 4
923
+
924
+
925
+ @slow
926
+ def test_presentation():
927
+ def _test(P):
928
+ G = P.presentation()
929
+ return G.order() == P.order()
930
+
931
+ def _strong_test(P):
932
+ G = P.strong_presentation()
933
+ chk = len(G.generators) == len(P.strong_gens)
934
+ return chk and G.order() == P.order()
935
+
936
+ P = PermutationGroup(Permutation(0,1,5,2)(3,7,4,6), Permutation(0,3,5,4)(1,6,2,7))
937
+ assert _test(P)
938
+
939
+ P = AlternatingGroup(5)
940
+ assert _test(P)
941
+
942
+ P = SymmetricGroup(5)
943
+ assert _test(P)
944
+
945
+ P = PermutationGroup(
946
+ [Permutation(0,3,1,2), Permutation(3)(0,1), Permutation(0,1)(2,3)])
947
+ assert _strong_test(P)
948
+
949
+ P = DihedralGroup(6)
950
+ assert _strong_test(P)
951
+
952
+ a = Permutation(0,1)(2,3)
953
+ b = Permutation(0,2)(3,1)
954
+ c = Permutation(4,5)
955
+ P = PermutationGroup(c, a, b)
956
+ assert _strong_test(P)
957
+
958
+
959
+ def test_polycyclic():
960
+ a = Permutation([0, 1, 2])
961
+ b = Permutation([2, 1, 0])
962
+ G = PermutationGroup([a, b])
963
+ assert G.is_polycyclic is True
964
+
965
+ a = Permutation([1, 2, 3, 4, 0])
966
+ b = Permutation([1, 0, 2, 3, 4])
967
+ G = PermutationGroup([a, b])
968
+ assert G.is_polycyclic is False
969
+
970
+
971
+ def test_elementary():
972
+ a = Permutation([1, 5, 2, 0, 3, 6, 4])
973
+ G = PermutationGroup([a])
974
+ assert G.is_elementary(7) is False
975
+
976
+ a = Permutation(0, 1)(2, 3)
977
+ b = Permutation(0, 2)(3, 1)
978
+ G = PermutationGroup([a, b])
979
+ assert G.is_elementary(2) is True
980
+ c = Permutation(4, 5, 6)
981
+ G = PermutationGroup([a, b, c])
982
+ assert G.is_elementary(2) is False
983
+
984
+ G = SymmetricGroup(4).sylow_subgroup(2)
985
+ assert G.is_elementary(2) is False
986
+ H = AlternatingGroup(4).sylow_subgroup(2)
987
+ assert H.is_elementary(2) is True
988
+
989
+
990
+ def test_perfect():
991
+ G = AlternatingGroup(3)
992
+ assert G.is_perfect is False
993
+ G = AlternatingGroup(5)
994
+ assert G.is_perfect is True
995
+
996
+
997
+ def test_index():
998
+ G = PermutationGroup(Permutation(0,1,2), Permutation(0,2,3))
999
+ H = G.subgroup([Permutation(0,1,3)])
1000
+ assert G.index(H) == 4
1001
+
1002
+
1003
+ def test_cyclic():
1004
+ G = SymmetricGroup(2)
1005
+ assert G.is_cyclic
1006
+ G = AbelianGroup(3, 7)
1007
+ assert G.is_cyclic
1008
+ G = AbelianGroup(7, 7)
1009
+ assert not G.is_cyclic
1010
+ G = AlternatingGroup(3)
1011
+ assert G.is_cyclic
1012
+ G = AlternatingGroup(4)
1013
+ assert not G.is_cyclic
1014
+
1015
+ # Order less than 6
1016
+ G = PermutationGroup(Permutation(0, 1, 2), Permutation(0, 2, 1))
1017
+ assert G.is_cyclic
1018
+ G = PermutationGroup(
1019
+ Permutation(0, 1, 2, 3),
1020
+ Permutation(0, 2)(1, 3)
1021
+ )
1022
+ assert G.is_cyclic
1023
+ G = PermutationGroup(
1024
+ Permutation(3),
1025
+ Permutation(0, 1)(2, 3),
1026
+ Permutation(0, 2)(1, 3),
1027
+ Permutation(0, 3)(1, 2)
1028
+ )
1029
+ assert G.is_cyclic is False
1030
+
1031
+ # Order 15
1032
+ G = PermutationGroup(
1033
+ Permutation(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14),
1034
+ Permutation(0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13)
1035
+ )
1036
+ assert G.is_cyclic
1037
+
1038
+ # Distinct prime orders
1039
+ assert PermutationGroup._distinct_primes_lemma([3, 5]) is True
1040
+ assert PermutationGroup._distinct_primes_lemma([5, 7]) is True
1041
+ assert PermutationGroup._distinct_primes_lemma([2, 3]) is None
1042
+ assert PermutationGroup._distinct_primes_lemma([3, 5, 7]) is None
1043
+ assert PermutationGroup._distinct_primes_lemma([5, 7, 13]) is True
1044
+
1045
+ G = PermutationGroup(
1046
+ Permutation(0, 1, 2, 3),
1047
+ Permutation(0, 2)(1, 3))
1048
+ assert G.is_cyclic
1049
+ assert G._is_abelian
1050
+
1051
+ # Non-abelian and therefore not cyclic
1052
+ G = PermutationGroup(*SymmetricGroup(3).generators)
1053
+ assert G.is_cyclic is False
1054
+
1055
+ # Abelian and cyclic
1056
+ G = PermutationGroup(
1057
+ Permutation(0, 1, 2, 3),
1058
+ Permutation(4, 5, 6)
1059
+ )
1060
+ assert G.is_cyclic
1061
+
1062
+ # Abelian but not cyclic
1063
+ G = PermutationGroup(
1064
+ Permutation(0, 1),
1065
+ Permutation(2, 3),
1066
+ Permutation(4, 5, 6)
1067
+ )
1068
+ assert G.is_cyclic is False
1069
+
1070
+
1071
+ def test_dihedral():
1072
+ G = SymmetricGroup(2)
1073
+ assert G.is_dihedral
1074
+ G = SymmetricGroup(3)
1075
+ assert G.is_dihedral
1076
+
1077
+ G = AbelianGroup(2, 2)
1078
+ assert G.is_dihedral
1079
+ G = CyclicGroup(4)
1080
+ assert not G.is_dihedral
1081
+
1082
+ G = AbelianGroup(3, 5)
1083
+ assert not G.is_dihedral
1084
+ G = AbelianGroup(2)
1085
+ assert G.is_dihedral
1086
+ G = AbelianGroup(6)
1087
+ assert not G.is_dihedral
1088
+
1089
+ # D6, generated by two adjacent flips
1090
+ G = PermutationGroup(
1091
+ Permutation(1, 5)(2, 4),
1092
+ Permutation(0, 1)(3, 4)(2, 5))
1093
+ assert G.is_dihedral
1094
+
1095
+ # D7, generated by a flip and a rotation
1096
+ G = PermutationGroup(
1097
+ Permutation(1, 6)(2, 5)(3, 4),
1098
+ Permutation(0, 1, 2, 3, 4, 5, 6))
1099
+ assert G.is_dihedral
1100
+
1101
+ # S4, presented by three generators, fails due to having exactly 9
1102
+ # elements of order 2:
1103
+ G = PermutationGroup(
1104
+ Permutation(0, 1), Permutation(0, 2),
1105
+ Permutation(0, 3))
1106
+ assert not G.is_dihedral
1107
+
1108
+ # D7, given by three generators
1109
+ G = PermutationGroup(
1110
+ Permutation(1, 6)(2, 5)(3, 4),
1111
+ Permutation(2, 0)(3, 6)(4, 5),
1112
+ Permutation(0, 1, 2, 3, 4, 5, 6))
1113
+ assert G.is_dihedral
1114
+
1115
+
1116
+ def test_abelian_invariants():
1117
+ G = AbelianGroup(2, 3, 4)
1118
+ assert G.abelian_invariants() == [2, 3, 4]
1119
+ G=PermutationGroup([Permutation(1, 2, 3, 4), Permutation(1, 2), Permutation(5, 6)])
1120
+ assert G.abelian_invariants() == [2, 2]
1121
+ G = AlternatingGroup(7)
1122
+ assert G.abelian_invariants() == []
1123
+ G = AlternatingGroup(4)
1124
+ assert G.abelian_invariants() == [3]
1125
+ G = DihedralGroup(4)
1126
+ assert G.abelian_invariants() == [2, 2]
1127
+
1128
+ G = PermutationGroup([Permutation(1, 2, 3, 4, 5, 6, 7)])
1129
+ assert G.abelian_invariants() == [7]
1130
+ G = DihedralGroup(12)
1131
+ S = G.sylow_subgroup(3)
1132
+ assert S.abelian_invariants() == [3]
1133
+ G = PermutationGroup(Permutation(0, 1, 2), Permutation(0, 2, 3))
1134
+ assert G.abelian_invariants() == [3]
1135
+ G = PermutationGroup([Permutation(0, 1), Permutation(0, 2, 4, 6)(1, 3, 5, 7)])
1136
+ assert G.abelian_invariants() == [2, 4]
1137
+ G = SymmetricGroup(30)
1138
+ S = G.sylow_subgroup(2)
1139
+ assert S.abelian_invariants() == [2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
1140
+ S = G.sylow_subgroup(3)
1141
+ assert S.abelian_invariants() == [3, 3, 3, 3]
1142
+ S = G.sylow_subgroup(5)
1143
+ assert S.abelian_invariants() == [5, 5, 5]
1144
+
1145
+
1146
+ def test_composition_series():
1147
+ a = Permutation(1, 2, 3)
1148
+ b = Permutation(1, 2)
1149
+ G = PermutationGroup([a, b])
1150
+ comp_series = G.composition_series()
1151
+ assert comp_series == G.derived_series()
1152
+ # The first group in the composition series is always the group itself and
1153
+ # the last group in the series is the trivial group.
1154
+ S = SymmetricGroup(4)
1155
+ assert S.composition_series()[0] == S
1156
+ assert len(S.composition_series()) == 5
1157
+ A = AlternatingGroup(4)
1158
+ assert A.composition_series()[0] == A
1159
+ assert len(A.composition_series()) == 4
1160
+
1161
+ # the composition series for C_8 is C_8 > C_4 > C_2 > triv
1162
+ G = CyclicGroup(8)
1163
+ series = G.composition_series()
1164
+ assert is_isomorphic(series[1], CyclicGroup(4))
1165
+ assert is_isomorphic(series[2], CyclicGroup(2))
1166
+ assert series[3].is_trivial
1167
+
1168
+
1169
+ def test_is_symmetric():
1170
+ a = Permutation(0, 1, 2)
1171
+ b = Permutation(0, 1, size=3)
1172
+ assert PermutationGroup(a, b).is_symmetric is True
1173
+
1174
+ a = Permutation(0, 2, 1)
1175
+ b = Permutation(1, 2, size=3)
1176
+ assert PermutationGroup(a, b).is_symmetric is True
1177
+
1178
+ a = Permutation(0, 1, 2, 3)
1179
+ b = Permutation(0, 3)(1, 2)
1180
+ assert PermutationGroup(a, b).is_symmetric is False
1181
+
1182
+ def test_conjugacy_class():
1183
+ S = SymmetricGroup(4)
1184
+ x = Permutation(1, 2, 3)
1185
+ C = {Permutation(0, 1, 2, size = 4), Permutation(0, 1, 3),
1186
+ Permutation(0, 2, 1, size = 4), Permutation(0, 2, 3),
1187
+ Permutation(0, 3, 1), Permutation(0, 3, 2),
1188
+ Permutation(1, 2, 3), Permutation(1, 3, 2)}
1189
+ assert S.conjugacy_class(x) == C
1190
+
1191
+ def test_conjugacy_classes():
1192
+ S = SymmetricGroup(3)
1193
+ expected = [{Permutation(size = 3)},
1194
+ {Permutation(0, 1, size = 3), Permutation(0, 2), Permutation(1, 2)},
1195
+ {Permutation(0, 1, 2), Permutation(0, 2, 1)}]
1196
+ computed = S.conjugacy_classes()
1197
+
1198
+ assert len(expected) == len(computed)
1199
+ assert all(e in computed for e in expected)
1200
+
1201
+ def test_coset_class():
1202
+ a = Permutation(1, 2)
1203
+ b = Permutation(0, 1)
1204
+ G = PermutationGroup([a, b])
1205
+ #Creating right coset
1206
+ rht_coset = G*a
1207
+ #Checking whether it is left coset or right coset
1208
+ assert rht_coset.is_right_coset
1209
+ assert not rht_coset.is_left_coset
1210
+ #Creating list representation of coset
1211
+ list_repr = rht_coset.as_list()
1212
+ expected = [Permutation(0, 2), Permutation(0, 2, 1), Permutation(1, 2),
1213
+ Permutation(2), Permutation(2)(0, 1), Permutation(0, 1, 2)]
1214
+ for ele in list_repr:
1215
+ assert ele in expected
1216
+ #Creating left coset
1217
+ left_coset = a*G
1218
+ #Checking whether it is left coset or right coset
1219
+ assert not left_coset.is_right_coset
1220
+ assert left_coset.is_left_coset
1221
+ #Creating list representation of Coset
1222
+ list_repr = left_coset.as_list()
1223
+ expected = [Permutation(2)(0, 1), Permutation(0, 1, 2), Permutation(1, 2),
1224
+ Permutation(2), Permutation(0, 2), Permutation(0, 2, 1)]
1225
+ for ele in list_repr:
1226
+ assert ele in expected
1227
+
1228
+ G = PermutationGroup(Permutation(1, 2, 3, 4), Permutation(2, 3, 4))
1229
+ H = PermutationGroup(Permutation(1, 2, 3, 4))
1230
+ g = Permutation(1, 3)(2, 4)
1231
+ rht_coset = Coset(g, H, G, dir='+')
1232
+ assert rht_coset.is_right_coset
1233
+ list_repr = rht_coset.as_list()
1234
+ expected = [Permutation(1, 2, 3, 4), Permutation(4), Permutation(1, 3)(2, 4),
1235
+ Permutation(1, 4, 3, 2)]
1236
+ for ele in list_repr:
1237
+ assert ele in expected
1238
+
1239
+ def test_symmetricpermutationgroup():
1240
+ a = SymmetricPermutationGroup(5)
1241
+ assert a.degree == 5
1242
+ assert a.order() == 120
1243
+ assert a.identity() == Permutation(4)