Inversion of a permutation (source code)

= Inversion of a permutation
{title2=$\operatorname{inv}(\pi)$}

For a <permutation> $\pi$ of $\{1,\ldots,n\}$, an inversion is a pair $i<j$ with $\pi(i)>\pi(j)$. Its number equals the <Coxeter length> for adjacent <transpositions>: each adjacent swap changes the count by one, and swapping adjacent descents sorts the permutation in exactly that many steps.