SymPy 中是否有检查两个排列是否相等的命令?

Is there any command that checks two permutations are equal in SymPy?

利用群论中的循环符号https://en.wikipedia.org/wiki/Cyclic_permutation,显然有(计算顺序从左到右):

Blockquote (1,2)(2,3)=(1,3,2)=(3,4)(1,4,2)(3,4) Blockquote

但是 Python returns 中的以下代码是“错误的”:

from sympy.combinatorics import Permutation
a = Permutation(1,2)
b = Permutation(2,3)
c = Permutation(3,4)
d = Permutation(1,4,2)

print(a*b == c*d*c)
False

print(a*b)
print(c*d*c)
(1 3 2)
(4)(1 3 2)

从代码的最后一部分我们可以很容易地看出问题是 SymPy 将 "a*b" 视为集合 {0,1,2,3} 上的排列,而将 "c*d*c" 视为作为集合 {0,1,2,3,4} 的排列。

有什么简单的技巧可以解决这个问题吗?

您需要设置排列操作所在集合的大小:

In [92]: from sympy.combinatorics import Permutation
    ...: a = Permutation(1,2, size=5)
    ...: b = Permutation(2,3, size=5)
    ...: c = Permutation(3,4, size=5)
    ...: d = Permutation(1,4,2, size=5)

In [93]: print(a*b == c*d*c)
True

这在文档中有解释(请参阅 help(Permutations)): https://docs.sympy.org/latest/modules/combinatorics/permutations.html#sympy.combinatorics.permutations.Permutation