An algorithm computing combinatorial specifications of permutation classes∗ F. Bassino† M. Bouvel‡ A. Pierrot§ C. Pivoteau¶,† D. Rossink
arXiv:1506.00868v1 [math.CO] 2 Jun 2015
June 3, 2015
Abstract This article presents a methodology that automatically derives a combinatorial specification for a permutation class C, given its basis B of excluded patterns and the set of simple permutations in C, when these sets are both finite. This is achieved considering both pattern avoidance and pattern containment constraints in permutations. The obtained specification yields a system of equations satisfied by the generating function of C, this system being always positive and algebraic. It also yields a uniform random sampler of permutations in C. The method presented is fully algorithmic.
1
Introduction
Permutation classes were introduced in the seventies and it soon became clear that these classes – or the underlying pattern order on permutations – were interesting objects whose set would deserve to be studied as a combinatorial family on its own. However, until ten years ago, most of the research on these permutation classes has focused on enumeration results of specific classes. From then, a more global line of research has started to develop with the goal of describing general properties of permutation classes [Vat15, and references therein]. A fruitful approach for obtaining such results is to consider permutations through their substitution decomposition. In this framework, it appears that the family of simple permutations somehow contains most of the difficulty. This holds for enumerative problems [AA05, AAB11, AB14, ASV12, among others], but also in other areas like algorithmics [BBCP07, BR06]. In this context, our goal is to solve algorithmically a combinatorial problem on permutation classes: computing in an automatic way a combinatorial description for any given class (under some conditions). We first have to determine how to describe the permutation class C in input. We will suppose that C is given by its basis B of excluded ∗
This work was completed with the support of the ANR project MAGNUM number 2010 BLAN 0204. LIPN UMR 7030, Universit´e Paris 13 and CNRS, Villetaneuse, France. ‡ CNRS and Institut f¨ ur Mathematik, Universit¨at Z¨ urich, Zurich, Switzerland. § LRI UMR 8623, Universit´e Paris Sud and CNRS, Orsay, France. ¶ LIGM UMR 8049, Universit´e Paris Est and CNRS, Marne-la-Vall´ee, France. k ´ LIX UMR 7161, Ecole Polytechnique and CNRS, Palaiseau, France. †
1
patterns and the set SC of simple permutations in C, assuming that both these sets are finite. Notice that by earlier work [BRV08, BBPR15], it is enough to know B to decide whether SC is finite and (in the affirmative) to compute SC [PR12]. Two previous articles consider this question of finding a combinatorial description of a permutation class C, given B and SC which are both finite. The first answer is provided in [AA05], where the authors prove that the generating function of such a class is algebraic. The main step in the proof is to construct a system of combinatorial equations describing C using substitution decomposition. Although the proof is in essence constructive, there is still some work to be done to fully automatize this process. Notice also that the description of C obtained in this way is a priori ambiguous. Next [BHV08] gives a second proof of the above algebraicity result which also relies on combinatorial descriptions of classes, the descriptions being this time non ambiguous. This is an elegant approach that generalizes to the generating functions of some subsets of permutation classes (involutions, alternating permutations, . . . ). However, the level of generality of this proof makes it difficult to extract an explicit construction from it. Our method to compute combinatorial descriptions of classes focuses on two aspects that were not essential in those previous works. First, we want this method to be constructive and fully algorithmic. Second, we insist on obtaining non ambiguous descriptions, namely combinatorial specifications that allow to enter the framework of the symbolic method [FS09]. This framework has several nice features including automatic translation of the specifications into systems of equations for the generating series, and generic algorithms for uniform random sampling [FZVC94, DFLS04]. Indeed, as discussed later, the initial motivation of our work was to provide such random samplers for the study of permutations classes from a probabilistic perspective. To our knowledge, there is no result so far on the random generation of permutations in classes defined by pattern avoidance. It may come from the existence of a naive algorithm to generate uniformly at random a permutation in a class whose basis B of excluded patterns is given: generate a random permutation σ; test whether it avoids every pattern in B; in this case return σ, otherwise reject σ and try again. This procedure is however very inefficient. Indeed, the probability of rejection tends to 1 as n grows, since there are n! permutations of size n and only O(cn ) in the class, for some constant c – from Stanley-Wilf ex-conjecture, now Marcus-Tardos Theorem [MT04]. Moreover, testing whether a permutation σ contains a pattern π of B is an N P -hard problem for general π [BBL98] (and except for some very special patterns π, the known algorithms are of exponential complexity w.r.t. the size of π). The reason why we want a constructive method, and actually a proper algorithm, is in order to have it implemented. Indeed the resulting program can then be plugged into routine algorithms for random sampling. This provides us with tools for the observation of uniform random permutations in many classes, opening towards the study of average properties of such permutations, from an experimental point of view. Another look at this question is given in some recent works describing the average shape of permutations in the simplest classes (avoiding one pattern of size three) [AM14, HRS14, MP14a, MP14b]. Because our goal differs from that of [AA05, BHV08], so do the means to reach this goal. As in [AA05], our starting point is substitution decomposition and decomposition trees in which we propagate pattern avoidance constraints. This process yields an ambiguous description of the class, from which we derive a combinatorial specification as 2
follows: we get rid of the ambiguity by introducing complement sets, which means that we are not only propagating avoidance constraints but also containment constraints. Even though the purposes of those two types of constraint are opposite, the ways to propagate them are very similar. This article is organized as follows. Section 2 proceeds with some background on permutation classes, substitution decomposition, and the symbolic method. After briefly solving the case of substitution-closed classes in Section 3, we explain in two steps how to obtain a combinatorial specification for other classes C. Section 4 gives an algorithm producing an ambiguous system of combinatorial equations describing C. Next, Section 5 describes a disambiguation algorithm to obtain from it a combinatorial specification for C. We conclude in Section 6 by giving the algorithmic context around our work: we describe an algorithmic chain from the basis B of a class C to random sampling of permutations in C, illustrate it on an example, and give some perspectives opened by this work.
2 2.1
Some background on permutations and combinatorial specifications Permutation patterns and permutation classes
A permutation σ of size |σ| = n is a bijective map from [1..n] = {1, . . . , n} to itself. We represent a permutation by a word σ = σ1 σ2 . . . σn , where each letter σi denotes the image of i under σ. We denote ε the only permutation of size 0; ε is also called the empty permutation. Definition 2.1. For any sequence s of k distinct integers, the normalization of s is the permutation π of size k which is order-isomorphic to π, i.e., s` < sm whenever π` < πm . For any permutation σ of size n, and any subset I = {i1 , . . . , ik } of {1, . . . , n} with i1 < . . . < ik , σI denotes the permutation of size k obtained by normalization of the sequence σi1 . . . σik . Definition 2.2. A permutation π is a pattern of a permutation σ if and only if there exists a subset I of {1, . . . , |σ|} such that σI = π. We also say that σ contains or involves π, and we write π 4 σ. A permutation σ that does not contain π as a pattern is said to avoid π. Example 2.3. The permutation σ = 316452 contains the pattern 2431 whose occurrences are 3642 and 3652. But σ avoids the pattern 2413 as none of its subsequences of length 4 is order-isomorphic to 2413. The pattern containment relation 4 is a partial order on permutations, and permutation classes are downsets under this order. In other words: Definition 2.4. A set C of permutations is a permutation class if and only if for any σ ∈ C, if π 4 σ, then we also have π ∈ C. Throughout this article, we take the convention that a permutation class only contains permutations of size n ≥ 1, i.e., ε ∈ / C for any permutation class C. 3
Every permutation class C can be characterized by a unique antichain B (i.e., a unique set of pairwise incomparable elements) such that a permutation σ belongs to C if and only if it avoids every pattern in B (see for example [AA05]). The antichain B is called the basis of C, and we write C = Av(B). The basis of a class C may be finite or infinite; it is described as the permutations that do not belong to C and that are minimal in the sense of 4 for this criterion.
2.2
Simple permutations and substitution decomposition of permutations
The description of permutations in the framework of constructible structures (see Section 2.3) that will be used in this article relies on substitution decomposition of permutations. Substitution decomposition is a general framework, adapted to various families of discrete objects [MR84], that is based on core items and relations and in which every object can be recursively decomposed into core objects using relations. In the case of permutations, core elements are simple permutations and relations are substitutions. Definition 2.5. An interval of a permutation σ of size n is a non-empty subset {i, . . . , (i+ ` − 1)} of consecutive integers of {1, . . . , n} whose images by σ also form a set of consecutive integers. The trivial intervals of σ are {1}, . . . , {n} and {1, . . . , n}. The other intervals of σ are called proper. Definition 2.6. A block (resp. normalized block) of a permutation σ is any sequence σi1 . . . σim (resp. any permutation σI ) for I = {i1 , . . . , im } an interval of σ. Definition 2.7. A permutation σ is simple when it is of size at least 4 and it contains no interval, except the trivial ones. Notice that the permutations 1, 12 and 21 also have only trivial intervals, nevertheless they are not considered to be simple here. Moreover no permutation of size 3 has only trivial intervals. For a detailed study of simple permutations, in particular from an enumerative point of view, we refer the reader to [AA05, AAK03, Bri10]. Let us only mention that the number of simple permutations of size n is asymptotically equivalent to en!2 as n grows. Let σ be a permutation of size n and π 1 , . . . , π n be n permutations of size p1 , . . . , pn respectively. Define the substitution σ[π 1 , π 2 , . . . , π n ] of π 1 , π 2 , . . . , π n in σ (also called inflation in [AA05]) to be the permutation obtained by concatenation of n sequences of integers S 1 , . . . , S n from left to right, such that for every i, j, the integers of S i form a block, are ordered in a sequence order isomorphic to π i , and S i consists of integers smaller than S j if and only if σi < σj . The interested reader may find a formal definition in [Pie13, Definition 0.25]. When a permutation τ may be written as τ = σ[π 1 , π 2 , . . . , π n ], we also say that σ[π 1 , π 2 , . . . , π n ] provides a block decomposition of τ . Example 2.8. The substitution 1 3 2[2 1, 1 3 2, 1] gives the permutation 2 1 4 6 5 3. In particular, 1 3 2[2 1, 1 3 2, 1] is a block decomposition of 2 1 4 6 5 3. When substituting in σ = 12 or 21, we often use ⊕ (resp. ) to denote the permutation 12 (resp. 21). 4
Definition 2.9. A permutation π is ⊕-indecomposable (resp. -indecomposable) if it cannot be written as ⊕[π 1 , π 2 ] (resp. [π 1 , π 2 ]). Simple permutations, together with ⊕ and , are enough to describe all permutations through their substitution decomposition: Theorem 2.10 (Proposition 2 of [AA05]). Every permutation π of size n with n ≥ 2 can be uniquely decomposed as either: • ⊕[π 1 , π 2 ], with π 1 ⊕-indecomposable, • [π 1 , π 2 ], with π 1 -indecomposable, • σ[π 1 , π 2 , . . . , π k ] with σ a simple permutation. Remark 2.11. The simple permutation σ in the third item of Theorem 2.10 is a pattern of permutation π. Hence, as soon as π belongs to some permutation class C, then so does σ. Another version of Theorem 2.10 may be found in the literature, where the first (resp. second) item is replaced by 12 . . . k[π 1 , . . . , π k ] (resp. k . . . 1[π 1 , . . . , π k ]) for all possible k ≥ 2 where all π i are ⊕- (resp. -)indecomposable. This variant has the advantage of avoiding the asymmetry of Theorem 2.10 with respect to the π i . For this reason, it may be preferred for a use in combinatorics. However, we focus here on algorithmic aspects, and the statement of Theorem 2.10 is more adapted for this purpose. Indeed, there are only two cases of non-simple skeletons or roots (namely ⊕ = 12 and = 21) instead of the infinite families of permutations 12 . . . k and k . . . 21 for any k ≥ 2. Theorem 2.10 provides the first step in the decomposition of a permutation π. To obtain its full decomposition, we can recursively decompose the permutations π i in the same fashion, until we reach permutations of size 1. This recursive decomposition can naturally be represented by a tree, that is called the substitution decomposition tree (or decomposition tree for short) of π. Definition 2.12. The substitution decomposition tree T of a permutation π is the unique ordered tree encoding the substitution decomposition of π, where each internal node is either labeled by ⊕, – those nodes are called linear – or by a simple permutation σ – prime nodes. Notice that in decomposition trees, linear nodes are always binary, and the left child of a node labeled by ⊕ (resp. ) may not be labeled ⊕ (resp. ), since π 1 is ⊕-indecomposable (resp. -indecomposable) in the first (resp. second) item of Theorem 2.10. Example 2.13. The permutation π = 6 9 8 7 3 11 5 4 10 17 1 2 14 16 13 15 12 can be recursively decomposed as π = 2413[476519328, 1, 12, 35241] = 2413[31524[⊕[1, [1, [1, 1]]], 1, 1, [1, 1], 1]], 1, ⊕[1, 1], [2413[1, 1, 1, 1], 1]] and its decomposition tree is given in Figure 1. 5
2413 ⊕
31524 ⊕
2413
Figure 1: Decomposition tree of π = 6 9 8 7 3 11 5 4 10 17 1 2 14 16 13 15 12.
Definition 2.14. The substitution closure Cˆ of a permutation class C is defined as ∪k≥1 C k where C 1 = C and C k+1 = {σ[π 1 , . . . , π n ] | σ ∈ C and π i ∈ C k for any i from 1 to n = |σ|}. Because simple permutations contain no intervals, we have: Remark 2.15. For any class C, the simple permutations in Cˆ are exactly the simple permutations in C. Consequently, for any permutation class C, this allows to describe Cˆ as the class of all permutations whose decomposition trees can be built on the set of nodes {⊕, } ∪ SC , where SC denotes the set of simple permutations in C (if 12 and 21 belong to C; otherwise we have to remove ⊕ or from the set of nodes). ˆ or equivalently Definition 2.16. A permutation class C is substitution-closed if C = C, if for every permutation σ of C, and every permutations π 1 , π 2 , . . . , π n of C (with n = |σ|), the permutation σ[π 1 , π 2 , . . . , π n ] also belongs to C. Like before, a substitution-closed permutation class can therefore be seen as the set of decomposition trees built on the set of nodes {⊕, } ∪ SC (if 12 and 21 belong to C; but otherwise C is trivial and has at most one permutation of each size). The terminology wreath-closed permutation class is also used, derived on the term wreath product sometimes used to denote the substitution operation in the context of permutations [AA05, for instance]. Remark 2.17. In [AA05], it is proven that substitution-closed permutation classes can be characterized as the permutation classes Av(B) whose basis B contains only simple permutations (or maybe 12 or 21 for trivial classes).
6
2.3
From combinatorial specifications to generating functions and random samplers
Let us leave aside permutations for now, and review some basics of the symbolic method about constructible structures and their description by combinatorial specifications. We will see in Theorem 5.11 of Section 5 that the classes of permutations we are interested in fit in this general framework. A class C of combinatorial structures is a set of discrete objects equipped with a notion of size: the size is a function of C → N denoted | · | such that for any n the number of objects of size n in C is finite. Among the combinatorial structures, we focus on constructible ones, from the framework introduced in [FS09]. Basically, a constructible combinatorial class is a set of structures that can be defined from atomic structures of size 1 (denoted by Z), possibly structures of size 0 (denoted by E), and assembled by means of admissible constructors. While a complete list of these combinatorial constructors is given in [FS09], we only use a (small)P subset of them: the disjoint union, denoted by ] or + (we may also use the notation ), to choose between structures; and the Cartesian product, denoted by ×, to form pairs of structures. More formally, a constructible combinatorial class is one that admits a combinatorial specification. Definition 2.18. A combinatorial specification for a combinatorial class C1 is an equation or a set of equations of the form C1 = H1 (E, Z, C1 , C2 , . . . , Cm ), C2 = H2 (E, Z, C1 , C2 , . . . , Cm ), .. . C = H (E, Z, C , C , . . . , C ), m
m
1
2
m
where each Hi denotes a term built from C1 , . . . , Cm , Z and E using admissible constructors. For example, the equation I = E + Z × I describes a class I whose elements are finite sequences of atoms. In this framework, the size of a combinatorial structure is its number of atoms (Z) and from there, combinatorial structures can be counted according to their size. The size information for a whole combinatorial class, sayP C, is encoded by its ordinary generating function, which is a formal power series C(z) = n≥0 cn z n where the coefficient cn is the P number of structures of size n in C. Note that we also have C(z) = π∈C z |π| Combinatorial specifications of combinatorial classes may be automatically translated into systems defining their generating function (possibly implicitly). This system is obtained by means of a dictionary that associates an operator on generating functions to each admissible constructor. The complete dictionary is given in [FS09], together with the proof that this translation from constructors of combinatorial classes to operators on their generating functions is correct. Here, we only use the constructors disjoint union and Cartesian product, which are respectively translated to sum and product of generating functions. 7
A lot of information can be extracted from such functional systems; in particular, one can compute as many coefficients of the series as required, and [FS09] provides many tools to get asymptotic equivalents for these coefficients. Combinatorial specifications may also be automatically translated into uniform random samplers of objects in the class described by the specification. Indeed, a specification can be seen as a (recursive) procedure to produce combinatorial objects, and randomizing the choices made during this procedure transforms the specification into a random sampler. To ensure that such random samplers are uniform (i.e. that for any n, two objects of the same size n have the same probability of being produced), two methods have been developed: the recursive method [FZVC94] and the Boltzmann method [DFLS04]. In the first one, the coefficients of the generating functions are used for the probabilistic choices to ensure uniformity, making this method well-adapted for generating a large sample of objects of relatively small size: this requires to compute only once a relatively small number of coefficients. The focus of the second one is to allow the generation of very large objects, with a small tolerance (of a few percents) allowed on their size. Coefficients of the generating functions are not needed in Boltzmann samplers, but rather the generating functions themselves. More precisely, the value of the generating function at a given point needs to be computed, and this is solved in [PSS12].
3
Combinatorial specification of substitution-closed classes
Recall that we denote by Cˆ the substitution closure of the permutation class C, and that ˆ or equivalently when the permutations in C C is a substitution-closed class when C = C, are exactly the ones whose decomposition trees have internal nodes labeled by ⊕, or any simple permutation of C. For the purpose of this article, we additionally introduce the following notations: Definition 3.1. For any set A of permutations, A+ (resp. A− ) denotes the set of permutations of A that are ⊕-indecomposable (resp. -indecomposable) and SA denotes the set of simple permutations of A. Then Theorem 2.10 directly yields the following proposition: Proposition 3.2 (Lemma 11 of [AA05]). Let Cˆ be a substitution-closed class (that tains 12 and 21). 1 Then Cˆ satisfies the following system of equations, denoted ECˆ: ˆ ] [Cˆ− , C] ˆ ]U ˆ ˆ Cˆ = 1 ] ⊕[Cˆ+ , C] π∈SCˆ π[C, . . . , C] ˆ ] U ˆ ˆ Cˆ+ = 1 ] [Cˆ− , C] π∈SCˆ π[C, . . . , C] ˆ ] U ˆ ˆ Cˆ− = 1 ] ⊕[Cˆ+ , C] π∈S ˆ π[C, . . . , C]. C
con(1) (2) (3)
By uniqueness of the substitution decomposition, unions are disjoint and so Equaˆ tions (1) to (3) describe unambiguously the substitution-closed class C. Hence, Proposition 3.2 can be transposed in the framework of constructible structures as follows: 1
It will be the case until the end of the article and will not be recalled again.
8
Theorem 3.3. Let C be a substitution-closed class. Then C can be described as a constructible combinatorial class in the sense of Section 2.3 with the combinatorial specification:2 P C = Z + C+ × C + C− × C + · · × C} π∈SC C | × ·{z |π| P + − C =Z + C ×C + · · × C} π∈SC C | × ·{z |π| P − + C =Z + C ×C + · · × C} . π∈SC C | × ·{z |π|
Moreover this system can be translated into an equation for the generating function C: Proposition 3.4 (Theorem 12 of [AA05]). Let C be a substitution-closed class, with generating function C(z). Then C(z)2 + (SC (C(z)) − 1 + z)C(z) + SC (C(z)) + z = 0 with SC (z) denoting the generating function that enumerate simple permutations in C, P |π| i.e. SC (z) = π∈SC z . Hence, in the case of a substitution-closed class C (and for the substitution closure of any class), the system EC that recursively describes the permutations in C can be immediately deduced from the set SC of simple permutations in C. As soon as SC is finite and known, this system is explicit and gives a combinatorial specification. Our next goal is to describe an algorithm that computes a combinatorial system of equations for a general permutation class C from the simple permutations in C, like for the case of substitution-closed classes. However, when the class is not substitution-closed, this is not as straightforward as what we have seen in Proposition 3.2, and we provide details on how to solve this general case in the following sections.
4
A possibly ambiguous combinatorial system for permutation classes
Theorem 10 of [AA05] states that a permutation class with finitely many simple permutations has an algebraic generating function. We follow the guideline of the constructive proof of this theorem, where the authors describe a method to derive a system of equations for a class C with finitely many simple permutations from the combinatorial specification of its substitution closure. However, unlike [AA05], we make the whole process fully algorithmic. The key idea of the method is to describe recursively the permutations in C, replacing the constraint of avoiding the elements of the basis by constraints in the subtrees of the 2
Instead of C × · · · × C , we should write Φπ (C, · · · , C ) where Φπ is an operator depending of π which | {z } | {z } |π|
|π|
behaves similarly to the Cartesian product. So the sum is indeed a disjoint union.
9
decomposition tree of permutations in C. This is done by computing the embeddings of non-simple permutations γ of the basis3 B of C into simple permutations π belonging to the class C (and into ⊕ and ). These embeddings are block decompositions of the permutations γ, each (normalized) block being translated into a new avoidance constraint pushed downwards in the decomposition tree. We then need to add new equations in the specification for C to take into account these new constraints. An essential remark is that the obtained combinatorial system may be ambiguous, since it may involve unions of sets that are not always disjoint. We will tackle the problem of computing a non-ambiguous system in Section 5.
4.1
A first system of equations
Consider a permutation class C, whose basis is B and which is not substitution-closed. ˆ We compute a system describing C by adding constraints to the system obtained for C, as in [AA05]. We denote by B ? the subset of non-simple permutations of B and by AhEi the set of permutations of A that avoid every pattern in E, for any set A of permutations and any set E of patterns. Notice that we have (AhEi)+ = A+ hEi: both notations correspond to permutations of A that avoid E and that are ⊕-indecomposable. The same goes for A− . Proposition 4.1. Let C be a permutation class, that contains 12 and 21. We have C δ = Cˆδ hB ? i for δ ∈ { , +, −}4 . Moreover, ˆ ˆ ? ˆ ? i = 1 ] ⊕[Cˆ+ , C]hB ˆ ? i ] [Cˆ− , C]hB ˆ ?i ] U ChB π∈SC π[C, . . . , C]hB i ˆ ?i ] U ˆ ˆ ? Cˆ+ hB ? i = 1 ] [Cˆ− , C]hB π∈SC π[C, . . . , C]hB i ˆ ˆ ? ˆ ?i ] U Cˆ− hB ? i = 1 ] ⊕[Cˆ+ , C]hB π∈SC π[C, . . . , C]hB i,
that
(4) (5) (6)
all these unions being disjoint. ˆ ? i. Conversely, let σ ∈ ChB ˆ ?i Proof. Let σ ∈ C, then σ ∈ Cˆ and σ avoids B ? , thus σ ∈ ChB and let π ∈ B. If π ∈ B ? then σ avoids π. Otherwise, π is simple and π ∈ / C, hence ˆ Indeed by definition of C, ˆ S ˆ = SC (see Remark 2.15). Since σ ∈ C, ˆ σ avoids π ∈ / C. C ˆ ? i = C, thus Cˆδ hB ? i = C δ . Then the result follows from π. Hence σ ∈ C. Finally ChB Proposition 3.2 recalling that SCˆ = SC . Equations (4), (5) and (6) do not provide a combinatorial specification because the ˆ . . . , C]hB ˆ ? i are not simply expressed from the terms appearing on the left-hand terms π[C, side of these equations. To solve this problem, we can think of another way of adding constraints to Equation (1). Instead of decorating all terms with constraint hB ? i like in Equation (4), on the right-hand side of Equation (1), we propagate this constraint into the subtrees. This constraint propagation is realized by Lemma 18 of [AA05] which ˆ . . . , C]hB ˆ ? i as union of smaller sets: expresses sets π[C, ˆ . . . , C]hB ˆ ? i = Sk π[ChE ˆ i,1 i, ChE ˆ i,2 i, . . . , ChE ˆ i,k i] π[C, (7) i=1 3 Recall that [AA05, Theorem 9] ensures that, as soon as C contains finitely many simple permutations, then the basis of C is finite. 4 δ C for δ ∈ { , +, −} means that C δ is either C or C + or C − .
10
where the Ei,j are sets of permutations which are patterns of some permutations of ˆ B ? . For instance, with C = Av(231), we have B ? = {231}, and [Cˆ− , C]h231i = − ˆ ˆ [C h12i, Ch231i]. In this example, notice that the set Cˆ− h12i, which is not part of the system, has appeared on the right-hand side of this equation, and we now need a new equation to describe it. In the general case, applying Equation (7) introduces sets of the form Cˆδ hEi,j i on the right-hand side of an equation of the system that do not appear on the left-hand side of any equation. We will call such sets right-only sets. For each such set, we will need to add a new equation to the system, starting from Equation (1), (2) or (3) depending on δ, and propagating constraint Ei,j instead of B ? . This creates new right-only terms in these new equations, and they are treated recursively in the same way. This process terminates, since the Ei,j are sets of patterns of elements of B ? , and there is only a finite number of such sets (as B is finite). The key to the precise description of the sets Ei,j , and to their effective computation, is given by the embeddings of permutations γ that are patterns of some β ∈ B ? into the simple permutations π of C.
4.2
Embeddings: definition and computation
Recall that ε denotes the empty permutation, i.e. the permutation of size 0. We take the convention Ahεi = ∅. A generalized substitution (also called lenient inflation in [BHV08]) σ{π 1 , π 2 , . . . , π n } is defined like a substitution with the particularity that any π i may be the empty permutation. Notice that σ[π 1 , π 2 , . . . , π n ] necessarily contains σ whereas σ{π 1 , π 2 , . . . , π n } may avoid σ. For instance, the generalized substitution 1 3 2{2 1, ε, 1} gives the permutation 2 1 3 which avoids 1 3 2. Thanks to generalized substitutions, we define the notion of embedding, which expresses how a pattern γ can be involved in a permutation whose decomposition tree has a root π: Definition 4.2. Let π = π1 . . . πn and γ be two permutations of size n and p respectively and Pγ the set of intervals5 of γ, including the trivial ones. An embedding of γ in π = π1 . . . πn is a map α from {1, . . . , n} to Pγ such that: • if the intervals α(i) and α(j) are not empty, and i < j, then α(i) consists of smaller indices than α(j); • as a word, α(1) . . . α(n) is a factorization of the word 1 . . . |γ| (which may include empty factors). • it holds that π{γα(1) , . . . , γα(n) } = γ – see Definition 2.1 (p.3) for the definition of γα(i) . ( 1 7→ [1..|γ|] Example 4.3. For any permutations γ and π, α : is an embedding k > 1 7→ ∅ of γ in π. Indeed γ[1..|γ|] = γ and π{γ, ε, . . . , ε} = γ. 5
Recall that in this article, an interval of a permutation is a set of indices corresponding to a block of the permutation.
11
Note that if we denote the non-empty images of α by α1 , . . . , αN and if we remove from π the πi such that α(i) = ε, we obtain a pattern σ of π such that γ = σ[γα1 , . . . , γαN ]. But this pattern σ may occur at several places in π so a block decomposition γ = σ[γα1 , . . . , γαN ] may correspond to several embeddings of γ in π. Example 4.4. There are 12 embeddings of γ = 5 4 6 3 1 2 into π = 3 1 4 2, which correspond for instance to the generalized substitutions π{3241, 12, ε, ε}, π{3241, ε, ε, 12} and π{ε, ε, 3241, 12} for the same expression of γ as the substitution [3241, 12], or π{3241, 1, ε, 1} which is the only one corresponding to 312[3241, 1, 1]. These 12 embeddings are shown in Table 1.
γ = 1[546312]
= π{546312, ε, ε, ε} = π{ε, 546312, ε, ε} = π{ε, ε, 546312, ε} = π{ε, ε, ε, 546312} γ = [213, 312] = π{213, 312, ε, ε} = π{213, ε, ε, 312} = π{ε, ε, 213, 312} γ = [3241, 12] = π{3241, 12, ε, ε} = π{3241, ε, ε, 12} = π{ε, ε, 3241, 12} γ = 231[21, 1, 312] = π{21, ε, 1, 312} γ = 312[3241, 1, 1] = π{3241, 1, ε, 1}
γα(1) 546312 ε ε ε 213 213 ε 3241 3241 ε 21 3241
γα(2) ε 546312 ε ε 312 ε ε 12 ε ε ε 1
γα(3) ε ε 546312 ε ε ε 213 ε ε 3241 1 ε
γα(4) ε ε ε 546312 ε 312 312 ε 12 12 312 1
Table 1: The embeddings of γ = 5 4 6 3 1 2 into π = 3 1 4 2. Notice that this definition of embeddings conveys the same notion as in [AA05], but it is formally different and it will turn out to be more adapted to the definition of the sets Ei,j in Section 4.3. For now, we present how to compute the embeddings of some permutation γ into a permutation π. This is done with AllEmbeddings (Algo. 1) in two main steps. First we compute all block-decompositions of γ. Left side of Table 1 shows some blockdecompositions of γ = 5 4 6 3 1 2 (exactly those that can be expressed as a generalized substitution in π = 3 1 4 2). Then for each block-decomposition of γ, we compute all the embeddings of γ into π which correspond to this block-decomposition (see right side of Table 1). The procedure BlockDecompositions (Algo. 2) finds all the block-decompositions of γ. It needs to compute all the intervals of γ. Such intervals are pairs of indices (i, j) with i ≤ j such that maxi≤k≤j (γk ) − mini≤k≤j (γk ) = j − i. Denoting by p the size of γ, this remark allows to compute easily all the intervals starting at i, for each i ∈ [1..p]. Then, BlockDecompositions builds the set D of all sequences of intervals of the form (i1 , j1 ), . . . , (im , jm ) with i1 = 1, jm = p, and ik+1 = jk + 1 for all k < m. These sequences correspond exactly to the block-decompositions of γ. They are computed iteratively, starting from all the intervals of the form (1, i) and examining how they can be extended to a sequence of intervals in D. To this end, notice that any sequence 12
Algorithm 1: AllEmbeddings(γ, π) Data: Two permutations γ and π Result: The set of embeddings of γ into π begin E ←∅ D ← BlockDecompositions(γ) foreach d ∈ D do E ← E ∪ Embeddings(d, π)
/* See Algo. 2 */ /* See Algo. 3 */
return E
(i1 , j1 ), . . . , (im , jm ) as above but such that jm 6= p is the prefix of at least one sequence of D, since for every i ∈ [1..p], at least (i, i) is an interval of γ. For each i ∈ [1..p], computing Intervals(γ, i) is done in O(p), so O(p2 ) is enough to compute once and for all the results of Intervals(γ, i) for all i ∈ [1..p] (providing we store them). The computation of all block-decompositions of γ with BlockDecompositions(γ) then costs O(p 2p ). Indeed there are at most 2p−1 such sequences of D and each sequence of D contains at most p intervals. At each step, the algorithm extends a sequence already built. Thus the (amortized) overall complexity is O(p 2p ) and this bound is tight. The procedure Embeddings (Algo. 3) finds the embeddings of γ in π which correspond to a given block-decomposition of γ. The output D of BlockDecompositions corresponds to all the substitutions σ[γ (1) , . . . , γ (m) ] which are equal to γ. For each d ∈ D we first determine the corresponding skeleton σ defined as the normalization of a sequence s1 . . . sm of m integers, where each si is an element of γ falling into the i-th block of this decomposition. Then, we compute the set of occurrences of σ in π, since they are in one-to-one correspondence with embeddings of γ into π which corresponds to the given substitution γ = σ[γ (1) , . . . , γ (m) ]. These occurrences are naively computed by testing, for every subsequence of m elements of π, whether it is an occurrence of σ. The preprocessing part of Embeddings (Algo. 3), which consists in the computation of the skeleton σ, costs O(m). The examination of all possible occurrences of σ in π is n then performed in O(m m ), where n is the size of π. p In total, computing the set D of block-decompositions of γ is performed in O(p 2 ). p−1 The set D contains at most m−1 block-decompositions in m blocks, so that the complex p−1 P n ity of the main loop of AllEmbeddings is at most pm=1 m m ≤ p 2n+p−1 . Note m−1 that it can be reduced to min(p, n) 2n+min(p,n)−1 , by discarding all block-decompositions of γ in m > nP blocks, since these p−1 will never be used in an embedding of γ into π. The p n upper bound m=1 m m m−1 is tight, as can be seen with p ≤ n, γ = 12 . . . p and π = 12 . . . n.
4.3
Propagating constraints
To compute our combinatorial specification, we want to “decorate” Equations (1) to (3) with pattern avoidance constraints. These constraints apply to every set π[Cˆ1 , . . . , Cˆn ] that appears in a disjoint union on the right-hand side of an equation. For each such 13
Algorithm 2: BlockDecompositions(γ) Data: A permutation γ Result: The set D of block-decompositions of γ begin D ← ∅; P ← Intervals(γ, 1) foreach u = (i1 , j1 ), . . . , (im , jm ) ∈ P do P ← P \ {u} if jm = |γ| then D ← D ∪ {u} else S ← Intervals(γ, jm + 1) P ← P ∪ {u · s | s ∈ S}
return D /* Returns the set of intervals of γ of the form (i, j) Intervals (γ, i I←∅ max ← γi ; min ← γi for j from i to |γ| do max ← max(max, γj ); min ← min(min, γj ) if max − min = j − i then I ← I ∪ {(i, j)} return I
*/
(
set, the pattern avoidance constraints can be expressed by pushing constraints into the subtrees, using embeddings of excluded patterns in the root π. For instance, assume that ˆ C, ˆ C, ˆ C]hγi. ˆ γ = 5 4 6 3 1 2 ∈ B ? and SC = {3142}, and consider 3142[C, The embeddings ˆ C, ˆ C, ˆ C]. ˆ of γ in 3142 indicates how the pattern γ can be found in the subtrees in 3142[C, The first embedding of Example 4.4 indicates that the full pattern γ can appear all included in the first subtree. On the other hand, the last embedding of the same example tells us that γ can spread over all the subtrees of 3142 except the third. In order to avoid this particular embedding of γ, it is enough to avoid one of the induced pattern γI on one of the subtrees. However, in order to ensure that γ is avoided, the constraints resulting from all the embeddings must be considered and merged. This is formalized in Proposition 4.5. Proposition 4.5. Let π be a simple permutation of size n and C1 , . . . , Cn be sets of permutations. For any permutation γ, the set π[C1 , . . . , Cn ]hγi rewrites as a union of sets of the form π[D1 , . . . , Dn ] where, for all i, Di = Ci hγ, . . . i and the restrictions appearing after γ (if there are any) are patterns of γ corresponding to normalized blocks of γ. More precisely, we have [ π[C1 hE1,k1 ...k` i, . . . , Cn hEn,k1 ...k` i] (8) π[C1 , . . . , Cn ]hγi = (k1 ,...,k` )∈Kγπ
where Kγπ = {(k1 , . . . , k` ) ∈ [1..n]` | ∀i, γαi (ki ) 6= ε and γαi (ki ) 6= 1} and Em,k1 ...k` = {γαi (ki ) | i ∈ [1..`] and ki = m}. 14
Algorithm 3: Embeddings(d, π) Data: A permutation π of size n and a block-decomposition d ∈ D of γ, d = (i1 , j1 ), . . . , (im , jm ) Result: The set of embeddings of γ into π which correspond to d begin if m > n then /* No embedding of γ into π corresponding to d */ return ∅ else /* σ is the skeleton such that d = σ[γ (1) , . . . , γ (m) ] */ σ ← γ{i1 ,i2 ,...,im } E ←∅ foreach subset S = {s1 , . . . , sm } of {1, 2, . . . , n} with s1 < . . . < sm do if π{s1 ,s2 ,...,sm } = σ then ( α(sk ) = [ik ..jk ] for 1 ≤ k ≤ m α ← embedding of γ in π such that α(i) = ε for i ∈ /S E ← E ∪ {α} return E
Similarly, ⊕[C1+ , C2 ]hγi (resp. [C1− , C2 ]hγi) rewrites as a union of sets ⊕[D1+ , D2 ] (resp. [D1− , D2 ]). Proposition 4.5 is directly inspired from the proof of Lemma 18 of [AA05]. There is however a difference in the statement. While we stop at the condition Di = Ci hγ, . . . i (which appears in the proof of Lemma 18 in [AA05]), [AA05] rephrases it as: Di is Ci hγi or a strong subclass of this class (that is, a proper subclass of Ci which has the property that every basis element of Di is involved in some basis element of Ci ). Notice that this rephrasing is not always correct (but this does not affect the correctness of the result of [AA05] which uses their Lemma 18). A counter example is obtained taking π = 2413, Ci = Av(12) for all i and γ = 213. Then, considering the embedding of γ in π that maps 21 in π1 and 3 in π2 , we have D1 = C1 h213, 21i = Av(12, 21), which is not a strong subclass of C1 hγi = Av(12). Even though the result of Proposition 4.5 already appears in [AA05], we (re)prove it below. The main difference is that we go further into the details, to provide a proof which is nonetheless constructive as in [AA05], but also explicit, so that it can be directly used for algorithmic purpose. Proof. We first consider the case of a simple root π. Let γ be a permutation and {α1 , . . . , α` } be the set of embeddings of γ in π, each αi being associated to the generalized substitution γ = π{γαi (1) , . . . , γαi (n) }. Let σ = π[σ (1) , . . . , σ (n) ] where each σ (k) ∈ Ck . Then σ avoids γ if and only if for every embedding αi (with 1 ≤ i ≤ `), there exists ki ∈ [1..n] such that γαi (ki ) is not a pattern of σ (ki ) , i.e. such that σ (ki ) avoids γαi (ki ) . Equivalently, σ avoids γ if and only if there exists a tuple (k1 , . . . , k` ) ∈ [1..n]` such that for every embedding αi (with 1 ≤ i ≤ `),
15
σ (ki ) avoids γαi (ki ) . Thus, ` \
[
π[C1 , . . . , Cn ]hγi =
(k1 ,...,k`
)∈[1..n]`
π[C1 , . . . , Cki hγαi (ki ) i, . . . , Cn ].
i=1
But, for any set A of permutations we have Ahεi = ∅. So if for some i ∈ [1..`], γαi (ki ) = ε, T then `i=1 π[C1 , . . . , Cki hγαi (ki ) i, . . . , Cn ] = ∅. The same goes for the trivial permutation 1 since every permutation contains 1. Therefore, we have: π[C1 , . . . , Cn ]hγi =
[
` \
(k1 ,...,k` )∈Kγπ
i=1
π[C1 , . . . , Cki hγαi (ki ) i, . . . , Cn ],
with Kγπ = {(k1 , . . . , k` ) ∈ [1..n]` | ∀i, γαi (ki ) 6= ε and γαi (ki ) 6= 1}. Following Example 4.4, and denoting α1 to α12 the embeddings of Table 1 from top to bottom, we have for example k = (1, 2, 3, 4, 1, 4, 4, 2, 1, 4, 4, 1) ∈ Kγπ . Moreover, as π is simple, by uniqueness of the substitution decomposition we have for any sets of permutations E1 , . . . , En , F1 , . . . , Fn : π[C1 hE1 i, . . . , Cn hEn i] ∩ π[C1 hF1 i, . . . , Cn hFn i] = π[C1 hE1 ∪ F1 i, . . . , Cn hEn ∪ Fn i]. Thus, π[C1 , . . . , Cn ]hγi =
[
π[C1 hE1,k1 ...k` i, . . . , Cn hEn,k1 ...k` i].
(k1 ,...,k` )∈Kγπ
where Em,k1 ...k` = {γαi (ki ) | i ∈ [1..`] and ki = m}. Following the same example again, E1,k = {γα1 (1) , γα5 (1) , γα9 (1) , γα12 (3) } = {546312, 213, 3241}, E2,k = {546312, 12}, E3,k = {546312} and E4,k = {546312, 312, 12}. From Equation (8), Proposition 4.5 follows as soon as we ensure that each set Em,k1 ...k` contains γ and possibly other restrictions that are patterns of γ corresponding to normalized blocks of γ. For a given m ∈ [1..n], there always exists an embedding of γ in π that maps the whole permutation γ to πm . Denoting this embedding αjm , we have γαjm (m) = γ and γαjm (q) = ε for q 6= m. Consequently, if kjm 6= m then γαjm (kjm ) = ε and (k1 , . . . , k` ) ∈ / Kγπ . Therefore when (k1 , . . . , k` ) ∈ Kγπ then kjm = m and the set Em,k1 ...k` contains at least γαjm (kjm ) = γ. Moreover, by definition its other elements are patterns of γ corresponding to normalized blocks of γ. Notice now that the proof immediately extends to the case of roots ⊕ and . Indeed, in the above proof, we need π to be simple only because we use the uniqueness of the substitution decomposition. In the case π = ⊕ (resp. ), the uniqueness is ensured by taking the set C1+ of ⊕-indecomposable permutations of C1 (resp. the set C1− of indecomposable permutations). Example 4.6. For π = and γ = 3412, there are three embeddings of γ in π: α1 which follows from the generalized substitution 3142 = {3412, ε}, α2 which follows from 3142 = {ε, 3412}, and α3 which follows from 3142 = {12, 12}. So Kγπ = {(1, 2, 1), (1, 2, 2)} and the application of Equation (8) gives [C1− , C2 ]h3412i = [C1− h3412, 12i, C2 h3412i] ∪ [C1− h3412i, C2 h3412, 12i], which simplifies to [C1− , C2 ]h3412i = [C1− h12i, C2 h3412i] ∪ [C1− h3412i, C2 h12i]. 16
Algorithm 4: AmbiguousSystem(B) Data: A finite basis of patterns defining C = Av(B) S such that SC is known and finite. Result: A system of equations of the form D = π[D1 , . . . , Dn ] defining C. begin ˆ B?) E ← EqnForClass(C, while there is a right-only Cˆδ hEi in some equation of E do E ← E ∪ EqnForClass(Cˆδ , E)
We can extend Proposition 4.5 to the case of a set P of excluded patterns, instead of a single permutation γ: Proposition 4.7. For any simple permutation π of size n and for any set of permutations P , the set π[C1 , . . . , Cn ]hP i rewrites as a union of sets π[D1 , . . . , Dn ] where for all i, Di = Ci hP ∪ Pi i with Pi containing only permutations corresponding to normalized blocks of elements of P . Similarly, ⊕[C1+ , C2 ]hP i (resp. [C1− , C2 ]hP i) rewrites as a union of sets ⊕[D1+ , D2 ] (resp. [D1− , D2 ]) where for i = 1 or 2, Di = Ci hP ∪ Pi i with Pi containing only permutations corresponding to normalized blocks of elements of P . This proposition is proved by induction on the size of P , using Proposition 4.5. Now we have all the results we need to describe an algorithm computing a (possibly ambiguous) combinatorial system describing C.
4.4
An algorithm computing a combinatorial system describing C
We describe here an algorithm that takes as input the set SC of simple permutations in a class C and the basis B of C (both finite), and that produces in output a (possibly ambiguous) system of combinatorial equations describing the permutations of C through their decomposition trees. Recall (from p.10) that B ? denotes the subset of non-simple permutations of B. The main step is performed by EqnForClass (Algo. 5), taking as input a set E of patterns (initially B ? ). Its working principle is to take an equation of the form (1), (2) or (3) (p.8) describing some Cˆδ , then add one by one the constraints of E using Equation (8) as described in procedure AddConstraints. Ultimately, the procedure AmbiguousSystem (Algo. 4) keeps adding new equations to the system which consists originally of the equation describing Cˆδ hB ? i. This algorithm performs repeated calls to EqnForClass, until every π[C1 , . . . , Cn ]hEi is replaced by some π[C10 , . . . , Cn0 ] and until every Ci0 = Cˆδ hEi i appearing in the system is defined by an equation. All the sets E are sets of normalized blocks, therefore of patterns of some permutations in B ? . Since B is finite, there is only a finite number of patterns of elements of B ? , hence a finite number of possible E, and AmbiguousSystem terminates. As for its complexity, it depends on the number of equations in the output system for which we give bounds in Section 5.5.
17
Algorithm 5: EqnForClass(Cˆδ , E) Data: E is a set of permutations, Cˆδ is given by SC and δ ∈ { , +, −} Result: An equation defining Cˆδ hEi as a union of π[C1 , . . . , Cn ] begin E ← Equation (1) or (2) or (3) (depending on δ) foreach constraint γ in E do foreach t = π[C1 , . . . , Cn ] that appears in E do t ← AddConstraints(π[C1 , . . . , Cn ], γ) /* this step modifies E */ return E S /* Returns a rewriting of π[C1 . . . Cn ]hγi as a union π[D1 , . . . Dn ] */ AddConstraints (π[C1 . . . Cn ], γ compute all the embeddings of γ in π with AllEmbeddings /* Algo. 1 */ π compute Kγ and sets Em,k1 ...k` defined in Equation (8) S return (k1 ,...,k` )∈Kγπ π[C1 hE1,k1 ...k` i, . . . , Cn hEn,k1 ...k` i] (
The correctness of the algorithm is a consequence of Propositions 4.1 and 4.7. We therefore have: Proposition 4.8. For any permutation class C with a finite number of simple permutations, we can derive a finite system of combinatorial equations describing C using AmbiguousSystem (Algo. 4). The equations of this system are all of the form S D0 = 1 ∪ π[D1 , . . . , Dn ], where Di = Cˆδ hB ? ∪ Bi i with δ ∈ { , +, −} and Bi contains only permutations corresponding to normalized blocks of elements of B ? . This system is complete, that is: every Di that appears in the system is the left part of one equation of the system. Example 4.9. Consider the class C = Av(B) for B = {1243, 2413, 531642, 41352}: C contains only one simple permutation (namely 3142), and B ? = {1243}. Applying the procedure AmbiguousSystem to this class C gives the following system of equations: ˆ Ch1243i
= ∪
ˆ ˆ ˆ 1 ∪ ⊕[Cˆ+ h12i, Ch132i] ∪ ⊕[Cˆ+ h1243i, Ch21i] ∪ [Cˆ− h1243i, Ch1243i] ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ 3142[Ch1243i, Ch12i, Ch21i, Ch132i] ∪ 3142[Ch12i, Ch12i, Ch132i, Ch132i] (9)
ˆ Ch12i ˆ Ch132i
=
ˆ Ch21i
=
ˆ 1 ∪ [Cˆ− h12i, Ch12i] ˆ ˆ 1 ∪ ⊕[Cˆ+ h132i, Ch21i] ∪ [Cˆ− h132i, Ch132i] ˆ 1 ∪ ⊕[Cˆ+ h21i, Ch21i].
C h1243i
=
....
ˆ+
=
(10) (11) (12)
This is a simplified version of the actual output of AmbiguousSystem. For instance, with a literal application of the algorithm, instead of Equation (9) we would get: ˆ ˆ ˆ ˆ Ch1243i = 1 ∪ ⊕[Cˆ+ h1243, 12i, Ch1243, 132i] ∪ ⊕[Cˆ+ h1243i, Ch1243, 132, 21i] ∪ [Cˆ− h1243i, Ch1243i] ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ∪ 3142[Ch1243, 12i, Ch1243, 12i, Ch1243, 132i, Ch1243, 132i] ∪ 3142[Ch1243, 12i, Ch1243, 12i, Ch1243, 132i, Ch1243, 132, 21i] ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ∪ 3142[Ch1243, 12i, Ch1243, 12i, Ch1243, 132, 21i, Ch1243, 132i] ∪ 3142[Ch1243, 12i, Ch1243, 12i, Ch1243, 132, 21i, Ch1243, 132, 21i] ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ∪ 3142[Ch1243i, Ch1243, 12i, Ch1243, 132, 21i, Ch1243, 132i] ∪ 3142[Ch1243i, Ch1243, 12i, Ch1243, 132, 21i, Ch1243, 132, 21i]
18
Nevertheless, this union can be simplified. The simplification process will be described more thoroughly in Section 5.6. We illustrate it by two examples. First, since a permutaˆ tion that avoids 12 or 132 will necessarily avoid 1243, the term ⊕[Cˆ+ h1243, 12i, Ch1243, 132i] + ˆ rewrites ⊕[Cˆ h12i, Ch132i] (see Proposition 5.16 p. 29). We can also remove some terms ˆ ˆ ˆ ˆ of the union, such as 3142[Ch1243, 12i, Ch1243, 12i, Ch1243, 132i, Ch1243, 132, 21i] which is ˆ ˆ ˆ ˆ included in 3142[Ch12i, Ch12i, Ch132i, Ch132i] (see Proposition 5.18 p. 29). Such simplifications can be performed on the fly, each time a new equation is computed. The system of combinatorial equations produced by AmbiguousSystem (Algo. 4) is ambiguous in general: the unions are not necessarily disjoint. This is the case with ˆ Example 4.9, where Equation (9) gives an ambiguous description of the class Ch1243i: the two terms with root ⊕ have non-empty intersection, and similarly for root 3142. In [AA05], this combinatorial system is used exclusively to deduce a system of equations satisfied by the generating function of the class. For this purpose, it is enough to apply the inclusion-exclusion principle to the combinatorial system. On Equation (9) of Example 4.9, this would give: ˆ ˆ ˆ ˆ Ch1243i = 1 ∪ ⊕[Cˆ+ h12i, Ch132i] ∪ ⊕[Cˆ+ h1243i, Ch21i] \ ⊕[Cˆ+ h12i, Ch21i] ˆ ˆ ˆ ˆ ˆ ∪ [Cˆ− h1243i, Ch1243i] ∪ 3142[Ch12i, Ch12i, Ch132i, Ch132i] ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ∪ 3142[Ch1243i, Ch12i, Ch21i, Ch132i] \ 3142[Ch12i, Ch12i, Ch21i, Ch132i].
The combinatorial system so obtained contains negative terms in general. While this provides a system of equations allowing the (implicit) determination of the generating function of the class, this does not give a combinatorial specification of the class. When turning towards random generation of permutations in a class, a combinatorial system describing the class with negative terms is not enough, since the “subtraction” of combinatorial objects is not handled by random samplers. In the next section, we explain how inclusion-exclusion can be avoided and replaced by an explicit description of complement sets to obtain combinatorial specifications.
5
A non-ambiguous combinatorial system, i.e., a combinatorial specification
We can interpret the work presented in [BHV08] as a method for the computation of a combinatorial specification of a permutation class C with finite basis and finitely many simple permutations. In this article the authors give (among other results) an alternative proof of the result of [AA05], that a class with finitely many simple permutations has an algebraic generating function. At the core of this proof is the introduction of querycomplete sets of properties on permutations. The focus is again on generating functions, but in [BHV08], the systems of equations for the generating functions are positive and non-ambiguous. Indeed, they echo a description of the permutations in the class which is a combinatorial specification. We review the proof of [BHV08] in Section 5.1. The method for obtaining a specification with query-complete sets used in [BHV08] is however not algorithmic. As we explain in Section 5.1, we believe it may be adapted into an algorithm, but that would not be efficient. For this reason, from Section 5.2 we turn to an alternative way of computing combinatorial specifications of permutation 19
classes, which is algorithmic. We start from the ambiguous system produced by AmbiguousSystem (Algo. 4), and we disambiguate this system to obtain a new positive one. To avoid inclusion-exclusion, which may produce negative terms, the key idea is to introduce complement sets, thereby transforming pattern avoidance constraints into pattern containment constraints.
5.1
Specifications from query-complete sets
Following [BHV08], we call a property any set P of permutations, and we say that a permutation π satisfies P when π ∈ P . A set P of properties is query-complete if, for every simple permutation σ of length m (and also for σ = ⊕ or ) and for every property P ∈ P, it can be decided whether σ[α1 , . . . , αm ] satisfies P knowing only which properties of P are satisfied by each αi . To a permutation class C with finite basis B, [BHV08] associates a query-complete set PB which consists of the following properties: the set of ⊕-indecomposable permutations, the set of -indecomposable permutations, and the set Av(ρ) for every permutation ρ which is a pattern of some β ∈ B. Since B is finite, note that PB is also finite. We may then partition C into a finite number of disjoint subsets, according to the properties of PB satisfied by the permutations of C. For X ⊆ PB , we denote by CX the set of permutations that satisfy every property in X and do not satisfy any property in PB \ X . It follows that C = ] CX (13) where the union runs over the subsets X of PB containing Av(β) for every β ∈ B. For such a set X , using substitution decomposition, we may then write ] CX = 1X ] CX⊕ ] CX ] CXσ (14) σ∈SC
where 1X is either the set {1} if the permutation 1 belongs to CX , or the empty set otherwise, and where CXσ is the subset of CX of permutations whose decomposition tree has root σ. Since P is query-complete, for each set of properties X ⊆ PB and for each simple permutation σ of length m (and also for σ = ⊕ or ), it can be decided whether σ[α1 , . . . , αm ] belongs to CXσ from the knowledge of the properties of PB satisfied by each αi . In the case where σ is simple, this allows to write ] CXσ = σ[CX1 , . . . , CXm ] (15) where the union is over the set EX ,σ of all m-uples (X1 , . . . , Xm ) of subsets of PB such that if, for every i ∈ [1..m], it holds that αi ∈ CXi then U σ[α1 , . . . , αm ] ∈ CX . In the case where σ = ⊕ (resp. ), we write similarly CXσ = σ[CX1 , CX2 ], but to ensure uniqueness of the decomposition we further enforce that X1 contains the property of being ⊕-indecomposable (resp. -indecomposable). Note that since PB is finite, the unions in Equations (13) and (15) are finite. Therefore, putting together Equations (13), (14) and (15) (for every X such that {Av(β) : β ∈ B} ⊆ X ⊆ PB , and every σ ∈ {⊕, } ∪ SC ), we obtain a combinatorial specification for C. 20
This specification is explicit, except for the sets EX ,σ . To extract an algorithm from this method, we would therefore need to compute these sets. The proof of [BHV08] that PB is a query-complete set of properties may be translated into an algorithm to compute the sets EX ,σ . This algorithm would require to compute the set of embeddings of ρ in σ for every permutation σ ∈ {⊕, } ∪ SC and for every permutation ρ which is a pattern of some β ∈ B. A first problem is that it would be a huge computation. A second problem is that the size of the specification produced would also be larger than what we actually need. In some sense, when considering the partition of C into CX in Equation (13), we are looking at a very fine level of details, where a coarser level would be enough. As an alternative, we give in the following another method to compute a combinatorial specification, which is fully algorithmic and which avoids the computation of superfluous information. This specification is inherited from the substitution decomposition, and is obtained starting from the ambiguous system produced by AmbiguousSystem (Algo. 4) in Section 4. It is a system of the form {Hi = 1Hi ] U U σ∈SC ∪{⊕, } (Hj1 ,...,Hjm )∈Ei,σ σ[Hj1 , . . . , Hjm ]}1≤i≤p where 1Hi is either {1} or ∅, H1 = C and the Ei,σ are some finite sets that can be computed effectively. Notice that such specifications can also be interpreted as descriptions of permutation classes by query-complete sets. Indeed, the set {Hi }1≤i≤p is a query-complete set since σ[α1 , . . . , αm ] ∈ Hi if and only if (α1 , . . . , αm ) ∈ Hj1 × · · · × Hjm for some (Hj1 , . . . , Hjm ) ∈ Ei,σ .
5.2
On the need of pattern containment constraints
As announced above, we present an alternative way of computing combinatorial specifications, which consists in the disambiguation of the ambiguous system produced by AmbiguousSystem. The starting point of the disambiguation is to rewrite ambiguous ¯ B, ¯ C¯ (see Figure 2). terms like A ∪ B ∪ C as a disjoint union using complement sets A, A
4
1 5
7 3
2 6
B
A∪B∪C = 1 ] 2 ] 3 ] 4 ] 5 ] 6 ] 7 = (A ∩ B ∩ C) ] (A ∩ B ∩ C) ] (A ∩ B ∩ C) ] (A ∩ B ∩ C) ] (A ∩ B ∩ C) ] (A ∩ B ∩ C) ] (A ∩ B ∩ C)
C Figure 2: Rewriting unions as disjoint unions. By disambiguating the union A ∪ B ∪ C using complement sets instead of negative terms (as it was done in [AA05] by inclusion-exclusion), we obtain an unambiguous description of the union with only positive terms. But when taking the complement of a set defined by pattern avoidance constraints, these are transformed into pattern containment constraints. Therefore, for any set P of permutations, we define the restriction PhEi(A) as the set of permutations of P that avoid every pattern of E and contain every pattern of A: Definition 5.1. For any set P of permutations, we set PhEi(A) = {σ ∈ P | ∀π ∈ E, π 64 σ and ∀π ∈ A, π 4 σ}. 21
When P = Cˆδ for δ ∈ { , +, −} and C a permutation class, such a set is called a restriction. Notice that for A = ∅, ChEi(∅) is the standard permutation class ChEi. We also denote C(E) = Ch∅i(E), and similarly for Cˆδ . Remark 5.2. Our convention that no permutation class contains the empty permutation ε implies that ε ∈ / Cˆδ hEi(A), for any restriction Cˆδ hEi(A). We can also make the assumption that ε ∈ / E and ε ∈ / A, since Cˆδ h{ε} ∪ Ei(A) = ∅ and Cˆδ hEi({ε} ∪ A) = Cˆδ hEi(A) for any E and A. Moreover we assume that A ∩ E is empty and that 1 ∈ / E, otherwise δ δ δ ˆ ˆ ˆ C hEi(A) = ∅. We finally assume that 1 ∈ / A since C hEi(A) = C hEi(A \ {1}). Restrictions are stable by intersection as PhEi(A) ∩ PhE 0 i(A0 ) = PhE ∪ E 0 i(A ∪ A0 ). Definition 5.3. A restriction term is a set of permutations π[D1 , D2 , . . . , Dn ] for π a simple permutation, ⊕[D1+ , D2 ] or [D1− , D2 ] where each Di is a restriction of the form ˆ ChEi(A). By uniqueness of the substitution decomposition of a permutation (Theorem 2.10), restriction terms are stable by intersection and the intersection is performed componentwise for terms sharing the same root: π[D1 , . . . , Dn ] ∩ π[T1 , . . . , Tn ] = π[D1 ∩ T1 , . . . , Dn ∩ Tn ].
5.3
From union to disjoint union, for each equation
The disambiguation of the system obtained by AmbiguousSystem (Algo. 4) is performed by Disambiguate (Algo. 6). It consists in two main operations. One is the disambiguation of an equation according to the root of the terms. This may introduce right-only restrictions, leading to the second procedure named EqnForRestriction which computes new equations (that are added to the system) to describe these new restrictions (Algo. 7). As we do not know how to decide whether an equation is ambiguous or not, we apply the first step to every equation in the system. Algorithm 6: Disambiguate(E) Data: An ambiguous system E of equations /* obtained by Algo. 4 */ Result: A combinatorial specification equivalent to E begin while there is an equation F in E that has not been processed do foreach root π that appears several times in F do Replace the restriction terms of F whose root is π by a disjoint union using Equations (16), (17) and (18) while there exists a right-only restriction Cˆδ hEi(A) in some equation of E do S E ← E EqnForRestriction(Cˆδ ,E,A). /* Algo. 7 */ return E As stated in Proposition 4.8, every equation F of our system can be written as t = 1 ∪ t1 ∪ t2 ∪ t3 . . . ∪ tk where the ti are restriction terms (some π[D1 , D2 , . . . , Dn ]) and t is a 22
restriction (some Cˆδ hEi(A), with A = ∅ at the beginning of the disambiguation process). By uniqueness of the substitution decomposition of a permutation, restriction terms of this union which have different roots π are disjoint. Thus for an equation we only need to disambiguate unions of terms with same root. For example in Equation (9) (p.18), there are two pairs of ambiguous terms which are terms with root 3142 and terms with root ⊕. Every ambiguous union can be written in an unambiguous way: Proposition 5.4. Let A1 , . .S . , An be n sets and for Sneach of them denote Ai the complement n of Ai in any set containingT i=1 Ai . The union i=1 Ai rewrites as the disjoint union of the 2n − 1 sets of the form ni=1 Xi with Xi ∈ {Ai , Ai } and at least one Xi is equal to Ai . This proposition is the starting point of the disambiguation. See Figure 2 for an example. In order to use Proposition 5.4, we have to choose in which set we take complements. Definition 5.5. For any restriction term t, we define its complement t as follows: ˆ we set t = π[C, ˆ . . . , C] ˆ \ t; • if t = π[D1 , . . . , Dn ] with π simple and for all i, Di ⊂ C, ˆ we set t = ⊕[Cˆ+ , C] ˆ \ t; • if t = ⊕[D1+ , D2 ] with D1 , D2 ⊂ C, ˆ \ t. ˆ we set t = [Cˆ− , C] • if t = [D1− , D2 ] with D1 , D2 ⊂ C, Moreover for any restriction D of Cˆδ with δ ∈ { , +, −}, we set D = Cˆδ \ D. From Proposition 5.4, every ambiguous union of restriction terms sharing the same root in an equation of our system can be written in the following unambiguous way: T U T Sk (16) i∈X ti . X⊆[1...k],X6=∅ i∈X ti ∩ i=1 ti = ˆ ˆ For instance, consider terms with root 3142 in Equation (9): t1 = 3142[Ch12i, Ch12i, ˆ ˆ ˆ ˆ ˆ ˆ Ch132i, Ch132i] and t2 = 3142[Ch1243i, Ch12i, Ch21i, Ch132i]. Equation (16) applied to t1 and t2 gives an expression of the form ˆ Ch1243i = 1 ∪ ⊕[. . .] ∪ ⊕[. . .] ∪ [. . .] ∪ (t1 ∩ t2 ) ] (t1 ∩ t2 ) ] (t1 ∩ t2 ). We now explain how to compute the complement t of a restriction term t. Proposition 5.6. Let t = π[D1 , . . . , Dn ] be a restriction term. Then t is the disjoint union of the 2n − 1 sets of the form π[X1 , . . . , Xn ] with Xi ∈ {Di , Di }, and not all Xi are equal to Di : ] t= π[D10 , . . . , Dn0 ] where Di0 = Di if i ∈ X and Di0 = Di otherwise, (17) X ⊆{1,...,n},X 6=∅
For example, [D1 , D2 ] = [D1 , D2 ] ] [D1 , D2 ] ] [D1 , D2 ]. Proof. Let σ = π[σ1 , . . . , σn ] ∈ t. Assume that for each i σi ∈ Di , by uniqueness of substitution decomposition we get a contradiction. Therefore σ ∈ π[X1 , . . . , Xn ] with Xi ∈ {Di , Di }, and not all Xi are equal to Di . Conversely if σ ∈ π[X1 , . . . , Xn ] with Xi ∈ {Di , Di } and at least one Xi is equal to Di , ˆ . . . , C] ˆ and σ ∈ then σ ∈ π[C, / t. Finally for such sets Xi that are distinct, the sets π[X1 , . . . , Xn ] are disjoints. Indeed Di ∩ Di is empty and the writing as π[σ1 , . . . , σn ] is unique. So the union describing t is disjoint. The proof is similar when π = ⊕ or π = . 23
Proposition 5.6 shows that ti is not a restriction term in general. However it can be expressed as a disjoint union of some π[D10 , . . . , Dn0 ], where the Di0 are either restrictions or complements of restrictions. The complement operation being pushed from restriction terms down to restrictions, we now compute D, for a given restriction D = Cˆδ hEi(A), D denoting the set of permutations of Cˆδ that are not in D. Notice that, given a permutation σ of A, then any permutation τ of Cˆδ hσi is in D because τ avoids σ whereas permutations of D must contain σ. Symmetrically, if a permutation σ is in E then permutations of Cˆδ (σ) S SS ˆδ ˆδ are in D. It is straightforward to check that Cˆδ hEi(A) = σ∈E C (σ) σ∈A C hσi . Unfortunately this expression is ambiguous. As before, we can rewrite it as an unambiguous union: Proposition 5.7. Let D = Cˆδ hEi(A) be a restriction with δ ∈ { , +, −}, k = |E| and ` = |A|. Then D is the disjoint union of the 2k+` − 1 restrictions Cˆδ hE 0 i(A0 ) with (E 0 , A0 ) a partition of E ] A such that (E 0 , A0 ) 6= (E, A). In other words, ] Cˆδ hEi(A) = Cˆδ hX ∪ Y i(Y ∪ X), where X = A \ X and Y = E \ Y . (18) X⊆A,Y ⊆E X×Y 6=∅×∅
Proof. Let τ ∈ D = Cˆδ \D. Define E 0 = {π ∈ E∪A | π τ } and A0 = {π ∈ E∪A | π 4 τ }. Observe that τ ∈ Cˆδ hE 0 i(A0 ). Moreover E 0 ∩A0 = ∅, E 0 ∪A0 = E ∪A and (E 0 , A0 ) 6= (E, A) otherwise τ would be in D. Conversely let τ ∈ Cˆδ hE 0 i(A0 ) with (E 0 , A0 ) a partition of E ] A such that (E 0 , A0 ) 6= (E, A), then τ ∈ Cˆδ . As (E 0 , A0 ) 6= (E, A), either there is some σ in E that τ contains, or there is some σ in A that τ avoids. In both cases, τ ∈ / D thus τ ∈ Cˆδ \ D = D. Finally for distinct partitions (E 0 , A0 ) of E ∪ A, the sets Cˆδ hE 0 i(A0 ) are disjoints. Indeed a permutation in two sets of this form would have to both avoid and contain some permutation of E ∪ A, which is impossible. Proposition 5.7 shows that D is not a restriction in general but can be expressed as a disjoint union of restrictions. For instance, ˆ ˆ ˆ ˆ Ch231, 123i(4321) = C(123, 231, 4321) ] Ch123i(231, 4321) ] Ch231i(123, 4321) ] ˆ ˆ ˆ ˆ Ch4321i(123, 231) ] Ch123, 4321i(231) ] Ch231, 4321i(123) ] Ch123, 231, 4321i.
Moreover by uniqueness of the substitution decomposition, π[D1 , . . . , Dk ] Dk0 , . . . , Dn ] = π[D1 , . . . , Dk , . . . , Dn ] ] π[D1 , . . . , Dk0 , . . . , Dn ]. Therefore using Equation (17) we have that for any restriction term ti , its complement ti can be expressed as a disjoint union of terms: Proposition 5.8. For any restriction term t, its complement t can be written as a disjoint union of restriction terms. More precisely if t = π[D1 , . . . , Dn ] with Di = Cˆδi hEi i(Ai ) Pn and m = i=1 |Ei | + |Ai |, then t is the disjoint union of the 2m − 1 restriction terms t = π[D10 , . . . , Dn0 ] such that for all i, Di0 = Cˆδi hEi0 i(A0i ) with (Ei0 , A0i ) a partition of Ei ] Ai , and there exists i such that (Ei0 , A0i ) 6= (Ei , Ai ). By distributivity of intersection over disjoint union, Equation (16) above can therefore be rewritten as a disjoint union of intersection of terms. Because terms are stable by intersection, the right-hand side of Equation (16) is hereby written as a disjoint union of terms. This leads to the following result: 24
Algorithm 7: EqnForRestriction(Cˆδ , E, A) Data: Cˆδ , E, A with E, A sets of permutations, Cˆδ given by SCˆ and δ ∈ { , +, −}. Result: An equation defining Cˆδ hEi(A) as a union of restriction terms. begin E ← Equation (1) or (2) or (3) (depending on δ) foreach avoidance constraint γ in E do foreach t = π[C1 , . . . , Cn ] that appears in E do t ← AddConstraints(π[C1 , . . . , Cn ], γ) /* See Algo. 5 */ foreach containment constraint γ in A do foreach t = π[C1 , . . . , Cn ] that appears in E do t ← AddMandatory(π[C1 , . . . , Cn ], γ) return E AddMandatory (π[D1 , . . . , Dn ], γ return a rewriting of π[D1 , . . . , Dn ](γ) as a union of restriction terms using Eq. (19) (
Proposition 5.9. Any union of restriction terms can be written as a disjoint union of restriction terms, and this can be done algorithmically using Equations (16), (17) and (18). All together, for any equation of our system, we are able to rewrite it unambiguously with disjoint unions of restriction terms. As noted previously, some new right-only restrictions may appear during this process, for example as the result of the intersection of several restrictions or when complementing restrictions. To obtain a complete system we must compute iteratively equations defining these new restrictions using EqnForRestriction (Algo. 7) described below in Section 5.4. Finally, the termination of Disambiguate (Algo. 6) is easily proved. Indeed, for all the restrictions Cˆδ hEi(A) that are considered in the inner loop of Disambiguate, every permutation in the sets E and A is a pattern of some element of the basis B of C. And since B is finite, there is a finite number of such restrictions. As for AmbiguousSystem (Algo 4), the complexity of Disambiguate depends on the number of equations produced that we discuss in Section 5.5.
5.4
Computing an equation for each restriction
Let Cˆδ hEi(A) be a restriction. Our goal here is to find an equation describing this restriction using smaller restriction terms (smaller w.r.t. inclusion). If A = ∅, this is exactly the problem addressed in Section 4 and solved by pushing down the pattern avoidance constraints in the procedure AddConstraints of EqnForClass (Algo. 5). The procedure EqnForRestriction (Algo. 7) below shows how to propagate also the pattern containment constraints induced by A 6= ∅. The pattern containment constraints are propagated by AddMandatory, in a very similar fashion to the pattern avoidance constraints propagated by AddConstraints. 25
Algorithm 8: Specification(B) Data: A finite basis of patterns defining C = Av(B) such that SC is known and finite. Result: A combinatorial specification defining C. begin E ← AmbiguousSystem(B) /* Algo. 4 */ return Disambiguate(E) /* Algo. 6 */
To compute t(γ) for γ a permutation and t = π[D1 , . . . , Dn ] a restriction term, we first compute all embeddings of γ into π. In this case, a permutation belongs to t(γ) if and only if at least one embedding is satisfied. Then π[D1 , . . . , Dn ](γ) rewrites as a union of sets of the form π[D1 (γ1 ), . . . , Dn (γn )] where, for all i, γi is a normalized block6 of γ which may be empty or γ itself (recall that if γi is empty, then Dj (γi ) = Dj ). More precisely: Proposition 5.10. Let π be a permutation of size n and D1 , . . . , Dn be sets of permutations. For any permutation γ, let {α1 , . . . , α` } be the set of embeddings of γ in π, then ` [ π[D1 , . . . , Dn ](γ) = π[D1 (γαi (1) ), D2 (γαi (2) ), . . . , Dn (γαi (n) )]. (19) i=1
For instance, for t = 3142[D1 , D2 , D3 , D4 ] and γ = 546312, there are 12 embeddings of γ into 3142 (see Table 1 p.12), and the embedding 3142{21, ε, 1, 312} contributes to the above union with the term 3142[D1 (21), D2 , D3 (1), D4 (312)]. Proof. Let σ ∈ π[D1 , . . . , Dn ]; then σ = π[σ1 , . . . , σn ] where each σk ∈ Dk . Then σ contains γ, if and only if there exists an embedding αi of γ = π[γαi (1) . . . γαi (n) ] such that γαi (j) is a pattern of σj for all j. Hence, any restriction term t = π[D1 , . . . , Dn ](γ) rewrites as a (possibly ambiguous) union of restriction terms. We are now able to present the main algorithm of this article: Algo. 8. Notice that although the unions of Equation (19) may be ambiguous, they will be transformed into disjoint unions by the outer loop of Disambiguate (Algo. 6). Finally, the algorithm produces an unambiguous system (i.e. a combinatorial specification) which is the result of a finite number of iterations of computing equations followed by their disambiguation. ˆ E) in AmbiguousSystem (Algo. 4) can be replaced Notice that EqnForClass(C, by EqnForRestriction(Cˆδ ,E,A) with A = ∅. Theorem 5.11. Let C be a permutation class given by its basis B, assumed to be finite. Assume also that the set SC of simple permutations in C is finite and given. Denote by B ? the set of non-simple permutations of B. The procedure Specification (Algo.U8) produces a finite combinatorial system of equations of the form D0 = 1 · 1{1∈D0 } ] π[D1 , . . . , Dn ], where each Di is a restriction Cˆδ hEi(A) with δ ∈ { , +, −}, E and A contain only normalized blocks of elements of B ? , 6
Recall from Definition 2.6 (p.4) that the normalized blocks of γ are the permutations γI obtained when restricting γ to any of its intervals I.
26
and every Di that appears in the system is the left part of one equation of the system. In particular this provides a combinatorial specification of C.
5.5
Size of the specification obtained
As explained earlier, the complexity of Specification (Algo. 8) depends on the number of equations in the computed specification, which may be quite large. We were not able to determine exactly how large it can be, and could only provide in Proposition 5.12 and Corollary 5.13 upper bounds on its size (i.e., number of equations) which seems to be (very) overestimated. We leave open the question of improving the upper bound on the size of the specification produced by our method. However, we point out that such an upper bound cannot be less than an exponential (in the sum of the sizes of the excluded patterns). Indeed, we give in Proposition 5.14 a generic example where our method produces such an exponential number of equations in the specification. Nevertheless, this example was created on purpose, and in a lot of cases the number of equations obtained is not so high. Proposition 5.12. Let C = Av(B) and B ? be the set of non-simple permutations of B. Let P ? be the set of normalized blocks of permutations of B ? . The number of equations ? in the specification of C computed by the procedure Specification is at most 3|P | . Proof. In the specification we obtain, every equation is of the form Cˆδ hEi(A) = . . . , where δ ∈ { , +, −}, E ∪ A ⊆ P ? . As explained in Remark 5.2 (p.22), we can further assume that E ∪ A ⊆ P ? \ {1} and that E ∩ A = ∅. The number of equations is then bounded by the number of such triplets ? (δ, E, A) which is 31+(|P |−1) . Using the previous proposition and the fact that the number of blocks of a permutation of size k is less than k 2 , we have the following consequence: P Corollary 5.13. Let C = Av(B) and t = π∈B |π|. The number of equations in the 2 specification of C computed by Specification is at most 3t . However, Specification is designed to compute only the equations we need, and the number of equations produced is in practice much smaller. See for instance the example of Section 6.2, where B ? = {1243, 2341} and P ? = {1, 12, 21, 123, 132, 1243, 2341}: the upper bound of Proposition 5.12 is 37 = 2187, but only 16 equations are effectively computed. But as shown by the following proposition, Specification produces in the worst case a specification with a number of equations that is exponential in t. Proposition 5.14. For each n ≥ 4, there exists a class Cn = Av(Bn ) whose specification computed by the procedure Specification (Algo. 8) has at least 2s equations, where the sum t of the sizes of the elements of Bn is approximately s, in the sense that 1 < t/s s. Proof. For any n ≥ 4, denote by Sn the set of simple permutations of size n and by sn its cardinality. Remember from [AAK03] that sn ∼ en!2 . Fix some n ≥ 4, let s = s2n−1 , and define γ = ⊕[τ1 , . . . , τs ] with {τi : 1 ≤ i ≤ s} = S2n−1 and Bn = S2n ∪ {γ}. Notice 27
that Bn is an antichain, and consider the class Cn = Av(Bn ). The sum of the sizes of the elements of Bn is t = 2n · s2n + (2n − 1) · s2n−1 . Thus s < t and t/s ∼ 4n2 . Using Stirling )2n+ constant . formula, t and s are both of order ( 2n e It is not hard to see that Cn contains a finite number of simple permutations. Indeed, it follows from [ST93] (see details in [PR12] for instance) that Cn contains no simple permutation of size 2n or more. Note also that the simple permutation π = 246135 is small enough that it belongs to Cn . Moreover, Bn? = {γ} and from Proposition 4.1, Cn = Cˆn hγi. We claim that the computations performed by AddConstraints(π[Cˆn , . . . , Cˆn ], γ) in AmbiguousSystem(Bn ) (Algo. 4) will create at least 2s right-only terms, thus giving rise to at least 2s additional equations in the specification of Cn . More precisely, with notations from AmbiguousSystem and denoting ` the number of embeddings of γ in π, we prove that that for each subset E of S2n−1 , there exists a tuple (k1 , . . . , k` ) ∈ Kγπ such that E2,k1 ,...k` = E ∪ {γ}, ensuring that Cˆn hE ∪ {γ}i appear in the system of equations. Let us start by classifying the embeddings of γ in π into three categories. For all i ∈ [1..s], let us denote by αi the embedding of γ in π that sends τi to π2 , ⊕[τ1 , . . . , τi−1 ] to π1 and ⊕[τi+1 , . . . , τs ] to π3 ; and let αs+1 be the embedding of γ in π that sends γ to π2 . The remaining embeddings of γ in π are denoted {αi | i ∈ [s + 2..`]}. Notice that for any i 6= s + 1, there exists some ki ∈ [1..6], with ki 6= 2, such that γαi (ki ) 6= ε and γαi (ki ) 6= 1 (since for each j, τj is simple and |π| < |τj |, thus τj has to be entirely embedded in some πk ). This remark allows to consider, for each subset E of S2n−1 , a tuple (k1 , . . . k` ) defined as follows. For i ∈ [1..s], we set ki = 2 if τi ∈ E, and otherwise we choose ki 6= 2 such that γαi (ki ) 6= ε and γαi (ki ) 6= 1. We set ks+1 = 2. For i ∈ [s + 2..`], we choose ki 6= 2 such that γαi (ki ) 6= ε and γαi (ki ) 6= 1. Consequently, the following properties hold: - (k1 , . . . k` ) ∈ Kγπ (defined in Equation (8) p.14); - ki = 2 if and only if τi ∈ E or i = s + 1; - for τi ∈ E, γαi (ki ) = τi ; - and for i = s + 1, γαi (ki ) = γ. This ensures that E2,k1 ,...k` = E ∪ {γ} as claimed.
5.6
Simplifications on the fly
During the computation of the equations by Specification (Algo. 8), many restriction terms appear, that may be redundant or a bit more intricate than necessary. For instance, in the equations obtained when pushing down the constraints in the subtrees using the rewriting described in Propositions 4.7 (p.17) and 5.10 (p.26), some element of a given union may not be useful because it may be included in some other element of the union. We simplify these unions by deleting the useless elements, using the Proposition 5.18 below. Moreover we do an other kind of simplification, with Proposition 5.16: when a restriction D of the form Cˆδ hEi(A) arise, it can often be written as D = Cˆδ hE 0 i(A0 ) with E 0 (resp. A0 ) having fewer elements than E (resp. A). We use the description having as few elements as possible. Propositions 5.15 and 5.17 further allow some trivial simplifications. Proposition 5.15. A restriction Cˆδ hEi(A) is the empty set as soon as there exist π ∈ E and σ ∈ A such that π 4 σ. 28
For any sets E and A of patterns, min E (resp. max A) denote the subset of E (resp. A) containing all minimal (resp. maximal) elements of E (resp. A) for the pattern order 4. Proposition 5.16. In any equation, every restriction Cˆδ hEi(A) may be replaced by Cˆδ hmin Ei(max A) without modifying the set of permutations described. Proof. The proposition is an immediate consequence of Cˆδ hEi(A) = Cˆδ hmin Ei(max A). This identity follows easily from two simple facts: if a permutation σ avoids π then σ avoids all patterns containing π; and if σ contains π then σ contains all patterns contained in π. Proposition 5.17. The restriction term π[C1 , . . . , Cn ] is the empty set as soon as there exists i such that Ci = ∅. In this case, π[C1 , . . . , Cn ] may be removed from any union of restriction terms without modifying the set of permutations described by this union. Proposition 5.18. Consider a union of restriction terms containing two terms with the same root π[C1 , . . . , Cn ] and π[D1 , . . . , Dn ]. If for all i, Ci ⊆ Di , then we may remove π[C1 , . . . , Cn ] from this union without modifying the set of permutations it describes. Proof. If for all i, Ci ⊆ Di , then π[C1 , . . . , Cn ] ⊆ π[D1 , . . . , Dn ], and this gives the result immediately. Performing the simplifications of Proposition 5.16 requires that we can compute min E and max A effectively. This can be done naively by simply checking all pattern relations between all pairs of elements of E (resp. A). Similarly, to perform all simplifications induced by Proposition 5.18, we would need to be able to decide whether Ci ⊆ Di , for any restrictions Ci and Di . Lemma 5.19 below gives a sufficient condition for the inclusion of a restriction into another, hence allowing to perform some simplifications. Lemma 5.19. Let δ ∈ { , +, −} and E1 , E2 , A1 and A2 be any sets of permutations. Then Cˆδ hE1 i(A1 ) ⊆ Cˆδ hE2 i(A2 ) as soon as: • for each π ∈ E2 , there exists τ ∈ E1 such that τ 4 π, and • for each π ∈ A2 , there exists τ ∈ A1 such that π 4 τ . Proof. Assume the two conditions of the statement are satisfied. Consider σ ∈ Cˆδ hE1 i(A1 ), and let us prove that σ ∈ Cˆδ hE2 i(A2 ). Let π ∈ E2 . By assumption, there exists τ ∈ E1 such that τ 4 π. Since σ ∈ Cˆδ hE1 i, σ avoids τ . From τ 4 π, we conclude that σ also avoids π. Therefore σ ∈ Cˆδ hE2 i. Similarly, let π ∈ A2 . There exists τ ∈ A1 such that π 4 τ . Since σ ∈ Cˆδ hE1 i(A1 ), we know that σ contains τ . Consequently, σ also contains π. Hence σ ∈ Cˆδ hE2 i(A2 ). Note that the condition given by Lemma 5.19 is sufficient, but it is not necessary. Indeed for E1 = {34152}, A1 = {364152}, we have Cˆδ hE1 i(A1 ) = ∅. In particular Cˆδ hE1 i(A1 ) ⊆ Cˆδ h123i(132) even though the first condition of Lemma 5.19 is not satisfied. We may however wonder if the condition of Lemma 5.19 could be necessary under the assumption that E1 , E2 , A1 and A2 satisfy additional conditions, like Cˆδ hE1 i(A1 ) being nonempty and E2 and A2 being antichains. 29
Any of the simplifications explained above can be performed on the fly, each time a new restriction term appears while running the procedure Specification. This allows to compute systems of equations significantly more compact than the raw output of our algorithm. We do not claim that these simplifications constitute an exhaustive list of all possible simplifications. But Propositions 5.16 to 5.18 and Lemma 5.19 cover all simplifications that are performed in our implementation of Specification, and in the example of Section 6.2.
6 6.1
Algorithmic context, an example and perspectives An algorithmic chain from B to random permutations in Av(B)
Our main result, reported in Theorem 5.11, can and should be viewed in the context of other recent algorithms from the literature. Together, they provide a full algorithmic chain starting with the finite basis B of a permutation class C, and computing a specification for C, from which it is possible to sample permutations in C uniformly at random. Figure 3 shows an overview of this algorithmic chain, and we review its main steps below. Note that this procedure may fail to compute its final result, namely when C contains an infinite number of simple permutations, this condition being tested algorithmically. We have chosen that the permutation class in input of our procedure should be given by its basis B, that we require to be finite. This does not cover the whole range of permutation classes, but it is one of the possible ways to give a finite input to our algorithm. There are of course other finite descriptions of permutation classes, even some with infinite basis (by a recognition procedure for example). The assumption of the description by a finite basis has been preferred for two reasons: first, it encompasses most of the permutation classes that have been studied; and second, it is a necessary condition for classes to contain finitely many simple permutations (see [AA05]) and hence for our algorithm to succeed. First step: Finite number of simple permutations First, we check whether C = Av(B) contains only a finite number of simple permutations. This is achieved using algorithms of [BBPR10] when the class is substitution-closed and of [BBPR15] otherwise. The P complexity of these algorithms is respectively O(n log n) and O(n log n + p2k ), where n = β∈B |β|, p = max{|β| : β ∈ B} and k = |B|. Second step: Computing simple permutations The second step of the algorithm is the computation of the set of simple permutations SC contained in C = Av(B), when we know it is finite. Again, when C is substitution-closed, SC can be computed by an algorithm that is more efficient than in the general case. The two algorithms are described in [PR12], and their complexity depends on the output: O(N · `p+2 · |B|) in general and O(N · `4 ) for substitution-closed classes, with N = |SC |, p = max{|β| : β ∈ B} and ` = max{|π| : π ∈ SC }. In the case of substitution-closed classes, the set of simple permutations in C gives an immediate access to a specification for C – see Theorem 3.3 (p.9). In the general case, 30
B: finite basis of excluded patterns
Constraints propagation Compute an ambiguous system by propagation of pattern avoidance constraints
Compute an Disambiguation of the unambiguous system combinatorial system of equations - transform intersecting for generating functions using the inclusion-exclusion principle
unions into disjoint unions introducing complement sets - express complement sets by means of pattern containment constraints
B contains permutations that are not simple Av(B) is not substitution-closed
B contains only simple permutations Av(B) is substitution-closed
Is there a finite number of simple permutations in the class C=Av(B)? O(n log n + p 2k )
NO STOP
O(n log n) YES
Computation of the subset Sc of simple permutations in C O(N. l
p+2
4
O(N. l )
.k)
direct Specification for C
Generating functions Uniform random samplers
Figure 3: The full algorithmic chainPstarting from the basis B of a permutation class C, with complexities given w.r.t. n = β∈B |β|, k = |B|, p = max{|β| : β ∈ B}, N = |SC | and ` = max{|π| : π ∈ SC } where SC is the set of simple permutations of C. finding such a specification is the algorithmic problem that we have addressed in this article, and solved. Third step: Computing a combinatorial specification This corresponds to the computation of an ambiguous system of equations describing C, and of a subsequent combinatorial specification for C, as described in Sections 4 and 5 respectively. From a combinatorial specification for C, that we may obtain algorithmically as described above, there are two natural algorithmic continuations, which we have reviewed in Section 2.3. Fourth step: Computing the generating function C(z) of C With the dictionary P of [FS09], a system of equations defining C(z) = n≥0 cn z n is immediately deduced from the specification. Because our specification involves only disjoint unions and Cartesian products, the resulting system is positive and algebraic. In some favorable cases, this system may be solved for C(z) explicitly. Even if it is not the case, many information may still be derived from the system, in particular about the coefficients cn or the growth rate of the class. An alternative for the computation of C(z) As explained in [AA05] and recalled at the end of Section 4, it is also possible to obtain such a system of equations for C(z) from an ambiguous system describing C, applying the inclusion-exclusion principle. In this case, the obtained system is algebraic but with negative terms in general. Fifth step: reviewed the translate the tations in C.
Random sampling of permutations in C In Section 2.3, we have principles that allow, in the same fashion as the dictionary of [FS09], to combinatorial specification for C into uniform random samplers of permuRemark that this translation is possible only with a specification, i.e. an 31
unambiguous system describing C. Indeed, whereas adapted when considering generating functions (where subtraction is easily handled), the inclusion-exclusion principle cannot be applied for random generation (since “subtracting combinatorial objects” is not an option in a procedure to produce them). To illustrate that this algorithmic chain is effective, we show some observations that are produced through it in Figures 4 and 5 (p.35 and 36). In the conclusion, we shall comment these observations, and explain further research directions that they open. Before we turn to that, we present how our algorithms run on an example.
6.2
Example: Combinatorial specification for C = Av(1243, 2341, 2413, 41352, 531642)
We apply the method described in this article to find a combinatorial specification for the permutation class C = Av(B) where B = {1243, 2341, 2413, 41352, 531642}.7 From this description we derive its generating function and furthermore generate at random large permutations of the class. We follow the different steps described in the diagram of Figure 3. First, notice that Av(B) is not substitution-closed as 1243 and 2341 are non-simple permutations and belong to the basis of the class. Then we test whether the class contains a finite number of simple permutations. In our case, the only simple permutation of the class is 3142. 6.2.1
Ambiguous system for C
Specification for the substitution-closure Cˆ of C The starting point of our algorithm is the set of simple permutations SC in C (here SC = {3142}), and more precisely the combinatorial specification for the substitution closure Cˆ of C that immediately follows from SC . Specifically, Equations (1), (2) and (3) of Proposition 3.2 (p.8) translate into the following system: ˆ ] [Cˆ− , C] ˆ ] 3142[C, ˆ C, ˆ C, ˆ C] ˆ Cˆ = 1 ] ⊕[Cˆ+ , C] + − ˆ ] 3142[C, ˆ C, ˆ C, ˆ C] ˆ Cˆ = 1 ] [Cˆ , C] ˆ ] 3142[C, ˆ C, ˆ C, ˆ C]. ˆ Cˆ− = 1 ] ⊕[Cˆ+ , C]
(20) (21) (22)
From Cˆ to C = Av(B) An ambiguous combinatorial system describing C = Av(B) is then obtained from B and SC applying AmbiguousSystem (Algo. 4, p. 17). Starting from Equation (20), it consists in adding the non-simple pattern avoidance constraints (denoted B ? in AmbiguousSystem) imposed by the avoidance of B. In our case, 1243 and 2341 are the only two non-simple patterns in B, and we can compute an ambiguous ˆ system for C = Ch1243, 2341i by adding these two constraints one after the other using ˆ ? ). the procedure EqnForClass(C,B ˆ To compute Ch1243i, we propagate the constraint h1243i into each term of Equation (20) using embeddings of γ = 1243 into ⊕, and 3142. This gives the following 7
The reader interested in more details about this example can find them in [Pie13, Section 3.5].
32
equation: ˆ ˆ ˆ ˆ Ch1243i = 1 ∪ ⊕[Cˆ+ h12i, Ch132i] ∪ ⊕[Cˆ+ h1243i, Ch21i] ∪ [Cˆ− h1243i, Ch1243i] ˆ ˆ ˆ ˆ ˆ ˆ ˆ ˆ ∪ 3142[Ch1243i, Ch12i, Ch21i, Ch132i] ∪ 3142[Ch12i, Ch12i, Ch132i, Ch132i] (23) As explained in Section 5.6, to obtain the above equation, two types of simplification have been performed on the output of EqnForClass. First, when a union contains two terms such that one is strictly included in the other, then the smaller term has been removed (see Proposition 5.18). Second, when two excluded patterns are such that the avoidance of one implies the avoidance of the other, then the larger one has been removed ˆ ˆ (see Proposition 5.16) – for instance we have simplified Ch1243, 12i into Ch12i. ˆ ˆ Next we add the constraint 2341 in the above equation as Ch1243ih2341i = Ch1243, 2341i. We propagate the constraint 2341 into the 5 different terms that appear in Equation (23), and perform simplifications as described above. Iterating this process for new classes Cˆδ hEi of the right side of the above equations leads to the following ambiguous system: ˆ ˆ ˆ Ch1243, 2341i = 1 ∪ ⊕[Cˆ+ h1243, 2341i, Ch21i] ∪ ⊕[Cˆ+ h12i, Ch132, 2341i] (24) − ˆ ˆ ˆ ˆ ˆ ∪ [Cˆ h123i, Ch1243, 2341i] ∪ 3142[Ch12i, Ch12i, Ch12i, Ch132, 2341i] ˆ ˆ ˆ ˆ ˆ Cˆ+ h1243, 2341i = 1 ∪ [Cˆ− h123i, Ch1243, 2341i] ∪ 3142[Ch12i, Ch12i, Ch12i, Ch132, 2341i] ˆ ˆ Ch21i = 1 ∪ ⊕[Cˆ+ h21i, Ch21i] Cˆ+ h12i = 1 ˆ ˆ ˆ Ch132, 2341i = 1 ∪ ⊕[Cˆ+ h132, 2341i, Ch21i] ∪ [Cˆ− h132, 123i, Ch132, 2341i] − + ˆ ˆ ˆ ˆ ˆ Cˆ h123i = 1 ∪ ⊕[Cˆ h12i, Ch12i] ∪ 3142[Ch12i, Ch12i, Ch12i, Ch12i] ˆ ˆ Ch12i = 1 ∪ [Cˆ− h12i, Ch12i] Cˆ+ h21i = 1 ˆ Cˆ+ h132, 2341i = 1 ∪ [Cˆ− h132, 123i, Ch132, 2341i] ˆ Cˆ− h132, 123i = 1 ∪ ⊕[Cˆ+ h12i, Ch21, 12i] − Cˆ h12i = 1 ˆ Ch21, 12i = 1.
6.2.2
Disambiguation
All equations in the above system are unambiguous, except for the first one. Indeed, ˆ ˆ the intersection of t1 = ⊕[Cˆ+ h12i, Ch132, 2341i] and t2 = ⊕[Cˆ+ h1243, 2341i, Ch21i] is + ˆ ˆ ⊕[C h12i, Ch21i] which is not empty. To disambiguate those terms we use the procedure Disambiguate (Algo. 6, p. 22). Thus we can write (t1 ∪ t2 ) as (t1 ∩ t¯2 ) ] (t¯1 ∩ t2 ) ] (t1 ∩ t2 ). The computation of the complement terms t¯1 and t¯2 (with Equation (17)) increases the number of terms in the disjoint union that describes t1 ∪ t2 , producing in this case a disjoint union of 15 terms. After eliminating terms that are empty or strictly included in another one, Equation (24) in the previous system is replaced by: 33
ˆ ˆ ˆ ˆ Ch1243, 2341i = 1 ] ⊕[Cˆ+ h1243, 2341i(12), Ch21i] ] ⊕[Cˆ+ h12i, Ch132, 2341i(21)] ] ⊕[Cˆ+ h12i, Ch21i] ˆ ˆ ˆ ˆ ˆ ] [Cˆ− h123i, Ch1243, 2341i] ] 3142[Ch12i, Ch12i, Ch12i, Ch132, 2341i].
ˆ As noticed in Section 5.3, new right-only terms like Ch132, 2341i(21) appear in this equation. But these terms are not defined by our system, so we have to compute a description for these new terms. This is done in the procedure Disambiguate by iterating EqnForRestriction (Algo. 7) which returns a combinatorial equation. This algorithm works in a fashion similar to the previous ones, except that we have ˆ to deal with pattern containment constraints. For instance, in Ch132, 2341i(21), the permutations must contain 21 as a pattern. For this term, we describe how Algorithm EqnForRestriction computes an additional equation. We do not give details for the other right-only terms. First, starting from Equation (20), we add the pattern avoidance constraints, namely ˆ 132 and 2341, and compute an equation for Ch132, 2341i like before. We obtain the following equation: ˆ ˆ ˆ Ch132, 2341i = 1 ∪ ⊕[Cˆ+ h132, 2341i, Ch21i] ∪ [Cˆ− h132, 123i, Ch132, 2341i].
(25)
Then, we add the pattern containment constraints (here 21) to this equation, considering embeddings of 21 in ⊕ and . The equation obtained after simplification is ˆ ˆ ˆ Ch132, 2341i(21) = ⊕[Cˆ+ h132, 2341i(21), Ch21i] ∪ [Cˆ− h132, 123i, Ch132, 2341i]. We iterate this method until each term that appear on the right hand side of an equation of the system is defined by an unambiguous equation, which finally leads to the following unambiguous system: ˆ Ch1243, 2341i = ] + ˆ C h12i =
ˆ ˆ ˆ 1 ] ⊕[Cˆ+ h12i, Ch132, 2341i(21)] ] ⊕[Cˆ+ h1243, 2341i(12), Ch21i] ] ⊕[Cˆ+ h12i, Ch21i] − ˆ ˆ ˆ ˆ ˆ [Cˆ h123i, Ch1243, 2341i] ] 3142[Ch12i, Ch12i, Ch12i, Ch132, 2341i]
ˆ 1 ] [Cˆ− h12i, Ch12i] ˆ ˆ ˆ Ch132, 2341i(21) = ⊕[Cˆ+ h132, 2341i(21), Ch21i] ] [Cˆ− h132, 123i, Ch132, 2341i] + − − ˆ ˆ Cˆ h1243, 2341i(12) = [Cˆ h123i(12), Ch1243, 2341i(12)] ] [Cˆ h12i, Ch1243, 2341i(12)] − ˆ ˆ ˆ ˆ ˆ ] [Cˆ h123i(12), Ch12i] ] 3142[Ch12i, Ch12i, Ch12i, Ch132, 2341i] ˆ Ch21i = − ˆ C h123i = ˆ Ch12i =
ˆ 1 ] ⊕[Cˆ+ h21i, Ch21i] ˆ ˆ ˆ ˆ ˆ 1 ] ⊕[Cˆ+ h12i, Ch12i] ] 3142[Ch12i, Ch12i, Ch12i, Ch12i] − ˆ 1 ] [Cˆ h12i, Ch12i]
ˆ ˆ ˆ Ch132, 2341i = 1 ] ⊕[Cˆ+ h132, 2341i, Ch21i] ] [Cˆ− h132, 123i, Ch132, 2341i] − ˆ C h12i = 1 + ˆ ˆ C h132, 2341i(21) = [Cˆ− h132, 123i, Ch132, 2341i] ˆ Cˆ− h132, 123i = 1 ] ⊕[Cˆ+ h12i, Ch21, 12i] − + ˆ ˆ ˆ ˆ ˆ ˆ ˆ C h123i(12) = ⊕[C h12i, Ch12i] ] 3142[Ch12i, Ch12i, Ch12i, Ch12i] ˆ ˆ ˆ ˆ Ch1243, 2341i(12) = ⊕[Cˆ+ h12i, Ch132, 2341i(21)] ] ⊕[Cˆ+ h12i, Ch21i] ] ⊕[Cˆ+ h1243, 2341i(12), Ch21i] ] ] + ˆ C h21i =
ˆ ˆ [Cˆ− h123i(12), Ch12i] ] [Cˆ− h12i, Ch1243, 2341i(12)] − ˆ ˆ ˆ ˆ ˆ [Cˆ h123i(12), Ch1243, 2341i(12)] ] 3142[Ch12i, Ch12i, Ch12i, Ch132, 2341i]
1 + ˆ ˆ C h132, 2341i = 1 ] [Cˆ− h132, 123i, Ch132, 2341i] ˆ Ch21, 12i = 1.
34
6.2.3
Byproducts of the combinatorial specification
The translation of the above specification into a system of equations for the generating function of C produces in this specific case a system that can be solved, giving access to a closed form for the generating function of C: (z 6 − 7z 5 + 20z 4 − 28z 3 + 20z 2 − 7z + 1)z . 1 − 9z + 32z 2 − 59z 3 + 62z 4 − 37z 5 + 13z 6 − 2z 7 We can also translate this specification into (Boltzmann or recursive) uniform random samplers of permutations in C. We have used the recursive sampler8 so obtained to uniformly generate permutations in C. Then, observing them, we can gain some intuition of what they look like on average. Namely, Figure 4 shows the “average diagram” of a permutation in C. The diagram of a permutation σ is the set of points in the plane at coordinates (i, σi ), and the picture in Figure 4 is obtained by drawing uniformly at random 30 000 permutations of size 500 in C, and by overlapping their diagrams – the darker a point (x, y) is, the more of these permutations have σ(x) = y. The “average diagram” of permutations in C and in other classes will be discussed in the conclusion. C(z) =
Figure 4: The shape of permutations in the class C of Section 6.2. Recall that C is not substitution-closed.
6.3
Perspectives
As described in Section 6.1, our main result gives an algorithm that produces, for any class Av(B) containing finitely many simple permutations, a recursive (resp. Boltzmann) uniform random sampler. When generating permutations with such samplers, complexity is measured w.r.t. the size of the permutation produced and is quasilinear (resp. quadratic but can be made linear using classic tricks and allowing a small variation on the size of the output permutation [DFLS04]). However, the complexity is not at all measured w.r.t. the number of equations in the specification nor w.r.t. the number of terms in each equation. 8
In this case (and in the one of Figure 5), we chose a recursive sampler over a Boltzmann one because it is more suitable when you want to sample many random permutations of the same medium size.
35
In our context, this dependency is of course relevant, and opens a new direction in the study of random samplers. Even if its complexity is not fully analyzed, our algorithmic chain from B to random samplers can be implemented in a software, providing a tool for observing random permutations in classes Av(B). It can be used experimentally, to test conjectures for instance, and it opens the way to further develop the ideas of [AM14, HRS14, MP14a, MP14b] by studying the random behavior of permutations in classes. For the moment, we only have a prototype implementing this algorithmic chain. But it already allows to repeat experiments like those of Section 6.2 for other classes. For example, Figure 5 shows average diagrams of permutations in the class Av(2413, 3142) of separable permutations, and in another substitution-closed class. These are obtained overlapping the diagrams of 10 000 permutations of size 100 (resp. 500). The representation is however different from Figure 4: in these 3D representations, for a point at coordinates (x, y, z), z is the number of permutations such that σ(x) = y.
Figure 5: The shape of separable permutations (left), and of permutations taken in the substitution-closed class whose set of simple permutations is {2413, 3142, 24153} (right). A natural question is then to describe the average shape of such permutations, and this is indeed a work in progress. Another direction would be to somehow measure the randomness of permutations in a given class, by comparing random permutations in general with random permutations in a class, or random permutations in two different classes, w.r.t. well-known statistics on permutations. But the perspectives opened by our work are not only for the study of random permutations. Indeed, the specifications obtained could also be used to compute or estimate growth rates of permutation classes, to provide improvements on the known bounds on these growth rates [Cib09]. Moreover, we could also explore the possible use of the computed specifications to provide more efficient algorithms to test membership of a permutation to a class. We should also mention that our procedure fails to be completely general. Although the method is generic and algorithmic, the classes that are fully handled by the algorithmic process are those containing a finite number of simple permutations. By [AA05], such 36
classes have finite basis (which is a restriction we imposed already), but they also have an algebraic generating function. Of course, this is not the case for every permutation class. We may wonder how restrictive this framework is, depending on which problems are studied. First, does it often happen that a permutation class contains finitely many simple permutations? From the work of [Vat10] it seems that a majority of permutations classes are not algebraic, thus do not contain finitely many simple permutations. But quantifying this phenomenon is a direction of research yet to be explored. Second, we may want to describe some problems (maybe like the distribution of some statistics) for which algebraic permutation classes are representative of all permutation classes. Notice that even if a class C contains an infinite number of simple permutations, we can use our approach to perform random generation of permutations of the class C. More precisely, fixing the maximum size n of permutations we want to generate, we can apply our algorithm to a class C 0 ⊆ C containing finitely many simple permutations and that coincides with C up to size n. It is enough to choose C 0 which is the subclass of C whose set of simple permutations consists in all simple permutations of C of size at most n, whose computation is explained in [PR12]. However if the maximal size n is large and if C has many simple permutations, the complexity of our algorithm will be even harder to control. This approach is therefore relevant when the class has an infinite number of simple permutations, but a small number of each size. To enlarge the framework of application of our algorithm computing specifications, we could explore the possibility of extending it to permutation classes that contain an infinite number of simple permutations, but that are finitely described (like the family of oscillations of [BRV08] for instance). With such an improvement, more classes would enter our framework, but it would be hard to leave the algebraic case. This is however a promising direction for the construction of more efficient random samplers for such permutation classes. Acknowledgment Many thanks to Mireille Bousquet-M´elou for pointing out that our work is related to the query-complete sets of [BHV08].
References [AA05]
Michael H. Albert and Mike D. Atkinson. Simple permutations and pattern restricted permutations. Discrete Math., 300(1-3):1–15, 2005.
[AAB11]
Michael H. Albert, Mike D. Atkinson, and Robert Brignall. The enumeration of permutations avoiding 2143 and 4231. Pure Mathematics and Applications, 22(2):87 – 98, 2011.
[AAK03]
Michael H. Albert, Mike D. Atkinson, and Martin Klazar. The enumeration of simple permutations. J. Integer Seq., 6, 2003.
[AB14]
Michael H. Albert and Robert Brignall. Enumerating indices of Schubert varieties defined by inclusions. J. Comb. Theory Ser. A, 123(1):154–168, April 2014.
37
[AM14]
Mahshid Atapour and Neal Madras. Large deviations and ratio limit theorems for pattern-avoiding permutations. Combinatorics, Probability and Computing, 23:161–200, 3 2014.
[ASV12]
Mike D. Atkinson, Bruce E. Sagan, and Vincent Vatter. Counting (3 + 1)avoiding permutations. Eur. J. Comb., 33(1):49–61, January 2012.
[BBCP07] S`everine B´erard, Anne Bergeron, C´edric Chauve, and Christophe Paul. Perfect sorting by reversals is not always difficult. IEEE/ACM Trans. Comput. Biol. Bioinformatics, 4(1):4–16, 2007. [BBL98]
Prosenjit Bose, Jonathan F. Buss, and Anna Lubiw. Pattern matching for permutations. Inform. Process. Lett., 65:277–283, 1998.
[BBPR10] Fr´ed´erique Bassino, Mathilde Bouvel, Adeline Pierrot, and Dominique Rossin. Deciding the finiteness of simple permutations contained in a wreath-closed class is polynomial. Pure Mathematics and Applications, 21(2):119–135, 2010. [BBPR15] Fr´ed´erique Bassino, Mathilde Bouvel, Adeline Pierrot, and Dominique Rossin. An algorithm for deciding the finiteness of the number of simple permutations in permutation classes. Adv. Appl. Math., 64:124–200, 2015. [BHV08]
Robert Brignall, Sophie Huczynska, and Vincent Vatter. Simple permutations and algebraic generating functions. J. Combin. Theory Ser. A, 115(3):423– 441, 2008.
[BR06]
Mathilde Bouvel and Dominique Rossin. The longest common pattern problem for two permutations. Pure Mathematics and Applications, 17(1-2):55–69, 2006.
[Bri10]
Robert Brignall. A survey of simple permutations. In Steve Linton, Nik Ruˇskuc, and Vincent Vatter, editors, Permutation Patterns, volume 376 of London Math. Soc. Lecture Note Ser., pages 41–65. Cambridge Univ. Press, 2010.
[BRV08]
Robert Brignall, Nik Ruˇskuc, and Vincent Vatter. Simple permutations: decidability and unavoidable substructures. Theoret. Comput. Sci., 391(12):150–163, 2008.
[Cib09]
Josef Cibulka. On constants in the F¨ uredi–Hajnal and the Stanley–Wilf conjecture. J. Combin. Theory Ser. A, 116(2):290 – 302, 2009.
[DFLS04] Philippe Duchon, Philippe Flajolet, Guy Louchard, and Gilles Schaeffer. Boltzmann samplers for the random generation of combinatorial structures. Comb. Probab. Comput., 13(4–5):577–625, 2004. [FS09]
Philippe Flajolet and Robert Sedgewick. Analytic combinatorics. Cambridge University Press, Cambridge, 2009.
38
[FZVC94] Philippe Flajolet, Paul Zimmerman, and Bernard Van Cutsem. A calculus for the random generation of labelled combinatorial structures. Theoret. Comput. Sci., 132(1-2):1–35, 1994. [HRS14]
Christopher Hoffman, Douglas Rizzolo, and Erik Slivken. Pattern avoiding permutations and brownian excursion. Preprint available at http://arxiv. org/abs/1406.5156, 2014.
[MP14a]
Neal Madras and Lerna Pehlivan. Structure of random 312-avoiding permutations. Preprint available at http://arxiv.org/abs/1401.6230, 2014.
[MP14b]
Sam Miner and Igor Pak. The shape of random pattern-avoiding permutations. Adv. Appl. Math., 55(0):86 – 130, 2014.
[MR84]
Rolf H. M¨ohring and Franz J. Radermacher. Substitution decomposition for discrete structures and connections with combinatorial optimization. Annals of Discrete Math., 19:257–356, 1984.
[MT04]
Adam Marcus and G´abor Tardos. Excluded permutation matrices and the Stanley-Wilf conjecture. J. Comb. Theory, Ser. A, 107(1):153–160, 2004.
[Pie13]
Adeline Pierrot. Combinatorial and algorithmic results on permutation classes. PhD thesis, Univ. Paris Diderot - Paris 7, 2013.
[PR12]
Adeline Pierrot and Dominique Rossin. Simple permutation poset. Preprint available at http://arxiv.org/abs/1201.3119, 2012.
[PSS12]
Carine Pivoteau, Bruno Salvy, and Mich`ele Soria. Algorithms for combinatorial structures: Well-founded systems and Newton iterations. J. Comb. Theory Ser. A, 119(8):1711–1773, 2012.
[ST93]
James H. Schmerl and William T. Trotter. Critically indecomposable partially ordered sets, graphs, tournaments and other binary relational structures. Discrete Math., 113:191–205, 1993.
[Vat10]
Vincent Vatter. Permutation classes of every growth rate above 2.48188. Mathematika, 56:182–192, 2010.
[Vat15]
Vincent Vatter. Handbook of Enumerative Combinatorics, chapter Permutation classes (chapter 12). Discrete Mathematics and its applications. CRC Press, 2015.
39