Restricted generating trees for weak orderings

Motivated by the study of pattern avoidance in the context of permutations and ordered partitions, we consider the enumeration of weak-ordering chains obtained as leaves of certain restricted rooted trees. A tree of order $n$ is generated by inserting a new variable into each node at every step. A node becomes a leaf either after $n$ steps or when a certain stopping condition is met. In this paper we focus on conditions of size 2 ($x=y$, $x<y$, or $x\le y$) and several conditions of size 3. Some of the cases considered here lead to the study of descent statistics of certain `almost' pattern-avoiding permutations.


Introduction
A weak-ordering chain in the variables x 1 , x 2 , · · · , x n is an expression of the form where op is either < or =. We let WOC(n) denote the set of all weak-ordering chains in n variables. Every w ∈ WOC(n) corresponds to an ordered partition of [n] = {1, . . . , n} obtained from the indices of the variables in w, where the numbers i and j are in the same block of the partition whenever x i = x j . For example, Therefore, if WOC(0) consists of the empty chain, weak-ordering chains are enumerated by the sequence (f n ) n≥0 of Fubini numbers (ordered Bell numbers) 1, 1, 3, 13, 75, 541, 4683, 47293, . . . , [5, A000670], which satisfy the recurrence f 0 = 1 and f n = n i=1 n i f n−i for n ≥ 1.
Every element w ∈ WOC(n) can be recursively generated starting with x 1 , and then inserting x i (together with either < or =) into a previously constructed weak-ordering chain of length i − 1. This process generates a rooted labeled tree whose nodes at level i are labeled by the elements of WOC(i). For example, for n = 3, we get the tree where ij is a shortcut for x i < x j and ij represents x i = x j . Now, suppose that we wish to stop the above generating process as soon as we have a tie. In other words, suppose that we do not allow nodes with x i = x j for some i > j to have descendants. Then, the above tree would take the form with only 11 leaves instead of 13. We call (1.1) a restricted generating tree of weak-ordering chains subject to the stopping condition x i = x j . As another example, consider the stopping condition x i < x j < x k with i < j < k. In this case, the generating tree at level 3 looks like the tree for WOC(3): but the node with label 123 will have no descendants as the generating tree grows.
The goal of this paper is to study the enumeration of weak-ordering chains subject to various stopping conditions. This is equivalent to counting the number of leaves of the corresponding restricted generating subtree of WOC(n).
Our strategy relies on separating the leaves that avoid the stopping condition, call them active leaves, from the leaves that contain the stopping condition, call them inactive leaves. Throughout this paper, we will consistently use a n to denote the total number of active leaves after n steps, and b n for the total number of inactive leaves. We also let ∆ n be the number of leaves that become inactive at level n, thus ∆ 1 = 0 and ∆ n = b n − b n−1 for n ≥ 2. Note that the meaning of active/inactive depends on the given stopping condition.
For example, for the stopping condition x i = x j , we have The five inactive leaves at step 3, see (1.1), are the ones labelled in red. This manuscript is organized as follows. In Section 2, we start with the simpler case when the stopping condition involves only one operation (=, <, or ≤). In Sections 3-5, we consider stopping conditions of the form x i1 op x i2 op x i3 where op is either < or ≤. Our approach leads to descent statistics of certain 'almost' pattern-avoiding permutations. Finally, in Section 6, we consider the k-equal case and other stopping conditions with restrictions in both the order and the sizes of the parts in the partitions corresponding to the weak-ordering chains.
2 Trees with stopping condition of size 2 In this section, we will discuss the enumeration of weak-ordering chains subject to the stopping conditions Theorem 2.1 (Stopping condition x i = x j ) If w n is the number of weak-ordering chains in WOC(n), subject to the stopping condition x i = x j with i = j, then w n = 2n! − 1. This sequence starts with 1, 3, 11, 47, 239, 1439, 10079, 80639, . . ., cf. [5, A020543].
Proof: First, since an active leaf is a weak-ordering chain that avoids a tie, the number of active leaves in WOC(n) is just the number of permutations on {x 1 , . . . , x n }, so a n = n!.
On the other hand, every leaf that becomes inactive at level j is a descendant of an active node at level j − 1. In fact, everyone of these active weak-ordering chains generates j − 1 inactive leafs, obtained by replacing x k with x j = x k for k ∈ {1, . . . , j − 1}. Therefore, which implies that the total number of inactive leaves is given by In conclusion, w n = a n + b n = 2n! − 1. ✷ Theorem 2.2 (Stopping condition x i < x j ) If w n is the number of weak-ordering chains in WOC(n), subject to the stopping condition x i < x j with i < j, then w n = (n − 1)2 n−1 + 1. That is, 1, 3, 9, 25, 65, 161, 385, 897, . . . , cf. [5, A002064].
Proof: The stopping condition implies that the indices of any active weak-ordering chain in WOC(n) must appear in decreasing order x n op x n−1 op · · · op x 1 , and we can choose op to be either < or =.
Proof: The only active chain at level n is x n < x n−1 < · · · < x 1 , so a n = 1. Moreover, the active chain x j−1 < · · · < x 1 generates 2(j − 1) inactive leaves at level j, obtained by replacing x k with either Before we proceed, let us review some of the basic objects in the study of patterns in permutations. We refer to the book by Kitaev [3] for more details.
A permutation of size n is a one-to-one function σ : [n] → [n]. We use the common one-line notation σ = σ(1) · · · σ(n) and denote by S n the set of all permutations of size n. The reverse of σ is the permutation σ r = σ(n) · · · σ(1), and the complement is A permutation σ is said to have an ascent at position i if σ(i) < σ(i + 1), and it has a descent at i if σ(i) > σ(i + 1).
An occurrence of a pattern τ in a permutation σ is a subsequence in σ (of length |τ |) whose entries are in the same relative order as those in τ . For example, the permutation 23154 has two occurrences of the pattern 123 (namely 235 and 234), but the permutation 53214 avoids the pattern 123. We use the standard notation S n (τ ) to denote the set of all permutations in S n that avoid the pattern τ .
As mentioned in the introduction, WOC(n) is in one-to-one correspondence with the set of ordered partitions of [n]. For such an ordered partition π, we let σ π be the underlined permutation obtained by merging the parts of π and underlining the entries coming from the same block of π. In this section, we adopt the convention of writing adjacent underlined entries in decreasing order. For example, Let V n (σ) be the set of chains in WOC(n) projecting to σ. A descent σ(i) > σ(i+1) in the permutation σ could come from x σ(i) < x σ(i+1) or x σ(i) = x σ(i+1) in the chain. Thus, if σ has d descents, then V n (σ) has 2 d elements. Moreover, if a chain contains an increasing subsequence x i1 < x i2 < x i3 , then the projected permutation must contain a 123-pattern. As a consequence, the set of active chains in WOC(n), subject to the stopping condition where S n (123) is the set of 123-avoiding permutations on [n], and S d n (123) denotes the subset of permutations in S n (123) having exactly d descents. Therefore, the number of active leaves at level n is given by a n = n−1 Barnabei et al. [1,Thm. 6] gave a closed form for 1 + E(x, y) from which we deduce Therefore, the generating function A(x) = ∞ n=1 a n x n satisfies .
where C m denotes the m-th Catalan number. This sequence starts with 1, 3, 12, 56, 284, 1516, 8384, 47600, . . . , cf. [5, A226316]. Using a version of Krattenthaler's bijection between Dyck paths and 123-avoiding permutations (cf. [3,4]), it can be checked that the set of active chains in WOC(n) with stopping condition x i1 < x i2 < x i3 is in one-to-one correspondence with the set of Dyck paths of semilength n where valleys and triple downsteps come in 2 colors. (i) Our connection between weak-ordering chains and permutations makes it clear that a leaf is inactive if the associated permutation has a 123 pattern. Thus, in order to count the elements that become inactive at level n, we need to enumerate the following set: where σ ′ ∈ S n−1 denotes the permutation obtained from σ ∈ S n by removing n. In addition, we define (i) A Dyck path of semilength n is a lattice path from (0, 0) to (0, 2n) with steps U = (1, 1) and D = (1, −1), never going below the x-axis. A valley is a subpath DU.
Proposition 3.5 If g n,d = |G d n (123)|, then g 3,0 = 1, and for n > 3 and 1 ≤ d ≤ n − 3, where E x , E y = ∇E, and E(x, y) is the function in (3.2). In other words, Proof: For n > 3, every σ in G d n (123) can be generated by inserting n into a permutation σ ′ ∈ S d n−1 (123) ∪ S d−1 n−1 (123) at a position where it creates a 123 pattern. If σ ′ has d descents, then n may only be inserted at a descent or at the last position of σ ′ . Thus, each On the other hand, if σ ′ has d − 1 descents, then n will have to be inserted at one of the n − d available ascents of σ ′ in order to create an extra descent. Therefore, each σ ′ ∈ S d−1 n−1 (123) generates n − d permutations in S d n . Together, the above insertion procedures generate (d + 1)e n−1,d + (n − d)e n−1,d−1 permutations of size n with d descents. However, since the elements of G d n (123) are required to have a 123 pattern, we need to remove the e n,d permutations that avoid 123.
The first statement about G(x, y) then follows from (3.6) by means of routine algebraic manipulations. The closed form statement is just a consequence of (3.2). ✷ Theorem 3.7 If w n is the number of weak-ordering chains in WOC(n), subject to the stopping condition The sequence (w n ) n∈N starts with 1, 3, 13, 69, 401, 2433, 15121, 95441, . . ., and Proof: By (3.1), the number of active leaves after n steps is a n = n−1 d=0 2 d e n,d , and their generating function A(x) is given by .
On the other hand, a weak-ordering chain that becomes inactive at level j ≥ 3 leads to a σ ∈ S j that has a 123 pattern, and such that σ ′ ∈ S j−1 (123). The number of such permutations having d descents is The formula for w n = a n + b n follows from the fact that b n = n j=3 ∆ j .
Finally, using Proposition 3.5 we can write This case is more restrictive than the previous one. For example, the chains that were previously active leaves, will now turn into inactive leaves. In order to handle the stopping condition at the permutation level in a consistent manner (i.e. using descents in the permutation to mark the places where the corresponding chain may have an = symbol), it is convenient to consider underlined 321-avoiding permutations. We will then use the complement map to obtain underlined 123-avoiding permutations that correspond to the weak-ordering chains with the stopping condition This process will be explained and illustrated in the proof of the following proposition.
Proposition 4.1 The set of active leaves in WOC(n), subject to the stopping condition x i1 ≤ x i2 ≤ x i3 with i 1 < i 2 < i 3 , is in one-to-one correspondence with the set of Dyck paths of semilength n where each subpath UDD can take on two colors. If we let a n denote the number of such paths, then their generating function A(x) satisfies where C(x) is the Catalan function, and therefore, a n = Proof: We will prove the statement by establishing a bijection that relies on a known map between Dyck paths and 321-avoiding permutations, see e.g. [3]. We represent a Dyck path as a lattice path from (0, 0) to (n, n), starting with an N-step (0, 1), ending with an E-step (1, 0), and never going below the line y = x. We will allow NEE to take on two colors. Given a Dyck path P of the above type, drawn on a coordinate grid, place a dot in every cell bounded by an NE-turn of the path, and then place dots in increasing order (from left to right) so that every column below the path has exactly one dot with no two dots in the same row. This gives the plot of a 321-avoiding permutation σ P , and we underline adjacent elements of the permutation if the corresponding steps in the path are orange. For example, for n = 3 we have the following 9 elements: Finally, we take the complement of σ P (keeping the underlines) and construct the weak-ordering chain w P associated with P by replacing ij in σ c P with x i < x j and ij with x i = x j . Note that σ c P ∈ S n (123), hence w P does not contain the stopping condition. Also observe that, while x i = x j and x j = x i represent the same chain, our map gives the partition blocks in the form: smallest element first, followed by the rest of the elements in decreasing order.
The above paths correspond to the chains: We now illustrate the inverse by means of an example. Suppose we have the active leaf To this weak-ordering chain we associate the underlined permutation σ w = 57 26 413 with complement σ c w = 31 62 475. Finally, constructing the Dyck path corresponding to 3162475 and making orange the NEE steps above underlined numbers, we arrive at which is a colored Dyck path of the desired form.
Note that a permutation σ on [n] with d descents gives rise to 2 d chains. Since the reverse σ r is a 123-avoiding permutation with d ascents (hence n − 1 − d descents), we conclude that the number of active leaves is given by where e n,d = |S d n (123)|. Thus A(x) = 1 2 E(2x, 1 2 ) with E(x, y) from (3.2), which simplifies to the claimed expression. ✷ Theorem 4.3 If w n is the number of weak-ordering chains in WOC(n), subject to the stopping condition The sequence (w n ) n∈N starts with 1, 3, 13, 59, 269, 1227, 5613, 25771, 118765, . . ., and the generating Proof: We already know that the number of active chains is given by (4.2), so we only need to focus on the inactive ones. Note that inactive chains at level j come from permutations in S j that contain the pattern 321 and such that their reduced permutation (obtained by removing j) belongs to S j−1 (321). The set of such permutations having exactly d descents is in bijection with G j−1−d j (123) (as defined in (3.4)), and therefore, each such permutation induces 2 d g j,j−1−d inactive weak-ordering chains. Hence We can then use Proposition 3.5 to write its generating function B(x) as Combined with Proposition 4.1, this gives a closed form for 1 + W (x) = 1 + A(x) + B(x). ✷

Stopping condition
The set of active leaves in WOC(n), subject to the stopping condition x i1 ≤ x i2 < x i3 with i 1 < i 2 < i 3 , is in one-to-one correspondence with the set of Dyck paths of semilength n in which valleys may be marked. They are counted by the little Schröder numbers 1, 3, 11, 45, . . . , [5, A001003].
Proof: We will use the same map between 321-avoiding permutations and Dyck paths used in Proposition 4.1 to provide a bijection between active weak-ordering chains of length n and Dyck paths from (0, 0) to (n, n) in which valleys may be marked. It is easy to check that these paths are counted by the little Schröder numbers. For every possibly marked Dyck path P , we plot the corresponding 321-avoiding permutation σ P and underline adjacent elements of σ P if there is a marked valley between their plots. For example, for n = 3 there are 11 such elements: Note that, by construction, a 312 pattern can never occur. We then take the reverse of σ P (keeping the underlines) and construct the weak-ordering chain w P associated with P by replacing ij in σ r P with x i < x j and ij with x i = x j . The resulting underlined permutation σ r P avoids 123 and does not contain a 213 pattern. Hence, the chain w P does not contain the stopping condition. For example, the above paths correspond to the active chains: The reverse map is straightforward. From an active chain, read the underlined permutation made from its indices (with the convention that in a block of equal elements, indices are sorted in decreasing order). Then take the reverse permutation (necessarily 321-avoiding) and draw the associated Dyck paths, marking the valleys that correspond to underlined adjacent entries in the permutation. ✷ Observe that, since the number of Dyck paths with v valleys is counted by the Narayana numbers N n,v = 1 n n v n v+1 , the number of active leaves is given by Proof: The formula for ℓ n,d follows from an argument similar to the one made for the proof of (3.6).
There are (d + 1)N n−1,d permutations of size n with d descents that can be created by inserting n (at a descent or at the end) into the N n−1,d elements of S d n−1 (213). In addition, there are (n − d)N n−1,d−1 such permutations that can be generated from S d−1 n−1 (213). To get the total number of elements in G d n (213), we combine the above permutations and remove the ones that avoid 213 (counted by N n,d ).
As a consequence, if N (x, y) is the generating function for the Narayana numbers, then Finally, using the known formula one derives the closed form of L(x, y). ✷ Theorem 5.3 If w n is the number of weak-ordering chains in WOC(n), subject to the stopping condition The sequence (w n ) n∈N starts with 1, 3, 13, 65, 341, 1827, 9913, 54273, 299209, 1658723, . . . , and the Proof: The first summation in the claimed formula for w n represents the number of active weak-ordering chains (Proposition 5.1). Thus their generating function can be written as In order to derive a formula for the number ∆ j of active chains that become inactive at level j, we will provide a bijection φ between these chains and the set of permutations in j−2 d=1 G d j (213) where descents may be underlined. That implies ∆ 1 = ∆ 2 = 0, and for j ≥ 3, ∆ j = j−2 d=1 2 d ℓ j,d . As a consequence, the total number of inactive chains will be given by with generating function Combining the active and inactive chains, we get the formulas for w n and W (x). We finish the proof by describing the bijection φ. Let w ∈ WOC(n) be a chain that becomes inactive at level n, and let σ w be the permutation corresponding to w obtained from the indices of the variables, with the usual convention that indices of equal elements are underlined and listed in decreasing order. Observe that for w to be inactive, the entry n in σ w must be part of either a 123 pattern or a 213 pattern, while the reduced permutation σ ′ w must avoid both patterns. In particular, this implies that the entry n − 1 in σ w cannot be to the right of entry n.
If n − 1 and n are not adjacent, we proceed as follows: • Map σ ′ w to the 213-avoiding permutation τ ′ w having the same right-to-left maxima (ii) , keeping the underlines in the same positions.
• If i is the position of n in σ w , we let φ(w) be the permutation obtained by inserting n into τ ′ w at position i.
Since n − 1 must be left of n in σ w , the permutation φ(w) will always contain a 213-pattern. For example, for the chain x 6 < x 8 < x 7 = x 4 < x 2 < x 9 < x 5 = x 1 < x 3 , the above steps give the permutations (ii) A right-to-left maximum of a permutation is an entry with no larger entries to its right.
If n − 1 and n are adjacent in σ w , then it must be of the form σ 0 (n − 1)n * , where σ 0 is a decreasing permutation of size at least 1 with no underlines. In this case, we create the permutationσ w = (n−1)σ 0 n * and proceed as in the previous case. For example, for x 6 < x 5 < x 8 < x 9 < x 7 = x 4 = x 2 < x 1 < x 3 , we get: Observe that if the original permutation σ w starts with n − 1, there must be either an ascent or a 21 pattern left of n, soσ w cannot create a duplicate. The above algorithm can be easily reversed, showing the invertibility of φ. ✷

Other stopping conditions
In this section, we generalize the stopping condition x i = x j to chains of arbitrary length. We also consider some conditions with restrictions in both the order and the sizes of the parts in the partitions corresponding to the weak-ordering chains.
The k-equal stopping condition For the stopping condition x i1 = · · · = x i k with k > 1, active chains in the set WOC(n) correspond to ordered partitions of [n] with parts of size at most k − 1. Thus, a n (number of active leaves at level n) satisfies the recurrence relation a i = f i for 1 ≤ i < k, and a n = k−1 i=1 n i a n−i for n ≥ k, where f i denotes the i-th Fubini number, cf. [5, A276921]. To verify this formula, observe that the set of active leaves can be organized by the size of the last block in the partition, so it is the union of k − 1 disjoint sets. There are n i possible blocks of size i, and once such a block has been chosen as the last block of the partition, there are a n−i possible active partitions for the remaining elements.
We now derive a formula for the number b n of inactive chains at step n. The first stopping condition can only occur after k steps, so b 1 = · · · = b k−1 = 0.
Inactive nodes of length j ≥ k correspond to ordered partitions of [j] having a part of size k that contains j, and such that all other parts have size less than k. There are j−1 k−1 ways to form the block of size k that contains j, and for the remaining j − k elements, we choose i to be in parts to the left of that block. Thus, where (a n ) n∈N is the sequence enumerating the active chains. Therefore, for n ≥ k, Finally, the total number of weak-ordering chains subject to the above stopping condition can be obtained by adding the active and inactive chains.
Theorem 6.1 If w n is the number of weak-ordering chains in WOC(n), subject to the stopping condition x i1 = · · · = x i k with k > 1, then w i = f i for 1 ≤ i < k, where f i is the ith Fubini number, and for n ≥ k, where (a n ) n∈N is the sequence that counts the corresponding active chains.

Stopping condition
We start by discussing the number a n of active chains. Clearly, a 1 = 1 and a 2 = 3. For n ≥ 3, let w ∈ WOC(n) and let π w = {B 1 , B 2 , . . . , B ℓ } be its corresponding ordered partition of [n]. The chain w is active if for every block B j with more than one element, its second largest element is smaller than all the elements in every block B i with i < j.
We enumerate these partitions by the size of their last block. If the size of B ℓ is k ≥ 1, then we must have B ℓ = {1, 2, . . . , k − 1, i k }, with k ≤ i k ≤ n. All other blocks must correspond to an active partition of the set {k, . . . , n}\{i k }. So, we have the following recurrence relation for n ≥ 1 (setting a 0 = 1): a n = n k=1 (n − k + 1)a n−k = n−1 k=0 (k + 1)a k .
We now proceed to derive a formula for ∆ n , the number of inactive leaves at step n. The base cases are ∆ 1 = ∆ 2 = 0. Furthermore, we claim that ∆ n = n∆ n−1 + (n − 2)a n−2 , for n ≥ 3. (6.2) First observe that, given an active partition π a of [n − 2], the partition obtained by adding the block {n − 1, n} to the end of π a is inactive. Moreover, π a can be used to create n − 3 more inactive partitions as follows: Choose i such that 2 ≤ i ≤ n − 2. Then, for every element j ≥ i of π a , replace j by j + 1 and place the block {i, n} at the end of the modified partition. This gives (n − 2)a n−2 inactive partitions of [n] having a last block of size 2. The remaining inactive partitions must have a last block of size 1 or larger than 2. They can be generated from the ∆ n−1 inactive partitions at level n − 1 by the following process: • For every inactive partition π of [n − 1] and i ∈ {1, . . . , n − 1}, replace j by j + 1 for every j ≥ i and add the singleton {i} to the end of the modified partition. This gives (n − 1)∆ n−1 inactive partitions of [n].
• Alternatively, replacing j by j + 1 in π and adding 1 to the last block, yields ∆ n−1 additional inactive partitions of [n].
Stopping condition x i1 ≤ x i2 = x i3 with i 1 < i 2 < i 3 As in the above case, we start by discussing the active chains. Once again, a 1 = 1 and a 2 = 3.
For the enumeration of the chains that become inactive at step n, the base cases are ∆ 1 = ∆ 2 = 0, and ∆ 3 = 2 (namely x 1 < x 2 = x 3 and x 1 = x 2 = x 3 ). For n ≥ 4 we have ∆ n = (n − 1)∆ n−1 + (n − 2)∆ n−2 + a n−1 − a n−2 . (6.3) To show this, we look at four disjoint cases: (c) For every active partition π a of [n − 2], the partition obtained by adding the block {n − 1, n} to the end of π a is inactive. Moreover, we can create n − 3 additional inactive partitions of [n] as follows: Choose i such that 2 ≤ i ≤ n − 2. For every j ≥ i, replace j by j + 1 in π a and add the block {i, n} to the end of the modified partition. Together, we have (n − 2)a n−2 inactive partitions whose last block is of size 2 and does not contain the element 1.
(d) Finally, every active partition π a of [n − 3] generates n − 2 inactive partitions of [n] obtained by relabeling π a so that we can add the block {1, i, n} with i ∈ {2, . . . , n − 1} to the end of it. There are (n − 2)a n−3 inactive partitions of this type.