Major index (source code)

= Major index
{title2=$\operatorname{maj}(\pi)$}

The <major index> of a <permutation> $\pi=\pi_1\cdots\pi_n$ is the sum of its <permutation descent> positions:
$$
\operatorname{maj}(\pi)=\sum_{\substack{1\le i<n\\\pi_i>\pi_{i+1}}}i.
$$
It uses positions, rather than the values being compared. For $3142$, the <permutation descents> occur at positions one and three, giving $\operatorname{maj}=4$, whereas the descent number is two.

The <major index> has the same distribution over all <permutations> of $n$ elements as the <inversion number>:
$$
\sum_{\pi\in S_n}q^{\operatorname{maj}(\pi)}=\prod_{j=1}^n(1+q+\cdots+q^{j-1}).
$$
For $n=3$, the six values give $1+2q+2q^2+q^3$. Individual statistics need not agree: $312$ has major index one and two inversions. The shared generating <polynomial> is a statement about their distribution across the whole <symmetric group>.<Enumerative Combinatorics, Volume 1 (second-edition draft) by Richard Stanley>[sections 1.3–1.4, inversions and major index]{ref}