Sorting with pattern-avoiding stacks: the $132$-machine

This paper continues the analysis of the pattern-avoiding sorting machines recently introduced by Cerbai, Claesson and Ferrari [CCF]. These devices consist of two stacks, through which a permutation is passed in order to sort it, where the content of each stack must at all times avoid a certain pattern. Here we characterize and enumerate the set of permutations that can be sorted when the first stack is $132$-avoiding, solving one of the open problems proposed in [CCF]. To that end we present several connections with other well known combinatorial objects, such as lattice paths and restricted growth functions (which encode set partitions). We also provide new proofs for the enumeration of some sets of pattern-avoiding restricted growth functions and we expect that the tools introduced can be fruitfully employed to get further similar results.


Introduction
Pattern-avoiding sorting machines were introduced in a recent paper by Cerbai, Claesson and Ferrari [CCF]. In the classical formulation of the Stacksort problem [Kn], an input permutation π = π 1 . . . π n is scanned from left to right and, when π i is the current element, either π i is pushed onto the stack or the top element of the stack is popped and appended to the output. If there is a sequence of push and pop operations that produces a sorted output (that is, the identity permutation), then the input permutation is said to be sortable. There is a well known algorithm, called Stacksort, that sorts every sortable permutation. It has two key properties: 1. the stack is increasing, meaning that the elements inside the stack are maintained in increasing order (from top to bottom); 2. the algorithm is right greedy, meaning that it always chooses to perform a push operation as long as the stack remains increasing in the above sense; here the expression "right greedy" refers to the usual pictorial representation of this problem, in which the input permutation is on the right, the stack is in the middle and the output permutation is on the left (see Figure 1, left).
The notion of pattern avoidance allows us to efficiently characterize the set of the permutations that can be sorted by Stacksort. Let S n be the symmetric group over a set of cardinality n, consisting of all permutations of length n. Given two permutations σ ∈ S k and π = π 1 · · · π n ∈ S n , with k n, we say that σ is a pattern of π when there exist indices 1 i 1 < i 2 < · · · < i k n such that π i 1 π i 2 . . . π i k (as a permutation) is isomorphic to σ, that is, π i 1 , π i 2 , . . . , π i k are in the same relative order of size as the elements of σ, in which case we write σ π i 1 π i 2 . . . π i k . This notion of patterns in permutations defines a partial order, and the resulting poset is known as the permutation pattern poset. When σ is a pattern of π, we say that π contains σ, otherwise π avoids σ. A downset I of the permutation pattern poset, also called a permutation class, can be described in terms of its minimal excluded permutations (or, equivalently, the minimal elements of the complementary upset); these permutations are called the basis of I. When B is the basis of I we write I = Av (B).
Returning to Stacksort, it is well known that a permutation is sortable if and only if it avoids the pattern 231. As a consequence, the number of sortable permutations of length n is the n-th Catalan number. Given that describing the set of sortable permutations is rather manageable in the classical case, one would think that similar results can be derived by considering a slightly more general version of the problem, where a second stack is connected in series to the first one. Despite the many attempts, very few results have been obtained. For example, Murphy [M] showed that thus sortable permutations are a class with infinite basis. To describe the basis and to enumerate the permutations in question remain open problems.
Due to the toughness of the problem in its full generality, several authors have considered weaker formulations by introducing some constraints on the sorting device. In his PhD thesis [W], West studied permutations that can be sorted by two stacks connected in series using a right greedy algorithm. This is equivalent to making two passes through a stack. Similarly, Smith [Sm] considered two stacks in series, where the first stack is required to be decreasing. It is worth noting that, due to the properties of classical stacksort, the second (final) stack turns out to be necessarily increasing. Pattern-avoiding machines constitute a further proposal to approach the general problem of sorting with two stacks. Let σ be a permutation. The σ-machine consists of two stacks connected in series (see Figure 1, right), obeying the following constraints: 1. At each step of the procedure, the elements in each stack must avoid certain forbidden configurations, reading from top to bottom. The second stack is increasing, that is, the sequence of numbers contained in the stack has to avoid the pattern 21. We express this by saying that the stack is 21-avoiding. In the same spirit, the first stack is σ-avoiding.
2. The algorithm performed with the two stacks connected in series is right greedy. As already observed, this is equivalent to making two passes through a stack, performing the right greedy algorithm at each pass. However, due to the restriction described above, during the first pass the stack is σ-avoiding, whereas during the second pass it is 21-avoiding.
We refer to the σ-avoiding stack as the σ-stack. A permutation π is σ-sortable if it is sortable by the σ-machine. Denote by Sort(σ) the set of σ-sortable permutations and by Sort n (σ) the set of σ-sortable permutations of length n. Denote by s σ (π) the output of the σ-stack on input π. Observe that, since s σ (π) is the input to the second (classical) stack, a permutation π is σ-sortable if and only if s σ (π) avoids 231. This fact, which will be frequently used throughout the paper, allows us to restrict our attention to the behavior of the σ-stack when analyzing the sortability of π.
In [CCF], the authors determine the patterns σ such that Sort(σ) is a permutation class, providing explicitly the corresponding basis.
Theorem 1 completely describes the sets of σ-sortable permutations that are permutation classes. The remaining cases are much more challenging. For example, amongst the six permutations of length three, Sort(321) = Av(123, 132) as a consequence of the previous result, but so far the only other solved pattern is 123: 123-sortable permutations are shown to be enumerated by the partial sums of partial sums of the Catalan numbers (sequence A294790 in [Sl]) via a bijection with Schröder paths avoiding the pattern UHD [CF]. In this paper we deal with one of the remaining patterns of S 3 , namely 132.
In Section 3 we characterize 132-sortable permutations as those avoiding the classical pattern 2314 and a certain mesh pattern.
In Section 4 we exploit the pattern avoidance characterization of Sort(132) to provide a geometrical description of these permutations. This ultimately allows us to find a recursive construction for Sort(132), which is used to provide a bijection between Sort(132) and the set of restricted growth functions (rgfs, to be defined in next section) avoiding the pattern 12231. The enumeration of the 12231-avoiding rgfs was obtained by Jelínek and Mansour in [JM], where they present a much more general mechanism that determines the entire Wilf-equivalence class of these avoiders, that is, the class of patterns that are avoided by the same number of rgfs of each length n. Their counting sequence is the binomial transform of the Catalan numbers, which is A007317 in the OEIS [Sl].
In Section 5 we exhibit direct combinatorial proofs for the enumeration of some patterns in the same Wilf-equivalence class as 12231. We exhibit links with lattice paths and pattern-avoiding permutations. Two of these patterns are enumerated via a bijection with a family of labeled Motzkin paths, which provides a natural combinatorial interpretation for a beautiful continued fraction for A007317. We also conjecture that a slight variation on the same approach should lead to the enumeration of many other patterns in the same Wilf-class. Finally, some of the results in this section lead to an independent proof of the enumeration of Sort(132).
A Dyck path is a path in the discrete plane Z × Z starting at the origin of a fixed Cartesian coordinate system, ending on the x-axis, never falling below the x-axis and using two kinds of steps, namely upsteps U = (1, 1) and downsteps D = (1, −1). The length of a Dyck path is its final abscissa, which coincides with the total number of its steps. See Figure 2 for an example of Dyck path. According to their semilength, Dyck paths are counted by Catalan numbers (sequence A000108 in [Sl]). The n-th Catalan number is c n = 1 n+1 2n n and the associated ordinary generating function is C(x) = (1 − √ 1 − 4x)/(2x). A slightly more general notion of lattice path is obtained by allowing one more kind of step, the horizontal step H = (1, 0). The resulting paths are called Motzkin paths and their enumeration (with respect to the total number of steps) is given by the Motzkin numbers (sequence A001006 in [Sl]).
A Restricted Growth Function (rgf) of length n is a sequence of positive integers R = r 1 · · · r n such that r 1 = 1 and r i 1 + max {r 1 , . . . , r i−1 } for each i 2. The rgfs of length n bijectively encode set partitions of [n] = {1, 2, . . . , n}, where, for example, the partition of [5] written in standard notation as 13-25-4 has rgf 12132, whose 3 in place 4 indicates that 4 is in the third block.
Denote by R n the set of rgfs of length n and let R = n 1 R n . The notion of pattern avoidance can be naturally extended to rgfs. Given a sequence of positive integers Q = q 1 q 2 · · · q k , define the standardization of Q as the string std(Q) obtained by replacing all occurrences of the i-th smallest element with i, for all i. Then, given a rgf R = r 1 . . . r n and a sequence of positive integers Q = q 1 . . . q k , with k n, Q is a pattern of R if there is a subsequence r i 1 . . . r i k of R such that std(r i 1 . . . r i k ) = Q. In this case we write Q R (and say that R contains Q); otherwise, we say that R avoids Q. We use the notation R(Q) to denote the set of the rgfs avoiding Q and R n (Q) = R n ∩ R(Q). For a more detailed survey on the notion of pattern avoidance in rgfs, we refer the reader to [JM] and [CDDGGPS]. Observe that if R is a rgf then each occurrence of the integer k in R, for any k 1, is preceded by some occurrence of all the integers 1, . . . , k − 1. A useful consequence is the following lemma, whose easy proof is omitted.
Lemma 2. Let R be a rgf and let Q = q 1 q 2 . . . q k be a sequence of positive integers. Let Q = std(Q) = q 1 . . . q k and suppose that q 1 = t, for some t 1. Then Q R if and only if 12 . . . (t − 1)Q R. 3 Pattern avoidance characterization of Sort (132) For the remainder of this paper, we let σ = 132.
In this section we characterize Sort(σ) in terms of pattern avoidance. First we need to introduce a slightly more general notion of pattern, originally given by Brändén and Claesson in [BC]. A mesh pattern of length k is a pair (τ, A), where τ ∈ S k and A ⊆ [0, k] × [0, k] is a set of pairs of integers. The elements of A identify the lower left corners of forbidden squares in the plot of τ (see Figure 2). An occurrence of the mesh pattern (τ, A) in π is then an occurrence of the classical pattern τ in π such that no elements of π are placed into a forbidden square of A.
We start by proving a useful decomposition lemma for σ-sortable permutations. Given a permutation π we decompose it as π = m 1 B 1 m 2 B 2 . . . m k B k , where m 1 m 2 · · · m k = 1 are the ltr-minima of π and each block B i contains all the elements strictly between two consecutive ltr-minima. We refer to this as the ltr-minima decomposition of π.
Lemma 3. Let π be a permutation and let π = m 1 B 1 m 2 B 2 . . . m k B k be its ltr-minima decomposition. Then: 1. s σ (π) = B 1 B 2 · · · B k m k m k−1 · · · m 2 m 1 , where each B i is a suitable rearrangement of the elements of B i .
2. If π is σ-sortable, then x > y for each x ∈ B i , y ∈ B j , with i < j. Proof.
1. For each x ∈ B 1 , m 1 xm 2 231, thus every element of B 1 has to be popped from the σ-stack before m 2 enters. After that, we have m 1 and m 2 on the σ-stack, with m 1 > m 2 and m 2 above m 1 . Note that they cannot both be part of a 132, therefore m 2 remains on the σ-stack until the end of the sorting process. Similarly, each element of B 2 has to be popped before m 3 enters, since m 3 xm 2 132 for each x ∈ B 2 . The same argument holds for every m j with j 2.
2. Suppose there are two elements x, y such that x < y, x ∈ B i and y ∈ B j , with i < j.
Then, as a consequence of the previous item, xym k is an occurrence of 231 in s σ (π), which is a contradiction since π is σ-sortable.
Lemma 4. Let π ∈ Sort n (σ) and let π = m 1 B 1 m 2 B 2 · · · m k B k be its ltr-minima decomposition. Then, when the next element of the input is b ∈ B i the content of the σ-stack when read from bottom to top is m 1 m 2 · · · m i b 1 b 2 · · · b t , where {b 1 , . . . b t } is a (possibly empty) subset of B i such that b 1 < b 2 < · · · < b t .
Proof. The first i ltr-minima m 1 , . . . , m i of π lie at the bottom of the σ-stack, by Lemma 3. Then the remaining elements b 1 , . . . , b t of B i in the σ-stack must be in increasing order from bottom to top, for otherwise, if b h > b for some h < , then s σ (π) would contain b b h m i 231, contradicting the σ-sortability of π.
We next show that σ-sortable permutations are characterized by the avoidance of a classical pattern and a mesh pattern. This leads to a more precise geometrical description of these permutations, as we will show in the next section. For the rest of the paper, let µ = (132, {(0, 2), (2, 0), (2, 1)}) be the mesh pattern depicted in Figure 2. An occurrence of the mesh pattern µ is thus an occurrence acb of the classical pattern 132 such that: • every element that precedes a in π is either smaller than b or greater than c; • every element between c and b in π is greater than b.
Proof. Let π = m 1 B 1 m 2 B 2 · · · m k B k be the ltr-minima decomposition of π. Suppose, for a contradiction, that π contains an occurrence bcad of 2314. When a enters the σ-stack, at least one element between b and c, call it x, has already been popped from the σ-stack, otherwise we would get the forbidden pattern acb 132 inside the σ-stack. Hence, by Lemma 3, s σ (π) contains xdm k 231, violating the hypothesis that π is σ-sortable.
Next suppose that acb is an occurrence of 132 in π. We wish to show that acb is part of an occurrence of either 3142, 2413 or 1423, thus proving that π avoids the mesh pattern µ. Let m(a) be the ltr-minimum of the block that contains a (in particular, m(a) = a if a is a ltr-minimum itself). Then m(a) a and m(a) exits the σ-stack after b and c (by Lemma 3), so c has to be popped before b enters, otherwise bcm(a) would be an occurrence of 231 inside s σ (π). We consider the following two cases. Note that a < b < c, so b, c are not ltr-minima in π.
• c ∈ B i and b ∈ B j , with i < j. In this case, m j < m(a) a, hence acm j b 2413, which is one of the desired patterns.
• c and b are in the same block B i . First suppose there is a ltr-minimum m = m , with < i, such that b < m < c; then m > m(a), so m precedes m(a) in π and macb 3142, again one of the listed patterns. Otherwise, suppose that, for every ltr-minimum m, either m < b or m > c and consider the element w that immediately precedes b in π. We wish to show that w < b, which will conclude the proof. Suppose, for a contradiction, that w > b and let x 1 , x 2 , . . . , x s = w be the elements on the σ-stack, after w has been pushed, that are not ltr-minima when we read from bottom to top. By Lemma 4, we have x 1 < x 2 < · · · < x s ; moreover for > t, all the elements x are popped from the σ-stack before b enters, because bx x t 132. We also observe that necessarily x t c, otherwise c would already have been popped and s σ (π) would contain the pattern cx t m(a) 231. We can now assert that b is pushed onto the σ-stack immediately above x t . In fact, x < b for every < t; moreover, our hypothesis implies that either m < b or m > c for every ltr-minimum m inside the σ-stack, therefore b cannot be the first element of an occurrence of 231 (read from top to bottom) that involves elements inside the σ-stack. However this results in an occurrence bx t m(a) of 231 in s σ (π), which again contradicts the hypothesis that π is σ-sortable.
The condition of Theorem 5 is also sufficient for a permutation to be σ-sortable.
Proof. Suppose, for a contradiction, that π is not σ-sortable, that is, s σ (π) contains an occurrence of 231. Let π = m 1 B 1 m 2 B 2 · · · m k B k be the ltr-minima decomposition of π. By Lemma 3, we have s σ (π) = B 1 B 2 · · · B k m k m k−1 · · · m 2 m 1 . Since the ltr-minima are popped from the σ-stack in increasing order, neither b nor c can be a ltr-minimum. Suppose that b ∈ B i and c ∈ B j , for some i j. If i < j, then m i bm j c 2314, which is forbidden. Suppose instead that i = j and consider the leftmost ascent x < y in B i (indeed there is at least one ascent in B i , since the elements b, c constitute a noninversion in B i ). There are two possibilities.
1. If y comes after x in π then x has to be popped before y is pushed onto the σ-stack.
Therefore, when x is popped, there are two elements u, v in the σ-stack, with v above u, such that uvw 231, where w is the next element of the input. If v = x, then also v is popped after x (for the same reason), but this is a contradiction with the fact that x and y constitute an ascent in B i . Thus we have v = x and uxw 231, which implies that w = y and uxwy 2314 in π, contradicting the assumption that π avoids 2314.
2. Suppose instead that y precedes x in π. Observe that y has to be on the σ-stack when x enters, because s σ (π) contains the ascent (x, y) (this fact will be frequently used in the sequel). In this situation, m i yx is an occurrence of 132 in π. We now show that either m i yx is an occurrence of µ or π contains 2314. If there is an element z that precedes m i in π such that x < z < y (so that zm i yx 3142), then z cannot be a ltr-minimum. In such a case, in fact, by Lemma 3, z would be in the σ-stack below y when x is pushed, but zyx 231, which is impossible due to the restriction of the σ-stack. Instead, if z ∈ B for some < i, then m zm i y 2314. Therefore we can assume that every element that precedes m i in π is either smaller than x or greater than y. Finally, suppose that there is an element z between y and x in π such that z < x, which gives an occurrence m i yzx of either 2413 or 1423. Then, since y is still in the σ-stack when x is pushed and z precedes x in π, z enters the σ-stack above y, and so B I contains either x . . . z . . . y or z . . . x . . . y, with z < x. However, both cases give a contradiction, because (x, y) is the first ascent in s σ (π).
In accordance with Theorem 1, the set Av (2314, µ) is not a permutation class; this is due to the presence of the non-classical mesh pattern µ. For example, the σ-sortable permutation 2413 contains the pattern 132, which is not σ-sortable.
The above terminology refers to the graphical representation of π, see Figure 3. We now collect several properties of σ-sortable permutations, in order to find a geometric description of them, as well as their enumeration.
The next lemma provides a useful property of σ-sortable permutations. In spite of its simplicity, it gives a rather strong constraint on the shape of a σ-sortable permutation. Figure 3: The grid decomposition of the permutation π = 13 14 15 10 12 6 7 8 11 9 3 1 4 5 2. The image of π under the bijection of Theorem 16 is the restricted growth function φ(π) = 111223332345445.
Lemma 8. Let π be a σ-sortable permutation and suppose that the cell C i,j is nonempty, for some i, j. Then the cell C u,v is empty for each pair of indices (u, v) such that u < i and v > j.
Proof. Suppose there are two elements x ∈ C i,j and y ∈ C u,v such that u < i and v > j. Then m i xm v y 2314, which is impossible by Theorem 5.
Our next results are some pattern avoidance characterizations for C i,j , H i and C(π).
Lemma 9. Let π be a σ-sortable permutation and suppose that the cell C i,j contains an inversion x > y, where x precedes y in C i,j . Then there is an element z between x and y in π such that z < m i .
Proof. We refer to Figure 4 for a description of the statement of the lemma. For x and y as above, we have m i xy 132. In particular, x and y are in the same cell C i,j and m i is the corresponding ltr-minimum, hence every element w preceding m i in π is greater than x (because w > m i−1 and x < m i−1 ). Therefore, as a consequence of Theorem 5, there exists an element z between x and y in π such that z < y. If z < m i , then we are done. Otherwise, if z > m i , we can repeat the same argument using the occurrence m i xz of 132, in which we have replaced y with the element z that comes strictly before y in π; continuing in this way we eventually find an element of π with the desired property.
Proof. Suppose that C i,j contains an occurrence acb of 132. By Lemma 9, there exists an element z between c and b in π such that z < m i . In particular, m i azb 2314, which is Figure 4: The constructions of Lemma 9, left, and of Lemma 8, right. a contradiction since π is σ-sortable (by Theorem 5). On the other hand, if C i,j contains an occurrence bac of 213, then (b, a) is an inversion in the cell C i,j and therefore, again by Lemma 9, there is an element z between b and a in π with z < m i and m i bzc 2314, a contradiction.
Proof. This is a consequence of Lemma 3 and Proposition 10.
Proof. Suppose π contains an occurrence bac of 213 that does not involve any ltr-minimum and suppose that b ∈ C i,j for some i, j. Note that b < c, so, by Lemma 3, b and c must belong to the same vertical strip B j . Now, if a ∈ C ,j , with > i, then m i bac 2314, which is a contradiction, since π is σ-sortable. Therefore we must have a ∈ C i,j . This results in an occurrence m i ba of 132, with b and a both in the cell C i,j ; thus, by Lemma 9, there is an element z between b and a in π such that z < m i and m i bzc 2314, which is again a contradiction.
What we have established so far in this section are necessary conditions satisfied by σ-sortable permutations. Since each prefix of a σ-sortable permutation is still σsortable, removing the last element from a σ-sortable permutation π ∈ Sort n+1 (σ) returns a permutation π ∈ Sort n (σ). In other words, every permutation in Sort n+1 (σ) is obtained from a permutation π ∈ Sort n (σ) by inserting a new rightmost element and suitably rescaling the remaining ones. However, not just any integers are allowed for such an insertion. Inserting a new minimum, which corresponds to creating a new vertical strip, is always allowed, because it cannot create any new occurrence of 2314 or µ. On the other hand, if π has k ltr-minima and we try to insert a new element in one of the cells C i,k of the last vertical strip, we have to obey the conditions stated in Lemma 8 and Propositions 11 and 12. In particular, Proposition 11 implies that any permutation in H i is co-layered, that is, it is the skew sum of increasing permutations. Thus, in order to get a new co-layered permutation from a given one, and also in order to avoid the forbidden pattern 2314, we find that there are at most two possible ways to insert a new rightmost element in C i,k : 1. min: insert a new minimum in C i,k (which is also a new minimum of the horizontal strip H i ); 2. cons: create a consecutive ascent in the two final positions of C i,k , recalling that an ascent (a, b) is consecutive if b = a + 1. This approach is formalized as follows. Let π be a σ-sortable permutation with k ltr-minima. For i 1, the cell C i,k (belonging to the last vertical strip) is said to be active if both of the following conditions hold: (i) C u,v is empty for each u, v such that u > i and v < k; (ii) inserting a new rightmost element according to min does not create an occurrence of 213 in C(π).
Note that, thanks to condition (i), condition (ii) can be equivalently stated by saying that the permutation j i+1 C j,k is increasing. Moreover, if a cell C i,k is not active, then every insertion of a new rightmost element in C i,k results in a non σ-sortable permutation due to Lemma 8 and Proposition 12. We shall prove that if instead C i,k is active, then exactly one of the operations min and cons can be performed in order to obtain a σsortable permutation. To this end we distinguish two cases, depending on whether C i,k is empty or not.
Proposition 13. Let π = π 1 . . . π n be a σ-sortable permutation with k ltr-minima and let C i,k = γ 1 . . . γ t be a nonempty active cell of π. Let x = π n and suppose x ∈ C ,k . Then: 1. performing min on C i,k returns a σ-sortable permutation π if and only if > i; 2. performing cons on C i,k returns a σ-sortable permutation π if and only if i.

Proof.
1. Suppose < i and we want to insert a new rightmost element γ t+1 into C i,k according to min. Assume, for a contradiction, that the resulting permutation π is σ-sortable. The elements γ t and γ t+1 form an inversion in C i,k , so by Lemma 9 there exists an element z between γ t and γ t+1 in π such that z < m i . Hence m i γ t zx 2314, which contradicts the assumption that π is σ-sortable. Instead, if = i, that is, γ t = x = π n , then γ t γ t+1 is an inversion inside C i,k such that γ t and γ t+1 are adjacent in π. This implies that π is not σ-sortable (again as a consequence of Lemma 9).
Conversely, suppose that > i and γ t+1 is inserted into C i,k according to min. By Theorem 5, π ∈ Av(2314, µ), so we just have to show that the permutation π obtained after the insertion still avoids the two forbidden patterns. If γ t+1 plays the role of the 2 in an occurrence of 132, say acγ t+1 , then we have either acxγ t+1 1423 or acxγ t+1 2413, which means that the selected occurrence of 132 is not an occurrence of the mesh pattern µ. Otherwise, suppose there is an occurrence bcaγ t+1 of 2314 in π . If m k = 1 precedes c in π, then caγ t 213 in C(π), contradicting Proposition 12. On the other hand, if m k follows c in π, then c ∈ B j , for some j < k, and γ t ∈ B k , with c < γ t , contradicting Lemma 3.
2. Suppose we insert γ t+1 into C i,k according to cons and > i. Then γ t xγ t+1 is an occurrence of 213 in C(π ), hence π is not σ-sortable, due to Proposition 12, as desired.
Conversely, suppose that < i and we insert γ t+1 into C i,k according to cons; this means that γ t+1 = γ t + 1. The resulting permutation π does not contain an occurrence bcad of 2314 with γ t+1 = d, for otherwise bcax would be an occurrence of 2314 in π, contradicting the hypothesis that π is σ-sortable. On the other hand, suppose there are two elements a, c in π such that acγ t+1 is an occurrence of 132. We now prove that acγ t+1 is not an occurrence of the mesh pattern µ by distinguishing two cases.
If c > m i−1 (note that i > , so m i−1 exists), then a < γ t+1 < m i−1 , so m i−1 precedes a in π (because a < m i−1 and m i−1 is a ltr-minimum) and m i−1 acγ t+1 would be an occurrence of 3142. Instead, if c < m i−1 , then c is not a ltr-minimum, because a < c precedes c; moreover, c is in C i,k , since c < m i−1 and c > γ t+1 , hence cγ t x is an occurrence of 213 in C(π), which is impossible due to Proposition 12. Finally, if = i, then x = γ t , γ t+1 = γ t + 1 and they are adjacent in π , so γ t+1 is neither part of an occurrence of 2314 nor of µ, since otherwise γ t would be as well, contradicting the hypothesis that π is σ-sortable.
If C i,k is empty, then the operation cons does not make sense, so the only possibility is to try to perform min. The next proposition asserts that this can always be done.
Proposition 14. Let π = π 1 . . . π n be a σ-sortable permutation with k ltr-minima and let C i,k be an empty active cell of π. Let π be the permutation obtained from π by inserting a new rightmost element y in C i,k according to min. Then π is σ-sortable.
Proof. By Theorem 5 we have that π ∈ Av(2314, µ) and we want to prove that π ∈ Av(2314, µ). Suppose there are three elements b, c, a in π such that bcay 2314. Since c > b, the element c is not a ltr-minimum of π. Suppose that c ∈ C u,v , for some u, v. If a is a ltr-minimum, then of course v < k, and we have also u > i, because y is the minimum of its horizontal strip and y > c. This would imply that C u,v is a nonempty cell, with u > i and v < k, which is impossible since C i,k is active. Otherwise, if a is not a ltr-minimum, then cay 213 in C(π ), which again contradicts the assumption that C i,k is active.
Next, in order to prove that π does not contain the mesh pattern µ, suppose there are two elements a, c in π such that acy 132 and suppose c ∈ B j , for some j k. If j < k, then acm k y is an occurrence of 2413, as desired. Otherwise, if j = k, we have that c ∈ C ,k , for some < k, because C i,k is empty before we insert y; moreover, m precedes a in π, because m > y and a < y. Thus m acy 3142, as desired.
Corollary 15. Let π be a σ-sortable permutation. Then, for every active cell of π, exactly one of min and cons generates a σ-sortable permutation.
Propositions 13 and 14 can be interpreted as a constructive procedure to generate inductively every σ-sortable permutation. Starting from π ∈ Sort n (σ), one can either insert a new rightmost minimum or choose an active cell of π and insert a new rightmost element by performing either min or cons, according to the rules of Propositions 13 and 14. Moreover, if the number of active cells of π is t, then π produces t + 1 σ-sortable permutations of length n + 1: one for each active cell and one when a new minimum is inserted. In principle, this gives rise to a generating tree for σ-sortable permutations, which is often a useful tool for enumeration. Unfortunately, we have not been able to fully understand the succession rule of such a tree (namely, we do not know how to compute the number of active sites of the permutations generated by a permutation with a given number of active sites). However, by exploiting the grid structure of σ-sortable permutations, our generating procedure leads to a bijection with a class of pattern-avoiding rgfs.
Let π = π 1 . . . π n be a permutation with k ltr-minima m 1 , . . . , m k and set m 0 = +∞. Define the map φ by setting φ(π) = r 1 . . . r n , where r i = j if m j π i < m j−1 . In other words, the map φ scans the permutation π from left to right and records the index of the horizontal strip that contains the current element of π, including the ltr-minima in the corresponding strips. For example, if π = 13 14 15 10 12 6 7 8 11 9 3 1 4 5 2, then φ(π) = 111223332345445 (see Figure 3). Note that φ is defined for any permutations. We will now show that, when restricted to σ-sortable permutations, the map φ is a bijection between Sort n (σ) and R n (12231).
Proof. By Lemma 2, avoiding 12231 is equivalent to avoiding 2231. We start by proving that, for each σ-sortable permutation π, φ(π) avoids 2231, that is, φ is well-defined. Suppose, on the contrary, that φ(π) contains an occurrence r i 1 r i 2 r i 3 r i 4 of 2231. Consider the leftmost occurrence r j of the integer r i 1 in π (note that j i 1 ). Then r j corresponds through φ to the ltr-minimum of the horizontal strip of index r i 1 in π. Hence the elements π j π i 2 π i 3 π i 4 form an occurrence of 2314 in π, which contradicts Theorem 5.
That φ is injective is a consequence of Corollary 15. Moreover, using the construction of Proposition 13, we will show that φ is surjective. Given a rgf R = r 1 r 2 . . . r n , construct the permutation π R by scanning R from left to right and, when the current element is r , insert a new rightmost element π in the following way (suitably rescaling the previous elements when necessary): • when r is the first occurrence of an integer in R then π = 1; • otherwise, π is inserted in the horizontal strip H r , according to the rules of Proposition 13.  Table 3].
We now wish to prove that, if the rgf R avoids 2231, then π R is a σ-sortable permutation such that φ(π R ) = R. It is easy to see that φ(π R ) = R, as a direct consequence of the definition of φ. Since insertions inside active cells are always allowed, what remains to be shown is that each element is in fact inserted into an active cell. We now argue by contradiction, and suppose that y is the first element that is inserted into a nonactive cell C i,j . According to the definition of an active cell, there are two cases to consider.
1. If there exists a nonempty cell C u,v , with u > i and v < j, then, given any x ∈ C u,v , the elements of R corresponding to m u xm j y form an occurrence of 2231, which is forbidden.
2. Suppose that inserting a new rightmost element according to min creates an occurrence bay of 213 that does not involve any ltr-minima. Let H u be the horizontal strip that contains b and let H v be the horizontal strip that contains a. Note that v u > i. If v > u, then the elements corresponding to m u bay in R form an occurrence of 2231, which is again a contradiction. On the other hand, if v = u, then a belongs to the same horizontal strip of b, so, since a < b, a was inserted according to min. Therefore, by Proposition 13 and our choice of y, the element a that precedes a in C(π) belongs to H w , for some w > u. As a consequence, the elements m u ba c correspond to an occurrence of 2231 in R, which is impossible.
The enumeration of these rgfs follows from the results in [JM], where it is shown that 12231 is Wilf-equivalent to 12332 (see Table 1 here). Moreover, they also show that 1221-avoiding rgfs are enumerated by the Catalan numbers. Hence, as a consequence of Theorem 31 in [JM], we immediately obtain the following formula for σ-sortable permutations: The above sequence is A007317 in [Sl].

Combinatorial proofs for pattern-avoiding restricted growth functions
In the previous section we have completely solved the problem of counting σ-sortable permutations, by explicitly finding a bijection with the class of 12231-avoiding rgfs, whose enumeration is known [JM]. However, this does not provide a clear understanding of why the resulting counting sequence is the binomial transform of Catalan numbers. What we would like to have is a transparent bijective link between σ-sortable permutations and some combinatorial objects whose structure immediately reveals the connection with this counting sequence. The current section is devoted to illustrating some bijections involving sets of rgfs avoiding a certain pattern. Although the enumerations of these sets are known, essentially as corollaries of the general mechanism presented by Jelínek and Mansour [JM], we provide new direct combinatorial proofs, exhibiting links with other well studied combinatorial structures. More precisely, we start by describing a presumably new bijection between R n (1221) and the set of Dyck paths of semilength n. Moreover, for some of the patterns p listed in Table 1, we describe bijections between R(p) and other combinatorial objects, such as labeled Motzkin paths and pattern-avoiding permutations. Finally, we define a bijection between R(12321) and R(12231) that, together with some of the previous results, gives a transparent bijective argument that fully explains the enumeration of σ-sortable permutations.

The pattern 1221
The following lemma is contained in [CDDGGPS] and provides a nice characterization of 1221-avoiding rgfs.
Lemma 18 ( [CDDGGPS], Lemma 6.2). Let R be a rgf. Then R ∈ R(1221) if and only if the subword w(R) obtained by removing the first occurrence of each letter in R is weakly increasing.
As an immediate consequence, we have the following corollary.
Corollary 19. Let R = r 1 . . . r n ∈ R(1221) and M = max(R). If R has no repeated elements let t = 1, otherwise let t be the maximum among repeated elements of R. Then r 1 . . . r n j ∈ R(1221) if and only if t j M + 1.
The previous corollary can be rephrased using the language of generating trees (see for instance [BDLPP]). In particular, we say that an integer x is an active site of the rgf R ∈ R(1221) whenever adding x at the end of R returns another rgf belonging to R(1221) (whose length is of course increased by one). Due to Corollary 19, the set of active sites of R is the interval {t, t + 1, . . . , M, M + 1} and thus there are M + 1 − t + 1 active sites, where M and t are as in the corollary. In the language of generating trees, any rgf obtained from R this way is called a child of R.
For the next theorem, we recall the definition of a double rise in a Dyck path, which is an occurrence of the consecutive pattern UU.
Theorem 20. There is a bijection ψ from R n (1221) to the set of Dyck paths of semilength n, such that the maximum of R ∈ R n (1221) equals one plus the number of double rises in the path ψ(R). As a consequence, denoting by f n,k the number of elements in R n (1221) whose maximum is k, we get that f n,k = n n,k , where n n,k is the (n, k)-th Narayana number.
Proof. Recall from [BDLPP] that every Dyck path P of semilength n + 1 is obtained (in a unique way) from a Dyck path P of semilength n by inserting a peak UD either before a D-step in the last descending run of P or after the last D-step. This construction gives rise to a well known generating tree for Dyck paths, such that the number of active sites of a path P is k + 1, where k is the length of the maximal suffix of P entirely made of D-steps. The path P is therefore a child of P in the associated generating tree. Our goal is to define (in a recursive fashion) a bijection α between the generating tree of R(1221) and the generating tree of Dyck paths. In other words, we wish to show that α is a bijection preserving both the size (that is, a rgf R ∈ R n (1221) is mapped to a Dyck path of semilength n) and the number of active sites.
We start by setting α(1) = UD. Note that 1 has two active sites, since the children of 1 are 11 and 12. The path UD has two active sites as well, since its children are UUDD and UDUD. Now let R = r 1 . . . r n and α(R) = p 1 . . . p 2n , for some n 1. Suppose that the number of active sites of both R and α(R) is k. Let M = max(R) and let t be the maximum element of R that is not a ltr-maximum of R. By Corollary 19, the active sites of R form the interval {t, t + 1, . . . , M, M + 1}, with M + 1 − t + 1 = k by hypothesis. Moreover, the length of the maximal suffix of D-steps of α(R) is k − 1. We shall describe α on the children of both R and α(R), and show that the number of active sites is still preserved.
• The child of R corresponding to the active site M is mapped to the path obtained from α(R) by inserting a new peak UD immediately after the last D-step of α(R).
Here the active sites of the resulting sequence are M + 1 − M + 1 = 2. The same happens for the resulting Dyck path, since the length of the maximal suffix of D-steps is 1.
• For i = t, . . . , M − 1, the child of R corresponding to the active site i is mapped to the path obtained from α(R) by inserting a new peak UD immediately before the (M + 1 − i)-th D step of the last descending run. The number of active sites of the resulting rgf is then M + 1 − i + 1 = M + 2 − i, which is also the length of the maximal suffix of D-steps of the resulting path.
• Finally, the child of R corresponding to the active site M + 1 is mapped to the path obtained from α(R) by inserting a new peak UD immediately before the first D-step of the last descending run of α(R). In this case the number of active sites of the resulting rgf is M + 2 − (t + 1) = k + 1. Moreover, the number of active sites of the resulting path is also k + 1, since the length of its maximal suffix of D-steps is increased by one with respect to α(R).
Therefore α is a bijection between the two generating trees, as desired. To conclude, observe that the number of double rises in α(R) is equal to max(R) − 1. Indeed, by definition of α, each double rise in α(R) corresponds to the first occurrence of an integer in R, except for the first occurrence of 1 (which does not create a double rise). As is well known (see for example [D]), the number of Dyck paths of semilength n with k − 1 double rises is given by n n,k , which gives the desired equality f n,k = n n,k .
Corollary 21. Let n 0 and g n = |R n (12332)|. Denote by g(n, k) the number of elements in R n (12332) whose maximum is k, for 1 k n. Then g(n + 1, k + 1) = n j=k n j n j,k .
Proof. As observed in [JM], every 12332-avoiding rgf of length n + 1 can be obtained by choosing n−j positions for the 1s (except for the first 1, which is fixed) and then choosing a rgf R ∈ R j (1221) for the remaining j spots (where the elements of R incremented by 1 will be inserted). In particular, if the maximum of R is k, then the resulting rgf has maximum k + 1. So, as a consequence of Theorem 20, we have g(n + 1, k + 1) = n j=k n j n j,k . As it turns out, the formula in Corollary 21 also enumerates σ-sortable permutations according to the number of their ltr-minima. A proof will be given in upcoming sections (Proposition 28 and Theorem 34) by means of a bijection between 12231-and 12321avoiding rgfs. However, although we have a precise geometrical description of Sort(σ), we have not been able to find a direct proof of this.
Open Problem 22. Prove directly (that is, without using a bijection involving different objects) that the number of 132-sortable permutations of length n + 1 with k + 1 left-toright minima is given by n j=k n j n j,k .

The patterns 12323 and 12332
Let be the ordinary generating function of σ-sortable permutations (equivalently, of R(12323) and of R(12332)). Then F (x) can be expressed using the following continued fraction (see, for example, [B, F]): A nice combinatorial interpretation of this continued fraction can be given in terms of labeled Motzkin paths, via Flajolet's general correspondence [F]. More precisely, |Sort n+1 (σ)| is the number of Motzkin paths of length n such that each horizontal step at height zero has two types of labels 0 , 1 and each horizontal step at height at least one has three types of labels 0 , 1 , 2 . Let M lab n be the set of such labeled Motzkin paths of length n. We now define a map β from M lab n to rgfs of length n + 1 (see Figure 5). Let P ∈ M lab n and let ∆ be an initially empty stack. We construct a rgf R by scanning from left to right the labels of P (including U and D for upstep and downstep, respectively). We start by setting R = 1. Then we append a new rightmost element to R according to the following rules, where L denotes the currently scanned label: • if L = U then append a new strict maximum M and push M onto ∆; • if L = D then append top(∆) and pop it from ∆; • if L = 0 , then append a new strict maximum (without pushing it onto ∆); • if L = 1 then append 1; • if L = 2 then append top(∆) (without popping it from ∆).
In other words, U corresponds to the first occurrence of a letter x that appears at least twice in R, D to the last occurrence of such a letter, and 2 to an occurrence of such an x that is neither the first nor the last. Moreover, the label 0 corresponds to an element x = 1 appearing only once and the label 1 corresponds to the element 1.
It is worth noting the correspondence between the labels of a Motzkin path P described above and properties of the set partition associated (in Section 2) to the rgf R = β(P ). Namely, if B is a block of cardinality at least 2 in such a partition and B doesn't contain 1, then U, D and 2 correspond, respectively, to the least, the largest and any of the remaining elements of the block. Furthermore, 0 corresponds to a singleton block not containing 1 and 1 corresponds to the elements of the block containing 1. With this correspondence the auxiliary stack ∆ is seen to keep track, at each stage of the construction of R, of the open blocks in the corresponding partition, that is those blocks that have not yet received all their elements.
Theorem 23. The map β is a bijection between M lab n and R n+1 (12323).
Proof. It is straightforward to see that β is injective and that β(P ) is a rgf for every P ∈ M lab n . Since |M lab n | = |R n (12323)|, we only need to show that β(P ) avoids 12323, for each P ∈ M lab n . Suppose, for a contradiction, that abcb c is an occurrence of 12323 in β(P ). This implies, of course, that b, c = 1. Without loss of generality, we may assume that b and c are the first occurrences of the corresponding integers in β(P ); then both b and c correspond to U-steps in P and are pushed onto ∆. Moreover, since b = b and b follows c in β(P ), when c enters ∆, b is still in, and so c lies above b in ∆. Now observe that the element b must correspond to either a D-step or a horizontal step labeled 2 of P . However, in both cases, when b is inserted into β(P ), b has to be at the top of the stack, hence c should have been popped. This would imply that there are no more occurrences of c in β(P ) after b , which is not the case, since c = c.
Remark 24. If we replace the stack ∆ with a queue Ξ, then the same map gives a bijection with rgfs avoiding 12332. The proof is analogous to the previous one, and is omitted.
Remark 25. If we restrict the previous bijections to Motzkin paths with no horizontal steps labeled 1 , then we get bijections with rgfs that avoid 1212 (if we use a stack ∆) or 1221 (if we use a queue Ξ), provided that we remove the 1 at the beginning and decrease all the other elements by one. This follows again from the characterization of R(12323) and R(12332) given in [JM]. The corresponding continued fraction is then: This gives an alternative proof of the fact that rgfs avoiding either 1221 or 1212 are enumerated by the Catalan numbers, whose generating function is known to be given by the above continued fraction.
Remark 26. As a consequence of the bijections in Theorem 23 and Remark 24, the statistic "sum of the numbers of U and 0 steps" in M lab n is equidistributed with the statistic "(value of the) maximum minus one" both in R n+1 (12332) and in R n+1 (12323). The same holds for the statistics "number of labels 0 " and "number of singletons = {1}", as well as for the statistics "number of labels 1 " and "number of occurrences of 1 minus one". Some computations seem to suggest that the distribution of the maximum is the same for several other patterns of the same Wilf-class, namely 12123, 12132, 12213, 12231, 12312, 12321, 12331, so we suspect that the same approach should lead to straightforward bijections, by suitably modifying the interpretation of the steps. For example, call r i a repeated ltr-maximum of a rgf r 1 r 2 . . . r n if r i = max {r 1 , . . . , r i−1 }. Then steps having label 1 seem to have the same distribution as the repeated ltr-maxima in R(12321) and R(12312), so in order to define a bijection with M lab it could be enough to find the "correct" interpretations for steps having labels D and 2 .

The patterns 12321 and 12312
In this subsection we deal with rgfs avoiding the patterns 12321 and 12312, respectively, by exhibiting a connection with permutations avoiding the patterns 321 and 312, respectively.
Let R = r 1 . . . r n be a rgf. Recall from Remark 26 that r i is said to be a repeated ltr-maximum when r i = max {r 1 , . . . , r i−1 }, that is, when r i is at least as great as all preceding letters, but not a ltr-maximum. Denote by R n.r. the set of rgfs with no repeated ltr-maxima. The notations R n.r. n and R n.r. (Q), for a pattern Q, are defined in the usual way. If R = r 1 . . . r n ∈ R n.r. is a rgf with no repeated ltr-maxima, denote by R the subsequence of R obtained by deleting its ltr-maxima. Note that R is not necessarily a rgf. For example, if R = 121311245246, then R = 111224.
Lemma 27. Let R ∈ R n.r. . Then R avoids 12321 if and only R is weakly increasing.
Proof. Suppose R = . . . ba . . ., where b > a. Note that b is not a repeated ltr-maximum of R, so there has to be an element c in R such that c > b and c comes before b. Then R contains an occurrence cba of 321 and therefore it also contains 12321, by Lemma 2.
Conversely, if R contains an occurrence abcb a of 12321, then b precedes a in R and b > a , so R is not weakly increasing.
We can now define a bijection between R n.r. (12321) and Av(321). In fact, the previous lemma roughly says that the combinatorial structure of elements of R n.r. (12321) is analogous to that of permutations in Av(321), that is, they can both be written as a shuffle of two weakly increasing sequences (namely, the strictly increasing sequence of the ltr-maxima and the weakly increasing sequence of the remaining elements). Let R = r 1 . . . r n ∈ R n.r. (12321) and suppose R = r i 1 . . . r i k , where k 0. Construct a permutation of length n by keeping the same positions for the ltr-maxima and mapping R to a strictly increasing sequence S = s 1 . . . s k as follows: • s 1 = r i 1 ; • s j = s j−1 + (r i j − r i j−1 ) + 1, for j 2.
Finally, in order to get a permutation that avoids 321, insert the remaining elements in increasing order (they will be the ltr-maxima). For instance, if R = 121314234, then R = 11234, so we get S = 12468 and the resulting permutation is 351729468 (bold elements are the ltr-maxima). Note that a rgf having maximum k (equivalently, with k ltr-maxima) is mapped to a permutation with k ltr-maxima. It is straightforward to prove that the resulting permutation avoids 321. Moreover, since 321-avoiding permutations are uniquely determined by positions and values of their ltr-maxima, the strictly increasing sequence S is enough to uniquely identify one such permutation. Therefore the map defined above is injective. Finally, the construction proposed can be easily inverted, so the map is a size-preserving bijection between R n.r. (12321) and Av(321). We thus have the following result, whose proof immediately follows from the above discussion.
Proposition 28. The number of rgfs in R n.r. n (12321) is c n . Moreover, the number of rgfs in R n.r. n (12321) having maximum k is given by n n,k .
Next we show that any rgf avoiding 12321 is obtained by choosing a sequence in R n.r. (12321) and then inserting some repeated ltr-maxima.
Theorem 29. Let R be a rgf and let α(R) be the sequence obtained from R by removing all the repeated ltr-maxima. Then α(R) is a rgf. Moreover, R avoids 12321 if and only α(R) avoids 12321.
Proof. It is easy to check that α(R) is still a rgf and clearly α(R) avoids 12321 if R does. On the other hand, suppose that R contains an occurrence abcb a of 12321. Note that b and a are not repeated ltr-maxima, so they are elements of α(R) and they follow c in R. Let c be the first occurrence of the integer c in R. Then c ∈ α(R) and c precedes b in α(R), so α(R) contains an occurrence c b a of 321, which is equivalent to containing 12321.
Moreover, there are n j=k n j n j,k rgfs in R n+1 (12321) with maximum k. Proof. This is a direct consequence of the results proved in this subsection, together with the fact that the first element of a rgf cannot be a repeated ltr-maximum.
Remark 31. The same approach can be used to find a bijection between R n.r. (12312) and Av(312). In fact, 312-avoiding permutations are also uniquely determined by the positions and values of their ltr-maxima, and a completely analogous argument can be applied. As a consequence, we also have |R n+1 (12312)| = n k=0 n k c k .

A bijection between R(12321) and R(12231)
In Section 4 we showed that σ-sortable permutations are in bijection with rgfs avoiding 12231. Although the labeled Motzkin path approach described in Section 5.2 could be fruitful, a direct combinatorial enumeration for the pattern 12231 seems to be rather more complicated than for the patterns treated in the previous section. Here we illustrate a bijection between R(12231) and R(12321), thus obtaining an independent proof of the enumeration of Sort(σ). From now on we say that r i 1 r i 2 r i 3 is an occurrence of the pattern 231 in R if r i 1 r i 2 r i 3 is an occurrence of 231 and r i 1 is not a ltr-maximum of R (that is, r i 1 is not the first occurrence of the corresponding integer). Note that R(12231) = R( 231) and also i 1 i 2 i 3 i 1 i 2 i 3 Figure 6: On the left, the rightmost occurrence of the pattern 321 in R (t) , with indices i 1 i 2 i 3 . Shaded boxes correspond to forbidden regions. On the right, the resulting pattern in R (t+1) , obtained by exchanging the elements in positions i 1 and i 2 .
• Finally, the case j 1 = i 1 and j 2 = i 2 is clearly impossible, since we have r Next we show that γ is a bijection by proving that the recursive construction defined above can be reversed. More precisely, R (t) can obtained from R (t+1) by transforming the leftmost occurrence of 231 into an occurrence of 321 (see Figure 7). Lemma 33. Let t 0. Let rm(R (t) , 321) = i 1 i 2 i 3 and lm(R (t+1) , 231) = j 1 j 2 j 3 . Then i 1 = j 1 and i 2 = j 2 .
Proof. We again refer to Figure 6 for an illustration of the constraints imposed on the elements of R (t) by the position of the rightmost occurrence of 321 inside R (t) . We proceed by induction on t.

Final remarks and future work
In Sections 3 and 4 we have characterized the elements of the set Sort(132), thus solving one of the open problems for pattern-avoiding machines introduced in [CCF]. For three remaining patterns σ of length 3, namely 213, 231 and 312, a characterization of the σsortable permutations remains to be found, as well as their enumeration. The pattern 231 seems to be significantly more challenging than the others. This is arguably due to what seems to be the case, according to computational evidence, namely that the 231-machine can sort more permutations of length n, for each n 3, than the machines associated to any other pattern of length 3 (in particular, it is the only one that can sort every permutation of length 3).
The enumeration of 132-sortable permutations has been obtained by means of a bijection with rgfs avoiding 12231, whose enumeration can be found in [JM] as an application of a much more general mechanism. In Section 5 we have found new direct proofs for related classes of rgfs, exhibiting connections with other well known combinatorial objects, such as lattice paths and pattern-avoiding permutations. In particular, the bijection with labeled Motzkin paths in Theorem 23 seems amenable to being extended and generalized, in order to cover the enumeration of many patterns in the same Wilf-equivalence class.