Enumerating Permutations by their Run Structure

Motivated by a problem in quantum field theory, we study the up and down structure of circular and linear permutations. In particular, we count the length of the (alternating) runs of permutations by representing them as monomials and find that they can always be decomposed into so-called `atomic' permutations introduced in this work. This decomposition allows us to enumerate the (circular) permutations of a subset of the natural numbers by the length of their runs. Furthermore, we rederive, in an elementary way and using the methods developed here, a result due to Kitaev on the enumeration of valleys.


Introduction
Let us adopt the following notation for integer intervals: . n]. Let S ⊂ N contain n elements. A permutation of S is a linear ordering p 1 , p 2 , . . . , p n of the elements of S. We denote the set of all n! permutations of S by S S and by S n if S = [n]. It is customary to write the permutation as the word p = p 1 p 2 · · · p n and we can identify the permutation p with the bijection p(i) = p i .
Replacing the linear ordering by a circular one, we arrive at the notion of circular permutations of S, i.e., the arrangments of the elements p 1 , p 2 , . . . , p n of S around an oriented circle (turning the circle over produces a different permutation). In this case one can always choose p 1 to be the smallest element of S so that p 1 = 1 if S = [n]. It is clear that the set C S of all circular permutations of S contains (n − 1)! elements; if S = [n], we denote it by C n . Circular permutations may be written as words of the form p =ṗ 1 p 2 · · ·ṗ n , where we emphasize the circular symmetry by a dot above outermost characters of the word. 1 Moreover, due to the circular symmetry we can define p(0) . = p(n) and p(n + 1) . = p (1). Let us introduce yet another class of permutations. We denote by A ± S ⊂ S S the rising and falling 'atomic' permutations 2 of an n-element subset S ⊂ N. We define A + S as those permutations that, when written as a word, begin with the smallest and end with the largest element of S. The falling atomic permutations A − S are reversed rising atomic permutations, i.e., they begin with the largest element of S and end with the smallest. Naturally, the cardinality of A ± S is (n − 2)!. If S = [n], we write A ± n and see that it is the set of permutations of the form 1 · · · n, i.e., p 1 = 1 and p n = n, or n · · · 1, i.e., p 1 = n and p n = 1, respectively.
We say that i is a descent of p if p(i) > p(i+1) and, conversely, that it is an ascent of a (circular) permutation p if p(i) < p(i + 1). For example, the permutation 52364178 has the descents 1, 4, 5 and the ascents 2, 3, 6, 7 whereas the circular permutation14536782 has the descents 3, 7, 8 and the ascents 1, 2, 4, 5, 6. We can collect all the descents of a (circular) permutation p in the descent set It is an elementary exercise in enumerative combinatorics to count the number of permutations of [n] whose descent set is given by a fixed S ⊆ [n − 1]. Let S = (1.1) see, for example, [3,Theorem 1.4]. This result is easily adapated to circular permutations.
Related to the notions of ascents and descents are the concepts of peaks and valleys: A peak occurs at position i if p(i − 1) < p(i) > p(i + 1), whereas a valley occurs in the opposite situation p(i − 1) > p(i) < p(i + 1). The peaks and valleys of a (circular) permutation p split it into runs, also called sequences or alternating runs.
We define a run of a (circular) permutation p to be an interval [i .
. j] such that p(i) ≷ p(i + 1) ≷ · · · ≷ p(j) is a monotone sequence, either increasing or decreasing, and so that it cannot be extended in either direction, i.e., it starts and ends at peaks, valleys and, in the case of linear permutations, at the outermost elements of a permutation; its length is defined to be j − i. For example, the permutation 5 2 3 6 [7 . . 9], of lengths 2, 1, 3, 2. Representing these runs by their image under the permutation, they are more transparently written as 5 2 , 2 3 6 , 6 4 1 , 1 7 8 and 1 4 5 , 5 3 , 3 6 7 8 , 8 2 1 respectively. The runs of (circular) permutations can also be neatly represented as directed graphs as shown in Figure 1. In these graphs the peaks and valleys correspond to double sinks and double sources.
Motivated by a problem in mathematical physics [5] (see also section 6), we are interested in the following issue, which we have not found discussed in the literature. Disregarding the ordering of the run lengths, one obtains a map from S n , C n or any other set of permutations to the set of partitions of n into strictly positive integers. Thus, 52364178 and 36724851 map to the partition 1 + 2 + 2 + 2 of 7, while14536782 anḋ 13 4 5 2 7 86 both correspond to the partition 1 + 2 + 2 + 3 of 8. Our interest is in the inverse map: given a partition Q of n, we ask for the number of permutations (in the set of permutations considered) corresponding to Q in the above sense; we say that Q is the run structure of these permutations.
The literature we have found focuses on issues such as the number of permutations in which all runs have length one, e.g., André's original study [2], or on the enumeration question where the order of run lengths is preserved, so obtaining a map to compositions, rather than partitions, of n. See, for example, [4], which studies this for the ordinary (noncircular) permutations. In principle our question could be obtained by specialising this more difficult problem, but here we take a direct approach. Another alternative approach not followed here, would be to take (1.1) as a starting point and summing over all descent sets corresponding to a particular run structure. However, this would neither be straightforward from the theoretical side, nor would it make for efficient computation. By contrast, our direct method was designed to facilitate computation; for the application in [5] calculations were taken up to n = 65 using exact integer arithmetic in Maple™ [8].
Sections 2, 3 and 4 deal, respectively, with the enumeration of the run structure of atomic, circular and linear permutations. Using a suitable decomposition, this is accomplished in each case by reducing the enumeration problem to that for atomic permutations. In section 5 we apply and extend the methods developed in the preceeding sections to enumerate the valleys of permutations, thereby reproducing a result of Kitaev [6]. Finally, in section 6, we discuss the original motivation for our work and other applications.

Atomic permutations
We begin by considering the enumeration of atomic permutations according to their run structure. Observe that any p ∈ A + n can be extended to a permutation in A + n+1 by replacing n with n + 1 and reinserting n in any position after the first and before the last. Thus, 1 3 4 2 5 can be extended to 1 5 3 4 2 6, 1 3 5 4 2 6, 1 3 4 5 2 6 or 1 3 4 2 5 6. Every permutation in A + n+1 arises in this way, as can be seen by reversing the procedure. The effect on the run lengths can be described as follows. . . ] in infinitely many variables x 1 , x 2 , . . . and with integer coefficients. That is, we express a partition Q = Q 1 + Q 2 + · · · + Q m as x Q1 x Q2 · · · x Qm (e.g., the partition 1 + 2 + 2 + 3 of 8 is written as x 1 x 2 2 x 3 ). Now, let Q be a partition and X the corresponding monomial. To this permutation there correspond Z A ± (Q) permutations in A ± n which can be extended to permutations in A ± n+1 in the manner described above. Introducing the (formally defined) differential operator we can describe this extension in terms of the action of D on X. We say that D 0 is the degree-preserving part of D; it represents the case 1 of increasing the length of a run: the differentiation ∂/∂x i removes one of the runs of length i and replaces it by a run of length i + 1, keeping account of the number of ways in which this can be done. Similarly, case 2 of splitting a run into 3 parts is represented by the degree-increasing part D + . For example, each of the 7 atomic permutations corresponding to the partition 1 + 1 + 3 can be extended as , each can be extended to two atomic permutations corresponding to the partitions 1 + 2 + 3, one corresponding to 1 + 1 + 4 and one to 1 + 1 + 1 + 1 + 2.
Therefore, starting from the trivial partition 1 of 1, represented as x 1 , we can construct a recurrence relation for polynomials A n = A n (x 1 , x 2 , . . . , x n ) which, at every step n ≥ 1, gives the number of atomic permutations Z A ± (Q) for each partition Q of n as the coefficients of the corresponding monomial in A n . That is, we define and, for any given partition Q of n, we can obtain Z A ± (Q) from the relation where the sum is over all partitions Q of n and Q(i) denotes the multiplicity of i in the partition Q. We summarize these results in the following proposition: of rising or falling atomic permutations of length n − 1 corresponding to a given run structure (i.e., a partition Q of n), is determined by the polynomial A n .
Note that atomic permutations always contain an odd number of runs and thus Z A ± (Q) is zero for even partitions Q. It will prove useful to combine all generating functions A n into the formal series which can be expressed compactly as the exponential The first few A n are given by from which we can read off that there is 1 permutation in A ± 6 corresponding to the trivial partition 5 = 5, 7 corresponding to the partition 5 = 1 + 1 + 3, 11 corresponding to 5 = 1 + 2 + 2 and 5 corresponding to 5 = 1 + 1 + 1 + 1 + 1. As a check, we note that 1 + 7 + 11 + 5 = 24, which is the total number of elements of A ± 6 ; similarly, the coefficients in the expression for A 6 sum to 120, the cardinality of A ± 7 . A direct check that the coefficients in A n sum to (n − 1)! for all n will be given in the last paragraph of section 5. The first degree term A (1) n of A n is x n as can be seen by a trivial induction using A (1) n−1 , which follows from the recurrence relation (2.2). Therefore Z A ± (n) = 1. For A (k) n with k > 1 also the effect of D + has to be taken into account, complicating things considerably. Nevertheless, the general procedure is clear: n can be obtained as Here one can make use of the following relation. Applying D 0 repeatedly to any monomial x i1 x i2 · · · x i k of degree k yields, as a consequence of the Leibniz rule, This observation provides the means to determine the third degree term A

.3) and thus
This equation can be further simplified to yield n of the polynomial A n , n ≥ 3, is given by The equation (2.4) for the third degree term A n can be rewritten into a formula for Z A ± (Q 1 + Q 2 + Q 3 ), i.e., the number of permutations of [n + 1] that start with 1, end with n + 1 and have three runs of lengths Q 1 , Q 2 , Q 3 , by changing the first sum to a sum over i, j, k ∈ {Q 1 , Q 2 , Q 3 }. In particular, this gives rise to three integer series for the special cases with n ∈ N.
The first series gives the number of atomic permutations with three runs of equal length n. It does not appear to be known in the literature nor can it be found in the OEIS [9] and the authors were not able to express it in a closed form. For the second series, however, a simple closed form can be found: is the number of atomic permutations in A ± 2n+2 with two runs of length n. One may understand this directly: there are 2n n permutations in which the length 1 run is between the others and 2n n − 1 in which it is either first or last. The third series, Z A ± (1 + 1 + n), i.e., the number of atomic permutations in A ± n+3 with two runs of length 1, is given by the odd numbers bigger than 3: Z A ± (1 + 1 + n) = 2n + 1 = 5, 7, 9, 11, 13, 15, . . . , (n ≥ 2).
Observe that terms of the form x n 1 in A n encode alternating permutations, which were already investigated by André in the 1880's [1]. As a consequence of his results, we find that the alternating atomic permutations are enumerated by the secant numbers S n , the coefficients of the Maclaurin series of sec can only be produced through an application of D on

Circular permutations
The methods developed in the last section to enumerate atomic permutations can also be applied to circular permutations. Indeed, any circular permutation in C n−1 can be extended to a permutation in C n by inserting n at any position after the first (e.g., 14 5 32 can be extended to16 4 5 32,14 6 5 32,14 5 6 32,14 5 3 62 or14 5 3 26). As in the case of atomic permutations, this extension either increases the length of a run or splits a run into three runs. Namely, we can increase the length of one run by inserting n at the end or the penultimate position of an increasing run or we can split a run of length i + j ≥ 2 into three runs of lengths i, j and 1 by inserting n after i elements of an increasing run or after i + 1 elements of a decreasing run.
Similar to the polynomials A n we can introduce polynomials C n representing the run structures of all elements of C n : giving in particular from which we can read off that there are 2 permutations in C 5 corresponding to 5 = 4+1, 6 corresponding to the partition 5 = 3 + 2 and 16 corresponding to 5 = 2 + 1 + 1 + 1.
As a check, we note that 6 + 16 + 2 = 24, which is the total number of elements of C 5 ; similarly, the coefficients in the expression for C 6 sum to 120, the cardinality of C 6 . More on this can be found in the last paragraph of section 5.
We can obtain Z C (Q) as the coefficient of the monomial corresponding to Q in C n , i.e., which leads us to a result analogous to proposition 2.1: Proposition 3.1. The number Z C (Q) of circular permutations of length n corresponding to a given run structure, is determined by the polynomial C n .
Note that circular permutations, exactly opposite to atomic permutations, always contain an even number of runs and thus Z C (Q) is zero for odd partitions Q.
The enumeration of circular and atomic permutations is closely related. In fact, introducing a generating function C as the formal series one can show the following: Proposition 3.2. The formal power series C is the square of a formal series A; namely, Proof. This may be seen in various ways, but the most convenient is to study the first-order partial differential equation (in infinitely many variables) satisfied by C.
As a consequence also the polynomials A n and C n are related via It then follows that the second degree part of C n is given by and, applying (2.4), that the fourth degree part can be written as Similar to the atomic permutations, we find that the alternating circular permutations satisfy (cf. [2, §41]) 1, 2, 16, 272, 7936, 353792, . . . (n ≥ 1, OEIS series A000182) and also Z C 2 + 2n−3 i=1 1 = T n , where T n are the tangent numbers, the coefficents of the Maclaurin series of tan x = T 1 x 1 + T 2 x 3 /3! + T 3 x 5 /5! + · · · . Furthermore, from (3.4) we find the relation which can be traced back to tan x = sec 2 x.
To conclude this section, we note that the argument of proposition 3.2 proves rather more: namely, that exp(λD) defines a ring homomorphism from C[x 1 , x 2 , . . . ] to the ring of formal power series C[[x 1 , x 2 , . . . ]]. This observation can be used to accelerate computations: for example, the fact that which reduces computation of A n+3 = D n+2 x 1 to the computation of D n x 3 . Once A is obtained, we may of course determine C by squaring.

Linear permutations
In the last section we studied the run structures of circular permutations C n and discovered that their run structures can be enumerated by the polynomials A n . One might ask, what the underlying reason for this is. Circular permutations of [n] have the same run structure as the linear permutations of the multiset {1, 1, 2, . . . , n} which begin and end with 1. These permutations can then be split into two atomic permutations at the occurence of their maximal element. For example, the circular permutatioṅ 14 5 32 can be split into the two atomic permutations 1 4 5 of {1, 4, 5} and 5 3 2 1 of {1, 2, 3, 5}. This also gives us the basis of a combinatorical argument for the fact that C = A 2 . Similarly it is in principle possible to encode the run structures of any subset of permutations using the polynomials A n . The goal of this section is to show how this may be accomplished for S S for any S ⊂ N. Before we discuss the decomposition of the run structure polynomials for all elements of S S in terms of the A n , it will prove useful to discuss the special subset of permutations that start with their largest element N ∈ S, i.e., those of the form N · · · . Corollary 4.1. Let N = max S of a subset S ∈ N of n + 1 elements. The run structure of the permutations of the form N · · · is enumerated by where the sum is over all partitions Q = Q 1 + Q 2 + · · · of n, |Q| is the number of parts of partition, ord Q is the symmetry order of the parts of Q (e.g., for Q = 1 + 1 + 2 + 3 + 3 we have ord Q = 2!2!) and n Q is the multinomial with respect to the parts of Q. It follows that the generating function for the X n is where we take X 0 = 1 by convention.
Proof. For each partition Q of n we can perform the following steps: 1. Choose subsets of S \ {N } of sizes determined by the parts of the partition; we denote the set of these subsets by R. There are n Q ways to do this thus giving the multinomial factor in (4.1).
2. Starting with an empty word w, perform the following iteration until the set R is empty a) select from R the set having the smallest minimal element (at odd steps of the iteration) or the one having the largest maximal element (at even steps), b) construct a word of the elements of the selected set such that it ends with smallest (at odd steps) elements or ends with the largest (at even steps), c) add the resulting word to the right of w to obtain the new word w, d) remove the selected set from R.

Construct the word N w.
The word constructed in the final step is a permutation consisting of atomic permutations as determined by the chosen partition. All permutations of the type considered here can be constructed by the procedure above. However, if two or more parts of the partition are the same, the same permutations is produced multiple times, thus leading to an overcounting. Namely, if the part i of the partition Q occurs Q(i) times, the same permutations will occur Q(i)! times because there are Q(i)! identical arrangements of atomic permutations. This accounts for the (ord Q) −1 factor, thus justifying the formula (4.1).
To establish the formula for X , we note that Faà di Bruno's formula [10, 1.4.13] together with (4.1) implies that from which the result follows immediately.
Note that X n and X also enumerate the run structure of permutations of the form · · · N as can be seen by a simple reflection. Moreover X also encodes the trivial case of permutations of a single element set which has no runs and is represented through X 0 . Using this result, it is easy to establish analog formulas to (4.1) and (4.2) for all permutations S S of S.
with P 0 = 1 and the generating function for the P n is

4)
Proof. Let us split the problem in half: Similar to splitting a circular permutation at its largest element into two atomic permutations which yielded the relation C = A 2 (cf. , proposition 3.2 and the argument in the first paragraph of this section), we can split any permutation at its largest element N into (up to) two permutations of the form · · · N (permutations ending with N ) and N · · · (permutations starting with N ). Note that one obtains only one the two possibilities if N is outermost in the original permutation. Hence we have reduced the problem to the case discussed in the corollary above. In fact, as the binomial n m is number of partitions of the set S \ {N } into two sets of size m and n − m; this gives (4.2). Then we may again apply Faà di Bruno's formula [10, 1.4.13] to find (4.3).
As in the last two sections we can also deduce the following: To conclude this section, we remark that the first few P n are given by Expanding the A k and writing the P n instead in terms of x i , we obtain from these which show no obvious structure, thereby making proposition 4.2 that much more remarkable.

Counting valleys
Instead of enumerating permutations by their run structure, we can count the number of valleys of a given (circular) permutation. Taken together, the terms C n involving a product of 2k of the x i relate precisely to the circular permutations C n with k valleys. Since any circular permutation in C n can be understood as a permutation of [3 . . n + 1] with a prepended 1 and an appended 2 (cf. beginning of section 4), C n may also be used to enumerate the valleys of ordinary permutations of [n − 1]. Namely, terms of C n+1 with a product of 2(k + 1) variables x i relate to the permutations of S n with k valleys (i.e., terms of P n+1 which are a product of 2k of the x i ).
Let V (n, k) count the number of permutations of n elements with k valleys. Then we see that the generating function for V (n, k) for each fixed n ≥ 1 is and we define K 0 (κ) . = 1. The first few K n are which coincide with the results in [11]. In particular, the constants are clearly the powers of 2, the coefficients of κ give the sequence A000431 of the OEIS [9] and the coefficients of κ 2 are given by the sequence A000487. Likewise, the coefficients of κ 3 may be checked against the sequence A000517. In fact, the same polynomials appear in André's work, in which he obtained a generating function closely related to (5.1) below; see [2, §158] (his final formula contains a number of sign errors, and is given in a form in which all quantities are real for κ near 0; there is also an offset, because his polynomial A n (κ) is our K n−1 (κ)).
Proposition 5.1. The bivariate generating function, i.e., the generating function for arbitrary n, is and is given in closed form by This result was found by Kitaev [6] and in the remainder of this section we will show how it may be derived from the recurrence relation (3.1) of C n . To this end, we first note that C n+1 satisfies the useful scaling relation .
(1 − νκ) ∂ K ∂ν + 2κ(κ − 1) where Φ(p) is a product over the runs of p, with each run of length r contributing a factor y r . Owing to the restriction p(2) < p(n), precisely half of the circular permutations are admitted, and so κ n = 1 2 C n (y 1 , y 2 , . . . , y n ). Thus the cumulant generating function is x•=y• and the moment generating function is exp W (λ) in the usual way. The values of y n depend on the physical quantity involved and the way it is averaged. In one case of interest y n = 8 n (R + ) ×n dk 1 dk 2 · · · dk n k 1 k 2 · · · k n exp −k 1 − (the sums of products must be interpreted as an overall factor of unity in the case n = 1). Numerical investigation leads to a remarkable identity with exact agreement for all terms so far computed (checked up to n = 65). We do not have a proof for this statement, but the conjecture seems fairly secure. In [5], this was used to deduce exp W (λ) = e −λ/6 (1 − 12λ) −1/72 (conjectured), which is the moment generating function of a shifted Gamma distribution. The other generating functions of interest, with these values for the x k are C(λ)| x•=y• = 4 (1 − 12λ) 2 , P(λ)| x•=y• = (1 − 12λ) −1/3 (conjectured).
A natural question is whether there are other sequences that can be substituted for the x k to produce generating functions with simple closed forms. To close, we give three further examples, with the corresponding generating functions computed. The first has already been encountered in section 5 and corresponds to the case x k = 1 for all k ∈ N.