music.dist¶
- music.dist(swap)[source]¶
Computes the cyclic distance between the two elements of a permutation.
- Parameters:
- swap
sympy.combinatorics.Permutation A permutation object with exactly two elements in its support.
- swap
- Returns:
intThe cyclic distance between the two elements.
Notes
The distance is adjusted to account for the circular nature of the permutation. If the difference is greater than or equal to half the size of the permutation, the distance is calculated as the size of the permutation minus the difference.
This measures the two lowest displaced positions, so it is meaningful for a transposition. For a permutation with a larger support the remaining displaced positions are ignored. The identity displaces nothing and gives zero.
Examples
>>> from sympy.combinatorics import Permutation >>> perm = Permutation([1, 0, 2]) >>> dist(perm) 1 >>> perm = Permutation([2, 0, 1]) >>> dist(perm) 1 >>> dist(Permutation([0, 1, 2])) # the identity displaces nothing 0