Pattern avoidance in forests of binary shrubs

We investigate pattern avoidance in permutations satisfying some additional restrictions. These are naturally considered in terms of avoiding patterns in linear extensions of certain forest-like partially ordered sets, which we call binary shrub forests. In this context, we enumerate forests avoiding patterns of length three. In four of the five non-equivalent cases, we present explicit enumerations by exhibiting bijections with certain lattice paths bounded above by the line $y=\ell x$, for some $\ell\in\mathbb{Q}^+$, one of these being the celebrated Duchon's club paths with $\ell=2/3$. In the remaining case, we use the machinery of analytic combinatorics to determine the minimal polynomial of its generating function, and deduce its growth rate.


Introduction
In this paper, we extend pattern avoidance to a previously unexamined combinatorial structure. Let S n be the set of permutations of length n. First, given permutations π = π 1 π 2 · · · π n ∈ S n and ρ = ρ 1 ρ 2 · · · ρ m ∈ S m we say that π contains ρ as a (classical) pattern if there exist 1 ≤ i 1 < i 2 < · · · < i m ≤ n such that π ia < π i b if and only if ρ a < ρ b . In this case we say that π i1 π i2 · · · π im is order-isomorphic to ρ (denoted π i1 π i2 · · · π im ∼ ρ) and that π i1 π i2 · · · π im reduces to ρ. If π does not contain ρ, then π is said to avoid ρ. This definition of pattern avoidance in permutations appears in many differing applications ranging from the analysis of sorting algorithms to algebraic Motivated by work with trees [4,9,14] and comb posets [17], Levin, Pudwell, Riehl and Sandberg [10] considered pattern avoidance in heaps. In particular a complete k-ary tree is a tree where each node has k or fewer children, all levels except possibly the last are completely full (i.e. level i contains k i−1 vertices), and the last level has all of its nodes to the left side (i.e. for any two vertices in the penultimate level, if the right vertex has a positive outdegree, then the outdegree of the left vertex is k, and no more than one vertex in the penultimate level has outdegree not equal to 0 or k).
A k-ary heap is a complete k-ary tree labeled with {1, . . . , n} such that every child has a larger label than its parent. We draw trees (respectively heaps) with the root at the bottom of the figure. An example of a 2-ary (i.e. binary) heap on 9 vertices is shown in Figure 1. Let H k n denote the set of k-ary n-vertex heaps. The heap in Figure 1 is a member of H 2 9 . Given a heap H, we associate a permutation π H with it by recording the vertex labels as they are encountered in a breadth-first search. For example, if H is the heap in Figure 1, then π H = 125349867. We say that heap H contains (respectively avoids) ρ as a pattern if π H contains (respectively avoids) ρ as a classical pattern, using the definition above. Let H k n (P ) be the set of members of H k n that avoid all patterns in the list P . While the heap in Figure 1 contains 123, 132, 213, 312, and 321, it is a member of H 2 9 (231). In [10], the authors determined H k n (ρ) for ρ ∈ (S 3 \ {321}), and H k n (P ) when |P | ≥ 2 and P ⊆ S 3 . In this paper we extend their pattern avoidance in a new direction by considering forests of heaps. A heap forest is an ordered collection of heaps. Given a forest F of heaps H 1 , H 2 , . . . , H n , we label all vertices in F with distinct integers from {1, . . . , |F |} (where |F | = |H 1 | + · · · + |H n |), and then associate the permutation π F = π H1 π H2 · · · π Hn . In other words, we concatenate the associated permutations for each heap to obtain the permutation associated to the forest. Given the forest in Figure 2, π F = 165(10)92438(11)7(12) (13). As before, we say that forest F avoids pattern ρ if π F avoids ρ. Note, from our example, that forests can be composed of heaps with varying numbers of vertices or even heaps that are k-ary for different values of k.
The consideration of heap forests introduces a number of new parameters to our problem, so we restrict our work to forests of binary (or more generally k-ary) shrubs. A shrub is a tree whose root has only leaves as children. In a binary shrub, each root vertex has exactly two descendants, so a binary shrub forest has 3n vertices where n is the number of heaps in the forest, while similarly in a k-ary shrub forest we have (k + 1)n vertices.
Let F k n be the set of all k-ary shrub forests of n heaps. In Figure 3, we see a member F of F 2 4 where π F = (10)(12)(11)129348576. Let F k n (P ) be the set of members of F k n that avoid all patterns in list P and S 2 n (P ) = π ∈ S 3n | π = π f for some f ∈ F 2 n (P ) .
Our main goal is to determine S 2 n (P ) where P ⊆ S 3 . In the rest of this paper, we determine S 2 n (ρ) exactly for each ρ = 321. A list of sequences and corresponding reference numbers from the On-Line Encyclopedia of Integer Sequences [13] is given in Table 1. This includes results for S 2 n (P ) where P contains more than one pattern of length 3. Details of the enumerations when |P | > 1 are omitted from this paper due to length, but can be found as an ancillary file attached to this arXiv submission at http://arxiv.org/src/1510.08036/anc/MultiplePatterns.pdf.
In the next section, we look at each of the sets avoiding a single pattern of length 3. For five of the patterns, we enumerate the set by establishing a bijection with a family of lattice paths from (0, 0) to (m, ℓm) for some ℓ ∈ Q + , bounded above by the line y = ℓx. In four cases, these lattice paths consist of unit east and north steps. S 2 n (123) is shown to be equinumerous to such paths with ℓ = 2 (Theorem 2.4), and more generally F k n (123) is equinumerous to such paths with ℓ = k (Theorem 2.3). S 2 n (132) is in bijection with these paths with ℓ = 3. Indeed, we prove a more general result concerning k-ary forests, that F k n (132) is equinumerous to these lattice paths with ℓ = k + 1 (Theorem 2.6). In the case of S 2 n (231), we establish a bijection with the celebrated case of paths bounded above by y = 2 3 x, the so-called "Duchon's club model" (Theorem 2.15), and more generally we outline how F k n (231) is equinumerous to such paths bounded above by y = k k+1 x. We prove that S 2 n (213) and S 2 n (312) are equinumerous (Theorem 2.12) and establish a bijection with lattice paths having east, north and northeast steps, bounded by y = 3x (Theorem 2.11). Finally, we investigate S 2 n (321). We are unable to enumerate this set explicitly. However, using functional equations, we are able to generate nearly a thousand terms of its enumeration sequence, prove that its generating function is algebraic and determine its minimal polynomial and growth rate (Theorem 2.18). We conclude in Section 3 with some questions. 2 Avoiding a pattern of length 3 To enumerate our first two sets, we make use of the following result, concerning lattice paths in a wedge, first proved by Fuss at the end of the 18th century. See [11, Section 12.1] for a modern presentation of the proof.
Proposition 2.1 (Fuss [8]). The number of lattice paths with unit East and North steps from (0, 0) to (m, ℓm) remaining weakly under the line y = ℓx is given by

Avoiding 123
We enumerate forests avoiding 123 by exhibiting a bijection with lattice paths bounded above by y = kx. We begin by establishing the fact that the labels of a 123-avoiding forest are uniquely determined by their root labels.

Lemma 2.2.
For any F ∈ F k n (123) with k ≥ 2 and n ≥ 0, the roots of the forest of F have decreasing labels as do the leaves.
Proof: Consider π F and suppose to the contrary that π i and π j are root labels where i < j and π i < π j . Then π i π j π k ∼ 123 where π k is a descendant of π j . Similarly if π i and π j are leaf labels where i < j and π i < π j , then π k π i π j ∼ 123 where π k is the parent of π i . Therefore if we know only the root labels of a labeled forest avoiding 123, the labels for the entire forest are uniquely determined. Note however, this is not the same as saying that any labeling of roots corresponds with a forest that avoids 123.
We are now in a position to enumerate F k n (123) and consequently S 2 n (123). Theorem 2.3. For k ≥ 2 and n ≥ 0, Proof: We will show that F k n (123) is in bijection with NE lattice paths from (0, 0) to (n, kn) weakly below the line y = kx. The result then follows by Proposition 2.1 with ℓ = k.
A 123-avoiding forest of k-ary shrubs is uniquely determined by its roots. Therefore, we must choose a set of n root labels, 1 = r 1 < r 2 < · · · < r n such that there are at least k unused labels larger than r n , at least 2k unused labels larger than r n−1 , and in general at least k(n−i+1) unused labels larger than r i for 1 ≤ i ≤ n. Then the roots of the forest have labels r n , r n−1 , . . . , r 2 , r 1 , the leaves use the remaining labels in decreasing order, and each tree has leaves with larger labels than the roots.
Similarly, in a NE lattice path from (0, 0) to (n, kn) weakly below the line y = kx, we must choose n steps to be East steps. To stay below the line y = kx, the ith east step must have k(n − i + 1) north steps after it (1 ≤ i ≤ n).
Thus, 123-avoiding k-ary shrub forests are in bijection with NE lattice paths below the line y = kx in the following way: given F ∈ F k n (123), let r i = π (k+1)(i−1)+1 for 1 ≤ i ≤ n be the roots of the forest corresponding to π F . Now construct a NE-lattice path of n East steps and kn North steps so that the jth step is an East step if and only if j ∈ {r 1 , . . . , r n }. This map is easily invertible. Given a NE-lattice path below y = kx, let r 1 < · · · < r n be the positions of the East steps. Then use r 1 , . . . , r n in decreasing order as the labels of the roots for a forest, and place the unused labels in decreasing order on the roots.
We then obtain our desired result by setting k = 2.

Avoiding 132
We enumerate forests avoiding 132 by giving a bijection with lattice paths bounded above by y = 3x. Indeed, we establish a stronger result, applicable to all k-ary shrub forests, exhibiting a bijection between F k n (132) and lattice paths bounded in the wedge below y = (k + 1)x. As with forests avoiding 123, we start by establishing that the labels of a 132-avoiding forest are also determined by their root labels. Proof: Define S to be the ordered set of currently unused labels in a forest of t heaps with v = k + 1 vertices each, and imagine we are assigning labels from left to right on heaps, and in breadth-first order on each heap. Initially, S = {1, 2, . . . , vt}. The labels in each heap are clearly larger than the label of their root, and in each heap are increasing (in order to avoid 132). In fact, not only are they larger, they are the smallest possible unused labels. In other words, the leaves of each root are labelled, from left to right, by the k smallest unused labels greater than the root. If not, the next largest label y would be used later (on its right) and would create a xzy ∼ 132 pattern where z is a leaf of (the root) x but not y. Thus we only need know the label of the roots in order to deduce the entire labeling of a 132-avoiding k-ary shrub forest of heaps. Furthermore, knowing the first root and the longest decreasing subsequence of roots is sufficient since if the roots are r 1 , r 2 , . . . , r t and we have r i < r i+1 < · · · < r j−1 > r j then r i > r j in order to avoid 132.
Again, Lemma 2.5 is not equivalent to saying that any labeling of roots corresponds with a forest that avoids 132.
It turns out that we can use the structure of 132-avoiding forests to describe not only S 2 n (132), but more generally F k n (132).
Proof: We provide a bijection from F k n (132) to the set P of paths under the line y = (k + 1)x from (0, 0) to (n, (k + 1)n) using North (0, 1) and East (1, 0) steps. The result then follows by Proposition 2.1 with ℓ = k + 1.
Define φ : P → F k n (132) as follows. Given p ∈ P , let 0 = w 1 ≤ w 2 ≤ · · · ≤ w n be the heights of the East steps in p. Let w ′ := (w n + 1)(w n−1 + 1) · · · (w 1 + 1). Label the first root w ′ leave root i unlabeled. Now, by Lemma 2.5 label the remaining forest vertices from left to right (and in breadth-first order on each heap), at each point using the smallest unused label larger than the most recent root. We claim this forest avoids 132. Suppose there were a 132 pattern not involving a root where ℓ plays the role of 1. Since ℓ's root is smaller than ℓ, there is another copy of 132 using ℓ's root. Now, by construction, all entries larger than a given root and after the root appear in increasing order, so this forest is 132-avoiding.
Next we describe φ −1 : F k n (132) → P , beginning with a 132-avoiding forest. We create a string y, with y 1 being the root of the first heap. We add an element to the string y for each root r i . If the permutation has been only increasing since r i−1 , set y i = y i−1 . If the permutation has had a descent (which could only occur between the last leaf of the tree with root r i−1 and the root r i ), set y i = r i . We then create a string y ′ by subtracting 1 from each element of y. Finally we reverse the string to obtain y ′r , which is our string displaying heights of the East steps in our path, which we claim lies below the line y = (k + 1)x. Notice that a path lies below y = (k + 1)x if and only if y ′r i since there are i − 1 other roots and ki leaves larger than r i as labels on the first i shrubs.
k+1 be the number of trees in our shrub forest. Our bound on y ′ i implies that This proof gives two easy corollaries. The first demonstrates that although we considered shrubs here, in special cases (such as avoiding 132) we can characterize the shrub condition more simply in terms of a permutation composed of a string of equal-length subpermutations. The second is our result restricted to binary shrubs. Corollary 2.7. Let σ be a permutation composed of a concatenation of m increasing sequences of length n. The number of such σ ∈ S nm (132) is given by Also, S 2 n (132) is a special case of Theorem 2.6.
n . Figure 5 shows two examples of lattice paths below y = 3x that correspond to members of S 2 (132).

Avoiding 213 or 312
The only pair of permutations ρ 1 , ρ 2 ∈ S 3 for which We prove this equivalence in Theorem 2.12 below. w = 034 = y ′r w = 022 = y ′r w ′ = 541 = y w ′ = 331 = y π = 567 489 123 π = 345 678 129 To enumerate these sets, we make use of a variant of the result of Fuss we used above, in which diagonal, as well as horizontal and vertical, steps are permitted.
We also require the following 'folklore' bijection between two families of lattice paths. This proposition follows directly from the invertibility of the affine map of the Euclidean plane implied in its statement. We enumerate forests avoiding 213 by exhibiting a bijection with a family of lattice paths which, by Proposition 2.10, are known to be equinumerous to paths bounded above by y = 3x. Theorem 2.11. S 2 n (213) = a n where a n is the number of lattice paths from (0, 0) to (4n, 0) with unit steps (1, 3), (2, 2), and (1, −1) staying weakly above the x-axis.
Proof: First we give a correspondence from lattice paths to 213-avoiding permutations.
Begin with a lattice path from (0, 0) to (4n, 0) that contains only (1, 3), (2, 2), and (1, −1) steps and stays weakly above the x-axis. Partition the path into segments that traverse exactly one unit in the vertical direction. (Each (2, 2) step will be partitioned into 2 segments and each (1, 3) step will be partitioned into 3 segments.) We label each segment of a (1, 3) or (2, 2) step as well as the midpoint of each (2, 2) step with a distinct label from {1, 2, . . . , 3n} in the following way: Locate the lowest line y = i from which an unlabeled up-segment begins. Find the rightmost such segment s beginning at y = i, and give s the lowest unused label. Let j be the number of segments and midpoints to the right of s. We now apply the j smallest unused labels to the subpath to the right of s and the remaining (larger) unused labels to the subpath to the left of s, and repeat this construction recursively. In the case that a subpath has no up-segments, it must consist of a single midpoint of a (2, 2)-step and so it receives the only unused label reserved for the subpath. Now, read the labels from left to right to obtain a permutation π.
Notice that π can be the labels of a binary shrub forest since the three labels on each increasing (1, 3) step or (2, 2) step correspond to the labels of a heap. By construction, the labels on a (1, 3) step form a 123 pattern while the labels on a (2, 2) step form a 132 pattern. Further, π avoids 213 since for each digit i, all labels larger than and left of i are greater than all labels larger than and right of i.
Next, we show how to reverse this correspondence, by giving a map from 213-avoiding permutations to lattice paths. Start with a binary shrub forest f . Consider f one heap at a time. A heap with an increasing pair of leaves corresponds to a (1, 3) step and a heap with a decreasing pair of leaves corresponds to a (2, 2) step. The (1, 3) and (2, 2) steps can be separated by (1, −1) steps. To determine the placement of the (1, −1) steps, we look at the roots of the heaps.
Take π and mark any digit that is the first digit of a pair of leaves with decreasing labels. Now, for each root, count the number of unmarked digits (roots and unmarked leaves) before the root and larger than the root. This is the number of (1, −1) steps that immediately precede the increasing step corresponding to that heap. Mark the digits that were just used and repeat. Finally, end the path by adding (1, −1) steps to return to the x-axis.
As an example, consider the path in Figure 6. Here, (2, 2) steps are shown with doubled lines to make them clearly distinct from (1, 3) steps. For the map from π to the path, the heaps 7 15 14, 11 13 12, and 2 4 3 have decreasing leaves, so each of them correspond to a (2, 2) step. The heaps 8 9 10 and 1 5 6 have increasing leaves, so each of them correspond to a (1, 3) step. The increasing steps in the path alternate between (2, 2) steps and (1, 3) steps. Now, we mark the digits 15, 13, and 4 in π. For the root 8, we see that 14 is unmarked and prior to 8, so we put one (1, −1) step between the first two upsteps and mark 14. For the root 11, we see no numbers larger than 11 and prior to 11 that have not yet been used, so we put zero (1, −1) steps between the second and third upsteps. For the root 1, we see 12, 11, 10, 9, 8, and 7 larger than 1 and prior to 1 that have not yet been used, so we put six (1, −1) steps between the third and fourth upsteps and mark 12, 11, 10, 9, 8, and 7. For the root 2, we see 5 and 6 larger than 2 and prior to 2 that have not yet been used, so we put two (1, −1) steps between the fourth and fifth upsteps and mark 5 and 6. Finally, we must take three (1, −1) steps at the end of the path to return to the x-axis.
We now show that 213-avoiding forests are equinumerous to those avoiding 312.
Proof: Consider a forest avoiding 213 as it is built from left to right. According to our correspondence a (2, 2) upstep indicates that the next heap forms a 132 pattern while a (1, 3) upstep indicates that the next heap in the forest forms a 123 pattern. The (1, −1) steps between the upsteps indicate the labels of the next in the following way: Suppose that the first k upsteps in our path encode a forest with labels {1, 2, . . . , 3k} where the last heap forms a 123 pattern with labels ℓ − 2, ℓ − 1, ℓ. We wish to append a single new heap to this forest. In order for the shrub forest to avoid 213, all labels on the new heap must Similarly, suppose that the first k upsteps in our path encode a forest with labels {1, 2, . . . , 3k} where the last heap forms a 132 pattern with labels ℓ − 2, ℓ − 1, ℓ. We wish to append a single new heap to this forest. In order for the shrub forest to avoid 213, all labels on the new heap must be consecutive. In particular, the labels on the new heap may be i + 1, i + 2, i + 3 for 0 ≤ i ≤ ℓ − 1 (and all labels larger than i on the original forest are incremented by 3). Let d be the number of downsteps immediately after the (2, 2) upstep corresponding to the last 132 pattern; then ℓ − d − 1 = i indicates the labels on the next heap to be appended are i + 1, i + 2, and i + 3.
In general, when we append a new 123 heap to the end of a 213-avoiding forest, we increase the number of sets of labels we can use on the next heap by 3, and when we append a new 132 heap to the end of a 213-avoiding forest, we increase the number of sets of labels we can use on the next heap by 2. The number k of (1, −1) downsteps tells us to use the (k + 1)st highest possible value for the root of the next appended heap.
Suppose that the first k upsteps in our path encode a forest with labels {1, 2, . . . , 3k} where the last heap forms a 123 pattern with labels ℓ − 2, ℓ − 1, ℓ. We wish to append a single new heap to this forest. In order for the shrub forest to avoid 312, all labels that are used on leaves of the new heap must be larger than all existing labels, but the root can appear lower. In particular, the labels on the new heap may be i, 3k + 2, 3k + 3 for 1 ≤ i ≤ 3k + 1 (and if i ≤ 3k then i may not be the larger digit in an inversion in the original forest on {1, 2, . . . , 3k}). Then, all labels larger than i − 1 on the original forest are incremented by 1 to obtain the new forest. Let d be the number of downsteps immediately after the (1, 3) upstep corresponding to the last 123 pattern; then ℓ − d = i indicates the labels on the next heap to be appended are i, 3k + 2, and 3k + 3.
Similarly, suppose that the first k upsteps in our path encode a forest with labels {1, 2, . . . , 3k} where the last heap forms a 132 pattern with labels ℓ − 2, ℓ − 1, ℓ. We wish to append a single new heap to this forest. In order for the shrub forest to avoid 312, all labels that are used on leaves of the new heap must be larger than all existing labels, and the root can appear lower. In particular, the labels on the new heap may be i, 3k + 2, 3k + 3 for 1 ≤ i ≤ 3k + 1 (and if i ≤ 3k then i may not be the larger digit in an inversion in the original forest on {1, 2, . . . , 3k}, so we know i = 3k in this case).
As before, when we append a new 123 heap to the end of a 312-avoiding forest, we increase the number of sets of labels we can use on the next heap by 3 (since i ∈ {3k − 1, 3k, 3k + 1} are new), and when we append a new 132 heap to the end of a 312-avoiding forest, we increase the number of sets of labels we can use on the next heap by 2 (since i ∈ {3k − 1, 3k + 1} are new). The number k of (1, −1) downsteps tells us to use the (k + 1)st highest possible value for the root of the next appended heap.
Proof: The result follows directly from Theorems 2.12 and 2.11, and Propositions 2.10 and 2.9 with ℓ = 3.
In general, k-ary shrub forests avoiding either 213 or 312 are in bijection with lattice paths using (1, −1) steps and 1 k+1 2k k steps of the form (j, k − j + 2) going from (0, 0) to ((k + 2)n, 0) and staying weakly above the x-axis. To find the step corresponding to a particular k-ary shrub permutation π let i be the value of the smallest number that plays the role of a 2 in a 21-pattern, or i = k + 2 if π is the identity. Then the corresponding step is (k + 2 − (i − 1), i − 1). This makes sense since if i is the smallest number that plays the role of 2 in a 21 pattern, then all digits greater than or equal to i must be larger than labels in new 213-avoiding shrubs appended to the end of the forest. With i − 1 smaller digits, there are i sets of consecutive values that can be used on the labels of a newly appended shrub. Using an upstep that takes i − 1 vertical units allows i choices for how many (1, −1) steps may come after it.

Avoiding 231
To enumerate S 2 n (231), we make use of the following celebrated result of Duchon concerning lattice paths bounded by y = 2 3 x. Proposition 2.14 (Duchon [5,Theorem 11]). The number of lattice paths of length 5n from the origin to the line y = 2 3 x with unit East and North steps that stay weakly below the line is given by i .
This sequence was investigated further by Banderier and Flajolet [1] under a slightly different formulation, whose equivalence follows from Proposition 2.10. This alternative perspective is known as "Duchon's club model": People arrive at a club by pairs and leave in threesomes. What is the number of possible scenarios from the club opening until it closes?
We enumerate forests avoiding 231 by exhibiting a bijection with Duchon's club paths. Proof: Let A n be the set of 231-avoiding permutations realizable on a binary shrub forest containing n heaps. Let B n be the set of lattice paths with 3n East (1, 0) and 2n North (0, 1) steps that stay at or below the line y = 2x 3 . To prove the theorem, we give a map φ : B n → A n ; then we prove that it is indeed a bijection by showing that it is injective, well-defined, and surjective. The result then follows by the application of Proposition 2.14.
To explain φ rigorously, we must first introduce some notation. Given b ∈ B n , we partition b into blocks of the form E k N with k ≥ 0. Since there are 2n N s (and b ends in N ), there are 2n blocks in b; call them B 1 , . . . , B 2n .
To determine φ(b), we first construct a permutation with vertical bars between certain pairs of adjacent digits. Given such a permutation a, write a = A 1 |A 2 | · · · |A ℓ . Also, given a subpermutation A i |A i+1 | · · · |A i+j , let A i − A i+j be the permutation formed by erasing all bars between these blocks. Finally, given a string of digits a, write a i+ for the string formed by incrementing all digits greater than or equal to i by 1.
We are now ready to describe φ. Let b ∈ B n have blocks B 1 , . . . , B 2n .

(a) If block
3. If i is even, then let a = 1|(a) 1+ . Recall that a value in a permutation is a left-to-right maximum if it is larger than all the values to its left. Notice that by construction, at the end of each step, the vertical bars appear immediately before each left-to-right maximum of a (except the first one). We add a bar in steps 2a and 3 when we introduce an ascent at the beginning of a by a = 1|(a) 1+ (and thus a create new left-to-right maximum). We erase bars in step 2b when we create a new left-to-right maximum that supersedes the left-to-right maxima from a previous step. It follows that while we do not use B 1 to encode additional digits of A, the number of E's in B 1 is the number of left-to-right maxima of a at the end of the algorithm describing the map φ. In general, notice that since It is clear that φ is injective; consider the rightmost block where two paths differ and thus two different digits will be appended to the beginning of a, resulting in different outputs. It remains to show that φ is well-defined and surjective.
To show that φ is well-defined, we must show that when we read a block B = E k N with k ≥ 0 in step 2 (including both cases 2a and 2b), a = A 1 |A 2 | · · · |A ℓ with ℓ ≥ k. Let b ′ = B 2n−j+1 · · · B 2n , the rightmost j blocks of b. We claim that the number of bars in a after we have read j blocks of b is given by where n E (W ) (resp. n N (W )) is the number of E (resp. N ) steps in word W . We begin with no bars. Every N block creates one more bar in step 2a. Every occurrence of an E k N block with k ≥ 1 (step 2b) creates a descent and reduces the number of bars by k − 1. After every second block (i.e. j+1 It is immediate from the fact that b ∈ B n lies below the line y = 2 3 x that for all 2 , as desired. Therefore, step 2 above is always possible. Now, we check that φ(b) ∈ S 2 n (231). First, a is indeed a permutation at each step in the algorithm for φ. We begin with a = 1. Each time we use step 2 or step 3 to prepend a new digit, all larger digits are incremented by 1 so a always consists of a string of consecutive non-repeating digits. Next, φ(b) has length 3n since we begin with 1 digit and obtain (2n − 1) new digits from step 2 and n new digits from step 3. Finally, φ(b) avoids 231 since the digit inserted into the first position of a must play the role of 2 in the 231 pattern. It is impossible for this digit to play the role of 2 in steps 2a and 3 since the first digit is the smallest. In case 2b, the permutation has all digits smaller than m appearing before all digits larger than m. Therefore, φ : B n → A n is well-defined.
Finally, to show that φ is surjective, we show that every a ∈ A n has a path b ∈ B n that is mapped to it. Given a, we can certainly reverse the encoding of ascents and descents prescribed by φ. To be rigorous, given a ∈ A n , we build the corresponding path b in the following way: 1. Let b be the empty path and let i = 3n − 1.

(a)
If i = 3z + 1 for some integer z, then b remains unchanged.
(This is the inverse of step 3 above.) (This is the inverse of step 2a above.) (c) If i = 3z + 1 for some integer z and a i > a i+1 , then b = E k N b where k is the number of left-to-right maxima of a i+1 · · · a 3n that are less than a i . (This is the inverse of step 2b above).
If i > 1 then return to step 2.
To show φ is surjective, we must verify that any path b formed in this way stays below the line y = 2 3 x. Suppose we have a ∈ A n such that φ −1 (a) / ∈ B n . Consider the first block B ℓ−1 = E k N (reading from right to left) where the corresponding path goes above the line y = 2 3 x, but B ℓ · · · B 2n is below the line. We have , or equivalently, n E (B ℓ · · · B 2n ) + k > 3 2 (n N (B ℓ · · · B 2n ) + 1). Since b comes from the map φ −1 , we know that Therefore, But by assumption n E (B ℓ · · · B 2n ) + k > 3 2 (n N (B ℓ · · · B 2n ) + 1) , so Simplifying, If n N (B ℓ · · · B 2n ) is even, then n N (B ℓ · · · B 2n ) = 2z for some integer z, so z + 1 2 < 2z+1 2 = z, which is a contradiction. On the other hand, if n N (B ℓ · · · B 2n ) is odd, then n N (B ℓ · · · B 2n ) = 2z+1 for some integer z, so z + 1 < 2z+2 2 = z + 1, which is also a contradiction. Therefore, any permutation in A n does indeed correspond to a path below the line y = 2 3 x. • We begin with i = 8 and a = 1.
Decrement i to 7 and return to step 2.
Decrement i to 6 and return to step 2.
Decrement i to 5 and return to step 2.
Decrement i to 4 and return to step 2.
Decrement i to 2 and return to step 2.
• Decrement i to 1. Since i = 1, we are done.
Notice that Theorem 2.15 generalizes as follows: F k n (231) is equinumerous with paths with unit East and North steps from (0, 0) to ((k + 1)n, kn) bounded above by y = k k+1 x. Given a path bounded by y = k k+1 x, we build the permutation for a 231-avoiding k-ary shrub forest from right to left. Each E i N block encodes information about a leaf of the forest, and after every set of k leaves we add a new right-to-left minimum as a root.

Avoiding 321
In contrast to the situation with other patterns of length 3, we are unable to present an explicit expression for the enumeration of forests avoiding 321. Nor do we exhibit a bijection with a family of lattice walks (though it is possible that such a bijection exists). However, using the techniques of analytic combinatorics, we are able to determine the generating function for this set, and its growth rate.

Deriving a functional equation
We begin by deriving a functional equation for a bivariate generating function, making use of a catalytic variable.
Recall that an inversion is an occurrence of 21 in a permutation. Given a permutation π, let its last inversion foot be the lower point of the rightmost inversion of π (if there is one), and let the statistic lif(π) count the number of entries of π with value greater than that of its last inversion foot. In other words, if |π| = n and π(i) is the rightmost entry that is not a left-to-right maximum, then lif(π) = n − π(i). If π is an increasing permutation (i.e., π = 12 · · · n), then we set lif(π) = n. Theorem 2.16. Let H(x, u) be the bivariate generating function for 321-avoiding binary shrub forests, where the coefficient of x n u k is the number of forests consisting of n shrubs whose underlying permutation σ (of length 3n) satisfies lif(σ) = k.
Then, H(x, u) satisfies the functional equation Proof: Consider S 2 n (321). These are permutations avoiding 321 of length 3n such that each of the n blocks of three consecutive values is an occurrence of either a 123 or a 132.
Let us consider how a permutation in S 2 n (321) may be extended by adding three points to its right in such a way that the resulting permutation is also a member of S 2 n (321). First of all, observe that whenever a point is added, it must have value greater than that of the last inversion foot, or else a 321 will be formed.
Suppose lif(σ) = k. Adding a new maximum entry to σ in the rightmost position does not alter the last inversion foot. In this case, the lif statistic of the resulting permutation is k + 1.
On the other hand, if a new point is added in any other valid location it results in a permutation whose lif statistic is at least 1 but is not greater than k, as 321 avoidance implies that the new point must have value greater than that of the previous last inversion foot.
Define the following four transition rules for the lif statistic: We now verify that the only valid ways to extend a permutation in S 2 n (321) (i.e., the only ways to add a 123 or 132 to the right without creating a 321) are either A then B then B, or else C then C then D.
To see this, first observe that if we wish to add a 123 or 132 pattern to the right of σ using values {|σ| + 1, |σ| + 2, |σ| + 3}, then adding the first two entries (12 if adding a 123, 13 if adding a 132) corresponds to applying C twice. Appending the rightmost entry effects the transition k → {k + 1} if a 123 is created and effects the transition k → {1} if a 132 is created. Therefore, if the 123 or 132 pattern is added entirely above the maximum entry of σ, the rule C then C then D captures all possible transitions for the lif statistic.
Suppose next that the first two entries in the pattern to be appended to σ are added below the maximum entry of σ. This corresponds to applying rule A twice. Moreover, we are now forbidden from creating a 132 pattern, as the maximum of σ together with the 32 would be a 321 pattern. The only option is to create a 123 pattern, and the placement of the last entry corresponds to rule B.
If on the other hand the first entry to be added lies below the maximum of σ but the second entry lies above (corresponding to applying rule A and then rule C), either a 123 or a 132 pattern can be created and the insertion of the last entry corresponds to rule B. This case (A then C then B), together with the previous case (A then A then B) combine to give the transition rule A then B then B.
Each of these transition rules can be represented as a linear operator acting on the generating functions, as follows (see [7,Exercises III.22,p.199 and V.20,p.365]): Thus H(x, u) satisfies the functional equation where the initial 1 corresponds to the empty shrub forest. Observing by arithmetic of formal power series that if , a computer algebra system can easily simplify the resulting expression to give the functional equation in the statement of the theorem.
The most efficient way to generate coefficients of H(x, u), and hence of H(x, 1), is to iterate the transition rules. Greater performance is achieved by combining the valid sequences of three steps into one rule, , . . . , k 6 , (k + 1) 3 , k + 2, k + 3 , the right hand side being a multiset in which multiplicities are represented by exponents.
Using Mathematica [16], we were able to calculate 993 values in the enumeration sequence for binary shrub forests avoiding 321. The first ten terms (including the empty forest) are: See A257995 in [13] for more.
A Maple program was then used to find a possible polynomial equation satisfied by the generating function. The first 250 terms sufficed to suggest that H(x, 1) was a root of the polynomial given in the statement of Theorem 2.18 below, and hence is algebraic.

Confirming algebraicity
To prove that H(x, u), and hence H(x, 1), is algebraic, we make use of a general result of Bousquet-Mélou and Jehanne [3]. To state their theorem, we first need to introduce some notation. Suppose is a bivariate formal power series. We define a sequence of operators ∆, ∆ 2 , ∆ 3 , . . ., that discard the low order terms, as follows: [3], Theorem 3). If P and Q are polynomials, then the functional equation

Theorem 2.17 (Bousquet-Mélou and Jehanne
has a unique solution for F (x, u) that is a formal power series in x whose coefficients are polynomials in u. Moreover, this solution is algebraic.
In addition, the definition of the ∆ operator implies that for k ≥ 0. Hence, the functional equation for G can be transformed into the form in Theorem 2.17 by making this substitution for k = 0, 1, 2, clearing denominators, and rearranging. Thus G(x, u) is algebraic, and hence so are H(x, u) and H(x, 1) and its derivatives.

Solving the functional equation
We would like to solve our functional equation to get an explicit expression for H(x, 1). Unfortunately, this is not possible. However, it is possible to determine the minimal polynomial of which H(x, 1) is a root.
Theorem 2.18. The generating function H 0 (x) = H(x, 1) for 321-avoiding binary shrub forests is a root of the polynomial Consequently, the growth rate of 321-avoiding binary shrub forests is approximately 39.88873, the greatest real root of the quartic polynomial Given a suitable functional equation, Bousquet-Mélou and Jehanne [3] present a way of setting up a system of polynomial equations that can then be solved to yield a polynomial having a root that is the desired generating function. They suggest that the "laziest approach" is to feed this system of equations to a Gröbner basis package and let it work. Unfortunately, as they comment, "this lazy approach often fails, because the computation tends to take forever". This has also been our experience. Submission of the appropriate equations to Singular, a computer algebra system optimized for working with polynomials, yielded no output after a week of processing.
We use a more practical strategy, derived from the results in [3] (see also Section 4 of [6]). For the necessary algebraic manipulation, Maple [12] was used.

Proof Proof of Theorem 2.18:
To start with, since our functional equation is linear in H(x, u), it can be expressed in the form where both K and P are polynomials that we omit for brevity and H i (x) = ∂ i H ∂u i (x, 1). Thus, we can use the kernel method to eliminate both H(x, u) and u. Observe that the kernel K(x, u) = 0 if and only if P (H 0 (x), H 1 (x), H 2 (x), x, u) = 0. We want to eliminate u from this pair of equations.
To do so, we calculate the resultant of K and P . The resultant of two polynomials is a monomial multiple of a polynomial in their coefficients which has the property that it is equal to zero if and only if the polynomials have a common root. The resultant is given by the determinant of a matrix (known as the Sylvester matrix) whose entries are coefficients of the polynomials.
Let R be the resultant of K and P with respect to u. Then we have where R 1 is a large polynomial that cannot be factored.
To eliminate H 1 (x) and H 2 (x), the discriminant of P can be used. The discriminant of a polynomial is a polynomial function of its coefficients which has the property that it is equal to zero if and only if the original polynomial has a multiple root. For example, it is well known that the discriminant of the quadratic ax 2 + bx + c with respect to x is b 2 − 4ac. (i) We now apply this approach twice. We do not give the polynomials involved explicitly, as they would cover many pages. Firstly, taking the discriminant of R 1 with respect to H 1 (x) yields a new equation where T 1 , T 2 and T 3 are polynomials. Thus both T 2 and T 3 are possibilities for the minimal polynomial of H(x, 1) = H 0 (x). We rule out the first choice by observing that T 2 (1, 0) is nonzero, whereas T 3 (1, 0) = 0 as is required from considering the constant term of the series expansion of H 0 (x). T 3 is, in fact, the polynomial presented in the statement of the theorem, which is the same as the minimal polynomial that we were able to guess based on the first 250 terms of the enumeration sequence.
The growth rate of the 321-avoiding binary shrub forests is then determined from the minimal polynomial by taking its discriminant with respect to H 0 (x). The growth rate is given by the reciprocal of one of the positive real roots of the discriminant (see [7, Note VII.36, p.504]). As the growth rate must be at least 1, the positive real root whose reciprocal gives the growth rate must be at most 1. This leaves only one candidate, which is the greatest real root of the quartic polynomial in the statement of the theorem.
(i) Resultants and discriminants are closely related, the discriminant of P with respect to x being, up to a monomial factor, the resultant of P (x) and P ′ (x).

Summary
Throughout this paper we have studied forests of binary shrubs that avoid any permutation pattern of length 3. This adds a new restriction to the classical pattern avoidance problem by requiring the digits π 3i+1 π 3i+2 π 3i+3 to form a 123 or a 132 pattern for all i.
Remarkably, forests avoiding a single pattern ρ ∈ {123, 132, 213, 231, 312} are in bijection with lattice paths in a wedge. It would be interesting to explore whether this phenomenon is more widespread. Are other similar pattern-avoiding structures equinumerous to such lattice paths? If so, is it possible to develop a more general theory to explain this?
In contrast to the other patterns, the enumeration of forests avoiding 321 required us to use the machinery of analytic combinatorics. However, perhaps, in this case too, there is a connection to lattice paths that remains to be uncovered.
One natural generalization also merits further investigation. In Theorem 2.6 and the discussion after Theorems 2.13 and 2.15, we generalized our results to the case of k-ary shrubs rather than binary shrubs. More of our results could be generalized in this way or to forests of tree structures other than shrubs.