Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 418346<Chapter><Heading>Permutation Encoding</Heading>12A permutation <M>\pi=\pi_{1} \ldots \pi_{n}</M> has rank encoding3<M>p_{1} \ldots p_{n}</M> where <M> p_{i}= |\{j : j \geq i, \pi_{j} \leq \pi_{i} \} | </M>.4In other words the rank encoded permutation is a sequence of <M>p_{i}</M> with <M>1\leq i\leq n</M>, where <M>p_{i}</M>5is the rank of <M>\pi_{i}</M> in <M>\{\pi_{i},\pi_{i+1},\ldots ,\pi_{n}\}</M>.6<Cite Key="RegCloSetPerms" />7<P/>8The encoding of the permutation 3 2 5 1 6 7 4 8 9 is done as follows:910<Table Align="c|c|c">11<Row>12<Item>Permutation</Item><Item>Encoding</Item><Item>Assisting list</Item>13</Row>14<Row>15<Item>325167489</Item><Item><M>\emptyset</M></Item><Item>123456789</Item>16</Row>17<Row>18<Item>25167489</Item><Item>3</Item><Item>12456789</Item>19</Row>20<Row>21<Item>5167489</Item><Item>32</Item><Item>1456789</Item>22</Row>23<Row>24<Item>167489</Item><Item>323</Item><Item>146789</Item>25</Row>26<Row>27<Item>67489</Item><Item>3231</Item><Item>46789</Item>28</Row>29<Row>30<Item>7489</Item><Item>32312</Item><Item>4789</Item>31</Row>32<Row>33<Item>489</Item><Item>323122</Item><Item>489</Item>34</Row>35<Row>36<Item>89</Item><Item>3231221</Item><Item>89</Item>37</Row>38<Row>39<Item>9</Item><Item>32312211</Item><Item>9</Item>40</Row>41<Row>42<Item><M>\emptyset</M></Item><Item>323122111</Item><Item><M>\emptyset</M></Item>43</Row>44</Table>4546Decoding a permutation is done in a similar fashion, taking the sequence <M>p_{1} \ldots p_{n}</M>47and using the reverse process will lead to the permutation <M>\pi=\pi_{1} \ldots \pi_{n}</M>,48where <M>\pi_{i}</M> is determined by finding the number that has rank <M>p_{i}</M> in49<M>\{\pi_{i}, \pi_{i+1}, \ldots , \pi_{n}\}</M>.50<P/>51The sequence 3 2 3 1 2 2 1 1 1 is decoded as:5253<Table Align="c|c|c">54<Row>55<Item>Encoding</Item><Item>Permutation</Item><Item>Assisting list</Item>56</Row>57<Row>58<Item>323122111</Item><Item><M>\emptyset</M></Item><Item>123456789</Item>59</Row>60<Row>61<Item>23122111</Item><Item>3</Item><Item>12456789</Item>62</Row>63<Row>64<Item>3122111</Item><Item>32</Item><Item>1456789</Item>65</Row>66<Row>67<Item>122111</Item><Item>325</Item><Item>146789</Item>68</Row>69<Row>70<Item>22111</Item><Item>3251</Item><Item>46789</Item>71</Row>72<Row>73<Item>2111</Item><Item>32516</Item><Item>4789</Item>74</Row>75<Row>76<Item>111</Item><Item>325167</Item><Item>489</Item>77</Row>78<Row>79<Item>11</Item><Item>3251674</Item><Item>89</Item>80</Row>81<Row>82<Item>1</Item><Item>32516748</Item><Item>9</Item>83</Row>84<Row>85<Item><M>\emptyset</M></Item><Item>325167489</Item><Item><M>\emptyset</M></Item>86</Row>87</Table>88<Section><Heading> Encoding and Decoding </Heading>8990<ManSection>91<Func Name="RankEncoding" Arg="p"/>92<Returns>A list that represents the rank encoding of the permutation <C>p</C>. </Returns>93<Description>94Using the algorithm above <C>RankEncoding</C> turns the permutation <C>p</C> into a list95of integers.96<Example><![CDATA[97gap> RankEncoding([3, 2, 5, 1, 6, 7, 4, 8, 9]);98[ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]99gap> RankEncoding([ 4, 2, 3, 5, 1 ]);100[ 4, 2, 2, 2, 1 ]101gap> ]]></Example>102</Description>103</ManSection>104105106107108<ManSection>109<Func Name="RankDecoding" Arg="e"/>110<Returns>A permutation in list form.</Returns>111<Description>112A rank encoded permutation is decoded by using the reversed process from encoding,113which is also explained above.114115<Example><![CDATA[116gap> RankDecoding([ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]);117[ 3, 2, 5, 1, 6, 7, 4, 8, 9 ]118gap> RankDecoding([ 4, 2, 2, 2, 1 ]);119[ 4, 2, 3, 5, 1 ]120gap> ]]></Example>121</Description>122</ManSection>123124125126127<ManSection>128<Func Name="SequencesToRatExp" Arg="list"/>129<Returns>A rational expression that describes all the words in <C>list</C>.</Returns>130<Description>131A list of sequences is turned into a rational expression by concatenating each sequence132and unifying all of them.133<Example><![CDATA[134gap> SequencesToRatExp([[ 1, 1, 1, 1, 1 ],[ 2, 1, 2, 2, 1 ],[ 3, 2, 1, 2, 1 ],135> [ 4, 2, 3, 2, 1 ]]);13611111U21221U32121U42321137gap> ]]></Example>138</Description>139</ManSection>140141142143</Section>144</Chapter>145146