group_constructs.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from sympy.combinatorics.perm_groups import PermutationGroup
  2. from sympy.combinatorics.permutations import Permutation
  3. from sympy.utilities.iterables import uniq
  4. _af_new = Permutation._af_new
  5. def DirectProduct(*groups):
  6. """
  7. Returns the direct product of several groups as a permutation group.
  8. Explanation
  9. ===========
  10. This is implemented much like the __mul__ procedure for taking the direct
  11. product of two permutation groups, but the idea of shifting the
  12. generators is realized in the case of an arbitrary number of groups.
  13. A call to DirectProduct(G1, G2, ..., Gn) is generally expected to be faster
  14. than a call to G1*G2*...*Gn (and thus the need for this algorithm).
  15. Examples
  16. ========
  17. >>> from sympy.combinatorics.group_constructs import DirectProduct
  18. >>> from sympy.combinatorics.named_groups import CyclicGroup
  19. >>> C = CyclicGroup(4)
  20. >>> G = DirectProduct(C, C, C)
  21. >>> G.order()
  22. 64
  23. See Also
  24. ========
  25. sympy.combinatorics.perm_groups.PermutationGroup.__mul__
  26. """
  27. degrees = []
  28. gens_count = []
  29. total_degree = 0
  30. total_gens = 0
  31. for group in groups:
  32. current_deg = group.degree
  33. current_num_gens = len(group.generators)
  34. degrees.append(current_deg)
  35. total_degree += current_deg
  36. gens_count.append(current_num_gens)
  37. total_gens += current_num_gens
  38. array_gens = []
  39. for i in range(total_gens):
  40. array_gens.append(list(range(total_degree)))
  41. current_gen = 0
  42. current_deg = 0
  43. for i in range(len(gens_count)):
  44. for j in range(current_gen, current_gen + gens_count[i]):
  45. gen = ((groups[i].generators)[j - current_gen]).array_form
  46. array_gens[j][current_deg:current_deg + degrees[i]] = \
  47. [x + current_deg for x in gen]
  48. current_gen += gens_count[i]
  49. current_deg += degrees[i]
  50. perm_gens = list(uniq([_af_new(list(a)) for a in array_gens]))
  51. return PermutationGroup(perm_gens, dups=False)