Python SymPy Permutation.commutes_with()方法
Permutation.commutes_with() : commutes_with() 是一个Sympy Python库函数,用于检查两个排列组合是否互换。假设’a’和’b’是’C’的一部分,那么a和b的换元是’C’的特征,如果a和b互换,即ab == ba。
语法 : sympy.combinatorics.permutations.Permutation.commutes_with()
返回 :
检查两个排列组合是否互换
代码 #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