CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

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

Views: 418346
1
<Chapter><Heading>Permutation Encoding</Heading>
2
3
A permutation <M>\pi=\pi_{1} \ldots \pi_{n}</M> has rank encoding
4
<M>p_{1} \ldots p_{n}</M> where <M> p_{i}= |\{j : j \geq i, \pi_{j} \leq \pi_{i} \} | </M>.
5
In 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>
6
is the rank of <M>\pi_{i}</M> in <M>\{\pi_{i},\pi_{i+1},\ldots ,\pi_{n}\}</M>.
7
<Cite Key="RegCloSetPerms" />
8
<P/>
9
The encoding of the permutation 3 2 5 1 6 7 4 8 9 is done as follows:
10
11
<Table Align="c|c|c">
12
<Row>
13
<Item>Permutation</Item><Item>Encoding</Item><Item>Assisting list</Item>
14
</Row>
15
<Row>
16
<Item>325167489</Item><Item><M>\emptyset</M></Item><Item>123456789</Item>
17
</Row>
18
<Row>
19
<Item>25167489</Item><Item>3</Item><Item>12456789</Item>
20
</Row>
21
<Row>
22
<Item>5167489</Item><Item>32</Item><Item>1456789</Item>
23
</Row>
24
<Row>
25
<Item>167489</Item><Item>323</Item><Item>146789</Item>
26
</Row>
27
<Row>
28
<Item>67489</Item><Item>3231</Item><Item>46789</Item>
29
</Row>
30
<Row>
31
<Item>7489</Item><Item>32312</Item><Item>4789</Item>
32
</Row>
33
<Row>
34
<Item>489</Item><Item>323122</Item><Item>489</Item>
35
</Row>
36
<Row>
37
<Item>89</Item><Item>3231221</Item><Item>89</Item>
38
</Row>
39
<Row>
40
<Item>9</Item><Item>32312211</Item><Item>9</Item>
41
</Row>
42
<Row>
43
<Item><M>\emptyset</M></Item><Item>323122111</Item><Item><M>\emptyset</M></Item>
44
</Row>
45
</Table>
46
47
Decoding a permutation is done in a similar fashion, taking the sequence <M>p_{1} \ldots p_{n}</M>
48
and using the reverse process will lead to the permutation <M>\pi=\pi_{1} \ldots \pi_{n}</M>,
49
where <M>\pi_{i}</M> is determined by finding the number that has rank <M>p_{i}</M> in
50
<M>\{\pi_{i}, \pi_{i+1}, \ldots , \pi_{n}\}</M>.
51
<P/>
52
The sequence 3 2 3 1 2 2 1 1 1 is decoded as:
53
54
<Table Align="c|c|c">
55
<Row>
56
<Item>Encoding</Item><Item>Permutation</Item><Item>Assisting list</Item>
57
</Row>
58
<Row>
59
<Item>323122111</Item><Item><M>\emptyset</M></Item><Item>123456789</Item>
60
</Row>
61
<Row>
62
<Item>23122111</Item><Item>3</Item><Item>12456789</Item>
63
</Row>
64
<Row>
65
<Item>3122111</Item><Item>32</Item><Item>1456789</Item>
66
</Row>
67
<Row>
68
<Item>122111</Item><Item>325</Item><Item>146789</Item>
69
</Row>
70
<Row>
71
<Item>22111</Item><Item>3251</Item><Item>46789</Item>
72
</Row>
73
<Row>
74
<Item>2111</Item><Item>32516</Item><Item>4789</Item>
75
</Row>
76
<Row>
77
<Item>111</Item><Item>325167</Item><Item>489</Item>
78
</Row>
79
<Row>
80
<Item>11</Item><Item>3251674</Item><Item>89</Item>
81
</Row>
82
<Row>
83
<Item>1</Item><Item>32516748</Item><Item>9</Item>
84
</Row>
85
<Row>
86
<Item><M>\emptyset</M></Item><Item>325167489</Item><Item><M>\emptyset</M></Item>
87
</Row>
88
</Table>
89
<Section><Heading> Encoding and Decoding </Heading>
90
91
<ManSection>
92
<Func Name="RankEncoding" Arg="p"/>
93
<Returns>A list that represents the rank encoding of the permutation <C>p</C>. </Returns>
94
<Description>
95
Using the algorithm above <C>RankEncoding</C> turns the permutation <C>p</C> into a list
96
of integers.
97
<Example><![CDATA[
98
gap> RankEncoding([3, 2, 5, 1, 6, 7, 4, 8, 9]);
99
[ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]
100
gap> RankEncoding([ 4, 2, 3, 5, 1 ]);
101
[ 4, 2, 2, 2, 1 ]
102
gap> ]]></Example>
103
</Description>
104
</ManSection>
105
106
107
108
109
<ManSection>
110
<Func Name="RankDecoding" Arg="e"/>
111
<Returns>A permutation in list form.</Returns>
112
<Description>
113
A rank encoded permutation is decoded by using the reversed process from encoding,
114
which is also explained above.
115
116
<Example><![CDATA[
117
gap> RankDecoding([ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]);
118
[ 3, 2, 5, 1, 6, 7, 4, 8, 9 ]
119
gap> RankDecoding([ 4, 2, 2, 2, 1 ]);
120
[ 4, 2, 3, 5, 1 ]
121
gap> ]]></Example>
122
</Description>
123
</ManSection>
124
125
126
127
128
<ManSection>
129
<Func Name="SequencesToRatExp" Arg="list"/>
130
<Returns>A rational expression that describes all the words in <C>list</C>.</Returns>
131
<Description>
132
A list of sequences is turned into a rational expression by concatenating each sequence
133
and unifying all of them.
134
<Example><![CDATA[
135
gap> SequencesToRatExp([[ 1, 1, 1, 1, 1 ],[ 2, 1, 2, 2, 1 ],[ 3, 2, 1, 2, 1 ],
136
> [ 4, 2, 3, 2, 1 ]]);
137
11111U21221U32121U42321
138
gap> ]]></Example>
139
</Description>
140
</ManSection>
141
142
143
144
</Section>
145
</Chapter>
146