Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563569 views
1
2
3 Permutation Encoding
3
4
A permutation π=π_1 ... π_n has rank encoding p_1 ... p_n where p_i= |{j : j
5
≥ i, π_j ≤ π_i } |. In other words the rank encoded permutation is a
6
sequence of p_i with 1≤ i≤ n, where p_i is the rank of π_i in {π_i,π_i+1,...
7
,π_n}. [2]
8
9
The encoding of the permutation 3 2 5 1 6 7 4 8 9 is done as follows:
10
11
Permutation │ Encoding │ Assisting list
12
325167489 │ ∅ │ 123456789
13
25167489 │ 3 │ 12456789
14
5167489 │ 32 │ 1456789
15
167489 │ 323 │ 146789
16
67489 │ 3231 │ 46789
17
7489 │ 32312 │ 4789
18
489 │ 323122 │ 489
19
89 │ 3231221 │ 89
20
9 │ 32312211 │ 9
21
∅ │ 323122111 │ ∅
22
23
Decoding a permutation is done in a similar fashion, taking the sequence p_1
24
... p_n and using the reverse process will lead to the permutation π=π_1 ...
25
π_n, where π_i is determined by finding the number that has rank p_i in
26
{π_i, π_i+1, ... , π_n}.
27
28
The sequence 3 2 3 1 2 2 1 1 1 is decoded as:
29
30
Encoding │ Permutation │ Assisting list
31
323122111 │ ∅ │ 123456789
32
23122111 │ 3 │ 12456789
33
3122111 │ 32 │ 1456789
34
122111 │ 325 │ 146789
35
22111 │ 3251 │ 46789
36
2111 │ 32516 │ 4789
37
111 │ 325167 │ 489
38
11 │ 3251674 │ 89
39
1 │ 32516748 │ 9
40
∅ │ 325167489 │ ∅
41
42
43
3.1 Encoding and Decoding
44
45
3.1-1 RankEncoding
46
47
RankEncoding( p )  function
48
Returns: A list that represents the rank encoding of the permutation p.
49
50
Using the algorithm above RankEncoding turns the permutation p into a list
51
of integers.
52
53
 Example 
54
gap> RankEncoding([3, 2, 5, 1, 6, 7, 4, 8, 9]);
55
[ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]
56
gap> RankEncoding([ 4, 2, 3, 5, 1 ]); 
57
[ 4, 2, 2, 2, 1 ]
58
gap> 
59

60
61
3.1-2 RankDecoding
62
63
RankDecoding( e )  function
64
Returns: A permutation in list form.
65
66
A rank encoded permutation is decoded by using the reversed process from
67
encoding, which is also explained above.
68
69
 Example 
70
gap> RankDecoding([ 3, 2, 3, 1, 2, 2, 1, 1, 1 ]);
71
[ 3, 2, 5, 1, 6, 7, 4, 8, 9 ]
72
gap> RankDecoding([ 4, 2, 2, 2, 1 ]);
73
[ 4, 2, 3, 5, 1 ]
74
gap> 
75

76
77
3.1-3 SequencesToRatExp
78
79
SequencesToRatExp( list )  function
80
Returns: A rational expression that describes all the words in list.
81
82
A list of sequences is turned into a rational expression by concatenating
83
each sequence and unifying all of them.
84
85
 Example 
86
gap> SequencesToRatExp([[ 1, 1, 1, 1, 1 ],[ 2, 1, 2, 2, 1 ],[ 3, 2, 1, 2, 1 ],
87
> [ 4, 2, 3, 2, 1 ]]);
88
11111U21221U32121U42321
89
gap> 
90

91
92
93