Python| SymPy Permutation.commutes_with() 方法
Permutation.commutes_with() : commutes_with()是一个 sympy Python库函数,用于检查两个排列是否是通勤的。假设'a' 和'b' 是'C' 的一部分,那么a 和b 的交换子是'C' 恒等式当且仅当a 和b 可交换,即ab == ba。
Syntax :
sympy.combinatorics.permutations.Permutation.commutes_with()
Return :
checks whether the two permutations are commuting
代码 #1:commutes_with() 示例
# Python code explaining
# SymPy.Permutation.commutes_with()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.commutes_with() method
# creating Permutation
a = Permutation([2, 0, 3, 1, 5, 4])
b = Permutation([3, 1, 2, 5, 4, 0])
print ("Permutation a - commutes_with form : ", a.commutes_with(b))
print ("Permutation b - commutes_with form : ", b.commutes_with(a))
输出 :
Permutation a – commutes_with form : False
Permutation b – commutes_with form : False
代码 #2 : commutes_with() 示例– 自换向器
# Python code explaining
# SymPy.Permutation.commutes_with()
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
# Using from sympy.combinatorics.permutations.Permutation.commutes_with() method
# creating Permutation
a = Permutation([[2, 4, 0],
[3, 1, 2],
[1, 5, 6]])
# SELF COMMUTATING
print ("Permutation a - commutes_with form : ", a.commutes_with(a))
输出 :
Permutation a – commutes_with form : True