Permutree sorting

Generalizing stack sorting and $c$-sorting for permutations, we define the permutree sorting algorithm. Given two disjoint subsets $U$ and $D$ of $\{2, \dots, n-1\}$, the $(U,D)$-permutree sorting tries to sort the permutation $\pi \in \mathfrak{S}_n$ and fails if and only if there are $1 \le i<j<k \le n$ such that $\pi$ contains the subword $jki$ if $j \in U$ and $kij$ if $j \in D$. This algorithm is seen as a way to explore an automaton which either rejects all reduced expressions of $\pi$, or accepts those reduced expressions for $\pi$ whose prefixes are all $(U,D)$-permutree sortable.


Introduction
The weak order is a classical lattice on the symmetric group where permutations are ordered by inclusion of inversion sets. Generalizing the classical Tamari lattice [17], N. Reading studied the lattice quotients of the weak order [13], in particular the Cambrian lattices [14,15]. Generalizing and interpolating between the weak order, the Cambrian lattices and the boolean lattice, we introduced permutree lattices in [12] based on the combinatorics of certain trees called permutrees. These permutree lattices have strong combinatorial, geometric and algebraic properties distinguishing them among all lattice quotients of the weak order: for instance, they are the only lattice quotients of the weak order which can be realized as removahedra [1] (i.e. polytopes obtained by removing inequalities in the facet description of the classical permutahedra, like the classical associahedra of [9,6]), and they define combinatorial Hopf algebras [12] analoguous to the Hopf algebras of C. Malvenuto and C. Reutenauer on permutations [11] and of J.-L. Loday and M. Ronco on binary trees [10].
Unlike Cambrian lattices which are well-understood for arbitrary finite Coxeter groups [14,15] with their connections to finite type cluster algebras [4,5], permutree lattices lack a combinatorial description beyond the symmetric group. To tackle this problem, this paper still focusses on type A permutree lattices but from the lens of reduced words for permutations (i.e. products of simple transpositions of minimal length). This approach not covered in [12] is more suitable to generalizations to finite Coxeter groups.
The goal of this paper is to identify reduced words which correspond to the minimal permutations of their permutree congruence classes. These permutations are generalizations of the stack-sortable permutations introduced by D. Knuth in his textbook [8,Sect. 2.2.1], which are characterized by the following equivalent conditions for a permutation π ∈ S n : (i) π is sent to the identity by the stack sorting operator S defined inductively by S(τ nρ) := S(τ )S(ρ)n. (ii) π avoids the pattern 231 (i.e. there is no p < q < r such that π r < π p < π q ). (iii) π is minimal among all linear extensions of a binary tree on n nodes (seen as a poset, where the nodes are labeled in inorder and the edges are oriented towards the leaves). (iv) For i < j < k, the inversion set inv(π) := {(π p , π q ) | p < q and π p > π q } of π contains the inversion (k, j) as soon as it contains the inversion (k, i). (v) π admits a reduced word of the form π = c I1 · · · c Ip with nested subsets I 1 ⊇ · · · ⊇ I p , where c {i1<···<ij } := s ij · · · s i1 is a product of the simple transpositions s i := (i i + 1).
It follows from (iii) that these permutations are counted by the Catalan number C n := 1 n+1 2n n . In [13,14,15], N. Reading defined natural counterparts to conditions (iii), (iv), and (v) above, parametrized by the choice of a Coxeter element c in a finite Coxeter group W : the minimality in c-Cambrian classes, the c-alignment, and the c-sortability. (We skip the general definitions of these conditions here as we stick with the combinatorics of the symmetric group.) In the situation of the symmetric group S n , we can think of a Coxeter element on S n as an orientation of an (n − 1)-path, or equivalently as a partition of {2, . . . , n − 1} into two subsets U and D. The Cambrian analogues of the conditions (ii), (iii), (iv) and (v) above are the following equivalent conditions for a permutation π ∈ S n : (ii') For i < j < k, the permutation π does not contain the subword jki if j ∈ U and kij if j ∈ D. (iii') π is minimal among all linear extensions of a c-Cambrian tree on n nodes.
A c-Cambrian tree is an oriented tree on [n] where node j has one parent if j / ∈ U and two parents if j ∈ U , and one child if j / ∈ D and two children if j ∈ D, with an additional local condition at each node similar to the binary search tree condition [2]. (iv') For i < j < k, if inv(π) contains (k, i), then it also contains (k, j) if j ∈ U and (j, i) if j ∈ D. (v') π admits a reduced word of the form π = c I1 · · · c Ip with nested subsets I 1 ⊇ · · · ⊇ I p , where c I := c i1 · · · c i |I| denotes the subword of c := c 1 · · · c n−1 indexed by I := {i 1 < · · · < i j }.
It turns out that for any Coxeter element c, the permutations satisfying these conditions are still counted by the Catalan number C n . The generalization to permutrees consists of taking two subsets U and D of {2, . . . , n − 1} that are not anymore required to form a partition of {2, . . . , n − 1} (they may intersect and may not cover all the set). It was proved in [12,3] that the conditions (ii'), (iii'), and (iv') are still equivalent for a permutation π ∈ S n . We call a permutation (U, D)-permutree minimal when it satisfies these conditions, i.e. when it is minimal (minimal number of inversions) in its (U, D)-permutree class. The number of (U, D)-permutree minimal permutations is called (U, D)-factorial-Catalan number and admits recursive formulae interpolating between the formulae for the factorial and for the Catalan number. Figure 1. The automata U(j) (left) and D(j) (right) defined recursively.
The objective of this paper is to discuss characterizations of permutree minimal permutations in terms of their reduced words. In other words, we aim at a condition playing the role of condition (v') and equivalent to conditions (ii'), (iii'), and (iv') for arbitrary subsets U and D of {2, . . . , n − 1}. We believe that understanding this characterization in type A could lead to a general characterization for all finite Coxeter groups since the condition (v') generalizes to all types for Cambrian lattices.
We first focus on the case where U = ∅ and D = {j} for some j ∈ {2, . . . , n − 1}, or the opposite. To characterize the permutree minimal permutations in terms of their reduced words in that situation, we use two automata U(j) and D(j) defined inductively as shown in Figure 1. The induction stops at U(n) and D(1), which are defined by deleting the transitions s n and s 0 respectively in Figure 1. Figure 2 presents the complete automaton U(j) after all recursion is done, and Figure 3 shows the automata U(2), D(2), U(3), and D(3). In all these pictures the initial state is marked with "start", the accepting states are doubly circled, all transitions are labeled with simple transpositions s i for i ∈ [n−1], and all missing transitions are loops (we assume the reader familiar with basic automata theory, see for instance [7]). Our main tool is the following statement, proved in Section 2.
Let us warn the reader on the fact that j is fixed in Theorem 1.1, while i and k are arbitrary such that 1 ⩽ i < j < k ⩽ n. A priori, we should try all possible reduced words of π to decide if one is accepted by the automaton U(j) (resp. D(j)). However, we can show that if π contains no subword jki (resp. kij) with i < j < k and has a descent s ℓ distinct from s j−1 (resp. s j ), then it has a reduced word starting with s ℓ and accepted by the automaton U(j) (resp. D(j)). In other words, there is no loss of generality in starting constructing a reduced word for π as long as we stay in the states of the top row of U(j) (resp. D(j)). This yields a simple algorithm to construct a reduced word accepted by U(j) (resp. D(j)). It also yields natural tree structures on the permutations characterized by Theorem 1.1, which can be glanced upon in Figure 3. These algorithmic and combinatorial consequences of Theorem 1.1 are explored in Section 3. Most results of Sections 2 and 3 are stated with respect to both automata U(j) and D(j) but proved only for U(j) as all proofs for D(j) are symmetric.
Consider now arbitrary subsets U and D of {2, . . . , n − 1}. It follows from Theorem 1.1 that a permutation is minimal in its (U, D)-permutree class if and only if it admits a reduced word accepted by U(j) for each j ∈ U and by D(j) for each j ∈ D. In general, the reduced words accepted by the automata U(j) for each j ∈ U and by D(j) for each j ∈ D are distinct. We prove however in Section 4 that there is a reduced word simultaneously accepted by all these automata when U and D are disjoint. • π admits a reduced word accepted by all automata U(j) for j ∈ U and D(j) for j ∈ D, • π contains no subword jki if j ∈ U and kij if j ∈ D for any i < j < k. Theorem 1.2 implies that given any permutation π avoiding jki if j ∈ U and kij if j ∈ D, we can sort π while preserving these avoiding conditions. The resulting sorting procedures, that we call (U, D)-permutree sorting, are discussed in Section 4.4. For instance, stack sorting is a ({2, . . . , n − 1}, ∅)-permutree sorting.
Finally, in the particular situation when the subsets U and D form a partition of {2, . . . , n − 1}, we actually show that the reduced word simultaneously accepted by the automata U(j) for j ∈ U and D(j) for j ∈ D is the c-sorting word of π as defined in [15]. This yields in particular an alternative proof that condition (v') characterizes the Cambrian minimal permutations. This new perspective on c-sortability is explored in Section 5.
2. Automata for reduced words 2.1. Reduced words, automata, and subword avoidance. We start with properly fixing the few notations needed in this paper. We consider the symmetric group S n of permutations of the set [n] := {1, . . . , n}. It is generated by the simple transpositions s i := (i i + 1) for i ∈ [n − 1] which are involutions s 2 i = id and satisfy the commutation relations s i · s j = s j · s i if |i − j| > 1 and the braid relations s i · s i+1 · s i = s i+1 · s i · s i+1 . Note that we multiply permutations as usual, so that the left multiplication by s i exchanges the entries with values i and i + 1, while the right multiplication by s i exchanges the entries at positions i and i + 1. Each permutation π decomposes into products of transpositions of the form π = s i1 · · · s i k with i 1 , . . . , i k ∈ [n − 1]. The minimal number of transpositions in such a decomposition is the length ℓ(π) of π and the decompositions of length ℓ(π) are the reduced words for π.
Consider now the automata U(j) and D(j) described in the introduction, see Figures 1, 2, and 3. We call a state healthy, ill, or dead depending on whether it belongs to the top, middle, or bottom row of the automata. Each state has n−1 possible transitions, one for each s i for i ∈ [n − 1], but we only explicitly indicate the ones between different states. The automata U(j) and D(j) take as entry a reduced word s i1 · · · s i ℓ Algebraic Combinatorics, Vol. 6 #1 (2023) for a permutation of S n and read it from left to right. We start at the initial state (marked with "start"), and at step t we follow the transition marked by the letter s it if any, or stay in the current state otherwise. After ℓ steps, the reduced word s i1 · · · s i ℓ is declared accepted if the current state is accepting (doubly circled, healthy or ill states), and rejected otherwise (dead states).
For a fixed j ∈ {2, . . . , n − 1}, we say that a permutation π avoids jki (resp. kij) if for any i < j < k, the word jki (resp. kij) does not appear as a subword of the one-line notation of π, or said differently if there are no positions p < q < r such that π(r) < π(p) = j < π(q) (resp. π(q) < π(r) = j < π(p)). We insist on the fact that while the value j is fixed, i and k take all possible values such that 1 ⩽ i < j < k ⩽ n. This convenient notion here should not be mixed up with the notion of pattern avoidance where j is not fixed. For instance, a permutation avoids the pattern 231 if and only if it avoids jki for all j ∈ {2, . . . , n − 1}.
Example 2.1. The permutation 42135 avoids 2ki, 3ki, and 4ki (and therefore the pattern 231), but contains ki3 (and therefore the pattern 312) because its one-line notation contains 423.

2.2.
Behavior under left multiplication. In the perspective of proving Theorem 1.1, we study the two properties "π admits a reduced word accepted by U(j) (resp. D(j))" and "π avoids jki (resp. kij)". In this section, we study the behavior of these properties under left multiplication. We treat separately the cases when we multiply by a permutation commuting with both s j−1 and s j (Lemma 2.2), by s j−1 (Lemma 2.4), and by s j (Lemma 2.6). (1) τ admits a reduced word accepted by U(j) (resp. D(j)) if and only if σ · τ admits a reduced word accepted by U(j) (resp. D(j)), (2) τ avoids jki (resp. kij) if and only if σ · τ avoids jki (resp. kij).
Algebraic Combinatorics, Vol. 6 #1 (2023) Proof. Consider a reduced word w starting with s j−1 and accepted by U(j). We deal with the two statements separately: (1) Since w starts with s j−1 , the values j −1 and j are reversed in τ . If j and j +1 were also reversed in τ , we would obtain that j − 1 and j + 1 are reversed. It follows that w must contain a s j at some point after the s j−1 . But this would lead to a dead state, contradicting the assumption that w is accepted.
Lemma 2.6. If a permutation τ ∈ S n does not permute j and j + 1 (resp. j − 1 and j), Proof. We deal with the two statements separately: (1) Suppose that w is a reduced word for τ accepted by U(j + 1). Since τ does not permute j and j + 1, we know that s j · w is a reduced word for s j · τ , and it is accepted by U(j) by construction. Conversely assume that s j · τ admits a reduced word w accepted by U(j). Since s j · τ permutes j and j + 1, w must contain a s j and cannot start by s j−1 by Lemma 2.4. Due to Lemma 2.2 we can also assume that w starts with s j . Thus the suffix is a reduced word for τ that is accepted by U(j + 1). (2) Observe that since j and j +1 are reversed in s j ·τ and not in τ , the value j +1 cannot serve as k in a subword jki of s j · τ and the value j cannot serve as i in a subword (j + 1)ki in τ . The result thus immediately follow from the fact that the left multiplication by s j only exchanges the values j and j + 1. □ Example 2.7. Consider j := 4 and the permutations τ 1 := 142536 and τ 2 := 142563 that do not permute 4 and 5. Multiplying we obtain s 4 · τ 1 = 152436 and s 4 · τ 2 = 152463. Observe that (1) the reduced word s 4 · s 3 · s 4 · s 2 of s 4 · τ 1 is accepted by U(4) and the reduced word s 3 · s 4 · s 2 of τ 1 is accepted by U (5), while all reduced words of s 4 · τ 2 are rejected by U(4) and all reduced words of τ 2 are rejected by U(5), (2) s 4 ·τ 1 avoids 4ki and τ 1 avoids 5ki, while s 4 ·τ 2 contains 463 and τ 2 contains 563.

2.3.
Proof of Theorem 1.1. With these lemmas in hand, we are now ready to show Theorem 1.1 that we repeat here for convenience.
The following conditions are equivalent for π ∈ S n : • π admits a reduced word accepted by the automaton U(j) (resp. D(j)), • π contains no subword jki (resp. kij) with i < j < k.
Proof of Theorem 1.1. We work by induction on the length of the permutations. Assume that a permutation π admits a reduced word accepted by U(j). Let s i be the first letter of this reduced word and let τ be such that π = s i · τ . We distinguish three cases: • If i = j − 1, then π avoids jki by Lemma 2.4 (2).
In all three cases, we proved that π avoids jki. Assume now that a permutation π avoids jki. Here, we have to be careful because not all reduced words for π will be accepted by U(j) a priori. So we have to construct a good reduced word for π. We distinguish two cases: • Assume first that there is m > j such that π reverses j and m, and pick m minimal for this property. It follows that π reverses ℓ and m for all ℓ in {j, . . . , m − 1}. In other words, π admits a reduced word starting by the cyclic permutation (j, j and τ such that π = σ · s j · τ and so that this word is reduced. By Lemmas 2.2 (2) and 2.6 (2), τ avoids (j + 1)ki. By induction, we obtain that it admits a reduced word accepted by U(j +1). By Lemmas 2.2 (1) and 2.6 (1), we conclude that π admits a reduced word accepted by U(j). • Assume now that j appears before all m > j in π. Consider any reduced word for π. If this word is accepted by U(j), we are done. Otherwise, it first uses s j−1 and then s j (otherwise, j and some m > j would be exchanged). Call i and k the two elements that are exchanged when the reduced word first uses s j . We have i < j < k and jki in π (because j and k are not exchanged in π, and i and k are already exchanged so they will remain exchanged in π), a contradiction.
In both cases, we proved that π admits a reduced word accepted by U(j). □

Structure of accepted reduced words
In this section, we explore some additional properties of the set of reduced words accepted by the automata U(j) and D(j) and derive relevant algorithmic and combinatorial consequences.
3.1. The set of accepted reduced words. Observe that a given permutation π may admit both accepted and rejected reduced words. For instance, the (non-simple) transposition (j − 1 j + 1) has reduced words s j · s j−1 · s j accepted by U(j) and s j−1 · s j · s j−1 rejected by U(j). However, Propositions 3.1, 3.2, and 3.3 below show that the set of accepted reduced words satisfies the following three principles: • Who can do more can do less! -The set of accepted reduced words is closed by prefix. • When health goes, everything goes! -If π admits an accepted reduced word, then π admits an accepted reduced word starting with any descent that remains in the healthy states. • All roads lead to Rome! -All accepted reduced words for π end at the same state.
Proposition 3.1. The set of reduced words accepted by U(j) (resp. D(j)) is closed by prefix.
Proof. This immediately follows from the fact that the set of reduced words is closed by prefix, and that the set of accepting states of U(j) is connected and contains the initial state. □ A permutation π ∈ S n that avoids jki (resp. kij) and reverses ℓ and ℓ + 1 admits a reduced word starting with s ℓ and accepted by U(j) (resp. D(j)).
Hence, τ has a reduced word accepted by U(j) by Theorem 1.1, and we conclude by Lemma 2.2 (1). □ Proposition 3.3. Given a permutation π ∈ S n , all the reduced words for π accepted by U(j) (resp. D(j)) end at the same state.
To prove Proposition 3.3, it would be enough to check that any two reduced words accepted by U(j) that differ by a single commutation or a single braid relation indeed end at the same state. However, we prefer to prove instead the following stronger but more technical version of Proposition 3.3.
denote the numbers of inversions involving j as the first and second entry respectively. Then (i) if ninv j (π) = 0, then all reduced words for π end at the same healthy state of U(j), (ii) if ninv j (π) = 0, then all reduced words for π end at the same state of U(j), which might be healthy if π avoids ji, ill if π contains ji but avoids jki, or dead if π contains jki, (iii) if ninv j (π) ̸ = 0 ̸ = ninv j (π), all accepted reduced words for π end at the same ill state of U(j) while the rejected reduced words may end at distinct dead states of U(j). Moreover, all reduced words for π accepted by U(j) end in the (ninv j (π) + 1)st column of U(j). A similar statement holds for D(j) by exchanging ninv j (π) and ninv j (π).

3.2.
Finding accepted reduced words. Proposition 3.2 has a strong algorithmic consequence. Imagine we want to test whether a permutation π ∈ S n is minimal in its permutree class for U = {j} and D = ∅. Of course, the quickest way is to check for all i < j < k whether π contains the subword jki. But since this interpretation will be lost beyond type A, let us impose the use of reduced words for π to make this test. While it would be a priori necessary to check all reduced words on the automaton U(j), Proposition 3.2 enables us to construct without loss of generality a candidate reduced word for π and we will just need to check that this one is accepted by U(j). Somewhat dually, one can also construct a reduced word accepted by U(j) that is a reduced word for π if and only if π avoids jki. This is done in the following algorithm, that we call ({j}, ∅)-permutree sorting. The reader is invited to write down the symmetric (∅, {j})-permutree sorting. We will discuss further permutree sorting in Section 4.4.
Proof. This algorithm constructs a candidate reduced word for π while following the automaton U(j) and prioritizing healthy states over ill states. Lines 2 to 5 start by all possible transitions s ℓ that remain in healthy states, updating j to j + 1 when ℓ = j according to Lemma 2.6 (if condition at line 5). When we have exhausted all these transitions, if we need to go to an ill state (if condition at line 6) applying s j−1 , then we are not anymore allowed to use s j and we obtain a candidate reduced word by sorting independently the first j positions of π with a reduced word in {s 1 , . . . , s j−1 } * and the last [n] ∖ [j] positions of π with a reduced word in {s j+1 , . . . , s n−1 } * . The resulting reduced word w is clearly accepted by U(j) because we never allow the transition from an ill state to the corresponding dead state. If w is a reduced word for π, then π avoids jki by Theorem 1.1. Conversely, if π avoids jki, then w must be a reduced word for π since the choice to start with s ℓ is valid in lines 2 to 5 by Proposition 3.2 and forced in lines 6 to 8 (since all reduced words of π then start by s ℓ ). □ Remark 3.8. We really wrote Algorithm 1 as a sorting algorithm. It first tries to sort the permutation π ∈ S n while avoiding to swap j − 1 and j for a certain token j (and changing the token when swapping j and j + 1). Once it is forced to swap j − 1 and j, it tries to sort the permutation π while avoiding to swap any value of  Proof. Consider a reduced word w = u · v where u is not in R(n, {j}, ∅, ≺). If u is not accepted by U(j), neither is w by Proposition 3.1. Otherwise, there exists a reduced word u ′ representing the same permutation as u, accepted by U(j) and ≺-lexicographic smaller than u. By Proposition 3.3, the reduced words u and u ′ end at the same state of U(j). Therefore, if w = u · v is accepted by U(j), so is u ′ · v. Since u ′ · v Algebraic Combinatorics, Vol. 6 #1 (2023) is ≺-lexicographically smaller than u · v and represents the same permutation, this ensures that w is not in R(n, {j}, ∅, ≺). □ Proposition 3.9 yields a natural generating tree for R(n, {j}, ∅, ≺) where the parent of a reduced word w is obtained by deleting its last letter. Replacing each reduced word by the corresponding permutation, this provides a generating tree for the ({j}, ∅)-permutree minimal permutations of S n . Of course there is a similar generating tree for the (∅, {j})-permutree minimal permutations of S n . Figure 3 presents these generating trees for n = 4 and j = 2, 3, with the priority order s 1 ≺ s 2 ≺ s 3 . It is natural to draw these trees on top of the Hasse diagram of the right weak order on permutations, defined by inclusion of inversion sets. In other words, the cover relations in weak order correspond to the swap of the values at two consecutive positions in a permutation, i.e. to a right multiplication by a simple transposition. The edges of the trees corresponding to the right multiplications by s 1 , s 2 and s 3 are colored by blue, red, and green respectively.

Intersection of automata
We now consider arbitrary subsets U and D of {2, . . . , n − 1}. We already know from [12] and Theorem 1.1 that the following conditions are equivalent for π ∈ S n : (i) the permutation π is minimal in its (U, D)-permutree class, (ii) for i < j < k, the permutation π does not contain the subword jki if j ∈ U and kij if j ∈ D, (iii) for each j ∈ U (each j ∈ D), there is a reduced word for π accepted by U(j) (resp. by D(j)).
A natural question is whether there is a reduced word simultaneously accepted by all these automata. We start with an example showing that this is not always the case.
Example 4.1. For j ∈ {2, . . . , n − 1}, consider U = {j} = D, and π = s j−1 · s j · s j−1 = s j · s j−1 · s j . Then, the word s j−1 · s j · s j−1 is accepted by D(j) but not by U(j), while the word s j · s j−1 · s j is accepted by U(j) but not by D(j).
This example clearly extends to all subsets U and D of {2, . . . , n − 1} with a nonempty intersection. In contrast, we will now show that this situation cannot occur when U and D are disjoint. • π admits a reduced word accepted by all automata U(j) for j ∈ U and D(j) for j ∈ D, • π contains no subword jki if j ∈ U and kij if j ∈ D for any i < j < k.
Proof. The direct implication is immediate from Theorem 1.1. For the converse implication, consider a permutation π that avoids jki for j ∈ U and kij for j ∈ D. ConsiderŪ := {j ∈ U | ninv j (π) ̸ = 0} andD := j ∈ D ninv j (π) ̸ = 0 . By Proposition 3.4 (ii), any reduced word for π is accepted by U(j) for j ∈ U ∖Ū and by D(j) for j ∈ D ∖D. We can therefore assume thatŪ = U andD = D and one of them is non-empty, sayŪ = U ̸ = ∅. Let j • := max(U ) and m be minimal such that j • < m and π −1 (j • ) > π −1 (m). By minimality of m, we obtain that π contains the subword mj • ℓ for any j • < ℓ < m. It implies that • ℓ is neither in U by maximality of j • , nor in D by assumption on π, for all j • < ℓ < m, • π reverses ℓ and m for all ℓ in {j • , . . . , m − 1}, so that π admits a reduced word of the form π = s m−1 · · · s j• · τ . Lemmas 2.2 (2) and 2.6 (2) ensure that • τ avoids jki for all j ∈ U ∖ {j • } and kij for all j ∈ D ∖ {m} (because j • , . . . , m − 1 are all distinct from j − 1 and j in these cases by the second observation above), • τ avoids (j • + 1)ki, • if m ∈ D, then τ avoids kij • . By induction, it follows that τ admits a reduced word w simultaneously accepted by all automata U(j) for j ∈ U ∖{j • } and j = j • +1, and all automata D(j) for j ∈ D ∖{m} and j = j • if m ∈ D. By Lemmas 2.2 (1) and 2.6 (1), we conclude that s m−1 · · · s j• · w is a reduced word for π simultaneously accepted by all U(j) for j ∈ U and D(j) for j ∈ D.   , D) the intersection of the automata U(j) for j ∈ U and D(j) for j ∈ D. We thus obtain the following statement.
Corollary 4.2. When U and D are disjoint, the following conditions are equivalent for π ∈ S n : • π admits a reduced word accepted by the automaton P(U, D), • π contains no subword jki if j ∈ U and kij if j ∈ D with i < j < k.
We say that a state of P(U, D) is healthy (resp. ill, resp. dead) when the corresponding states in U(j) for j ∈ U and D(j) for j ∈ D are all healthy (resp. contain at least one ill state, but no dead one, resp. contains at least one dead state). Figure 4 illustrates the automata P({4}, {2}) when n = 5 (left), P({3}, {2}) for n = 4 (middle), and P({2}, {4}) for n = 5 (right). For the first two automata, we draw the complete automata on top, and their skeleta on the bottom. Here, we call skeleton a simplification of the automaton that recognizes the same reduced words. It is obtained using the fact that the word is rejected as soon as we reach a dead state, and that the automata U(n) and D(1) accept all reduced words. For the last automaton, the complete intersection is too big, so we only draw the reachable healthy states. We color the transitions in red, blue, or purple depending on whether only U, only D, or both U and D change state.

4.3.
The set of accepted reduced words of P(U, D). Applying the principles of Section 3.1 to each automaton U(j) for j ∈ U and D(j) for j ∈ D, we derive similar principles for the automaton P(U, D). The following statements are direct consequences of Propositions 3.1, 3.2, and 3.3.

Permutree sorting.
We have seen that the set of reduced words for any (U, D)-permutree minimal permutation π that are accepted by P(U, D) is non-empty (by Corollary 4.2) and that the set of all reduced words that are accepted by P (U, D) is closed by prefix (by Proposition 4.3). Therefore, it is possible to sort π passing only through (U, D)-permutree minimal permutations along the way. This motivates the following definition.  Said differently, any procedure that looks for a reduced word accepted by P(U, D) gives a (U, D)-permutree sorting algorithm. For instance, Algorithm 1 is a ({j}, ∅)permutree sorting algorithm. We generalize it in the following algorithm, where we opted for a recursive style. As in Algorithm 1, the algorithm will read the automaton P(U, D) without actually constructing it. To virtually follow the edges of the automaton P(U, D), we use two operations on our sets U and D: Note that in Algorithm 2, we could ignore n in the list U (resp. 1 in the list D) since U(n) (resp. D(1)) accepts all reduced words. We have decided not to do it to be coherent with our recursive definition of U(j) and D(j).
Proof. This algorithm constructs a candidate reduced word for π following the automaton P(U, D) and prioritizing healthy states over ill states. It begins by checking Algebraic Combinatorics, Vol. 6 #1 (2023) all possible transitions s ℓ that keep P(U, D) in healthy states following Lemma 2.6 (if condition in line 2). Doing this in the intersection of automata translates to updating ℓ to ℓ + 1 when ℓ ∈ U and ℓ + 1 to ℓ when ℓ + 1 ∈ D (line 3). When we have exhausted all these transitions, we need to go to an ill state of P(U, D), i.e. to apply a transposition that sends at least one automaton of the intersection to an ill state. If there is ℓ + 1 ∈ U (resp. ℓ ∈ D) such that s ℓ is a descent of π and π([ℓ + 1]) = [ℓ + 1] (resp. π([ℓ − 1]) = [ℓ − 1]), then any reduced word for π is accepted by the automaton U(ℓ) (resp. D(ℓ)) by Proposition 3.4 (i). We can thus start with s ℓ and forget about the automaton U(ℓ) (resp. D(ℓ)) (lines 4, 5 and 6). Finally, if none of these options are possible, any reduced word for π will lead to a dead state in at least one of the automata, so that π is not (U, D)-sortable. We thus return the empty reduced word (line 7).

Permutree sorting versus Coxeter sorting
In this section, we discuss the particular case when U and D form a partition of {2, . . . , n − 1}. In that situation, we connect the (U, D)-permutree sorting with the c-sorting of N. Reading [16].

5.1.
Coxeter sorting word and Coxeter sortable permutations. We first recall the theory of c-sorting developed by N. Reading in [16]. While it was defined in arbitrary finite Coxeter groups, we focus on the symmetric group in this presentation. We consider a Coxeter element c of S n , i.e. the product of all simple transpositions {s 1 , . . . , s n−1 } in an arbitrary order. For a permutation π ∈ S n , the c-sorting word π(c) is the lexicographically smallest reduced word for π in the infinite word c ∞ = c · c · c · c · · ·. Note that strictly speaking, π(c) depends on a reduced word for c, not only on the Coxeter element c. Here, we assume that we have chosen a reduced word and hide this dependence. We let I 1 , . . . , I p denote the subsets of [n − 1] such that π(c) = c I1 · c I2 · · · c Ip where c I is the subword of c obtained by keeping only the letters s i for i ∈ I. The permutation π is c-sortable if I 1 ⊇ I 2 ⊇ · · · ⊇ I p . Note that this does not depend on the choice of the reduced word c, only on the Coxeter element c.
For our proofs we will need some simple yet useful facts from [16] on how prefixes of words influence sortability.
Lemma 5.1. Consider a Coxeter element of the form c = s ℓ · d and let π ∈ S n . Then • if π = s ℓ · τ with ℓ(π) = ℓ(τ ) + 1, then π(c) = s ℓ · τ (d · s ℓ ), • otherwise, π(c) = π(d · s ℓ ). (1) if s i appears before s j in c, then s i appears before s j in π(c), (2) if s j does not appear in between two occurrences of s i in π(c), then it does not appear after these occurrences either.
Proof. We deal with the two statements separately: (1) Immediate from the definition since both s i and s j appear in π(c).
(2) Since π is c-sortable, π(c) is formed by a succession of subwords that are nested. Thus if s j were to appear after the occurrences of s i it would have to appear between them as well. . . , n − 1} such that s j appears before (resp. after) s j−1 in c. For instance, when c = s 2 · s 5 · s 4 · s 3 · s 1 · s 6 , we obtain U c = {2, 4, 5} and D c = {3, 6}. Said differently, j ∈ U (resp. j ∈ D) if c is accepted by U(j) but not by D(j) (resp. by D(j) but not by U(j)). The goal of this section is the following connection between the c-sorting of Section 5.1 and the (U c , D c )-permutree sorting of Section 4.
Theorem 5.3. For any Coxeter element c and any permutation π, the following assertions are equivalent: (i) π is c-sortable, (ii) the c-sorting word π(c) is accepted by the automaton P(U c , D c ), (iii) there exists a reduced word for π accepted by the automaton P(U c , D c ), (iv) for each j ∈ {2, . . . , n − 1}, there exists a reduced word for π that is accepted by the automaton U(j) if j ∈ U c and D(j) if j ∈ D c , (v) π avoids jki for j ∈ U c and kij for j ∈ D c .
The equivalences (iii) ⇐⇒ (iv) ⇐⇒ (v) were already established earlier. Here, we aim at identifying the c-sorting word as a reduced word for π accepted by P(U c , D c ). We split the proof of the equivalences (i) ⇐⇒ (ii) ⇐⇒ (iii) into the following few lemmas.
Lemma 5.4. The c-sorting word of a c-sortable permutation is recognized by U(j) for j ∈ U c and by D(j) for j ∈ D c .
Proof. Consider j ∈ U c (the proof for j ∈ D c is symmetric). We distinguish two possible cases: • If π(c) contains no s j−1 , then π(c) either remains in the first healthy state or ends in the first ill state of U(j). • If π(c) contains s j−1 , then by Lemma 5.2 (1) s j−1 appears before s j in π(c) and π(c) leads to the second healthy state of U(j). From here on out, notice that π(c) cannot end at a dead state because of Lemma 5.2 (2). In both cases, π(c) is accepted by U(j). □ Lemma 5.5. A permutation π ∈ S n whose c-sorting word π(c) is accepted by Proof. Suppose that π is not c-sortable. We will find an automaton that rejects π(c) among the automata U(j) for j ∈ U c and D(j) for j ∈ D c . Once again, we work by induction on the length of π and the size of c. Let s ℓ be the first letter of c and write c = s ℓ · d.
Since s ℓ appears before s ℓ−1 and s ℓ+1 in c, we have ℓ ∈ U c and ℓ + 1 ∈ D c . Moreover, the letter s ℓ yields to the next healthy state in both automata U(ℓ) and D(ℓ+1), and remains in the initial state for all other automata U(j) Algebraic Combinatorics, Vol. 6 #1 (2023) for j ∈ U c ∖{ℓ} and D(j) for j ∈ D c ∖{ℓ+1}. We now distinguish two cases, depending on whether ℓ and ℓ + 1 are reversed in π. Assume first that ℓ and ℓ + 1 are reversed in π and write π = s ℓ · τ . We then have π(c) = s ℓ · τ (d · s ℓ ) by Lemma 5.1, so that τ is not d · s ℓ -sortable. By induction hypothesis, τ (d · s ℓ ) is rejected by one of the automata U(j) for j ∈ U d·s ℓ and D(j) for j ∈ D d·s ℓ . Since U d·s ℓ = U c △ {ℓ, ℓ + 1} and D d·s ℓ = D c △ {ℓ, ℓ + 1}, Lemmas 2.2 and 2.6 ensure that π(c) = s ℓ · τ (d · s ℓ ) is rejected by one of the automata U(j) for j ∈ U c and D(j) for j ∈ D c .
Assume now that ℓ and ℓ + 1 are not reversed in π. Then π(c) does not use s ℓ and π is not d-sortable in W ⟨s ℓ ⟩ . By induction hypothesis, π(c) is rejected by one of the automata U(j) for j ∈ U d and D(j) for j ∈ D d . This concludes the proof since U d ⊆ U c and D d ⊆ D c . □ Lemma 5.6. If a permutation π ∈ S n admits a reduced word accepted by P(U c , D c ), then its c-sorting word π(c) is accepted by P(U c , D c ).
Proof. Once again, we work by induction on the length of π. Let s ℓ be the first letter of c and write c = s ℓ · d.
Since s ℓ appears before s ℓ−1 and s ℓ+1 in c, we have ℓ ∈ U c and ℓ + 1 ∈ D c . Moreover, the letter s ℓ yields to the next healthy state in both automata U(ℓ) and D(ℓ + 1), and remains in the initial state for all other automata U(j) for j ∈ U c ∖ {ℓ} and D(j) for j ∈ D c ∖ {ℓ + 1}. We now distinguish two cases, depending on whether ℓ and ℓ + 1 are reversed in π. Assume first that ℓ and ℓ+1 are reversed in π and write π = s ℓ ·τ . Using Lemma 5.1 it suffices now to show that after s ℓ , there is a reduced word for τ accepted by the automata. For each j, since the automaton D(j) or U(j) that we see accepts at least one reduced word for π and s ℓ does not lead to a ill state, it also accepts a reduced word for π starting with s ℓ by Proposition 3.2. Observe moreover that: • τ admits a reduced word accepted by U(j) for each j / ∈ {ℓ, ℓ+1} by Lemma 2.2. This lines up with the fact that the order of s j−1 and s j has not changed from c = s ℓ · d to d · s ℓ . • τ admits a reduced word accepted by U(ℓ + 1) and a reduced word accepted by D(ℓ) by Lemma 2.6. This fits the fact that ℓ now appears after ℓ − 1 and ℓ + 1 in d · s ℓ . By induction, we obtain that τ (d · s ℓ ) is accepted by P(U d·s ℓ , D d·s ℓ ), so that π(c) = s ℓ · τ (d · s ℓ ) is accepted P(U c , D c ).
Assume now that ℓ and ℓ + 1 are not reversed in π. We want to show that s ℓ never appears in the reduced words for π, i.e. that π([ℓ]) = [ℓ] and π([n] ∖ [ℓ]) = [n] ∖ [ℓ]. Otherwise, the reduced word w ℓ accepted by U(ℓ) would see first a s ℓ+1 , and then a s ℓ before it sees any s ℓ−1 , so that we would have an inversion kℓ in π for some ℓ < k. Similarly, the reduced word w ℓ+1 accepted by D(ℓ + 1) should see first a s ℓ−1 and then a s ℓ before it sees any s ℓ+1 , so that we would have an inversion (ℓ + 1)i in π for some i < ℓ + 1. Since ℓ and ℓ + 1 are not reversed, we see kℓ(ℓ + 1)i which contradicts twice Theorem 1.1. We conclude that this case never happens, so that we can work in the parabolic subgroup of permutations that never use s ℓ in their reduced words. □ 5.3. Some negative observations. We conclude this paper with some negative observations and warnings about the connection between c-sorting and (U c , D c )permutree sorting. First, we want to underline that using c-sorting words to test whether a permutation avoids jki or kij for a fixed j is dangerous for the following two reasons.
Remark 5.7. Even if a permutation π avoids jki (resp. kij) for a given j, there might be no Coxeter element c for which π is c-sortable and j ∈ U c (resp. j ∈ D c ). For Algebraic Combinatorics, Vol. 6 #1 (2023) instance, the permutation 41325 ∈ S 5 avoids 2ki and ki4, but contains 352 and 413, so it is not c-sortable for any Coxeter element c.
We conclude the paper with an observation about sorting networks and permutree sorting.
Remark 5.9. Given a Coxeter element c, the word c ∞ which is used to compute π(c) is a sorting network. This means that we decide beforehand a list of transpositions to apply if appropriate. On the other hand, the permutree sorting given in Algorithm 2 is not a sorting network. Indeed, the order on transpositions depends on the permutation and more specifically on the state of the automaton we are at. A natural question then occurs: can we replace the permutree sorting algorithm by a sorting network? Or said differently, when U and D are disjoint but do not cover {2, . . . , n − 1}, can we find a wordc which plays the role of c ∞ in the sense that looking at π(c) would be enough to check whether π is accepted by P(U, D)?
The answer is negative in general. A counter-example is found for n = 5, U = {2}, and D = {4}. In this case one can check through computer exploration that no reduced wordc of the maximal permutation 54321 can be used as a sorting network. Namely, for all choices ofc, there exist a permutation π which is accepted by P(U, D) whereas the reduced word π(c) is rejected. The healthy states of P({2}, {4}) are shown in Figure 4. We see that accepted reduced words can start with either s 2 or s 3 . For some permutations, such as 54213 shown in Example 4.8, all accepted reduced words start with s 3 whereas for some other permutations such as 35421, all accepted reduced words start with s 2 . This eventually leads to an empty intersection for the choice ofc.
Nevertheless, it seems interesting to study in which case the answer is positive. The Cambrian case with the c-sorting word when U and D form a partition of {2, . . . , n − 1} is one example. The case where |U | + |D| = 1 is another one. This is the case corresponding to Theorem 1.1 where we have only one automaton. In this case, we can construct a wordc by reading the healthy states of the automaton linearly, adding at each state the word (s i1 · · · s i k ) k s j where s i1 , . . . , s i k are the looping transitions and s j is the transition going to the next healthy state. This process gives a prefix that can be extended in any way to obtain a proper sorting wordc. For example, if U = {2}, we obtain the prefix s 3 · s 2 · s 1 · s 3 and indeed s 3 · s 2 · s 1 · s 3 · s 2 · s 1 acts as a sorting network equivalent to the ({2}, ∅)-permutree sorting. This process actually seems to extend to all cases where, at each healthy state of the intersection automaton, the choices for the healthy transitions commute. For example, in the case where n = 5, U = {4} and D = {2} as illustrated in Figure 4, the word s 1 · s 2 · s 4 · s 3 · s 2 · s 1 · s 4 · s 3 · s 2 gives a proper sorting network.