Counting occurrences of 132 in an even permutation

We study the generating function for the number of even (or odd) permutations on n letters containing exactly $r\gs0$ occurrences of 132. It is shown that finding this function for a given r amounts to a routine check of all permutations in $S_{2r}$.


Introduction
Let [n] = {1, 2, . . . , n} and S n denote the set of all permutations of [n]. We shall view permutations in S n as words with n distinct letters in [n]. A pattern is a permutation σ ∈ S k , and an occurrence of σ in a permutation π = π 1 π 2 · · · π n ∈ S n is a subsequence of π that is order equivalent to σ. For example, an occurrence of 132 is a subsequence π i π j π k (1 ≤ i < j < k ≤ n) of π such that π i < π k < π j . We denote by τ (π) the number of occurrences of τ in π, and we denote by s r σ (n) the number of permutations π ∈ S n such that σ(π) = r.
In the last decade much attention has been paid to the problem of finding the numbers s r σ (n) for a fixed r ≥ 0 and a given pattern τ (see [1,2,3,5,6,7,10,11,14,15,16,17,18,19]). Most of the authors consider only the case r = 0, thus studying permutations avoiding a given pattern. Only a few papers consider the case r > 0, usually restricting themselves to patterns of length 3. Using two simple involutions (reverse and complement ) on S n it is immediate that with respect to being equidistributed, the six patterns of length three fall into the two classes {123, 321} and {132, 213, 231, 312}. Noonan [13] proved that s 1 123 (n) = 3 n 2n n − 3 .
A general approach to the problem was suggested by Noonan and Zeilberger [14]; they gave another proof of Noonan's result, and conjectured that  In this paper, as a consequence of [12], we suggest a new approach to this problem in the case of even (or odd) permutations where σ = 132, which allows one to get an explicit expression for e r 132 (n) for any given r. More precisely, we present an algorithm that computes the generating functions E r (x) = n≥0 e r 132 (n)x n and O r (x) = n≥0 o r 132 (n)x n for any r ≥ 0. To get the result for a given r, the algorithm performs certain routine checks for each element of the symmetric group S 2r . The algorithm has been implemented in C, and yields explicit results for 0 ≤ r ≤ 6.

Recall definitions and preliminary results
To any π ∈ S n we assign a bipartite graph G π in the following way. The vertices in one part of G π , denoted V 1 , are the entries of π, and the vertices of the second part, denoted V 3 , are the occurrences of 132 in π. Entry i ∈ V 1 is connected by an edge to occurrence j ∈ V 3 if i enters j. For example, let π = 57614283, then π contains 5 occurrences of 132, and the graph G π is presented on Figure 1. We denote by G n π the connected component of G π containing entry n. Let π(i 1 ), . . . , π(i s ) be the entries of π belonging to G n π , and let σ = σ π ∈ S s be the corresponding permutation. We say that π(i 1 ), . . . , π(i s ) is the kernel of π and denote it ker π, σ is called the shape of the kernel, or the kernel shape, s is called the size of the kernel, and the number of occurrences of 132 in ker π is called the capacity of the kernel. For example, for π = 57614283 as above, the kernel equals 14283, its shape is 14253, the size equals 5, and the capacity equals 4.
We say that ρ is a kernel permutation if it is the kernel shape for some permutation π. Evidently ρ is a kernel permutation if and only if σ ρ = ρ. Let ρ ∈ S s be an arbitrary kernel permutation. We denote by S(ρ) the set of all the permutations of all possible sizes whose kernel shape equals ρ. For any π ∈ S(ρ) we define the kernel cell decomposition as follows. The number of cells in the decomposition equals s(s + 1). Let ker π = π(i 1 ), . . . , π(i s ); the cell C ml = C ml (π) for 1 ≤ l ≤ s + 1 and 1 ≤ m ≤ s is defined by where i 0 = 0, i s+1 = n + 1, and π(0) = 0 for any π. If π coincides with ρ itself, then all the cells in the decomposition are empty. An arbitrary permutation in S(ρ) is obtained by filling in some of the cells in the cell decomposition. A cell C is called infeasible if the existence of an entry a ∈ C would imply an occurrence of 132 that contains a and two other entries x, y ∈ ker π. Clearly, all infeasible cells are empty for any π ∈ S(ρ). All the remaining cells are called feasible; a feasible cell may, or may not, be empty. Consider the permutation π = 67382451. The kernel of π equals 3845, its shape is 1423. The cell decomposition of π contains four feasible cells: Figure 2). All the other cells are infeasible; for example, C 32 is infeasible, since if a ∈ C 32 , then aπ ′ (i 2 )π ′ (i 4 ) is an occurrence of 132 for any π ′ whose kernel is of shape 1423. Given a cell C ij in the kernel cell decomposition, all the kernel entries can be positioned with respect to C ij . We say that x = π(i k ) ∈ ker π lies below C ij if ρ(k) < i, and above C ij if ρ(k) ≥ i. Similarly, x lies to the left of C ij if k < j, and to the right of C ij if k ≥ j. As usual, we say that x lies to the southwest of C ij if it lies below C ij and to the left of it; the other three directions, northwest, southeast, and northeast, are defined similarly. Let us define a partial order ≺ on the set of all feasible cells by saying that C ml ≺ C m ′ l ′ = C ml if m ≥ m ′ and l ≤ l ′ .
(ii) Let C ml and C ml ′ be two nonempty feasibly cells such that l < l ′ . Then for any pair of entries a ∈ C ml , b ∈ C ml ′ , one has a > b.
(iii) Let C ml and C m ′ l be two nonempty feasibly cells such that m < m ′ . Then any entry a ∈ C ml lies to the right of any entry b ∈ C m ′ l .
Let π be any permutation with a kernel permutation ρ, and assume that the feasible cells of the kernel cell decomposition associated with ρ are ordered linearly according to ≺, C 1 , C 2 , . . . , C f (ρ) . Let d j be the size of C j . For example, let π = 67382451 with kernel permutation ρ = 1423, as on Figure 2, We denote by l j (ρ) the number of the entries of ρ that lie to the north-west from C j or lie to the south-east from C j . For example, let ρ = 1423, as on Figure 2, then l 1 (ρ) = 3, l 2 (ρ) = 2, l 3 (ρ) = 3, and l 4 (ρ) = 4. Clearly, l 1 (ρ) = s(ρ) − 1 and l f (ρ) = s(ρ) for any nonempty kernel permutation ρ.
For any permutation π with a kernel permutation ρ, Proof. To verify this formula, let us count the number of occurrences of the pattern 21 in π. There four possibilities for an occurrence of 21 in π. The first possibility is an occurrence occurs in one of the cells C j , so in this case there are j=1 21(C j ) occurrences. The second possibility is an occurrence occurs in ρ, so there are 21(ρ) occurrences. The third possibility is an occurrence of two elements which the first belongs to ρ and the second belongs to C i , so there are f (ρ) j=1 d j l j (ρ) (see Theorem 2.2) occurrences. The fourth possibility is an occurrence of two elements which the first belongs to C i and the second belongs to C j where i < j (Theorem 2.2 yields every entry of C i is greater than every entry of C j for all i < j), so there are 1≤i<j≤f (ρ) d i d j occurrences. Therefore, by Lemma 1.1 we have sign(π) = (−1) We We denote the set of all binary vectors of length n by B n . For any v ∈ B n , we define Let ρ be any kernel permutations, we denote by X ρ a [respectively; Y ρ a ] the set of all the binary vectors Let ρ be any kernel permutations and v = (v 1 , v 2 , . . . , v f (ρ) ) ∈ B f (ρ) , we denote by S(ρ; v) the set of all permutations of all sizes with kernel permutation ρ such that the corresponding cells C j satisfy (−1) dj = (−1) vj , in such a context v is called a length argument vector of ρ. By definitions, the following result holds immediately.
Lemma 2.4. For any kernel permutation ρ, Let ρ be any kernel permutations and let the set of all permutations in S(ρ; v) such that the corresponding cells C j satisfy sign(C j ) = 1 if and only if u j = 0, in such a context u is called a signature argument vector of ρ. By Lemma 2.4, the following result holds immediately.
Lemma 2.5. For any kernel permutation ρ, By definitions, the following result holds immediately.

Main Theorem
The main result of this note can be formulated as follows. Denote by K the set of all kernel permutations, and by K t the set of all kernel shapes for permutations in S t . Let ρ be any kernel permutation, for any a, b ∈ {0, 1} and any r 1 , . . . , r f (ρ) we define Proof. Let us fix a kernel permutation ρ ∈ K 2r+1 , a length argument vector v = (v 1 , . . . , v f (ρ) ) ∈ X (−1) a (ρ), and a signature argument vector u = (u 1 , . . . , Recall that the kernel ρ of any π contains exactly c(ρ) occurrences of 132. The remaining r − c(ρ) occurrences of 132 are distributed between the feasible cells of the kernel cell decomposition of π. By Theorem 2.2, each occurrence of 132 belongs entirely to one feasible cell, and the occurrences of 132 in different cells do not influence one another.
By this proposition, it suffices to search only permutations in S 2r . Below we present several explicit calculations.
3.1. The case r = 0. Let us start from the case r = 0. Observe that Theorem 3.1 remains valid for r = 0, provided the left hand side of Equation 3.1 for a = b = 0 is replaced by H r (0, 0) − 1 = 1 2 (E r (x) + E r (−x)) − 1; subtracting 1 here accounts for the empty permutation. So, we begin with finding kernel shapes for all permutations in S 1 . The only shape obtained is ρ 1 = 1, and it is easy to see that s(ρ 1 ) = 1, c(ρ 1 ) = 0, f (ρ 1 ) = 2,  0). Out present aim to find explicitly E 0 (x) and O 0 (x), thus we need the following notation. We define ), for all r ≥ 0. Therefore, by subtracting (respectively; adding) Equation 3
Proof. Let us define an order on the set B n , we say the vector v < u if there exists j such that u j + v j = 1, and u i = v i for all i = j. We say the 2 n vectors u 1 , · · · , u 2 n of B n are satisfy the ℓ-property if 0 = (0, 0, . . . , 0) = u 1 < u 2 < · · · < u 2 n , and we say the 2 n vectors u 1 , · · · , u 2 n are satisfy the c-property if the vectors  (0, 0, . . . , 0) and v 1 < · · · < v 2 m+1 , so the ℓ-property holds for m + 1. Hence, by induction on m we get that there exists an order of the vector of B n with the c-property. Now we are ready to prove the lemma. Without loss of generality we can assume that (0, 0, . . . , 0) ∈ Y n a (which means a = 1); otherwise it is enough to replace a by −a. Let x 1 , . . . , x 2 n all the vectors of B n with the c-property. Using (0, 0, . . . , 0) ∈ Y n a together with the c-property we get that x 2i−1 ∈ Y n a and x 2i ∈ Y n −a for all i = 1, 2, . . . , 2 n−1 . Therefore, for all i = 1, 2, . . . , 2 n−1 , where y p = (x 2p 2 , . . . , x 2p n ) for all p = 1, 2, . . . , 2 n−1 , and v = (v 2 , v 3 , . . . , v n ). Using the c-property for x 1 , . . . , x 2 n we get that the vectors y 1 , . . . , y 2 n−1 are satisfy the c-property in B n−1 . Hence by induction on n (by definitions, the lemma holds for n = 1), we get that the expression equals to a n j=1 g r (j).
As a remark, the vector (0, 0, . . . , 0) ∈ Y ρ zρ(v) if and only if z ρ (v) = 1 for any kernel permutation ρ and vector v. Therefore, by Theorem 3.1 and Lemma 4.1 we get the following result. As a remark, the above theorem yields two equations (for a = 0 and a = 1) that are linear on M r (x) and M r (−x). So, Theorem 4.2 provides a finite algorithm for finding M r (x) for any given r ≥ 0, since we have to consider all permutations in S 2r+1 , and to perform certain routine operations with all shapes found so far. Moreover, the amount of search can be decreased substantially due to the following proposition which holds immediately by Proposition 3.2 and Theorem 4.2. By this proposition, it is sufficient to search only permutations in S 2r . Besides, using Theorem 4.2 and the case r = 0 together with induction on r we get the following result.
Theorem 4.4. M r (x) is a rational function on x and √ 1 − 4x 2 for any r ≥ 0.
In view of our explicit results, we have even a stronger conjecture.
Conjecture 4.5. For any r ≥ 1, there exist polynomials A r (x), B r (x), C r (x), and D r (x) with integer coefficients such that