Efficient recurrence for the enumeration of permutations with fixed pinnacle set

Initiated by Davis, Nelson, Petersen and Tenner (2018), the enumerative study of pinnacle sets of permutations has attracted a fair amount of attention recently. In this article, we provide a recurrence that can be used to compute efficiently the number $|\mathfrak{S}_n(P)|$ of permutations of size $n$ with a given pinnacle set $P$, with arithmetic complexity $O(k^4 + k\log n)$ for $P$ of size $k$. A symbolic expression can also be computed in this way for pinnacle sets of fixed size. A weighted sum $q_n(P)$ of $|\mathfrak{S}_n(P)|$ proposed in Davis, Nelson, Petersen and Tenner (2018) seems to have a simple form, and a conjectural form is given recently by Flaque, Novelli and Thibon (2021+). We settle the problem by providing and proving an alternative form of $q_n(P)$, which has a strong combinatorial flavor. We also study admissible orderings of a given pinnacle set, first considered by Rusu (2020) and characterized by Rusu and Tenner (2021), and we give an efficient algorithm for their counting.


Introduction
Given a permutation π ∈ S n in one-line notation π 1 π 2 · · · π n , we consider its local maxima, i.e., elements π i for 2 ≤ i ≤ n − 1 such that π i−1 < π i > π i+1 . In this case, the index i is called a peak of π, and the element π i is called a pinnacle. We denote by [n] the set {1, 2, . . . , n}. The pinnacle set of a permutation π, denoted by Pin(π), is the set of pinnacles of π. For P ⊆ [n], we denote by S n (P ) the set of permutations with pinnacle set P . Peaks of permutations have already been much studied, partly due to its link to the algebraic aspect of the symmetric group through the peak algebra. Inspired by the studies on peaks, pinnacle sets of permutations were first explored in Davis et al. (2018), and various results were given there.
One of the main questions asked in Davis et al. (2018) is how to compute |S n (P )| efficiently. Two recurrences were proposed there, but both need super-exponential time in the number of pinnacles to compute. In Diaz-Lopez et al. (2021), an improved formula was given, but it is still a sum of superexponentially many terms. A formula with only exponentially many terms was given recently in Domagalski et al. (2021) using the inclusion-exclusion principle. Then, a new and simpler recurrence was proposed in Falque et al. (2021) that drastically improves the arithmetic complexity, i.e., the number of arithmetic operations, to O(max(P )|P | 2 ), but there is still a dependency on the values in P , thus not polynomial in the bit-length of input. In this article, we again improve on the arithmetic complexity, giving a recurrence (see Theorem 4.1) that can be used to compute |S n (P )| with polynomial arithmetic complexity in the bit-length of input.
Using the same recurrence in Theorem 4.1, through a computer algebra system, we also obtain general symbolic expressions of |S n (P )| for P of arbitrary fixed size, extending formulas given in Davis et al. (2018) for |P | = 1, 2. However, these expressions are messy in general. In Davis et al. (2018), it was suggested that the following weighted sum may have a simpler form: q n (P ) = Q⊆P 2 |Q| |S n (Q)|. (1) It is also observed in Davis et al. (2018) that we may use q n (P ) to recover |S n (P )| with the inclusionexclusion principle. In Falque et al. (2021), a general process of generating an expression of q n (P ) was conjectured, with a few examples of such expressions for small |P |, which are indeed simpler. We settle this problem by providing an alternative form of q n (P ) as a summation over some combinatorial objects. Our formula is equivalent to the one conjectured in Falque et al. (2021) (see Remark 5.3). For s ≤ k, let R k,s be the set of sequences r = (r 0 , r 1 , . . . , r k ) with the conditions • r 0 = 0, r k = s, r i ≥ 0 for all 0 ≤ i ≤ k; • r i = r i−1 ± 1 for all 1 ≤ i ≤ k.
We can interpret R k,s as the set of y-coordinate sequences of Dyck meanders of length k terminating on y = s. We define R k = ∪ k s=0 R k,s . Theorem 1.2 (See also Conjecture 5.1 in Falque et al. (2021)). For n ≥ 1 and P = {p 1 > p 2 > · · · > p k } ⊆ [n], we take the convention that p 0 = n + 1 and p k+1 = 1. Given r ∈ R k , we define its weight w R (r) by w R (r) = k m=0 (r m + 1) pm−pm+1 .
Then we have q n (P ) = 2 n−k−1 r∈R k w R (r).
Although the statement of Theorem 1.2 is purely combinatorial, our proof uses heavy computations. We thus ask naturally for a more satisfying combinatorial proof.
For permutations with the same pinnacle set, it is possible that their pinnacles appear in different orders, and not all orders are possible. A pinnacle order is called admissible if there is a permutation in which these pinnacles appear in that order. Given a pinnacle set P , we denote by O(P ) the set of all admissible pinnacle orders of P (its formal definition is postponed to Section 6). Admissible pinnacle order was first considered in (Rusu, 2020, Question 3). A characterization of O(P ) was given in Theorem 3.6 of Rusu and Tenner (2021) using the language of interruptions. In the same paper, the authors asked for a function that computes |O(P )|. As a response, a formula of |O(P )| was given in Domagalski et al. (2021), but it involves exponentially many terms in the size of P . In the article, we provide an efficient way to compute |O(P )| using a recurrence. Proposition 1.3. There is an algorithm that computes |O(P )| with O(|P | 2 ) arithmetic operations.
This article is organized as follows. Section 2 reduces the counting of S n (P ) to that of some weighted Motzkin paths, using a variant of the Françon-Viennot bijection (Proposition 2.3). It is then further reduced in Section 3 to the counting of appropriately weighted Dyck paths by compressing horizontal steps in the weighted Motzkin paths (Theorem 3.5). Given the formulation in Dyck paths, we provide in Section 4 the main result of this article (Theorem 4.1), a recurrence that allows us to compute |S n (P )| efficiently, as in Proposition 1.1. Using a variant of this recurrence, we provide in Section 5 a proof of Theorem 1.2. We then deal with the enumeration of admissible pinnacle orderings in Section 6.
Acknowledgment We would like to thank Jean-Christophe Novelli for bringing this subject to the attention of the author, for interesting discussions and for advice on the draft of this article. We would also like to thankÉric Fusy for pointing out the link between the construction in Section 2 and the Françon-Viennot bijection in Françon and Viennot (1979);Flajolet (1980). This work is not supported by any funding with precise predefined goal, but it is supported by the publicly funded laboratory LIGM of Université Gustave Eiffel.

Construction of permutations with a fixed pinnacle set
In the following, we consider cyclic permutations, which are equivalent classes of permutations under the action of position-shifting π → π with π i = π (i mod n)+1 for π ∈ S n . Cyclic permutations are marked with a bar, and we write its one-line notation ending with the largest element. For instance, the cyclic permutation π = 42135 is the equivalent class {42135, 21354, 13542, 35421, 54213}. We denote by S n+1 the set of cyclic permutations with n + 1 elements.
The pinnacles of a cyclic permutation π is defined in the same way as for normal permutations, up to cyclic index, and we also define S n+1 (P ) analogously. We observe that (n + 1) is always a pinnacle of π ∈ S n+1 . We denote by cyc(π) the cyclic completion of π ∈ S n , which is in S n+1 and whose one-line notation is obtained by adding (n + 1) at the end of that of π. For instance, cyc(2413) = 24135. It is clear that cyc is a bijection between S n and S n+1 . Furthermore, it also preserves Pin(π) in the following sense.
We recall that a Motzkin path of length n is a lattice path starting at (0, 0), ending at (n, 0), composed by up steps (1, 1), horizontal steps (1, 0) and down steps (1, −1), while always staying weakly above the x-axis. We denote by M n−1 the set of Motzkin paths of length n − 1. The name "Motzkin type" comes from the following lemma. Proof: We only need to show that s j (π) − s j+1 (π) ∈ {−1, 0, 1} for j ≥ 2. The element j in π can only be in three cases: • j is not next to any element at least j + 1, in this case s j (π) − s j+1 (π) = 1, as we have the new segment j; • j is next to only one element e at least j + 1, in this case s j (π) − s j+1 (π) = 0, as j joins the segment of e; • j is next to two elements e 1 , e 2 at least j + 1, in this case s j (π) − s j+1 (π) = −1. It is because e 1 and e 2 come from two different segments, as j ≥ 2, and then j fusions these two segments.
We thus conclude that M(π) is a Motzkin path. For the second part, we observe that an up step means the creation of a new segment, which is equivalent to the new element being a pinnacle.
Given a Motzkin path M , we define a weight on its steps. Up steps have weight 1, horizontal steps on height have weight 2( + 1), and down steps from height to − 1 have weight ( + 1). The weight of M , denoted by w M (M ), is the product of the weights of its steps. Proof: We construct π with M(π) = M step by step. We start from S n+1 = {(n + 1)}, then we follow M step by step, and construct the segment set S n+1−i by adding the element n + 1 − i to S n+2−i . There are three possible cases.
• The i-th step of M is an up step. Thus, S n+1−i has one more segment than S n+2−i . The only way to do is to add n + 1 − i as a new segment, that is, • The i-th step of M is a horizontal step of height h, meaning that n + 1 − i joins one of the h + 1 segments. There are 2(h + 1) such possibilities, as n + 1 − i can be attached to both ends of a segment.
• The i-th step of M is a down step from height h to h − 1, meaning that n + 1 − i joins two of the h + 1 segments. There are h(h + 1) possibilities, (h + 1) for the left segment and h for the right one.
To see that each sequence of possible choices gives a unique permutation π, we observe that π is totally determined by all the pairs (π(j), π(j + 1)). In the i-th step, we see that each choice determines uniquely the pairs containing n + 1 − i as the smaller element, and the sequence of choices thus determines π uniquely. Furthermore, each such permutation can be constructed in this way by looking at its segment sets. The number of choices for each step is exactly its weight. Thus, the number of permutations with Motzkin type M is w M (M ).
Given a set P ⊆ [n], we denote by M n−1,P the set of Motzkin paths M of length n − 1 such that, for each p ∈ P , the (n + 1 − p)-th step of M is an up step, and these are the only up steps of M . We have the following corollary. Proof: Let P = P ∪ {n + 1}. From Lemma 2.1, we have |S n (P )| = |S n+1,P |. We then conclude by Lemma 2.2 and the definition of M n−1,P .
As a corollary, we have a simple proof of the lower bound of |S n (P )| for |P | = k.
Proof: As S n (P ) = ∅, by Corollary 2.4, there is at least one Motzkin path M ∈ M n−1,P . Now, there are n − 2k − 1 horizontal step and k down steps in M , each contributing a factor at least 2. We thus have |S n (P )| ≥ w M (M ) ≥ 2 n−k−1 . For P min , from the definition of Motzkin type, it is clear that the only possible Motzkin type for π ∈ S n+1 with Pin(π) = P min ∪ {n + 1} is the one starting with 2 n−2k−1 horizontal steps, then ending with k pairs of up-and-down steps. This Motzkin path has exactly the minimal weight.
Remark 2.6. The construction in Proposition 2.3 can be seen as a variant of the Françon-Viennot bijection between permutations and weighted Motzkin paths, but we use a slightly different set of weights that is more adapted to our analysis afterwards. It was also formulated in terms of increasing binary trees in Flajolet (1980), which also provides a general theory to express the generating function of weighted Motzkin paths by continued fractions. In the original bijection, reformulated in our terms here, segments are already positioned in the permutation upon its creation, instead of free-floating. This leads to a weight + 1 on up steps starting at height , while the weight of down steps starting at height is reduced to + 1.

Motzkin path compression
A Dyck path is a Motzkin path without horizontal steps. It is clear that it has the same number of up steps and down steps. We denote by D n the set of Dyck paths of length 2n. Given a Motzkin path M , we define its Dyck compression, denoted by dc(M ), the Dyck path obtained by removing all horizontal steps in M . We define the Dyck type D(π) of a cyclic permutation π to be dc(M(π)). The following is a direct consequence of Lemma 2.2.
Proof: We know from Lemma 2.1 and 2.2 that pinnacles in Pin(π) are in bijection with up steps in M(cyc(π)), which are kept in D(cyc(π)).
Given n and P = {p 1 , p 2 , . . . , p k } ⊆ [n], we take the convention p 0 = n + 1 and p k+1 = 1. We define the gap sequence (g 0 , g 1 , . . . , g k ) of (n, P ) by taking g i = p i − p i+1 − 1 for all i. The name comes from the fact that g i is the number of steps between the i-th and the (i + 1)-st up step of Motzkin paths in M n−1,P .
We start by a computational lemma. For k ≥ 1, we denote by h m (x 1 , x 2 , . . . , x k ) the homogeneous symmetric function of order m with k variables: Readers are referred to (Stanley, 1999, Chapter 7) for more on symmetric functions. We have the following computational lemma for h m . .

Proof:
We proceed by induction on k. The equality holds trivially for k = 1. Now, to pass from k to k +1, first write h m (x 1 , . . . , x k+1 ) as a polynomial in x k+1 with coefficients h m (x 1 , . . . , x k ), then apply the induction hypothesis on these coefficients. Comparing the resulting expression of h m (x 1 , . . . , x k+1 ) with the claimed one, the induction step is reduced to the proof of the following equality: This equality holds by Lagrange interpolation. Now, given Proposition 3.1, for each pair (P, D) with P ⊆ [n] with |P | = k, and D a Dyck path of length 2k, we associate a weight w D (n, P, D) defined as follows. For 1 ≤ i ≤ k − 1, let d i be the number of down steps between the i-th and the (i + 1)-st up steps of D, and we also take d 0 = 0 and d k the number of down steps at the end of D. We also suppose that, for 1 ≤ i ≤ k, the i-th up step of D goes from height i − 1 to i , and we take 0 = 0. We thus have two tuples (d 0 , . . . , d k ) and ( 0 , . . . , k ) depending only on D. Let (g 0 , g 1 , . . . , g k ) be the gap sequence of (n, P ). We then define w D (n, P, D) by where f (d, , g) is defined as follows: f (d, , g) = 0 when d > g, otherwise Here, [h = 0] is the Iverson bracket for the condition h = 0, taking the value 1 when h = 0, and 0 otherwise. We remark that d i = i − i+1 + 1, but we choose the current notation for simplicity. The last equality of (4) is from Lemma 3.2.
and a Dyck path D of length 2k, the number of permutations π in S n (P ) with Dyck type D is w D (n, P, D).
Proof: Let (d 0 , . . . , d k ) and ( 0 , . . . , k ) be the two tuples used in (3), and (g 0 , . . . , g k ) the gap sequence of P . The length of D given P is imposed by Proposition 3.1. By Lemma 2.1 and Proposition 2.3, we only need to show that By the definition of M n−1,P , for each M ∈ M n−1,P , the (n + 1 − p i )-th step is an up step for each 1 ≤ i ≤ k. We now consider the steps between the i-th and the (i + 1)-st up step in M . There are g i such steps, d i of them are down steps, so g i − d i of them are horizontal. These horizontal steps come with heights from i to i − d i . The contribution of all possibilities is For steps after the last up step in M , the same formula applies. It also holds for the n − p 1 = g 0 horizontal steps that comes before the first up step in M by taking d 0 = 0. For down steps, we transfer their contribution to up steps of the same height in a Dyck path, as there are the same number of them.
As the heights of the ending point of up steps are exactly those i except for 0 = 0, the contribution is Collecting all factors, we have our claim by noticing that Remark 3.4. In the definition of w D (n, P, D), it may sound more natural if f (d i , h i , g i ) accounts directly the weights of the d i down steps. However, the current form is simpler and faster to compute, and more adapted to the proof of Theorem 1.2. Theorem 3.5. For P ∈ [n], let k = |P |, and we have Proof: This is a direct consequence of Proposition 3.3 by summing up all D ∈ D k .
Our model here is conceptually simpler, and involves only positive terms (considering the functions h m as counting combinatorial objects), in contrast to the approach in Domagalski et al. (2021) using the principle of inclusion-exclusion.

Recurrence for |S n (P )|
A valley Dyck prefix is a prefix of a Dyck path such that the rest of the path does not start with a down step, but can be empty. We can extend the definition of w D (n, P, D) to D being a valley Dyck prefix. Suppose that there are k up steps in D, then we take w D (n, P, in the case of Dyck paths, except d k being the number of down steps at the end of D. Let c n,P (i, j) be the total weight w D (n, P, D) for valley Dyck prefixes with i up steps and j down steps. Then we have the following recurrence.
Theorem 4.1. Given n and The function f (d, h, g) is defined in (4). As a consequence, we have Proof: The initial condition (5) stands for the empty valley Dyck prefix, and holds by definition. For the recurrence (6), consider a valley Dyck prefix D with i + 1 up steps and j down steps, and D the valley Dyck prefix of D before the last up step of D. It is clear that D has i up steps, and let j ≤ j be the number of down steps in D . There are thus j − j consecutive down steps at the end of D, starting at height i − j + 1. Their contribution to the weight is f (j − j , i − j + 1, g j+1 ). By summing over all possibilities of j , we have the recurrence. It is clear that c n,P (k, k) accounts for all Dyck paths, and we have the expression of |S n (P )| by Theorem 3.5.
The recurrence in Theorem 4.1 provides an efficient way to compute |S n (P )|. Now we describe a possible implementation as a proof of Proposition 1.1.
Proof of Proposition 1.1: Suppose that P ⊆ [n] with k = |P |. To compute |S n (P )|, we use the recurrence in Theorem 4.1, which has O(k 2 ) terms, and each term needs O(k) multiplications and evaluations of f (d, , g), and each f (d, , g) is essentially a sum of O(k) terms. We thus need O(k 4 ) operations to sum up these terms. We now see that these O(k 4 ) terms in f (d, , g) have the form ( +1−m) g (m!(d−m)!) −1 , with 0 ≤ m ≤ d. Moreover, there are only k + 1 values of g that are used, precisely those in the gap sequence, and we also have 1 ≤ + 1 − m ≤ k + 1. Thus, we can precompute all such powers with O(k 2 log n) operations using fast exponentiation, as g j ≤ n. The factorials can also be precomputed with O(k) operations. With such precomputation, each of the O(k 4 ) terms can be computed with a constant number of operations. The total arithmetic complexity is thus O(k 4 + k 2 log n).
The recurrence in Theorem 4.1 can also be easily computed symbolically using a computer algebra system, giving a closed-form, non-recursive formula for |S n (P )| for each fixed size of P . This settles Question 4.4 in Davis et al. (2018) for any fixed number of pinnacles. The cases |P | = 1, 2 have already appeared in Proposition 3.6 of Davis et al. (2018) and reproved in Falque et al. (2021) in a much simpler way.
Remark 4.2. Another use of Theorem 3.5 is the exhaustive generation of all permutations in S n (P ), which can be done in linear amortized time, i.e., each object generated in linear time on average. We first use the recurrence to identify viable Dyck paths. Then we decompress each Dyck path into a family of Motzkin paths by generating subsets of d down steps in the gap g for each contribution f (d, , g). This can be done by constant amortized time subset generators (see Chapter 7.2.1.3 of Knuth (2005)). For each Motzkin path, we generate choices for each step in the construction in the proof of Proposition 2.3, which takes constant amortized time, and then perform the construction, which takes linear time. It might be possible to improve the complexity to constant amortized time, potentially by creating suitable data structure to efficiently transpose changes of the choices for each step into the permutation.

A simple form of a weighted sum of |S n (P )|
We will now prove our formula of q n (P ) in Theorem 1.2. It is equivalent to Conjecture 5.1 in Falque et al. (2021), which will not be stated here (see Remark 5.3). We proceed as follows: we first propose a recurrence similar to that in Theorem 4.1 and prove that it computes q n (P ), then we prove inductively a general form for all terms in the recurrence, which implies our claim.
Proof: Given M a Motzkin path, we denote by |M | up the number of up steps in M . By Lemma 2.2 and Proposition 2.3, q n (P ) is the weighted sum of Motzkin paths M of length n − 1 whose up steps can occur as the (n+1−p i )-th step for all 1 ≤ i ≤ k, but not necessarily, and the weight is given by 2 |M |up w M (M ).
We denote this set of Motzkin paths by M n−1,P , which is exactly P ⊆P M n−1,P , and we have We now propose an altered weight w M (M ), where an up step has weight 1/2, a horizontal step on height has weight + 1, and a down step from height to − 1 has weight ( + 1). We observe that a Motzkin path M of length n−1 has n−1−2|M | up horizontal steps. Comparing step weights in w M (M ) and w M (M ), we have w M (M ) = 2 1−n · 2 |Mup| w M (M ).
Combining with (9), we have q n (P ) = 2 n−1 The proof of the recurrence is analogous to that of Theorem 4.1. This time, we consider valley Motzkin prefixes, which are prefixes such that the rest of the path is empty or starts with an up step. The altered weight w M (M ) also extends to these prefixes. We now claim that a n,P (i, j) is the weighted sum of valley Motzkin prefixes of length n−p i+1 , ending on height i−j, with the weight given by w M . In other words, these are valley Motzkin prefixes of Motzkin paths in M n−1,P whose (n + 1 − p i+1 )-th step is an up step. We must have 0 ≤ j ≤ i, as there may be at most i up steps in the valley Motzkin prefixes accounted by a n,P (i, j) for any i.
We now prove our claim by induction on i. The initial case i = 0 is given by definition. Now suppose that our claim holds for all i ≤ i. Consider a valley Motzkin prefix M of length n − p i+2 ending on height i + 1 − j, which is supposed to contribute to a n,P (i + 1, j). Either M has no up step, which can only occur when i + 1 = j, and in this case its contribution is 1, the same as the Iverson bracket in (8); or M as at least one up step. Let M be the prefix of M before its last up step, which is also a valley Motzkin prefix. Suppose that M is of length n − p i +1 and ending at height i − j for some i and j . It is clear that 0 ≤ i ≤ i, and we also have i − j ≥ i − j, as there is exactly one up step in M after M . The segment of M after its last up step starts at height i − j + 1, contains p i +1 − p i+2 − 1 steps, i − j − i + j of them are down steps by variation of height. Therefore, we have where the factor 1/2 is for the last up step of M . Summing over all possible i , j and M , we conclude the induction. We then conclude the proof by observing that a n,P (k, k) accounts for all Motzkin paths in M n−1,P .
In the proof of Theorem 1.2, we need the following computational result.
Proposition 5.2. For n > 0 and P (x) a polynomial of degree strictly less than n, we have n k=0 (−1) k n k P (k) = 0.
Proof: By linearity, it suffices to prove for P (x) = x(x − 1) · · · (x − k + 1) for all k < n. This is done by deriving k times by y the expansion of (1 − y) n , then setting y = 1.
We recall that R k,s is the set of y-coordinate sequences of Dyck meanders of length k ending at height s, and R k = ∪ k s=0 R k,s . Given r ∈ R k , we denote by r ↑ (resp. r ↓ ) the new sequence obtained by appending r k+1 = r k + 1 (resp. r k+1 = r k − 1). We can now prove Theorem 1.2.
Proof of Theorem 1.2: We prove the following result for a n,P (i, j) for 0 ≤ j ≤ i ≤ k: It implies our claim, as q n (P ) = 2 n−1 a n,P (k, k). We proceed by induction on i. For i = 0, the sum in a n,P (0, j) is empty except for j = 0, when we have a n,P (0, 0) = 1. Now assume that (10) holds for all i ≤ i, and we compute a n,P (i + 1, j) using the induction hypothesis and (8). We first check the case i + 1 = j, where the Iverson bracket (8) is 0, leading to a n, where Here, we used the generic expression without Iverson bracket of f (d, , g) in (4), as we never have i − j + 1 = 0 in the case i + 1 = j. We can also assume δ ≥ 0. For s − t > 2, by Proposition 5.2, the summation over δ is zero. Therefore, when s ≥ δ + 2, the only non-zero terms are for t = s − 2, s − 1, s, leading to However, when s = δ + 1, we discard the last term, and when s = δ, only the first term exists.
We now remark that we may extend the definition of w R to r − that may take −1 as the last element, and we have w R (r − ) = 0 in such cases. Recalling that g i+1 = p i+1 − p i+1 − 1, the contribution of r ∈ R i ,s to a n,P (i + 1, j) can thus be expressed by C + (r) − C − (r) from (13), where, for s ≥ i − j + 2, For s = i − j + 1, the last term in (13) is discarded, and we only have the first term of C + (r), while C − (r) remains unchanged. For s = i − j, not only C + (r) has only one term, but the term in (13) corresponding to C − (r) is also discarded, leaving C − (r) = 0. For s < i − j, we have C + (r) = C − (r) = 0.
We may also extend the definition of C + and C − to r − that may take −1 as the last element, and in this case, C + (r − ) = C − (r − ) = 0, as w R (r − ) = 0. The value of a n,P (i+1, j) is the sum of all contributions: a n, (14), the first term of C + (r) is exactly C − (r ↑ ), and the second is C − (r ↓ ). When s = i − j + 1 or s = i − j, we only have the first term in C + (r), but in this case C − (r ↓ ) = 0, and the same still holds.
Therefore, summing over all paths, the only contribution terms C + (r) that is left is when r ∈ R i,s with s ≥ i − j, and the only C − (r) left is for r ∈ R i−j,i−j , and we have C − (r) = 0 for such r. Using the fact that C − (r) = 0 for r ∈ R i+1,i−j , we have a n,P (i + 1, j) = i s=i−j r∈Ri,s For the case i + 1 = j, there are several differences that compensate each other. First, in this case, not all the i and j in the recurrence (8) are valid. More precisely, when j = i + 1, which is possible when i + 1 = j, we have a n,P (i , j ) = 0. Therefore, we should discard the term linked with j = i + 1, which also means that we can continue to use the generic expression without Iverson bracket of f (d, , g) in (4).
For terms being discarded, firstly, we may only sum over s from 0 to i in (11). Therefore, we always have s ≥ 0 in α(s, δ, u). Furthermore, in α(s, −1, u), we discard the terms with δ = −1 in (12), but not those with t = −1. When s ≥ 1, this has no effect. When s = 0, we discard the last term on the right-hand side of (13). The effect on C + (r) and C − (r) is the same as the general case, and the whole reasoning holds, except that we didn't account for the negative contribution term C − ((0)) = 1. However, it compensates with the Iverson bracket in (8), and the same result holds. We thus complete the induction on all cases.
Remark 5.3. Conjecture 5.1 in Falque et al. (2021) involves a relatively simple but non-trivial iterative procedure to generate an expression of q n (P ). However, it is equivalent to Theorem 1.2. We only briefly describe the reason here, without a detailed proof. In the procedure in Falque et al. (2021), there are two operators f e and f o , one used for even number of pinnacles, the other for the odd case. In our model of lattice paths, both operators "extend" the path by one step, up or down. The apparent difference between f e and f o is due to the fact that, when paths are extended to odd height (so even weight for horizontal steps), a power of 2 is collected somewhere else.
Theorem 1.2 also explains the phenomenon observed in Falque et al. (2021) that, in the computation of q n (P ), we may have 2 in P , although it cannot be a pinnacle. For P ⊆ [n] \ {1, 2}, let k = |P |. It is clear that q n (P ) = q n (P ∪ {2}), as S n (P ) = ∅ for any P containing 2. We check that, for each r ∈ R k , the contribution of r ↑ and r ↓ to q n (P ∪ {2}) is exactly twice that of r to q n (P ), which is compensated by the increment of number of pinnacles.
In Davis et al. (2018), it was proposed that, as q n (P ) may have a simpler form, it may be easier to compute |S n (P )| using q n (P ) and the principle of inclusion-exclusion. However, the arithmetic complexity of such computation is exponential in |P |, in contrast to Proposition 1.1 here.
Although the statement of Theorem 1.2 has a strong combinatorial flavor, its proof here is mainly computational, which is not quite satisfying. We thus have the following natural question: Open question 1. Is there a combinatorial or even bijective proof of Theorem 1.2?
If such a proof exists, it might lead us to a better understanding why the form of q n (P ) is much simpler than that of |S n (P )|.
A permutation σ ∈ S k is an admissible pinnacle ordering (or simply admissible ordering) of P if there is π ∈ S n (P ) with ord(π) = σ. We denote by O(P ) the set of admissible pinnacle ordering of P . Note that O(P ) does not depend on n, as in every π ∈ S n (P ), any element greater than p 1 cannot be a peak, and they must thus be located at the two ends of π. Hence, taking any n > p 1 will not lead to more admissible orderings than taking n = p 1 .
Given σ ∈ S k , we want to know whether σ is in O(P ). We have the following characterization of possible pinnacle orders σ for cyc(π) of a given Dyck type, using the Motzkin type of cyc(σ). To simplify the proof, for σ ∈ S k , we define its complement, denoted byσ, byσ(i) = k + 1 − σ(i). We recall that, for a cyclic permutation π, its segment set of level , denoted by S (π), is the set of maximal consecutive segments formed by elements at least in π, and we define s (π) = |S (π)|. Proposition 6.1. Given P ⊆ [n] with |P | = k, we fix D a Dyck path of length 2k such that there is some π * ∈ S n (P ) with D(cyc(π * )) = D. For a permutation σ ∈ S k , we let M be the Motzkin type of cyc(σ), that is, M = M(cyc(σ)). We have the following equivalence: (i) There exists π ∈ S n (P ) with D(cyc(π)) = D and ord(π) =σ; (ii) The Motzkin path M is compatible with the Dyck path D, that is, for all 1 ≤ i ≤ k − 1, the starting height of the i-th step of M never exceeds that of the i-th up step of D.
Proof: For simplicity, we take π = cyc(π) and σ = cyc(σ), and we suppose that P = {p 1 > p 2 > · · · > p k }. By construction, the pinnacles of π are exactly n + 1, p 1 , p 2 , . . . , p i−1 , corresponding to elements k + 1, k, . . . , k − i + 2 in σ, as ord(π) =σ and n + 1 is always a pinnacle in π. By the definition of M, the starting height of the i-th step of M is s k+2−i (σ) − 1. Similarly, from Lemma 2.2 and the definition of D, we know that the i-th up step of D corresponds to the pinnacle p i , and its starting height is s pi+1 (π) − 1.
Hence, in the following, we may replace (ii) by We start by proving (i) ⇒ (ii)'. The elements in each segment in S k+2−i (σ) correspond to pinnacles in π. However, if two elements j, j are not in the same segment of S k+2−i (σ), then there are two elements m, m < k + 2 − i that separate j and j in σ, which transposes to two pinnacles p k−m+1 , p k−m +1 ≤ p i that separate p k−j+1 and p k−j +1 in π. It means that p k−j+1 and p k−j +1 are not in the same segment in S pi+1 (π). The restriction of segments in S pi+1 (π) to pinnacles is thus a refinement of S k+2−i (σ) as set partition, and we have s k+2−i (σ) ≤ s pi+1 (π) to conclude (i) ⇒ (ii)'.
To show (ii) ⇒ (i), we only need to show a way to construct π satisfying (i). Knowing that there is π * ∈ S n (P ) such that D(cyc(π * )) = D, as in the proof of Proposition 2.3, we may alter any choices in the procedure to construct cyc(π * ) from its Motzkin type M(cyc(π * )) to construct π of the same Motzkin type, thus also with the same Dyck type. We leave choices for horizontal steps unchanged, focusing only on down steps. We now read each step of M and its choice in the construction of σ from M , and translate them to choices of down steps in M(cyc(π * )), which are just down steps in D. With an abuse of language that will be justified later, given an element or a segment in σ, we say that its corresponding segment in π is the one containing the corresponding pinnacles. There are three possible steps in M : • Up step: do nothing; • Horizontal step: suppose that it joins a new element i to an existing segment w in S i+1 (σ), then the next down step in D should join the corresponding segments of i and of w in the same way; • Down steps: suppose that it joins a new element i with two segments w and w , forming wiw , then we take the next two down steps in D to join the corresponding segments of i, w and w in the same way, with arbitrary order.
The procedure above is well-defined, as we mimic in π how segments join in σ, meaning that the corresponding pinnacles of elements in the same segment of σ, once it comes to existence during the reading of M , are also in the same segment of π after the translated steps. The only way that the process above fails is when it is about to deal with a new element in σ for the i-th step of M , but the corresponding pinnacle p i is not yet introduced by the i-th up step of M(π) (thus also that of D). Suppose that the starting height of the i-th step of M is i and that of the i-th up step of D is i . Steps in M for elements larger than i correspond by the process above to i − 1 − i down steps in D, as a step in M with height increment 1, 0, −1 consumes 0, 1, 2 down steps in D respectively. Then, for the i-th up step of D, there are i−1− i down steps before it. Therefore, our process fails for the i-th step of M when the first i − 1 steps in M produces strictly less down steps than those before the i-th up step in D, that is, But this is impossible due to (ii). Therefore, our process never fails, and it produces a permutation π with ord(π) =σ.
Given a pinnacle set P , a Dyck path D is a admissible Dyck type of P if there is some π ∈ S n (P ) such that D(cyc(π)) = D. By Proposition 6.1, to obtain |O(P )|, we only need to compute all Motzkin paths of length k − 1 that is compatible with any of the admissible Dyck types. The following characterization of admissible Dyck types of P allows us to focus on only one of them, instead of all, when computing |O(P )|.
Proposition 6.2. Let P = {p 1 > p 2 > · · · > p k } ⊆ [n] and D an admissible Dyck type of P . Let i be the starting height of the i-th up step of D. Then for all 2 ≤ i ≤ k, we have Proof: It is clear that i ≤ i−1 + 1, as there is no up step between the (i − 1)-st and the i-th up step. Now for the other inequality, as D is admissible, there is some π ∈ S n (P ) such that D(cyc(π)) = D. Consider all the steps of D after the i-th up step (itself included), among them k − i + 1 are up steps, and thus i + k − i + 1 are down steps, as D is a Dyck path. By the definition of D and M, these steps are from distinct elements from p i down to 2. Hence, we must have more elements than down steps, meaning As a simple corollary, we recover the characterization of admissible pinnacle sets (i.e., pinnacle sets P such that S n (P ) is not empty) in Davis et al. (2018), here stated and strengthened for our need.
Furthermore, when this condition is satisfied, there is an admissible Dyck type D P for P , with all i reaching the maximum. D P can be constructed as follows: for each 2 ≤ i ≤ k, we put max(0, i−1 −p i + 2 + 2(k − i)) down steps between the (i − 1)-st up step and the i-th one, and we add the correct number of down steps at the end to make D P a Dyck path. For D P , we have i = min ( i−1 + 1, p i − 3 − 2(k − i)).
Proof: For the "only if" part, suppose that there is an index i with p i < 3 + 2(k − i). If S n (P ) contains some π, we take D = D(cyc(π)), and by Proposition 6.2, the starting height i of the i-th step of D satisfies i ≤ p i − 3 − 2(k − i) < 0, which is impossible. Therefore, such an index i cannot exist.
For the "if" part, we first show that D P constructed above is an admissible Dyck type. As p i ≥ 3 + 2(k − i), the number of down steps between the (i − 1)-st and the i-th up steps is at most i−1 + 1, and accounting for the (i − 1)-st up step, we have i ≥ 0, showing that D P is indeed a Dyck path. To show that D P is admissible, we expand D P into a Motzkin path M that satisfies the condition in Lemma 2.2. This is always possible, as p i ≥ 3 + 2(k − i) implies that there are enough elements for down steps at each time, as in the proof of Proposition 6.2. With M a valid Motzkin type, by Proposition 2.3, we see that S n (P ) is not empty.
The equality for i holds by construction. Now, let D be an admissible Dyck type of P , with i the starting height of its i-th step. We show by induction that i ≤ i . This holds for i = 1 as i = i = 0. Suppose that i−1 ≤ i−1 , then by Proposition 6.2, We thus conclude the maximality of D P .
Given P ⊆ [n] with S n (P ) not empty, we call the Dyck path D P defined in Corollary 6.3 to be the maximal Dyck type of P . We can now characterize permutations in O(P ) in a simple way.
Theorem 6.4. Given P ⊆ [n] with |P | = k. A permutation σ is in O(P ) if and only if the Motzkin type of cyc(σ) is compatible (as defined in Proposition 6.1) with the maximal Dyck type D P of P . We thus have Proof: The "if" part follows directly from Proposition 6.1 by taking D = D P therein, as σ →σ is involutive. For the "only if" part, as σ ∈ O(P ), there exists π ∈ S n (P ) such that ord(π) = σ. By Proposition 6.1, the Motzkin type of cyc(σ) is compatible with the Dyck type of cyc(π), meaning that it is also compatible with D P , according to Corollary 6.3 and the definition of compatibility. By accounting for all possible M , using Proposition 2.3, we have the formula of |O(P )|. (2021), we say that a pinnacle set P with k = |P | is maximally admissible if O(P ) = S k . The following corollary recovers a result in Rusu and Tenner (2021).
Proof: From Theorem 6.4, we know that P is maximally admissible if and only if D P is compatible with all possible Motzkin paths of length k − 1. By definition, it is equivalent to D P being compatible with the Motzkin path that starts with k−1 2 up steps and ends with k−1 2 down steps. This is equivalent to say that i ≥ min(i − 1, k − i) for i for D P defined in Corollary 6.3.
We thus have i ≥ min(i − 1, k − i) to conclude the induction.
Using Theorem 6.4, we propose the following recurrence for |O(P )| that avoids the enumeration of the exponentially many Motzkin paths.

Proof:
The proof is similar to that of Theorem 4.1 and Proposition 5.1. We first extend the weight w M to prefixes of Motzkin paths. Then, the quantity b P (i, j) stands for the total weight of prefixes of Motzkin paths compatible with D P ending at (i, j), where D P is defined in Corollary 6.3. At b P (k − 1, 0), we thus have the total weights of Motzkin paths compatible with D P , and we conclude by Theorem 6.4.
The recurrence in Proposition 6.6 gives a concrete algorithm for Proposition 1.3.
Proof of Proposition 1.3: Let k = |P |. Computing |O(P )| using the recurrence in Proposition 6.6 needs two steps: computing i for i ∈ [k], which takes O(k) operations; computing b P (i, j) for i, j ∈ [k], which takes O(k 2 ) operations.
Using the algorithm above, we are able to compute |O(P )| for most practical purposes. We observe that, for fixed k = |P |, there is a finite number of possible non-zero values for |O(P )|. We denote this number by α k . A natural bound of α k is the (k − 1)-st Motzkin number, as the restriction imposed by D P essentially means summing over the weights of all Motzkin paths of length k − 1 below a given "ceiling", which is also a Motzkin path, when computing |O(P )|. However, this bound is not tight. For instance, a Motzkin path and its mirror, as ceilings, lead to the same weighted sum. An exhaustive computation shows that, for k from 1 to 19, the values of α k are: 1, 1, 2, 3,6,10,21,38,86,173,412,926,2331,5713,14981,38750,104907,279344,769429 At the time of writing, this sequence is not yet on the Online Encyclopedia of Integer Sequences OEIS Foundation Inc.. It may thus be interesting to study (α k ) k≥1 . A precise description of α k may be complicated, as it involves various symmetries and coincidences due to explicit values of the weights. However, we may expect (α k ) k≥1 to have the same asymptotic behavior as Motzkin numbers.
Open question 2. Does (α k ) k≥1 grow exponentially with the growth constant 3, the same as that of Motzkin numbers?