music.dist

music.dist(swap)[source]

Computes the cyclic distance between the two elements of a permutation.

Parameters:
swapsympy.combinatorics.Permutation

A permutation object with exactly two elements in its support.

Returns:
int

The cyclic distance between the two elements.

Notes

The elements are read as points on a circle of swap.size, so the distance is the shorter way round: the difference between the two, or the size less it, whichever is smaller.

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