GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
1[1X8 [33X[0;0YProperties of Permutations[133X[101X23[33X[0;0YIt has been of interest to the authors to compute different properties of4permutations. Inspections include plus- and minus-decomposable permutations,5block-decompositions of permutations, as well as the computation of the6direct and skew sum of permutations. First a couple of definitions on which7some of the properties are based on:[133X89[33X[0;0YAn interval of a permutation [22Xσ[122X is a set of contiguous values which in [22Xσ[122X have10consecutive indices.[133X1112[33X[0;0YA permutation of length [22Xn[122X is called simple if it only contains the intervals13of length 0, 1 and [22Xn[122X.[133X141516[1X8.1 [33X[0;0YIntervals in Permutations[133X[101X1718[33X[0;0YAs mentioned above, an interval of a permutation [22Xσ[122X is a set of contiguous19numbers which in [22Xσ[122X have consecutive indices. For example in [22Xσ = 4 6 8 7 1 5202 3[122X the following is an interval [22Xσ(2)σ(3)σ(4)=6 8 7[122X whereas [22Xσ(4)σ(5)σ(6)=7 1215[122X is not.[133X2223[1X8.1-1 IsInterval[101X2425[29X[2XIsInterval[102X( [3Xlist[103X ) [32X function26[6XReturns:[106X [33X[0;10Y[10Xtrue[110X, if [10Xlist[110X is an interval.[133X2728[33X[0;0YIsInterval takes in any list with unique elements, which can be ordered29lexicographically and checkes whether it is an interval.[133X3031[4X[32X Example [32X[104X32[4X[25Xgap>[125X [27XIsInterval([3,6,9,2]);[127X[104X33[4X[28Xfalse[128X[104X34[4X[25Xgap>[125X [27XIsInterval([2,6,5,3,4]);[127X[104X35[4X[28Xtrue[128X[104X36[4X[25Xgap>[125X [27X [127X[104X37[4X[32X[104X383940[1X8.2 [33X[0;0YSimplicity[133X[101X4142[33X[0;0YAs mentioned above a permutation is said to be simple if it only contains43intervals of length 0, 1 or the length of the permutation.[133X4445[1X8.2-1 IsSimplePerm[101X4647[29X[2XIsSimplePerm[102X( [3Xperm[103X ) [32X function48[6XReturns:[106X [33X[0;10Y[10Xtrue[110X if [10Xperm[110X is simple.[133X4950[33X[0;0YTo check whether [10Xperm[110X (length of [10Xperm[110X = [22Xn[122X) is a simple permutation51[10XIsSimplePerm[110X uses the basic algorithm proposed by Uno and Yagiura in [8] to52compare the [10Xperm[110X against the identity permutation of the same length.[133X5354[4X[32X Example [32X[104X55[4X[25Xgap>[125X [27XIsSimplePerm([2,3,4,5,1,1,1,1]);[127X[104X56[4X[28Xtrue[128X[104X57[4X[25Xgap>[125X [27XIsSimplePerm([2,4,6,8,1,3,5,7]);[127X[104X58[4X[28Xtrue[128X[104X59[4X[25Xgap>[125X [27XIsSimplePerm([3,2,8,6,7,1,5,4]);[127X[104X60[4X[28Xfalse[128X[104X61[4X[25Xgap>[125X [27X[127X[104X62[4X[32X[104X636465[1X8.3 [33X[0;0YPoint Deletion in Simple Permutations[133X[101X6667[33X[0;0YIn [7] it is shown how one can get chains of permutations by starting with a68simple permutation and then removing either a single point or two points and69the resulting permutation would still be simple. We have applied this theory70to create functions such that the set of simple permutations of shorter71length, by one deletion, can be found.[133X7273[1X8.3-1 OnePointDelete[101X7475[29X[2XOnePointDelete[102X( [3Xperm[103X ) [32X function76[6XReturns:[106X [33X[0;10YA list of simple permutations with one point less than [10Xperm[110X.[133X7778[33X[0;0Y[10XOnePointDelete[110X removes single points in the simple permutation and returns a79list of the resulting simple permutations, in their rank encoding.[133X8081[4X[32X Example [32X[104X82[4X[25Xgap>[125X [27XOnePointDelete([5,2,3,1,2,1]);[127X[104X83[4X[28X[ [ 2, 3, 1, 2, 1 ], [ 4, 1, 2, 2, 1 ] ][128X[104X84[4X[25Xgap>[125X [27XOnePointDelete([5,2,4,1,6,3]);[127X[104X85[4X[28X[ [ 2, 3, 1, 2, 1 ], [ 4, 1, 2, 2, 1 ] ][128X[104X86[4X[25Xgap>[125X [27X[127X[104X87[4X[32X[104X8889[1X8.3-2 TwoPointDelete[101X9091[29X[2XTwoPointDelete[102X( [3Xperm[103X ) [32X function92[6XReturns:[106X [33X[0;10YThe exceptional permutation with two point less than [10Xperm[110X.[133X9394[33X[0;0Y[10XTwoPointDelete[110X removes two points of the input exceptional permutation and95returns the list of the unique resulting permutation, in its rank encoding.[133X9697[4X[32X Example [32X[104X98[4X[25Xgap>[125X [27XTwoPointDelete([2,4,6,8,1,3,5,7]);[127X[104X99[4X[28X[ [ 2, 3, 4, 1, 1, 1 ] ][128X[104X100[4X[25Xgap>[125X [27XTwoPointDelete([2,3,4,5,1,1,1,1]);[127X[104X101[4X[28X[ [ 2, 3, 4, 1, 1, 1 ] ][128X[104X102[4X[25Xgap>[125X [27X[127X[104X103[4X[32X[104X104105[1X8.3-3 PointDeletion[101X106107[29X[2XPointDeletion[102X( [3Xperm[103X ) [32X function108[6XReturns:[106X [33X[0;10YA list of simple permutations with of shorter length than [10Xperm[110X.[133X109110[33X[0;0Y[10XPointDeletion[110X takes any simple permutation does not matter whether111exceptional or not and removes the right number of points.[133X112113[4X[32X Example [32X[104X114[4X[25Xgap>[125X [27XPointDeletion([5,2,3,1,2,1]);[127X[104X115[4X[28X[ [ 2, 3, 1, 2, 1 ], [ 4, 1, 2, 2, 1 ] ][128X[104X116[4X[25Xgap>[125X [27XPointDeletion([5,2,4,1,6,3]);[127X[104X117[4X[28X[ [ 2, 3, 1, 2, 1 ], [ 4, 1, 2, 2, 1 ] ][128X[104X118[4X[25Xgap>[125X [27XPointDeletion([2,4,6,8,1,3,5,7]);[127X[104X119[4X[28X[ [ 2, 3, 4, 1, 1, 1 ] ][128X[104X120[4X[25Xgap>[125X [27XPointDeletion([2,3,4,5,1,1,1,1]);[127X[104X121[4X[28X[ [ 2, 3, 4, 1, 1, 1 ] ][128X[104X122[4X[25Xgap>[125X [27X[127X[104X123[4X[32X[104X124125126[1X8.4 [33X[0;0YBlock-Decomposition[133X[101X127128[33X[0;0YGiven a permutation [22Xπ[122X of length [22Xm[122X and nonempty permutations [22Xα_1,...,α_m[122X the129inflation of [22Xπ[122X by [22Xα_1,...,α_m[122X, written as [22Xπ[α_1,...,α_m][122X, is the permutation130obtained by replacing each entry [22Xπ(i)[122X by an interval that is order131isomorphic to [22Xα_i[122X [4]. Conversely a block-decomposition of [22Xσ[122X is any132expression of [22Xσ[122X as an inflation [22Xσ=π[α_1,...,α_m][122X. The block decomposition of133a permutation is unique if and only if [22Xσ,π,α_1,...,α_n[122X all are in the same134pattern class and [22Xπ[122X is simple and [22Xπ≠ 1 2, 2 1[122X [1].[133X135136[33X[0;0YFor example the inflation of [22X25413[21,1,1,1,2413]=3 2 8 9 1 5 7 4 6[122X, written137in [5XGAP[105X this is [10X[[2,5,4,1,3],[2,1],[1],[1],[1],[2,4,1,3]][110X. This decomposition138of [22X3 2 8 9 1 5 7 4 6[122X is not unique. The unique block-decomposition, as139described above, for [22X3 2 8 9 1 5 7 4 6=2413[21,12,1,2413][122X or in [5XGAP[105X notation140[10X[3,2,8,9,1,5,7,4,6]=[[2,4,1,3],[2,1],[1,2],[1],[2,4,1,3]][110X.[133X141142[1X8.4-1 Inflation[101X143144[29X[2XInflation[102X( [3Xlist_of_perms[103X ) [32X function145[6XReturns:[106X [33X[0;10YA permutation that represents the inflation of the list of146permutations, taking the first permutation to be [22Xπ[122X, as described147in the definition of inflation.[133X148149[33X[0;0YInflation takes the list of permutations that stand for a box decomposition150of a permutation, and calculates that permutation by replacing each entry [22Xi[122X151in the first permutation by an interval order isomorphic to the permutation152in index [22Xi+1[122X.[133X153154[4X[32X Example [32X[104X155[4X[25Xgap>[125X [27XInflation([[3,2,1],[1],[1,2],[1,2,3]]);[127X[104X156[4X[28X[ 6, 4, 5, 1, 2, 3 ][128X[104X157[4X[25Xgap>[125X [27XInflation([[1,2],[1],[4,2,1,3]]);[127X[104X158[4X[28X[ 1, 5, 3, 2, 4 ][128X[104X159[4X[25Xgap>[125X [27XInflation([[2,4,1,3],[2,1],[3,1,2],[1],[2,4,1,3]]);[127X[104X160[4X[28X[ 3, 2, 10, 8, 9, 1, 5, 7, 4, 6 ][128X[104X161[4X[25Xgap>[125X [27X[127X[104X162[4X[32X[104X163164[1X8.4-2 BlockDecomposition[101X165166[29X[2XBlockDecomposition[102X( [3Xperm[103X ) [32X function167[6XReturns:[106X [33X[0;10YA list of permutations, representing the block-decomposition of168[10Xperm[110X. In the list the first permutation is [22Xπ[122X, as described in the169definiton of block-decomposition above.[133X170171[33X[0;0Y[10XBlockDecomposition[110X takes a plus- and minus-indecomposable permutation and172decomposes it into its maximal maximal intervals, which are preceded by the173simple permutation that represents the positions of the intervals. If a174plus- or minus-decomposable permutation is input, then the decomposition175will not be the unique decomposition, by the definition of plus- or minus-176decomposable permutations, see below.[133X177178[4X[32X Example [32X[104X179[4X[25Xgap>[125X [27XBlockDecomposition([3,2,10,8,9,1,5,7,4,6]);[127X[104X180[4X[28X[ [ 2, 4, 1, 3 ], [ 2, 1 ], [ 3, 1, 2 ], [ 1 ], [ 2, 4, 1, 3 ] ][128X[104X181[4X[25Xgap>[125X [27XBlockDecomposition([1,2,3,4,5]); [127X[104X182[4X[28X[ [ 1, 2 ], [ 1, 2, 3, 4 ], [ 1 ] ][128X[104X183[4X[25Xgap>[125X [27XBlockDecomposition([5,4,3,2,1]);[127X[104X184[4X[28X[ [ 2, 1 ], [ 4, 3, 2, 1 ], [ 1 ] ][128X[104X185[4X[25Xgap>[125X [27X [127X[104X186[4X[32X[104X187188189[1X8.5 [33X[0;0YPlus-Decomposability[133X[101X190191[33X[0;0YA permutation [22Xσ[122X is said to be plus-decomposable if it can be written192uniquely in the following form,[133X193194195[24X[33X[0;6Yσ = 12 [α_1,α_2][133X[124X196197[33X[0;0Ywhere [22Xα_1[122X is not plus-decomposable.[133X198199[33X[0;0YThe subset of a rational class, containing all permutations that are200plus-decomposable and in the class, has been found to be also rational under201the rank encoding.[133X202203[1X8.5-1 IsPlusDecomposable[101X204205[29X[2XIsPlusDecomposable[102X( [3Xperm[103X ) [32X function206[6XReturns:[106X [33X[0;10Y[10Xtrue[110X if [10Xperm[110X is plus-decomposable.[133X207208[33X[0;0YTo check whether [10Xperm[110X is a plus-decomposable permutation [10XIsPlusDecomposable[110X209uses the fact that there has to be an interval [22X1..x[122X where [22Xx <n[122X ([22Xn[122X = length210of the [10Xperm[110X) in the rank encoded permutation that is a valid rank encoding.[133X211212[4X[32X Example [32X[104X213[4X[25Xgap>[125X [27XIsPlusDecomposable([3,3,2,3,2,2,1,1]);[127X[104X214[4X[28Xtrue[128X[104X215[4X[25Xgap>[125X [27XIsPlusDecomposable([3,4,2,6,5,7,1,8]);[127X[104X216[4X[28Xtrue[128X[104X217[4X[25Xgap>[125X [27XIsPlusDecomposable([3,2,8,6,7,1,5,4]);[127X[104X218[4X[28Xfalse[128X[104X219[4X[25Xgap>[125X [27X[127X[104X220[4X[32X[104X221222223[1X8.6 [33X[0;0YMinus-Decomposability[133X[101X224225[33X[0;0YMinus-decomposability is essentially the same as plus-decomposability, the226difference is that if a permutation [22Xσ[122X is minus-decomposable, it can be227written uniquely in the following form,[133X228229230[24X[33X[0;6Yσ = 21 [α_1,α_2][133X[124X231232[33X[0;0Ywhere [22Xα_1[122X is not minus-decomposable.[133X233234[33X[0;0YHere also, the subset of a rational class, containing all permutations that235are minus-decomposable and in the class, has been found to be rational under236the rank encoding.[133X237238[1X8.6-1 IsMinusDecomposable[101X239240[29X[2XIsMinusDecomposable[102X( [3Xperm[103X ) [32X function241[6XReturns:[106X [33X[0;10Y[10Xtrue[110X if [10Xperm[110X is minus-decomposable.[133X242243[33X[0;0YTo check whether [10Xperm[110X (length of [10Xperm[110X = [22Xn[122X) is a minus-decomposable244permutation [10XIsMinusDecomposable[110X uses the fact that the first [22Xn-x[122X, where [22Xx<n[122X,245letters in the rank encoding of [10Xperm[110X have to be [22X>x[122X and that the letters from246position [22Xx+1[122X until the last one have to be [22X≤ x[122X.[133X247248[4X[32X Example [32X[104X249[4X[25Xgap>[125X [27XIsMinusDecomposable([3,3,3,3,3,3,2,1]);[127X[104X250[4X[28Xtrue[128X[104X251[4X[25Xgap>[125X [27XIsMinusDecomposable([3,4,5,6,7,8,2,1]);[127X[104X252[4X[28Xtrue[128X[104X253[4X[25Xgap>[125X [27XIsMinusDecomposable([3,2,8,6,7,1,5,4]);[127X[104X254[4X[28Xfalse[128X[104X255[4X[25Xgap>[125X [27X[127X[104X256[4X[32X[104X257258259[1X8.7 [33X[0;0YSums of Permutations[133X[101X260261[33X[0;0YThe direct sum of two permutations [22Xσ=σ_1 ... σ_k[122X and [22Xτ=τ_1...τ_l[122X is defined262as,[133X263264265[24X[33X[0;6Yσ ⊕ τ = σ_1 σ_2...σ_k τ_1+k τ_2+k...τ_l+k .[133X[124X266267[33X[0;0YIn a similar fashion the skew sum of [22Xσ, τ[122X is[133X268269270[24X[33X[0;6Yσ ⊖ τ = σ_1+l σ_2+l...σ_k+l τ_1 τ_2...τ_l .[133X[124X271272[33X[0;0YThe calculation of the direct and skew sums of permutations using the rank273encoding is also straight forward and is used in the functions described274below. The direct sum of two permutations [22Xσ,τ[122X represented as their rank275encoded sequences is the permutation which has the rank encoding that is the276concatention of the rank encoding of [22Xσ[122X and [22Xτ[122X. The skew sum of two277permutations [22Xσ,τ[122X encoded by the rank encoding is the concatenation of the278rank encodings of [22Xσ[122X and [22Xτ[122X where in the sequence corresponding to [22Xσ[122X under the279rank encoding each element has been increased by [22Xl[122X, with [22Xl[122X being the length280of [22Xτ[122X.[133X281282[1X8.7-1 PermDirectSum[101X283284[29X[2XPermDirectSum[102X( [3Xperm1[103X, [3Xperm2[103X ) [32X function285[6XReturns:[106X [33X[0;10YA permutation resulting from [10Xperm1[110X [22X⊕[122X [10Xperm2[110X.[133X286287[33X[0;0Y[10XPermDirectSum[110X returns the permutation corresponding to [10Xperm1[110X [22X⊕[122X [10Xperm2[110X if288[10Xperm1[110X and [10Xperm2[110X are both not rank encoded. If both [10Xperm1[110X and [10Xperm2[110X are rank289encoded, then [10XPermDirectSum[110X returns a rank encoded sequence.[133X290291[4X[32X Example [32X[104X292[4X[25Xgap>[125X [27XPermDirectSum([2,4,1,3],[2,5,4,1,3]);[127X[104X293[4X[28X[ 2, 4, 1, 3, 6, 9, 8, 5, 7 ][128X[104X294[4X[25Xgap>[125X [27XPermDirectSum([2,3,1,1],[2,4,3,1,1]);[127X[104X295[4X[28X[ 2, 3, 1, 1, 2, 4, 3, 1, 1 ][128X[104X296[4X[25Xgap>[125X [27X[127X[104X297[4X[32X[104X298299[1X8.7-2 PermSkewSum[101X300301[29X[2XPermSkewSum[102X( [3Xperm1[103X, [3Xperm2[103X ) [32X function302[6XReturns:[106X [33X[0;10YA permutation resulting from [10Xperm1[110X [22X⊖[122X [10Xperm2[110X.[133X303304[33X[0;0Y[10XPermSkewSum[110X returns the permutation corresponding to [10Xperm1[110X [22X⊖[122X [10Xperm2[110X if [10Xperm1[110X305and [10Xperm2[110X are both not rank encoded. If both [10Xperm1[110X and [10Xperm2[110X are rank306encoded, then [10XPermSkewSum[110X returns a rank encoded sequence.[133X307308[4X[32X Example [32X[104X309[4X[25Xgap>[125X [27XPermSkewSum([2,4,1,3],[2,5,4,1,3]);[127X[104X310[4X[28X[ 7, 9, 6, 8, 2, 5, 4, 1, 3 ][128X[104X311[4X[25Xgap>[125X [27XPermSkewSum([2,3,1,1],[2,4,3,1,1]);[127X[104X312[4X[28X[ 7, 8, 6, 6, 2, 4, 3, 1, 1 ][128X[104X313[4X[25Xgap>[125X [27X[127X[104X314[4X[32X[104X315316317318