SymPy | Permutation.next_trotterjohnson() in Python

Permutation.next_trotterjohnson() : next_trotterjohnson() is a sympy Python library function that returns the next permutation in Trotter-Johnson order. If self is the last permutation it returns None.

Syntax : sympy.combinatorics.permutations.Permutation.next_trotterjohnson()

Return : next permutation in Trotter-Johnson order

Code #1 : next_trotterjohnson() Example




# Python code explaining
# SymPy.Permutation.next_trotterjohnson()
Ā Ā 
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
Ā Ā 
# Using fromĀ 
# sympy.combinatorics.permutations.Permutation.next_trotterjohnson() methodĀ 
Ā Ā 
# creating Permutation
a = Permutation([[2, 0], [3, 1]])
Ā Ā 
b = Permutation([1, 3, 5, 4, 2, 0])
Ā Ā 
Ā Ā 
print ("Permutation a - next_trotterjohnson form : ", a.next_trotterjohnson())
print ("Permutation b - next_trotterjohnson form : ", b.next_trotterjohnson())


Output :

Permutation a – next_trotterjohnson form : (0 3 1 2)
Permutation b – next_trotterjohnson form : (0 1 5)(2 3 4)

Code #2 : next_trotterjohnson() Example – 2D Permutation




# Python code explaining
# SymPy.Permutation.next_trotterjohnson()
Ā Ā 
# importing SymPy libraries
from sympy.combinatorics.partitions import Partition
from sympy.combinatorics.permutations import Permutation
Ā Ā 
# Using fromĀ 
# sympy.combinatorics.permutations.Permutation.next_trotterjohnson() methodĀ 
Ā Ā 
# creating Permutation
a = Permutation([[2, 4, 0],Ā 
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā [3, 1, 2],
Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā Ā [1, 5, 6]])
Ā Ā 
Ā Ā 
print ("Permutation a - next_trotterjohnson form : ", a.next_trotterjohnson())


Output :

Permutation a – next_trotterjohnson form : (6)(0 3 5 1 2 4)

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button