SymPy | Permutation.unrank_trotterjohnson() in Python

SymPy | Permutation.unrank_trotterjohnson() in Python

The unrank_trotterjohnson() function in the Permutation class of SymPy's combinatorics module is used to convert a rank into a permutation, using the Trotter-Johnson ranking scheme.

The Trotter-Johnson ranking scheme is a method for ranking permutations, and it is used in various combinatorial algorithms.

Here's a brief introduction to how you can use unrank_trotterjohnson() with SymPy's Permutation class:

  • Setup: First, ensure you have SymPy installed:
pip install sympy 
  • Usage: Here's a basic usage of unrank_trotterjohnson():
from sympy.combinatorics import Permutation # Create a permutation using Trotter-Johnson unranking rank = 5 size = 3 # Size of the permutation perm = Permutation.unrank_trotterjohnson(rank, size) print(perm) # Output might be a permutation like [2, 1, 0] 

In the above code, we're retrieving the permutation of size 3 that corresponds to the Trotter-Johnson rank of 5.

It's worth noting that if you're not already familiar with the Trotter-Johnson ranking scheme, you might want to consult combinatorics literature or documentation related to permutation ranking to better understand its implications and use cases.


More Tags

sharding uiwebviewdelegate python-2.7 window.location navigator confirm formset roblox max contact-form

More Programming Guides

Other Guides

More Programming Examples