GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
1[1X3 [33X[0;0YPermutation Encoding[133X[101X23[33X[0;0YA permutation [22Xπ=π_1 ... π_n[122X has rank encoding [22Xp_1 ... p_n[122X where [22Xp_i= |{j : j4≥ i, π_j ≤ π_i } |[122X. In other words the rank encoded permutation is a5sequence of [22Xp_i[122X with [22X1≤ i≤ n[122X, where [22Xp_i[122X is the rank of [22Xπ_i[122X in [22X{π_i,π_i+1,...6,π_n}[122X. [2][133X78[33X[0;0YThe encoding of the permutation 3 2 5 1 6 7 4 8 9 is done as follows:[133X910Permutation │ Encoding │ Assisting list11325167489 │ [22X∅[122X │ 1234567891225167489 │ 3 │ 12456789135167489 │ 32 │ 145678914167489 │ 323 │ 1467891567489 │ 3231 │ 46789167489 │ 32312 │ 478917489 │ 323122 │ 4891889 │ 3231221 │ 89199 │ 32312211 │ 920[22X∅[122X │ 323122111 │ [22X∅[122X2122[33X[0;0YDecoding a permutation is done in a similar fashion, taking the sequence [22Xp_123... p_n[122X and using the reverse process will lead to the permutation [22Xπ=π_1 ...24π_n[122X, where [22Xπ_i[122X is determined by finding the number that has rank [22Xp_i[122X in25[22X{π_i, π_i+1, ... , π_n}[122X.[133X2627[33X[0;0YThe sequence 3 2 3 1 2 2 1 1 1 is decoded as:[133X2829Encoding │ Permutation │ Assisting list30323122111 │ [22X∅[122X │ 1234567893123122111 │ 3 │ 12456789323122111 │ 32 │ 145678933122111 │ 325 │ 1467893422111 │ 3251 │ 46789352111 │ 32516 │ 478936111 │ 325167 │ 4893711 │ 3251674 │ 89381 │ 32516748 │ 939[22X∅[122X │ 325167489 │ [22X∅[122X404142[1X3.1 [33X[0;0YEncoding and Decoding[133X[101X4344[1X3.1-1 RankEncoding[101X4546[29X[2XRankEncoding[102X( [3Xp[103X ) [32X function47[6XReturns:[106X [33X[0;10YA list that represents the rank encoding of the permutation [10Xp[110X.[133X4849[33X[0;0YUsing the algorithm above [10XRankEncoding[110X turns the permutation [10Xp[110X into a list50of integers.[133X5152[4X[32X Example [32X[104X53[4X[25Xgap>[125X [27XRankEncoding([3, 2, 5, 1, 6, 7, 4, 8, 9]);[127X[104X54[4X[28X[ 3, 2, 3, 1, 2, 2, 1, 1, 1 ][128X[104X55[4X[25Xgap>[125X [27XRankEncoding([ 4, 2, 3, 5, 1 ]); [127X[104X56[4X[28X[ 4, 2, 2, 2, 1 ][128X[104X57[4X[25Xgap>[125X [27X[127X[104X58[4X[32X[104X5960[1X3.1-2 RankDecoding[101X6162[29X[2XRankDecoding[102X( [3Xe[103X ) [32X function63[6XReturns:[106X [33X[0;10YA permutation in list form.[133X6465[33X[0;0YA rank encoded permutation is decoded by using the reversed process from66encoding, which is also explained above.[133X6768[4X[32X Example [32X[104X69[4X[25Xgap>[125X [27XRankDecoding([ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]);[127X[104X70[4X[28X[ 3, 2, 5, 1, 6, 7, 4, 8, 9 ][128X[104X71[4X[25Xgap>[125X [27XRankDecoding([ 4, 2, 2, 2, 1 ]);[127X[104X72[4X[28X[ 4, 2, 3, 5, 1 ][128X[104X73[4X[25Xgap>[125X [27X[127X[104X74[4X[32X[104X7576[1X3.1-3 SequencesToRatExp[101X7778[29X[2XSequencesToRatExp[102X( [3Xlist[103X ) [32X function79[6XReturns:[106X [33X[0;10YA rational expression that describes all the words in [10Xlist[110X.[133X8081[33X[0;0YA list of sequences is turned into a rational expression by concatenating82each sequence and unifying all of them.[133X8384[4X[32X Example [32X[104X85[4X[25Xgap>[125X [27XSequencesToRatExp([[ 1, 1, 1, 1, 1 ],[ 2, 1, 2, 2, 1 ],[ 3, 2, 1, 2, 1 ],[127X[104X86[4X[25X>[125X [27X[ 4, 2, 3, 2, 1 ]]);[127X[104X87[4X[28X11111U21221U32121U42321[128X[104X88[4X[25Xgap>[125X [27X[127X[104X89[4X[32X[104X90919293