Refining enumeration schemes to count according to permutation statistics

We consider the question of computing the distribution of a permutation statistics over restricted permutations via enumeration schemes. The restricted permutations are those avoiding sets of vincular patterns (which include both classical and consecutive patterns), and the statistics are described in the number of copies of certain vincular patterns such as the descent statistic and major index. An enumeration scheme is a polynomial-time algorithm (specifically, a system of recurrence relations) to compute the number of permutations avoiding a given set of vincular patterns. Enumeration schemes' most notable feature is that they may be discovered and proven via only finite computation. We prove that when a finite enumeration scheme exists to compute the number of permutations avoiding a given set of vincular patterns, the scheme can also compute the distribution of certain permutation statistics with very little extra computation.


Introduction
Enumeration schemes are special recurrences to compute the number of permutations avoiding a set of vincular patterns. In this paper, we discuss how to refine enumeration schemes to compute the distributions of certain permutation statistics over a set of pattern-avoiding permutations. This extends previous work in [6,9] which considers the distribution of only the inversion number.
Let [n] be shorthand for the set {1, . . . , n}. For a word w ∈ [n] k , we write w = w1w2 · · · w k and define the reduction red(w) to be the word obtained by replacing the i th smallest letter(s) of w with i. For example red(839183) = 324132. If red(w) = red(w ′ ), we say that w and w ′ are order-isomorphic and write w ∼ w ′ . We will commonly use the notation |w| to denote the length of w.
Vincular patterns resemble classical patterns, with the constraint that some of the letters in a copy must be consecutive. Formally, a vincular pattern of length k is a pair (σ, X) where σ is a permutation in S k and X ⊆ {0, 1, 2, . . . , k} is a set of "adjacencies." A permutation π ∈ Sn contains the vincular pattern (σ, X) if there is a k-tuple 1 ≤ i1 < i2 < · · · < i k ≤ n such that the following three criteria are satisfied: • red(πi 1 πi 2 · · · πi k ) = σ.
• i1 = 1 if 0 ∈ X and i k = n if k ∈ X.
In the present work we restrict our attention to patterns (σ, X) where σ ∈ S k and X ⊆ [k − 1], rendering the third containment criterion irrelevant. 1 The subsequence πi 1 πi 2 · · · πi k is called a copy of (σ, X). In the permutation π = 162534, the subsequence 1253 is a copy of (1243, {3}), but the subsequence 1254 is not a copy since the 5 and 4 are not adjacent in π. The "classical pattern" σ is precisely the vincular pattern (σ, ∅) since no adjacencies are required, while the "consecutive pattern" σ is the vincular pattern (σ, {1, 2, . . . , k − 1}) since all internal adjacencies are required.
In practice we write (σ, X) as a permutation with a dash between σj and σj+1 if j ∈ X. For example, (1243, {3}) is written 1-2-43. We occasionally refer to "the vincular pattern σ" or even "the pattern σ" without explicitly referring to X.
If the permutation π does not contain a copy of the pattern (σ, X), then π is said to avoid σ. We will notation Sn(σ) or Sn((σ, X)) to denote the set of permutations avoiding the (σ, X), and Sn(B) denotes those permutations avoiding every vincular pattern (σ, X) ∈ B.
Observe that a vincular pattern (σ, X) of length k exhibits similar symmetries to those of permutations, except for taking inverses. The reverse is given by (σ, X) r = (σ r , k − X) where k − X = {k − x : x ∈ X}. For example, (1-3-42) r = 24-3-1. The complement is (σ, X) c = (σ c , X). For example, (1-3-42) c = 4-2-13. It follows that that π avoids (σ, X) if and only if π r avoids (σ, X) r . Similarly, π avoids (σ, X) if and only if π c avoids (σ, X) c . See Steingrímssson's survey for a fuller history in [24]. From their earliest days, vincular patterns been linked to many of the common combinatorial structures such as set partitions and lattice paths in [14] as well as permutation statistics in [2]. Enumeration schemes were introduced by Zeilberger in [27] as an automated method to compute Sn(B) for many different B. Vatter improved schemes in [25] with the introduction of gap vectors, and Zeilberger provided an alternate implementation in [28]. The greatest feature of schemes is that they may be discovered by a computer: the user need only input the set B (along with bounds to the computer search) and the computer will return an enumeration scheme (if one exists within the bounds of the search) which computes Sn(B) in polynomial time. Pudwell extended these methods to consider pattern avoidance in permutations of a multiset in [22,20], as well as barred-pattern avoidance in [21]. The author and Pudwell extended schemes to sets of vincular patterns in [9].
A permutation statistic is any function f : n≥0 Sn → Z. The moststudied permutation statistic is the inversion number inv(π) = {(i, j) : i < j and πi > πj } . In terms of vincular patterns, inv(π) is the number of copies of 2-1 = (21, ∅). Similarly, the descent number des(π) = {i : πi > πi+1} is the number of copies of 21 = (21, {1}). In this work we will primarily consider permutation statistics which count the number of copies of a given vincular pattern, sometimes called pattern functions. It is shown in [2] that many well-known permutation statistics can be framed as linear combinations of pattern functions. For a permutation statistic f and set S ⊆ n≥0 Sn, the distribution of f over S is given by: (1) We also consider the simultaneous distribution of multiple statistics f = f1, . . . , fm over the same set S with the indeterminates q = q1 . . . , qm .
The distribution of f over S is given by: Distributions of statistics over sets of pattern-avoiding permutations have received increased attention of late, focusing primarily on sets of permutations avoiding classical patterns of length 3. Barcucci [15] by studying the inversion number and major index over Sn(τ ) for classical patterns τ ∈ S3. Bona and Homberger study the total number of classical patterns σ ∈ S3 over Sn(τ ) for another classical pattern τ ∈ S3 in [11,12,16]. Most recently, Burstein and Elizalde in [13] study the total number of vincular patterns of length 3 over Sn(τ ) for classical patterns τ ∈ S3.
Suppose that E is a finite enumeration scheme which gives a recurrence to compute Sn(B) for a given set of patterns B. The work in [6,9] demonstrates how to use E to compute F (Sn(B), inv, q). The present work demonstrates how to use E to compute the distribution F (Sn(B), f , q) where each statistic fi counts the number of copies of a vincular pattern of the form (σ, [|σ| − 1) or (σ, [|σ| − 2]) or counts the number of right-to-left minima or right-to-left maxima. The results are implemented in the Maple package Statter, available for download from the author's homepage.
The paper is organized as follows. Section 2 outlines the basics of enumeration schemes and their structure. Section 3 defines the notion of an "enumeration-scheme-compatible," or "ES-compatible," statistic. Subsection 3.2 presents three classes of ES-compatible statistics. Section 4 presents a technical result proving that any given finite enumeration scheme can be expanded to fit the additional requirements which EScompatible statistics can impose. Section 5 presents three specific examples of how enumeration schemes can be applied to explore statistics over sets Sn(B).

Overview of Enumeration Schemes
Enumeration schemes are succinct encodings for a family of recurrence relations enumerating a family of sets. The enumerated sets are actually subsets of Sn(B) determined by prefixes.
For pattern p ∈ S k , let Sn(B)[p] be the set of permutations π ∈ Sn(B) such that red(π1π2 . . . π k ) = p. We call p the prefix pattern. To refine further, let w ∈ [n] k and define Sn(B)[p; w] to be those permutations in π ∈ Sn(B)[p] such that π1π2 · · · π k = w. By looking at the prefix of a permutation, one can identify likely "trouble spots" where forbidden patterns may appear. For example, suppose we wish to avoid the (classical) pattern 1-2-3. Then the presence of the pattern 12 in the prefix indicates the potential for the whole permutation to contain a 1-2-3 pattern.
Enumeration schemes take a divide-and-conquer approach to enumeration. We define the child of a permutation p ∈ S k to be any permutation for p ∈ S k may be partitioned into the family of sets Sn(B)[p ′ ] for each of its children p ′ ∈ S k+1 (B) [p]. The sets indexed by these children are then considered as described below, and their sizes are totaled to obtain sn(B) [p]. In the end we have computed Sn(B) , since Sn(B) = Sn(B)[ǫ] = Sn(B) [1], where ǫ is the empty (i.e., , length 0) permutation.
For p ∈ S k a set Sn(B)[p] fits into one of three cases: (1) If n = k, then Sn(B)[p] is either {p} or ∅, depending on whether p avoids B.
(2) For each w ∈ [n] k such that red(w) = p, one of the following happens: Case (1) provides the base cases for our recurrence. If case (2) applies, then we will use it preferentially over case (3). If case (2) does not apply, we must divide Sn(B)[p] as in case (3). Determining whether case (2) applies makes use of gap vector criteria to test (2a) and reversible deletions to form the bijection in (2b). These concepts are outlined in the following subsections.

Gap Vectors
The differences between the values of letters in the prefix may be great that a forbidden pattern must appear. To make this more precise, we follow our example above and compute sn(1-2-3) [12]. Observe that Sn(1-2-3)[12; w1w2] is empty if w1 < w2 < n, since otherwise if π ∈ Sn(1-2-3)[12; w1w2] then πi = n for some i ≥ 3 and so w1w2n forms a 1-2-3 pattern. Since the possibility for any πi > w2 for i ≥ 3 prohibits the formation of a 1-2-3-avoiding permutation, we must restrict the space above w2.
To formalize this, consider Sn(B)[p; w] and let ci be the i th smallest letter in w. Let c0 = 0 and c k+1 = n + 1, and form the (k + 1)-vector g(n, w) so that the i th component is gi = ci −ci−1 −1. Note that gi counts the number of letters for any π ∈ Sn(B)[p; w] which lie strictly between ci−1 and ci, i.e., the number of letters πj following the prefix (j > k) and ci−1 ≤ πj ≤ ci. We call g(n, w) the spacing vector for w.
In the example above, if g(n, w) ≥ 0, 0, 1 in the product order of N 3 (i.e., component-wise), then Sn(1-2-3)[12; w] = ∅. We call 0, 0, 1 a gap vector for the prefix 12. More generally we may make the following definition: Definition 1. Given a set of forbidden patterns B and prefix p, then v is a gap vector for prefix p with respect to B if, for all n, Sn(B)[p; w] = ∅ for any w such that g(n, w) ≥ v. In this case we say that w satisfies the gap vector criterion for v.
Hence v = 0, 0, 1 is a gap vector for p = 12 with respect to B = {1-2-3}, and any prefix set w = w1w2 with w1 < w2 < n satisfies the gap vector condition for v.
Observe that gap vectors for a given prefix p ∈ S k form an upper order ideal in N k+1 , since if v is a gap vector so is any u ≥ v. Hence it suffices to determine only the minimal elements (which form a basis). For details on the discovery of gap vectors and automating the process, see [25,28,9].
Note that if the prefix p contains a pattern in B, then Sn(B)[p; w] = ∅ for any appropriate w, and so 0 = 0, 0, . . . , 0 is a gap vector.

Reversible Deletability
When w fails the gap vector criterion for all gap vectors v, we must rely on bijections with previously-computed Sn(B)[p;ŵ]. To continue our example above, consider Sn(1-2-3) [12; w1n]. Here w1n fails all gap vector criteria, because 0, 0, 1 forms the basis for the ideal of gap vectors and g(n, w1n) = w1 − 1, n − w1 − 1, 0 ≥ 0, 0, 1 . However, any π ∈ Sn(1-2-3)[12; w1n] has π2 = n, so we may use the map d2 : π1π2 . . . πn → red(π1π3 . . . πn) to form a bijection Sn The deletion of a letter always preserves pattern-avoidance properties when considering classical patterns, but inverting the map by inserting a letter has the potential for creating a forbidden pattern. Here, however, inserting an n at the second index cannot possibly create a 1-2-3, so we may safely reverse the deletion.
More generally define the deletion dr(π) := red(π1 . . . πr−1πr+1 . . . πn), that is, the permutation obtained by omitting the r th letter of π and reducing. Furthermore for a set R, define dR(π) to be the permutation obtained by deleting πr for each r ∈ R and then reducing. For a word w with no repeated letters, define dr(w) be the word obtained by deleting the r th letter and then subtracting 1 from each remaining letter larger than wr. Similarly, to construct dR(w) delete wr for each r ∈ R and subtract {r ∈ R : wr < wi} from each remaining wi. For example d3(6348) = 537 and d {1,3} (6348) = 36. It can be seen that this definition is equivalent to the one given above when w ∈ S k , and it allows for more succinct notation in the upcoming definition. In the unrestricted case, dR : Sn(∅)[p; w] → S n−|R| (∅)[dR(p); dR(w)] is a bijection for any set R ⊆ [|p|]. Sometimes we are lucky and the restriction to Sn(B)[p; w] is a bijection with S n−|R| (B)[dR(p); dR(w)], leading to the following definition: is a bijection for all words w failing the gap vector criterion for every gap vector of p with respect to B (i.e., dR is a bijection for all w such that Sn(B)[p; w] = ∅).
Note that the empty set R = ∅ is reversibly deletable for any p and B, but is uninteresting. Additionally, if 0 is a gap vector then any set R ⊆ [|p|] is vacuously reversibly deletable since Sn(B)[p; w] = ∅ for any prefix w.
Proving that a set is reversibly deletable for prefix p with respect to B can be carried out by a finite list of verifications, and thus can be done via computer. This is proven in [25] for the case that B contains only classical patterns, and in [9] in the case that B contains vincular patterns. The process of automated discovery itself is not relevant to the present work and will be omitted.

Formal Definition of Enumeration Schemes
We will now formally define an enumeration scheme.
Definition 3. Let B be a set of vincular patterns. An enumeration scheme for B is a set E of triples (p, G, R), where p is a permutation (i.e., , the prefix pattern), G is a basis of gap vectors for p with respect to B, and R is a reversibly deletable set for p with respect to B. Furthermore, E must satisfy the following criteria: To compute sn(B)[p; w] for a fixed n, p, and w, the enumeration scheme E is "read" by finding the appropriate triple (p, G, R) ∈ E and concluding: 1. If w satisfies the gap vector criteria for some v ∈ G, then sn(B)[p; w] = 0. 3. If w fails the gap criteria for all v ∈ G and R = ∅, then sn(B) When combined with the initial conditions that sn(B)[p; w] = 1 whenever p has length n and avoids B, the scheme provides a system of recurrences to compute sn(B)[p; w] and ultimately Sn(B) .
Starting with the pattern 1 yields no additional information, so R1 = ∅ and thus explaining the presence of (12, G12, R12) and (21, G21, R21). As discussed above, { 0, 0, 1 } forms a basis for the gap vectors for 12, and whenever w fails this gap vector criteria the second letter is reversibly deletable. For the fourth entry in the scheme, suppose that π ∈ Sn(∅) [21] contains a 1-2-3 pattern involving the first letter, say π1 < πi < πj for i < j. Then since π2 < π1, we see that π2 < πi < πj is another 1-2-3 pattern. Therefore π1 cannot be the deciding factor for whether π contains 1-2-3. Hence the index 1 is reversibly deletable, so R21 = {1}. Enumeration schemes exhibit a tree-like structure. The empty prefix ǫ serves as the root, and the children of each prefix are drawn as children in a rooted tree. When a prefix has nontrivial gap vector criteria, we list those basis vectors below it. When prefix p has a non-empty reversibly deletable set R, we draw an arrow from p to dR(p) labeled with "dR". See Figure 1 for an example. If |E| is finite, we say that B admits a finite enumeration scheme. A finite enumeration scheme gives us a polynomial-time algorithm to compute sn(B)[p; w]. We construct the system of recurrences based on the partitions and bijections above, along with base cases as given by the gap vector criteria and the trivial cases when Sn(B)[p] = {p} or ∅. For example, the above enumeration scheme in (3) translates into the following system of recurrences: The recurrences in (4) simplify to create the following recurrence: Amont other things, one can then evaluate this recurrence by hand to identify the closed form Sn(1-2-3) = 1 n+1 2n n , the Catalan numbers. The length of the longest prefix p appearing in finite scheme E is the called the depth of E. Not every set B admits a finite enumeration scheme, the simplest example being the classical pattern 2-3-1. Let E be the scheme for Sn(2-3-1), and let Jt = t(t − 1) · · · 21 be the decreasing permutation of length t. It can be shown that for any t there are no gap vectors for Jt and no non-empty reversibly deletable sets. Hence E must contain the triple (Jt, ∅, ∅) for each t ≥ 1 and hence E is infinite.
It should be noted that the enumeration scheme for Sn(1-3-2) is finite (of depth 2) and Sn(2-3-1) = Sn(1-3-2) by symmetry. More generally, it can be seen that if B admits an enumeration scheme EB of depth K then its set of complements B c = {σ c : σ ∈ B} also admits an enumeration scheme EBc of depth K. The analogous statements regarding B r = {σ r : σ ∈ B} do not hold and so B may not have a finite scheme while B r does, as exhibited by B = {2-3-1}.

.1 Definitions and interaction with enumeration schemes
The author proves in [6] that if B admits a finite enumeration scheme, then the distribution of the statistic inv(π) over Sn(B) can be computed via the same enumeration scheme. This is the consequence of comparing the inversion number of a permutation and its image under the deletion map dR : In particular, for π ∈ Sn the change in the inversion number after deleting the r th letter is given by where sgn(x) is the signum function: For the more general case, let R = {r1, . . . , rt} where rj < rj+1. Then the deletion dR has the following effect on inversion number: Observe that δR(π) can be written purely in terms of the letters π1, . . . , πr t . Therefore if E is an enumeration scheme for pattern set B, and (p, G, R) ∈ E, then δR is constant over the set Sn(B)[p; w] for any fixed w. Thus we define a new function ∆ inv R (w, n) on prefix words w, which takes on the value δ inv R (π) given by a π ∈ Sn(B)[p; w]. Therefore we may recursively compute the distribution of inv over The above results motivate the following definitions: For nonnegative integer m, a permutation statistic f is enumerationscheme-compatible (or "ES-compatible") with margin m if for any positive integer t and any R ⊆ [t], the R-deletion differences δ f R (π) = δ f R (π ′ ) whenever π and π ′ are two permutations of length n ≥ t + m such that π1 · · · πt+m = π ′ 1 · · · π ′ t+m . We denote this constant value ∆ f R (w, n) where w = π1 · · · πt+m.
In other words, permutation statistic f is ES-compatible with margin m if δ f R (π) may be determined from only the length of π and its first max R + m letters. Note that if f is ES-compatible with margin m, then f is also ES-compatible with margin m ′ for any m ′ ≥ m.
The results from [6] cited above may be rephrased as follows: It follows from the definition of ES-compatible that enumeration schemes are amenable to computing the distribution for any ES-compatible statistic: Theorem 6. Let f be a ES-compatible permutation statistic with margin m. If R is reversibly deletable for prefix p ∈ S k with respect to B and max R + m ≤ k, then where ∆ f R (w, n) has the value δ f R (π) for any π ∈ Sn(B)[p; w].
is a bijection. Shifting focus to the weight enumerators, we see that Thus we have proven equation (9).
By a similar proof we get the following multivariate generalization of Theorem 6: Theorem 7. Let f1, . . . , fs be ES-compatible permutation statistics, each with margin at most m, and let f = f1, . . . , fs and q = q1, . . . , qs . If R is reversibly deletable for prefix p ∈ S k with respect to B and max R+m ≤ k, then where each ∆ f i R (w, n) has the value δ f i R (π) for any π ∈ Sn(B)[p; w]. To more clearly tie Theorems 6 and 7 to enumeration schemes, we introduce the following terminology: For example, the scheme for 1-2-3-avoiding permutations given in (3) has clearance 0 because of the triple (12, { 0, 0, 1 }, {2}). The clearance of an enumeration scheme describes the largest margin that the scheme could accomodate, as detailed in the following corollaries.
Corollary 9. If f is a ES-compatible permutation statistic of margin m and E is an enumeration scheme for pattern set B with clearance at least m, then F (Sn(B), f, q) may be computed in polynomial time (via enumeration scheme E).
Corollary 10. Let f1, . . . , fs be ES-compatible permutation statistics, each with margin at most m, and let f = f1, . . . , fs and q = q1, . . . , qs . Let E be a finite enumeration scheme for pattern set B with clearance at least m. Then F (Sn(B), f , q) may be computed in polynomial time (via enumeration scheme E).
Clearly corollaries 9 and 10 are impractical if there is no scheme E satisfying the conditions stated. It will be shown in Theorem 15 of Section 4 that a finite scheme of any clearance is sufficient for a polynomial time computation since a scheme can be "deepened" to create a scheme for the same pattern set with any desired clearance.

Examples of ES-compatible statistics
We now take some time to prove some well-known permutaiton statistics are indeed ES-compatible.

Copies of consecutive patterns
We first consider statistics based on the number of copies of a given consecutive pattern. Several well-studied statistics can be phrased in terms of the number of copies of certain consecutive patterns. The descent number, des(π), is the number of copies of the consecutive pattern 21. The number of double-descents, i.e., indices i so that πi > πi+1 > πi+2, is the number of copies of the consecutive pattern 321. In Subsection 5.2 we discuss the distribution for the number of peaks, i.e., indices i so that πi−1 < πi and πi > πi+1, which is the total of the number of copies of 132 and the number of copies of 231.
Theorem 11. Let σ ∈ St and f (π) be the number of copies of the (consecutive) pattern (σ, [t − 1]) in π. Then f is a ES-compatible statistic with margin t − 1.
Remark. In terms relevant to enumeration schemes, for any permutation π ∈ Sn(B)[p; w] for a prefix of length k, where f counts the number of copies of a consecutive pattern.

Copies of vincular patterns
We next consider the number of copies of a vincular pattern of the form σ1 · · · σt−1-σt. The proof will proceed similarly to that of Theorem 11. Note that the inversion number inv(π) is the number of copies of 2-1, and so is a special case of this result. Subsection 5.3 extends the results in this section to apply the major index statistic.
Theorem 12. Let σ ∈ St and let g(π) be the number of copies of the pattern (σ, [t − 2]) in π. Then g is a ES-compatible statistic with margin t − 2.
Proof. Fix σ ∈ St and let k ≥ 1. We will prove that δ g R (π) := g(π) − g(dR(π)) is determined by the length of π together with the prefix π1 · · · π k for any R ⊆ [k − t + 2]. From this it follows that g is ES-compatible with margin t − 2.
Comparing Theorems 11 and 12, one might guess the trend continues, i.e., that patterns of the form (σ, [t − 3]) for σ ∈ St are ES-compatible with margin t − 3. An extension involving partially-ordered generalized patterns, as introduced by Kitaev in [17], provides the proper generalization. For example, a copy of the pattern 124-3 ′ -3 ′′ would be witnessed by a copy of either 125-3-4 or 125-4-3. Such a statistic of the form can be seen to be ES-compatible with margin t − 2 (one less than the length of the consecutive portion).

Right-to-left statistics
A letter wi of word w is a right-to-left maximum [resp., minimum] if wi > wj [resp., wi < wj ] for all j > i. Let rtlmax(w) be the number of right-to-left maxima in w and rtlmin(w) be the number of right-to-left minima in word w. For example, if π = 28674153, we see rtlmax(π) = 4 (for π2, π4, π7 and π8) and rtlmin(π) = 2 (for π6 and π8).
In this subsection we prove the following theorem: Theorem 13. The statistics rtlmin and rtlmax are ES-compatible with margin 0.
It will be useful to have the following characterization of the rightto-left minima and maxima for a permutation, which are based solely on prefixes. The proof follows directly from the definition above and is omitted. For the remainder of the section, we will restrict ourselves to the proof that rtlmax is ES-compatible. The proof that rtlmin is ES-compatible is analogous.

Deepening Schemes
Suppose that pattern set B admits a finite enumeration scheme. The question remains whether one can find a finite enumeration scheme for B with clearance sufficient to accomodate a given ES-compatible statistic with margin m. The algorithms from [9] can be altered to ensure that any constructed scheme has clearance c if such a scheme exists. The existence of such a scheme is guaranteed in the following theorem.
Theorem 15. Suppose the pattern set B has a finite enumeration scheme E. Then for any c ≥ 0 there is a finite enumeration scheme E ′ with clearance c.
To prove Theorem 15, we will first prove a lemma regarding reversibly deletable sets.
Lemma 16. Suppose that R is a reversibly deletable set for prefix p ∈ S k with respect to B. Then R is also reversibly deletable for any permutation Proof. If R ⊆ [k] is reversibly deletable for p ∈ S k , then dR : ; dR(w ′ )] to complete our proof. By the action of dR, the word formed by the first k−|R| letters of dR(w ′ ) is exactly dR(w), and so S n−|R| (B)[dR(p ′ ); dR(w ′ )] ⊆ S n−|R| (B)[dR(p); dR(w)], and the remaining inclusions are obvious from the definitions. Thus R is reversibly deletable for p ′ .
Note that the resulting set R in Lemma 16 is not necessarily a maximal reversibly-deletable set for p. For example, recall from Equation (3) that {2} is reversibly deletable for the prefix 12 with respect to B = {1-2-3}. Lemma 16 implies that {2} is reversibly deletable for the prefix 231, although the larger set {1, 2} is also reversibly deletable for 231.
We are now ready to prove Theorem 15.
Proof of Theorem 15. Let E be a finite enumeration scheme for B, with depth K. We will construct a scheme E ′ with clearance c ≥ 1. If c = 0, then E will suffice since any enumeration scheme has clearance 0. We will construct a (finite) set E ′ by creating a triple (p, G(p), R(p)) ∈ E ′ for each p ∈ K+c k=0 S k . For p = ǫ, let G(ǫ) = ∅ and R(ǫ) = ∅, so we see E ′ satisfies criterion 1 in Definition 3. For p = ǫ, let G(p) be a basis of gap vectors for p with respect to B, which may be constructed according to the algorithm described in [9].
We now construct R(p). If |p| < K+c, then let R(p) = ∅. If |p| = K+c, then let p ′ be the longest prefix p ′ = red(p1 · · · ps) such that there is a triple (p ′ , G ′ , R ′ ) in the original scheme E. Then |p ′ | ≤ K, and since no child of p ′ has a triple in E (by maximality of p ′ ) we know R ′ is nonempty. By Lemma 16, R ′ is also a reversibly deletable set for p, so we let R(p) = R ′ . Furthermore, R(p) = R ′ ⊆ [K], so |p| − max R(p) ≥ c and so we see that E ′ has clearance c.
We now verify that E ′ satisfies the criteria to be an enumeration scheme for B, as outlined in Definition 3. Each triple (p, G(p), R(p)) ∈ E ′ is constructed so that G(p) is a basis of gap vectors for p with respect to B and so that R(p) is a reversibly deletable set for p with respect to B. As previously mentioned, E ′ satisfies criterion 1 since (ǫ, ∅, ∅) ∈ E ′ . If R(p) = ∅, then |p| < K + c and so E ′ contains a triple (p ′ , G(p ′ ), R(p ′ )) for each child p ′ since E ′ contains a triple for every permutation of length |p| + 1. Therefore E ′ satisfies criterion 2a. If R(p) = ∅, then |p| = K + c and E ′ contains a triple (p, G(p), R(p)) forp = d R(p) (p) since E ′ contains a triple for every permutation with length less than K + c. Therefore E ′ satisfies criterion 2b.
It perhaps goes without saying that E ′ from the proof of Theorem 15 is not usually minimal, neither in terms of number of triples nor the encoded recurrence. For example, the proof constructs the following scheme E ′ with clearance 1 for B = {1-2-3} based on the scheme E in (3): In practice, therefore, it is better to alter the automated-discovery algorithms from [9] to construct ab initio a reversibly deletable set for each prefix p so that only sets R ⊆ [|p| − c] are considered. This change guarantees the clearance criterion holds, and Theorem 15 guarantees that the algorithm will succeed in finding a finite scheme whenever the algorithms would succeed without the clearance conditions. Such an approach yields the following scheme with clearance 1 for B = {1-2-3}.
Note in particular that the children of 21 do not need to appear in a scheme with clearance 1, since 21 has a nonempty reversibly deletable set which respects the clearance requirement. We close this section with a corollary combining Theorem 15 and Corollary 9.
Corollary 17. If f is a ES-compatible permutation statistic of margin m and E is an enumeration scheme for pattern set B, then F (Sn(B), f, q) may be computed in polynomial time.

Applications
We wish to take some time in this section to highlight some of the less obvious applications of the results above. Studying statistics over sets Sn(B) is relatively new, so much of what follows only scratches the surface. In what follows we use the common notation that (σ)(π) denotes the number of copies of vincular pattern σ in permutation π.

Implementation
The above algorithms have been implemented in a Maple package Statter. This package supercedes the package gVatter accompanying [9] and can perform the following tasks. 3. Read a given enumeration scheme to get the distribution of multistatistics given above.
A fuller investigation of the descent statistic over Sn(1-2-3), particularly its connection to Dyck paths, is given in [5].
The package Statter is available for download from the author's homepage.

Peaks and Valleys
A peak of a permutation π is a letter πi such that πi−1 < πi > πi+1. Let peak(π) be the number of peaks of π. Therefore peak(π) is the total number of copies of the consecutive patterns 132 and 231 in π. Likewise a valley is a letter πi such that πi−1 > πi < πi+1. If vall(π) is the number of valleys of π, then again we see that vall(π) is the total number of copies of the consecutive patterns 213 and 312 in π. Therefore we see that peak(π) and vall(π) are ES-compatible statistics.
Remark. The proof above implies that vall is equally distributed over Sn(1-2-3) and Sn(1-3-2) even when restricting further to those permutations with a given set of left-to-right minima. Letting LRmax(π) be the set of indices which are left-to-right minima for π, then for any S ⊆ [n].
For completeness we will comment that F (Sn(1-3-2), peak, q) appears in OEIS as A091894, suggesting the following correspondence. A Dyck path of semilength n is a lattice path from (0, 0) to (n, 0) composed of steps U = (1, 1) and D = (1, −1) which never goes below the x-axis. We will write Dyck paths as words Theorem 19. The number of permutations in Sn(1-3-2) with k peaks equals the number of Dyck paths of semilength n with k occurrences of the subfactor DDU .
Proof. Krattenthaler provides a bijection, Φ, in [18] from Sn(1-3-2) to the set of Dyck paths of semilength n. In that bijection, a permutation with k valleys maps to a Dyck path with k subfactors DDU . The remainder of this proof outlines this bijection.
Observe that if ltrmin(π) = k, then Φ(π) = U a 1 D b 1 U a 2 D b 2 · · · U a k D b k for ai > 0 and bi > 0. Therefore each left-to-right minima beyond π1 corresponds to a DU subfactor in Φ(π) . Furthermore if adjecent letters πi and πi+1 are both left-to-right minima, then the corresponding string of D's in the image is only a single D. Therefore DDU subfactors correspond to non-adjacent left-to-right minima, which by the claim from Theorem 18 correspond to valleys in the permutation.
The distributions from Theorems 18 and 19 are given in Tables 1 and  2. This data was generated by Statter.
A complete classification of the classical patterns according to peak-Wilf-equivalence is forthcoming in [10].
Therefore Corollary 10, Theorem 12 imply the following special case: Corollary 20. If B is a set of patterns such that B r := {τ r : τ ∈ B} admits a finite enumeration scheme, then F (Sn(B), maj, q) can be computed via enumeration scheme.
Distributions of the major index over avoidance sets Sn(τ ) for classical patterns τ ∈ S3 are studied by Dokos et al. in [15].

Conclusion and Future Work
The techniques above face the same limitations as enumeration schemes. In short, the recurrences produced are often complicated and do not translate nicely into generating functions. The methods discussed in Chapter 5 of [7] make some progress toward converting schemes to generating functions, but cannot account for the full range of recurrences that schemes can produce.
Further, not all sets of vincular patterns B admit a finite enumeration scheme, and there is no full characterization predicting whether a given B will admit a finite scheme. Data on how many sets B do admit a small scheme are available in [9].
We note that it should be possible to adapt the insertion encodings from [1,26] toward the purpose of computing F (Sn(B), f, q) for permutation statistics f based on counting copies of consecutive patterns. The insertion encoding offers two advantages over enumeration schemes: (1) the recurrences developed lead directly to generating functions, and (2) there are more [sets of] classical patterns which admit regular insertion encodings than finite enumeration schemes. The current state of insertion encodings, however, cannot handle vincular patterns, however. Such tools could a very helpful in classification of patterns under statistic-Wilfequivalence for various statistics.