Function Repository Resource:

# ToInversionVector

Get the inversion vector of a permutation written as a list

Contributed by: Wolfram Staff
 ResourceFunction["ToInversionVector"][p] gives the inversion vector of the permutation list p.

## Details and Options

The inversion vector of a permutation of length n lists the number of times k is preceded by an entry greater than k, where k runs from 1 to n.

## Examples

### Basic Examples (2)

This permutation has 3 numbers greater than 1 before 1, 2 numbers greater than 2 before 2, and so on:

 In[1]:=

Therefore, this is its inversion vector:

 In[2]:=
 Out[2]=

Here is another example:

 In[3]:=
 Out[3]=
 In[4]:=
 Out[4]=

### Scope (3)

Here are all six permutation of {1,2,3}:

 In[5]:=
 Out[5]=

Here are the corresponding inversion vectors:

 In[6]:=
 Out[6]=

In the factorial base, ivs represents the numbers from 0 to 3!-1:

 In[7]:=
 Out[7]=

George Beck

## Version History

• 1.0.0 – 31 May 2019

## Author Notes

The Combinatorica` function ToInversionVector did not include the final zero.