Wolfram Research

Function Repository Resource:

FromInversionVector

Source Notebook

Construct the permutation list corresponding to the given inversion vector

Contributed by: Wolfram Staff

ResourceFunction["FromInversionVector"][vect]

constructs the permutation list corresponding to the inversion vector vect.

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

Here is the inversion vector of a permutation:

In[1]:=
iv = ResourceFunction[
ResourceObject[
Association[
    "Name" -> "ToInversionVector", "UUID" -> "13fc9705-7630-4222-9eb6-a138870ab7ac", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "Gives the inversion vector of a permutation \
written as a list", "RepositoryLocation" -> URL[
      "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"], "WolframLanguageVersionRequired" -> "10.0", "SymbolName" -> "FunctionRepository`$\
04e180e545bb4d93acf51d01b32b8a74`ToInversionVector", "FunctionLocation" -> LocalObject[
      "file:///Users/georgebeck/Library/Wolfram/Objects/Resources/13f/\
13fc9705-7630-4222-9eb6-a138870ab7ac/download/DefinitionData"], "ShortName" -> "ToInversionVector"], ResourceSystemBase -> "https://www.wolframcloud.com/objects/\
resourcesystem/api/1.0"]]@{3, 5, 4, 1, 2}
Out[1]=

This gives back the permutation:

In[2]:=
ResourceFunction["FromInversionVector"]@iv
Out[2]=

Scope

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

In[3]:=
s3 = Permutations@{1, 2, 3}
Out[3]=

Here are the corresponding inversion vectors:

In[4]:=
ivs = ResourceFunction[
ResourceObject[
Association[
    "Name" -> "ToInversionVector", "UUID" -> "13fc9705-7630-4222-9eb6-a138870ab7ac", "ResourceType" -> "Function", "Version" -> "1.0.0", "Description" -> "Gives the inversion vector of a permutation \
written as a list", "RepositoryLocation" -> URL[
      "https://www.wolframcloud.com/objects/resourcesystem/api/1.0"], "WolframLanguageVersionRequired" -> "10.0", "SymbolName" -> "FunctionRepository`$\
04e180e545bb4d93acf51d01b32b8a74`ToInversionVector", "FunctionLocation" -> LocalObject[
      "file:///Users/georgebeck/Library/Wolfram/Objects/Resources/13f/\
13fc9705-7630-4222-9eb6-a138870ab7ac/download/DefinitionData"], "ShortName" -> "ToInversionVector"], ResourceSystemBase -> "https://www.wolframcloud.com/objects/\
resourcesystem/api/1.0"]] /@ s3
Out[4]=

The round trip works:

In[5]:=
s3 == ResourceFunction["FromInversionVector"] /@ ivs
Out[5]=

Resource History

See Also

License Information