toqito.perms.perm_sign
- toqito.perms.perm_sign(perm)[source]
Compute the “sign” of a permutation [WikParPerm].
The sign (either -1 or 1) of the permutation
permis-1**`inv, whereinvis the number of inversions contained inperm.Examples
For the following vector
\[[1, 2, 3, 4]\]the permutation sign is positive as the number of elements in the vector are even. This can be performed in
toqitoas follows.>>> from toqito.perms import perm_sign >>> perm_sign([1, 2, 3, 4]) 1
For the following vector
\[[1, 2, 3, 4, 5]\]the permutation sign is negative as the number of elements in the vector are odd. This can be performed in
toqitoas follows.>>> from toqito.perms import perm_sign >>> perm_sign([1, 2, 4, 3, 5]) -1
References
[WikParPerm]Wikipedia: Parity of a permutation https://en.wikipedia.org/wiki/Parity_of_a_permutation
- Parameters:
perm – The permutation vector to be checked.
- Returns:
The value 1 if the permutation is of even length and the value of -1 if the permutation is of odd length.