Skip to content

MahonianNumber ​

The number of permutations of {1,…,n}\{1, …, n\} with exactly kk inversions — entry kk of row nn of the Mahonian triangle.

MahonianNumber(n, k)the coefficient of qkq^k in the qq-factorial [n]q![n]_q!
CombinatoricaNumberOfPermutationsByInversions[n, k]
Typed signatures
TypePackageApplies
(integer, integer) -> integercombinatoricsalways

Domain: Combinatorics

Details
  • Equals Count(KInversionPermutations(n,k))Count(KInversionPermutations(n, k)), and the number of permutations pp with Inversions(p)=kInversions(p) = k.
  • Satisfies M(n,k)=∑d<nM(n−1,k−d)M(n, k) = \sum_{d < n} M(n - 1, k - d) and the symmetry M(n,k)=M(n,(n2)−k)M(n, k) = M(n, \binom{n}{2} - k). It is 00 for k>(n2)k > \binom{n}{2}.
  • Defined in Epsil as that recurrence over a table of rows; a bigint kernel answers, exactly, and tests/mahonian.test.ts holds the two together.
  • Combinatorica's NumberOfPermutationsByInversions; the same convention, with kk counted from 00. A negative nn or kk is left unevaluated, as compute-engine's Eulerian does (Combinatorica leaves a negative kk unevaluated too). The kernel also declines, rather than block, past about three million cell updates (about 0.2 s).
  • Not a core Wolfram head: there is no MahonianNumber in Wolfram 15 or the Function Repository.

Plot

Examples

2 more kept as data, checked against the oracles
Basic #

row 44: 1,3,5,6,5,3,11, 3, 5, 6, 5, 3, 1

live ↗
InMap(k↦MahonianNumber(4,k),0..1..6)\mathrm{Map}(k↦\mathrm{MahonianNumber}(4, k), 0..1..6)Out[1,3,5,6,5,3,1]\bigl\lbrack1, 3, 5, 6, 5, 3, 1\bigr\rbrack

Known value · OEIS A008302

the 1515 permutations of 55 with 33 inversions

live ↗
InMahonianNumber(5,3)\mathrm{MahonianNumber}(5, 3)Out1515

Known value · wolframscript 15.0.0, Combinatorica NumberOfPermutationsByInversions[n, k]

the empty permutation has no inversions

live ↗
InMahonianNumber(0,0)\mathrm{MahonianNumber}(0, 0)Out11

Known value · wolframscript 15.0.0, Combinatorica NumberOfPermutationsByInversions[n, k]

7>(32)7 > \binom{3}{2}

live ↗
InMahonianNumber(3,7)\mathrm{MahonianNumber}(3, 7)Out00

Known value · wolframscript 15.0.0, Combinatorica NumberOfPermutationsByInversions[n, k]

M(6,7)=101M(6, 7) = 101 both ways

live ↗
InMahonianNumber(6,7)=Count(KInversionPermutations(6,7))\mathrm{MahonianNumber}(6, 7)=\mathrm{Count}(\mathrm{KInversionPermutations}(6, 7))OutTrue\mathrm{True}
About
Examples7
Checked againstCombinatorica 6 agree
CrosswalkWikipedia ×2MathWorldWikidataEncyclopedia of MathematicsnLabBritannicaOEISCombinatorica

Implementation

mappedcombinatoricapackages/oracle/src/mappings.ts

Combinatorica calls the Mahonian numbers NumberOfPermutationsByInversions.

See also: Inversions, KInversionPermutations, Eulerian, MajorIndex