Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Give the lexicographic index of a permutation
| ResourceFunction["PermutationIndex"][perm] gives the lexicographic index of permutation perm. | 
Return the index of a permutation:
| In[1]:= | ![ResourceFunction["PermutationIndex"][{4, 3, 2, 1}]](https://www.wolframcloud.com/obj/resourcesystem/images/31e/31e38ce8-18e8-4c43-a7e2-90cf5ba6f951/43fda1be5a4b8066.png) | 
| Out[1]= |  | 
The first permutation of a given length has index 1:
| In[2]:= | ![ResourceFunction["PermutationIndex"][{1, 2, 3, 4, 5, 6, 7}]](https://www.wolframcloud.com/obj/resourcesystem/images/31e/31e38ce8-18e8-4c43-a7e2-90cf5ba6f951/1d8ba70e0622cd10.png) | 
| Out[2]= |  | 
Some large permutations:
| In[3]:= | ![large = Table[RandomSample[Range[20]], {4}]](https://www.wolframcloud.com/obj/resourcesystem/images/31e/31e38ce8-18e8-4c43-a7e2-90cf5ba6f951/5599a1cc46908e8c.png) | 
| Out[3]= |  | 
Large permutations can be indexed:
| In[4]:= | ![lr = ResourceFunction["PermutationIndex"] /@ large](https://www.wolframcloud.com/obj/resourcesystem/images/31e/31e38ce8-18e8-4c43-a7e2-90cf5ba6f951/7e25de870abef11e.png) | 
| Out[4]= |  | 
Terms don’t necessarily need to be positive or integer:
| In[5]:= | ![lrn = ResourceFunction["PermutationIndex"] /@ (-large + 1/2)](https://www.wolframcloud.com/obj/resourcesystem/images/31e/31e38ce8-18e8-4c43-a7e2-90cf5ba6f951/329eae3040915b2f.png) | 
| Out[5]= |  | 
The indices of permutations and negative permutations are balanced:
| In[6]:= |  | 
| Out[6]= |  | 
Differences of indices of even permutations:
| In[7]:= | ![Differences[
 ResourceFunction["PermutationIndex"] /@ GatherBy[Permutations[Range[5]], Signature][[1]]]](https://www.wolframcloud.com/obj/resourcesystem/images/31e/31e38ce8-18e8-4c43-a7e2-90cf5ba6f951/17b008156aa0cdab.png) | 
| Out[7]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License