Generating involutions, derangements, and relatives by ECO

HAL is a multi-disciplinary open access archive for the deposit and dissemination of scientific research documents, whether they are published or not. The documents may come from teaching and research institutions in France or abroad, or from public or private research centers. L’archive ouverte pluridisciplinaire HAL, est destinée au dépôt et à la diffusion de documents scientifiques de niveau recherche, publiés ou non, émanant des établissements d’enseignement et de recherche français ou étrangers, des laboratoires publics ou privés. Generating involutions, derangements, and relatives by ECO Vincent Vajnovszki

then {ϑ(x) ∩ O n } x∈On−1∪On−2 is a partition of O n , n ≥ 1, and ϑ is called an ECO operator.
In addition, if 3. for each x ∈ O n and y ∈ ϑ(x) one can compute y from x, and conversely, in constant time and constant size extra-space, then we call ϑ uniform.So, uniformity has an algorithmic meaning.
An ECO (or succession) rule corresponding to an ECO operator is a formal system consisting of a root e 0 and a set of productions of the form where e 0 and each e i (k), 1 ≤ i ≤ k, are integers.The right side of these productions are sequences of parenthesed integers.
An ECO rule explains how, to an object x ∈ O n with card(ϑ(x)) = k, the operator ϑ associates its k successors y 1 , y 2 , . . ., y j ∈ O n+1 , y j+1 , y j+2 , . . ., y k ∈ O n+2 with card(ϑ(y i )) = e i (k).Note that in productions above the size of objects does not occur explicitly, and when each object of size n has only successors of size n + 1, then these productions can be expressed simply (k) (e 1 (k))(e 2 (k)) . . .((e k )(k)).
which means that: • the root permutation, i.e. the length-1 permutation, has two successors, and • if a permutation has k successors, then each of them has in turn k + 1 successors, that is, each e i (k) equals k + 1.
• the permutation π is in S t+1 .
Moreover, any permutation in S t , t ≥ 2, can be uniquely obtained from a permutation in S t−1 by one of the two transformations above.
The algorithmic implementation of this construction is given by the recursive procedure in Algorithm 1.
Note that, if in this algorithm the last recursive call of gen Perm(t + 1) is removed, then it produces 1-cycles, that is, permutations consisting of a single cycle.In this case, the first levels of the obtained generating tree are presented in Figure 1(b), and this tree is the restriction to 1-cycles of the generating tree for unrestricted permutations in Figure 1(a).In the remainder of this paper we will give similar ECO-based recursive constructions together with their algorithmic implementations for Bell permutations, involutions, pure involutions and derangements.As for unrestricted permutations above, the computation tree for each obtained algorithm coincides with the induced tree of the corresponding ECO operator.

Bell permutations
where the subscript i is taken modulo j.Obviously, the cycle (x i x i+1 . . .x j−1 x 0 x 1 . . .x i−1 ) is equivalent to the cycle C and we choose to represent the cycles with their smallest element last.Any permutation is a product of disjoint cycles and the standard cycle representation of a permutation is obtained by imposing that cycles be written in increasing order of their smallest element (that is, their last Fig. 1: The first levels of the generating tree for permutations and 1-cycles.element).For example, the standard cycle representation of 4 2 5 1 7 6 3 ∈ S 7 is (4 1)(2)( 5 73)(6).As an aside independent of the rest of this article, let π ′ be the permutation in S n obtained after erasing the parentheses in the standard cycle representation of π ∈ S n .π can uniquely be recovered from π ′ and the transformation π → π ′ is a bijection from S n to itself.This map is essentially the transformation fondamentale of (14, Proposition 1.3.1),see also (23, pp. 17).We now consider the set B n of permutations in S n where each cycle is a decreasing sequence of integers.B n is in bijection with the set of all partitions of {1, 2, . . .n}: each cycle in π ∈ B n represents a block of the partition.For instance the partition corresponding to 4 2 7 1 3 6 5 ∈ B 7 is {4, 1}{2}{7, 5, 3}{6}.Thus, B n is counted by the Bell numbers (sequence A000110 in (22)) and we call it the set of Bell permutations.See also (16) for an alternative definition of Bell permutations in terms of pattern avoidance.
For π ∈ S n , a tail in π ∈ S n is an integer i such that π(i) is minimal in its cycle, and let T π denote the set of tails of π.
Lemma 1 B 1 = {1} and the set of tails of the permutation 1 is T 1 = {1}.If π ∈ B t , t ≥ 1, and its set of tails is T π , then (i) for any i ∈ T π , the permutation π • i, t + 1 is in B t+1 and its set of tails is T π , (ii) the permutation π is in B t+1 and its set of tails is T π ∪ {t + 1}.
Moreover, any permutation in B t , t ≥ 2, can be uniquely obtained from a permutation in B t−1 by one of the two transformations above.

Proof:
The proof is based on the following observations.If π ∈ B t , t ≥ 1, and i is a tail of π, then π(i) is the maximal element in the cycle of i and π • i, t + 1 is the permutation obtained from π by inserting t + 1 between i and π(i) in this cycle.So, π • i, t + 1 ∈ B t+1 and the set of tails of π • i, t + 1 equals that of π.On the other hand, π is a length t + 1 Bell permutation where t + 1 is a new single element cycle.✷ The previous recursive construction is embodied in the generating procedure in Algorithm 2 and the induced generating tree is the restriction to Bell permutations of the generating tree for unrestricted permutations induced by Fact 1.The first levels of this tree are depicted in Figure 2. Now we show how the construction in Lemma 1 is related to the ECO rule for Bell permutations in Table 1.Suppose that π is a Bell permutation with c cycles (and so, c = card(T π )).π produces c + 1 permutations: c by point (i) and one by point (ii).Let consider now a permutation with k successors, and so with k − 1 cycles.It produces • by point (i): k − 1 Bell permutations with k − 1 cycles each, and so with k successors; • by point (ii): one Bell permutation with k cycles, and so with k + 1 successors.

Involutions
An involution is a permutation π where π • π equals the identity permutation, and let I n ⊆ S n denote the set of length-n involutions.Here we give two recursive constructions for I n : by fixed points and by recurrence.

Involution by fixed points
Lemma 2 I 1 = {1} and the set of fixed points of the permutation 1 is F 1 = {1}.If π ∈ I t , t ≥ 1, and F π is the set of its fixed points, then (i) for any i ∈ F π , the permutation π • i, t + 1 is in I t+1 and its set of fixed points is F π \ {i}, (ii) the permutation π is in I t+1 and its set of fixed points is F π ∪ {t + 1}.
Moreover, any permutation in I t , t ≥ 2, can be uniquely obtained from a permutation in I t−1 by one of the two transformations above.
Proof: Clearly, every permutation obtained from a π ∈ I t , t ≥ 1, by each of the two transformations above is an involution.Conversely, for any τ ∈ I n , n ≥ 2, there exists a unique π ∈ I n−1 such that τ is obtained from π by one of these transformations.Indeed, if n is not a fixed point of τ , then let i = τ (n) and π be the involution defined by π(j) = τ (j) for all j, 1 ≤ j ≤ n − 1, except π(i) = i; and so τ = π • i, n .If n is a fixed point of τ , then π is simply defined by π(j) = τ (j) for all j, 1 ≤ j ≤ n − 1, and in this case τ = π.✷ The recursive construction in the previous lemma is implemented in Algorithm 3 and the first levels of the induced generating tree are depicted in Figure 3. Now we show how this lemma mirrors the first ECO rule for involutions in Table 1.Let π be an involution with f fixed points.Then it produces f + 1 involutions: f by point (i) and one by point (ii).Conversely, if π has k successors, then it has f = k − 1 fixed points and produces (2) n ≥ 2, and τ (n) = n − 1 (and so τ (n − 1) = n), or (3) n ≥ 2, n is not a fixed point of τ and τ (n) = n − 1.
Let now τ ∈ I n as in case (3).When n − 1 is a fixed point of τ let i = τ −1 (n) = τ (n) and define the length-(n − 2) permutation π by π(j) = τ (j) for all j, 1 ≤ j ≤ n − 2, except π(i) = i; in this case π is an involution, i is a fixed point of π and τ = π • i, n .So τ is obtained from π by the first transformation of the last point of the present lemma.
When n − 1 is not a fixed point of τ , then define the length-(n − 2) permutation π as and τ is obtained from π by the second transformation of the last point of the this lemma.✷ Below we show that the lemma above is related to the second ECO rule for involutions in Table 1.Its algorithmic counterpart is given by Algorithm 4 and in Figure 4 are depicted the first levels of the induced generating tree.
Algorithm 4 Procedure generating length-n involutions by recurrence.Initially π = 1 2 3 . . .n and the main call is gen Inv R(0).procedure gen Inv R(t) local i,σ; if t = n then Print(π); else gen Inv R(t + 1); If π is an involution of length t, then it has t + 2 successors: one of length t + 1 by point (i), and t + 1 of length t + 2 by point (ii) and (iii).Conversely, if π has k successors (and so length t = k − 2), then it produces • by point (i): one involution of length t + 1, and so with t + 3 = k + 1 successors • by point (ii) and (iii): k − 1 involutions of length t + 2, and so with t + 4 = k + 2 successors each.

Pure involutions
A pure involution (or fixed point free involution) is an involution with no fixed point, that is, with no entries i with π(i) = i.So, a pure involution is a permutation which is both an involution and a derangement and let P n denote the set of length-n pure involutions.Clearly P n = ∅ for any odd n.The next lemma is the restriction of Lemma 3 to involutions where fixed points are disallowed.Its algorithmic counterpart is the generating procedure given in Algorithm 5 and its corresponding ECO rule is given in Table 1.Proof: It is routine to check that for a π ∈ D t , t ≥ 0, the permutations obtained from π by applying each of the three transformations above is a derangement.Conversely, for every τ ∈ D n , n ≥ 2, we define a permutation π of length n − 1 or n − 2 such that τ is uniquely obtained from π by one of these transformations.For a τ ∈ D n one of the following cases occurs: (1) n belongs to a cycle of τ of length at least three, or In case (1) , let i = τ −1 (n) and define π as the length-(n − 1) permutation with π(j) = τ (j) for all j, 1 ≤ j ≤ n − 1, except π(i) = τ (n) = i.Clearly π ∈ D n−1 , τ = π • i, n and n belongs to a cycle of τ of length at least three.In this case τ is uniquely obtained from a π ∈ D n−1 and a i ∈ {1, 2, . . ., n − 1}.
Finally, let τ be as in case (3) above and define the length-(n − 2) permutation π by . In other words, π is the permutation obtained from τ by deleting the length-2 cycle containing n and then replacing (n − 1) in its cycle by i = τ (n), thus π ∈ D n−2 .For example π = 2 1 corresponds to τ = 4 3 2 1 and to τ = 3 4 1 2. π and τ are related by τ = π • π −1 (i), n − 1 • i, n • n − 1, n and so any permutation in D n satisfying case (3) above is uniquely obtained from a π ∈ D n−2 and an i ∈ {1, 2, . . ., n − 2}.If for a given π as in the previous 1. is a terminal call and produces a combinatorial object, or 2. produces at least two recursive calls, or 3. produces only one recursive call which in turn has either property 1 or 2.
All the algorithms presented in this paper are CAT.Indeed, if sets (of tails or of fixed points) are represented by linked lists, then in each generating procedure the amount of computation in each call is proportional to the number of recursive calls produced.In addition, except for the initial call of the procedure generating derangements (that is, gen Der(0)), all the algorithms satisfy the three CAT properties and that is a direct consequence of the shape and uniformity of the corresponding ECO rules and operators.

Concluding remarks
The techniques presented here were anticipated in (1; 7).Nevertheless, the previous approaches used strings of integers for encoding the objects and it was necessary to have another algorithm to retrieve the object.Also, the application of our method to other classes of permutations such as Bessel permutations (13; 8) (see the last row of Table 1 for their ECO system), or generally, to other classes of combinatorial objects, remains an interesting problem.

Fig. 2 :
Fig. 2:The first four levels of the generating tree for Bell permutations.It is simply the restriction to Bell permutations of the generating tree for unrestricted permutations in Figure1(a).The tails of each permutation are underlined.

Fig. 3 :
Fig. 3:The first four levels of the generating tree for involutions by fixed points.

Fig. 4 :
Fig. 4:The first five levels of the generating tree for involutions by recurrence.

Fig. 5 :
Fig. 5:The first five levels (the second level is empty) of the generating tree for derangements.

1
Algorithm producing exhaustively length-n permutations.n and π are both global variables and initially π is 1 2 3 . . .n ∈ S n .The main call is gen Perm(1) and the statement π := π • i, t + 1 after each recursive call restores the value of π before this call.