m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

109 lines
3.5 KiB

6 months ago
  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. def test_homomorphism():
  9. # FpGroup -> PermutationGroup
  10. F, a, b = free_group("a, b")
  11. G = FpGroup(F, [a**3, b**3, (a*b)**2])
  12. c = Permutation(3)(0, 1, 2)
  13. d = Permutation(3)(1, 2, 3)
  14. A = AlternatingGroup(4)
  15. T = homomorphism(G, A, [a, b], [c, d])
  16. assert T(a*b**2*a**-1) == c*d**2*c**-1
  17. assert T.is_isomorphism()
  18. assert T(T.invert(Permutation(3)(0, 2, 3))) == Permutation(3)(0, 2, 3)
  19. T = homomorphism(G, AlternatingGroup(4), G.generators)
  20. assert T.is_trivial()
  21. assert T.kernel().order() == G.order()
  22. E, e = free_group("e")
  23. G = FpGroup(E, [e**8])
  24. P = PermutationGroup([Permutation(0, 1, 2, 3), Permutation(0, 2)])
  25. T = homomorphism(G, P, [e], [Permutation(0, 1, 2, 3)])
  26. assert T.image().order() == 4
  27. assert T(T.invert(Permutation(0, 2)(1, 3))) == Permutation(0, 2)(1, 3)
  28. T = homomorphism(E, AlternatingGroup(4), E.generators, [c])
  29. assert T.invert(c**2) == e**-1 #order(c) == 3 so c**2 == c**-1
  30. # FreeGroup -> FreeGroup
  31. T = homomorphism(F, E, [a], [e])
  32. assert T(a**-2*b**4*a**2).is_identity
  33. # FreeGroup -> FpGroup
  34. G = FpGroup(F, [a*b*a**-1*b**-1])
  35. T = homomorphism(F, G, F.generators, G.generators)
  36. assert T.invert(a**-1*b**-1*a**2) == a*b**-1
  37. # PermutationGroup -> PermutationGroup
  38. D = DihedralGroup(8)
  39. p = Permutation(0, 1, 2, 3, 4, 5, 6, 7)
  40. P = PermutationGroup(p)
  41. T = homomorphism(P, D, [p], [p])
  42. assert T.is_injective()
  43. assert not T.is_isomorphism()
  44. assert T.invert(p**3) == p**3
  45. T2 = homomorphism(F, P, [F.generators[0]], P.generators)
  46. T = T.compose(T2)
  47. assert T.domain == F
  48. assert T.codomain == D
  49. assert T(a*b) == p
  50. def test_isomorphisms():
  51. F, a, b = free_group("a, b")
  52. E, c, d = free_group("c, d")
  53. # Infinite groups with differently ordered relators.
  54. G = FpGroup(F, [a**2, b**3])
  55. H = FpGroup(F, [b**3, a**2])
  56. assert is_isomorphic(G, H)
  57. # Trivial Case
  58. # FpGroup -> FpGroup
  59. H = FpGroup(F, [a**3, b**3, (a*b)**2])
  60. F, c, d = free_group("c, d")
  61. G = FpGroup(F, [c**3, d**3, (c*d)**2])
  62. check, T = group_isomorphism(G, H)
  63. assert check
  64. assert T(c**3*d**2) == a**3*b**2
  65. # FpGroup -> PermutationGroup
  66. # FpGroup is converted to the equivalent isomorphic group.
  67. F, a, b = free_group("a, b")
  68. G = FpGroup(F, [a**3, b**3, (a*b)**2])
  69. H = AlternatingGroup(4)
  70. check, T = group_isomorphism(G, H)
  71. assert check
  72. assert T(b*a*b**-1*a**-1*b**-1) == Permutation(0, 2, 3)
  73. assert T(b*a*b*a**-1*b**-1) == Permutation(0, 3, 2)
  74. # PermutationGroup -> PermutationGroup
  75. D = DihedralGroup(8)
  76. p = Permutation(0, 1, 2, 3, 4, 5, 6, 7)
  77. P = PermutationGroup(p)
  78. assert not is_isomorphic(D, P)
  79. A = CyclicGroup(5)
  80. B = CyclicGroup(7)
  81. assert not is_isomorphic(A, B)
  82. # Two groups of the same prime order are isomorphic to each other.
  83. G = FpGroup(F, [a, b**5])
  84. H = CyclicGroup(5)
  85. assert G.order() == H.order()
  86. assert is_isomorphic(G, H)
  87. def test_check_homomorphism():
  88. a = Permutation(1,2,3,4)
  89. b = Permutation(1,3)
  90. G = PermutationGroup([a, b])
  91. raises(ValueError, lambda: homomorphism(G, G, [a], [a]))