Coverage for /usr/lib/python3/dist-packages/sympy/combinatorics/group_constructs.py: 17%
29 statements
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
« prev ^ index » next coverage.py v7.9.1, created at 2025-06-14 15:55 +0200
1from sympy.combinatorics.perm_groups import PermutationGroup
2from sympy.combinatorics.permutations import Permutation
3from sympy.utilities.iterables import uniq
5_af_new = Permutation._af_new
8def DirectProduct(*groups):
9 """
10 Returns the direct product of several groups as a permutation group.
12 Explanation
13 ===========
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).
21 Examples
22 ========
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
31 See Also
32 ========
34 sympy.combinatorics.perm_groups.PermutationGroup.__mul__
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)