Equivalence Classes of Permutations Modulo Replacements Between 123 and Two-Integer Patterns

We explore a new type of replacement of patterns in permutations, suggested by James Propp, that does not preserve the length of permutations. In particular, we focus on replacements between 123 and a pattern of two integer elements. We apply these replacements in the classical sense; that is, the elements being replaced need not be adjacent in position or value. Given each replacement, the set of all permutations is partitioned into equivalence classes consisting of permutations reachable from one another through a series of bi-directional replacements. We break the eighteen replacements of interest into four categories by the structure of their classes and fully characterize all of their classes.


Introduction
A permutation is said to contain a pattern if it has a subpermutation order-isomorphic to the pattern. Modern study of permutation patterns was prompted by Donald Knuth in the form of stack-sortable permutations in [4], but has since evolved into an active combinatorial field. (For various other applications and motivations see Chapters 2 and 3 in the book by Sergey Kitaev [3].) Much of the work on permutation patterns has dealt with counting permutations that contain or avoid certain patterns.
The notion of replacing a pattern in a permutation with a new pattern was first mentioned in different forms, as the plactic and Chinese monoids, by Alain Lascoux and Marcel P. Schützenburger in [8], Gérard Duchamp and Daniel Krob in [2], and Julien Cassaigne et al. in [1]. These have since been translated into the language of pattern replacements and further studied. Steven Linton et al. consider in [9] several bi-directional pattern replacements between 123 and another pattern of length 3, as well as cases where multiple such replacements are allowed at the same time. They inspect these replacements when applied to elements in general position, elements with adjacent positions, and elements with adjacent positions and adjacent values. A couple papers, [11], by James Propp et al., and [6], by William Kuszmaul, follow up on replacements on elements with adjacent positions. Together these three papers enumerate the equivalence classes in a general S n and count the size of the class containing the identity for almost all cases. In addition, William Kuszmaul and Ziling Zhou examine in [7] equivalence classes under more general families of replacements. Throughout all of this work, permutation length was preserved under replacements. James Propp has suggested considering pattern replacements that do not preserve permutation length; that is, when a pattern is replaced with another pattern of different length. This paper takes the first step in this new direction by examining a group of replacements between patterns with three integer elements and two integer elements. We choose to use the classical type of replacement in which replaced elements need not be adjacent in position or value. To accommodate patterns of different lengths, we use a modified definition of patterns that includes the character * in place of certain integer elements, acting as a placeholder in the replacement procedure. Like previous works, we define equivalence as reachability through a series of bi-directional replacements, using which we can partition the set of permutations of all lengths into equivalence classes.
In particular, in this paper we investigate the equivalence classes for the 18 replacements of the form 123 ↔ β, where β contains exactly one * and two integers. First, we provide an overview of relevant definitions and notations in Section 2. Then, we break the 18 replacements into four categories and spend each of Sections 3, 4, 5, and 6 dealing with one of these categories. We fully characterize all equivalence classes for each of the considered replacements.

Definitions
We will use the standard definition of a permutation.

Definition 1.
A permutation π is a finite, possibly empty string consisting of the first n positive integers. We refer to n as the the length of the permutation, denoted by |π|.
The permutation of length 0 is the empty permutation, denoted by ∅. We will refer to the identity permutation of length n, 123 . . . n (or ∅ if n = 0), by id(n) and the reverse identity permutation of length n, n(n − 1)(n − 2) . . . 1 (or ∅ if n = 0), by rid(n).
We will also mention here a term that will emerge in Section 6: Definition 2. An element of a permutation is a left-to-right minimum if it has a value less than every element to its left.
The terms left-to-right maximum, right-to-left minimum, and right-to-left maximum are defined similarly.
We now introduce the classical notion of a pattern.
Definition 3. Let π and µ be permutations. A substring p of π forms a copy of the pattern µ if it is order-isomorphic to µ. If such a substring exists, π contains µ. Otherwise, π avoids µ.
The definition of patterns must be extended for our purposes to accommodate patterns that may contain * .
Definition 4. Let ρ and δ be strings each consisting of distinct positive integers and * 's. A substring r of ρ forms a copy of the * -pattern δ if the following conditions are met: • r and δ have stars in the same positions, and • r and δ, when ignoring all stars, are order-isomorphic to one another.
We take interest in replacements of patterns in permutations, that are not necessarily adjacent, to form new permutations of possibly different lengths. We define replacements using * -patterns to be able to work with changes in length: Definition 5. Let α and β be * -patterns of equal length. Given a permutation π, we say another permutation σ is a result of the replacement α → β on π if σ can be obtained from the following steps on π: 1. As necessary, renumber the integers in π, while preserving relative order, and add instances of * anywhere. Call this result ρ (1) .
2. Choose some substring a of ρ (1) that forms a copy of α. Also, choose a string b of distinct positive integers and * 's such that the following are true: • all elements common to both b and ρ (1) are contained in a, and • for all x ∈ N contained in both α and β, if y ∈ N in a is at the same position as x in α, then y is in b at the same position as x in β.
Replace a in ρ (1) with b and call the result ρ (2) .
3. Drop all instances of * in ρ (2) and renumber, while preserving relative order, so that the final result is a permutation ρ (3) = σ.
For clarity, in this paper we will show alongside replacements the involved substrings in the original and resulting permutations with square brackets. In our previous example, this would be [125 → 41]. Note that in the above definition it is possible that |π| = |σ|; that is, replacements do not necessarily preserve length.
We now introduce the notion of equivalence between permutations of possibly different lengths using two directions of a replacement. Definition 6. We call two permutations π and σ equivalent, written π ≡ σ, under the bi-directional replacement α ↔ β if σ can be attained through a sequence of α → β and β → α replacements on π.
We use this definition of equivalence to partition the set of all permutations, S 0 ∪ S 1 ∪ S 2 ∪ · · · , into equivalence classes. Our aim is to eventually characterize these classes.
Sometimes we find that it is impossible to apply a given replacement to a permutation, so that it is in its own class, which we will refer to by the following term.
Definition 7. The permutation π is isolated under a replacement α ↔ β if the equivalence class containing it has no other permutations.
The following property, which arises in particular in Section 3, if established gives great insight into the structure of equivalence classes. Definition 8. We say a replacement α ↔ β has the unraveling property if any given permutation is equivalent under α ↔ β to an identity permutation.
It is notable that if a replacement has the previous property, then there is at most one class per identity permutation.
It will be helpful in Sections 4 and 6 to talk about the shortest permutation equivalent to some given permutation under a replacement, for which we have the following definition.
Definition 9. The primitive permutation τ of π under a replacement α ↔ β is the unique permutation of shortest length equivalent to π, if it exists.
Note that for some permutations and replacements, a shortest equivalent permutation might not be unique, so in such cases we say that a primitive permutation does not exist.
Finally, we briefly note a symmetry that effectively cuts the number of distinct cases in half: if β and γ are reverse complements of one another, then π and σ are equivalent under 123 ↔ β if and only if their reverse complements are equivalent under 123 ↔ γ.
(Here reverse means flipped order of elements and complement means flipped value of elements.) For example, because 2314 ≡ 231 under 123 ↔ 13 * , we have 1423 ≡ 312 under 123 ↔ * 13. Note that this symmetry is due to the fact that 123 is its own reverse complement.
In the remainder of this paper we examine equivalence classes of replacements of the form 123 ↔ β, where β contains two of {1, 2, 3} and one * in some order. We cover the cases in which the integer elements of β are in decreasing order in Section 3. Then, in Section 4 we analyze cases where the two integer elements in β are in the same positions as in 123. In Section 5 we consider when the two integer elements of β are both shifted left or right one from their positions in 123. We deal with the four remaining cases in Section 6.
Under all nine replacements, descents are allowed to be rearranged into increasing order, which naturally suggests that they have the unraveling property. This is indeed the case: Lemma 10. If β is decreasing, then 123 ↔ β has the unraveling property.
Proof. The following proof is valid for any of 123 ↔ 31 or 123 ↔ 32. This will then cover 123 ↔ 21 by the reverse complement symmetry.
We proceed by inducting on the length of the permutation over the nonnegative integers. For the base case of length zero, we note that the only such permutation, ∅, is itself an identity permutation. Assume for the inductive step that any permutation of length n is equivalent to some identity permutation and consider any permutation π of length n + 1. By the inductive hypothesis, we may apply replacements on the last n integers of π so that they become an increasing string of m integers. Suppose the first element in this result is k. Then, we have Thus, in general for n ≥ 6 we can apply the above replacements to the first five elements of id(n) to obtain id(n) ≡ id(n + 1), so that id(5) ≡ id(6) ≡ id (7) ≡ . . . , which was to be shown. However, this misses id (4). We now show id(4) ≡ id (7) For n ≥ 5 we can apply the above replacements to the first four elements of id(n) to obtain id(n) ≡ id(n + 1), so that id(4) ≡ id(5) ≡ id(6) ≡ . . . .
Combining the above lemmas, we can explicitly find all the equivalence classes: Proof. It can easily be verified that each permutation in the first four classes is equivalent to every other permutation in that class, and that applying 123 ↔ β permutation in the first four classes produces a permutation also already in that class. Thus, the first four listed classes contain no other permutations. Also, by Lemma 10 every permutation not in those four classes must be equivalent to an identity of length at least 4. Then by Lemmas 11 and 12, all identities of length at least 4 are equivalent, so all remaining permutations are equivalent to one another, forming the fifth class.
4 Drop Only: 123 ↔ * 23, 123 ↔ 1 * 3, and 123 ↔ 12 * The replacements 123 ↔ * 23, 123 ↔ 1 * 3, and 123 ↔ 12 * simply drop or add an element in a 123 pattern. In the remainder of this section we will proceed simultaneously with 12 * and 1 * 3 by using γ to denote an arbitrary selection from the two, and later use the reverse complement symmetry to state the result of equivalence classes for 123 ↔ * 23.
We begin by defining a function that will take any given permutation to what we will show to be its primitive permutation.
First we show that p γ is preserved under one direction of the replacement: Lemma 15. If σ is the result of 123 → γ applied to π, then p γ (π) = p γ (σ).
Proof. When written out in terms of their elements, let π = π 1 . . . π k−1 π k π k+1 . . . π n and σ = σ 1 . . . σ k−1 σ k+1 . . . σ n , so that n = |π| = |σ| + 1 and if π k is dropped from π the remaining elements are order-isomorphic to σ. We now proceed with the proof separately for γ = 12 * and γ = 1 * 3. First consider γ = 12 * . We will simultaneously compare the processes of calculating p γ (π) and p γ (σ). Each iteration of step 2 in Definition 14 will be performed on copies of 123 at the same positions for computing p γ (π) and p γ (σ) when the entire copy of 123 is in the first k − 1 elements. The first iteration of step 2 in p γ (π) for which this is not true must be performed on a copy of 123 in which π k is the third element, because at least one such copy exists (the one on which 123 ↔ 12 * was applied to form σ). All iterations after this must again be performed on the same positions for p γ (π) and p γ (σ). Furthermore, the resulting strings of each iteration will be order-isomorphic for the two processes, so that the end results will be equal. Now suppose γ = 1 * 3. Again, each iteration of step 2 performed completely in the first k − 1 elements will be on the same positions for p γ (π) and p γ (σ). However, on the iterations for p γ (π) in which π k is the third element of a 123 pattern, a copy of 123 will be chosen for p γ (σ) in which the first two elements are at the same positions as those for p γ (π), but the third element will be to the right of σ k−1 . (We know at least one such third element exists: the third element of the 123 copy on which 123 ↔ 1 * 3 was applied to form σ.) Even though the copy of 123 chosen for p γ (π) and p γ (σ) are different, the middle elements that are dropped will be in the same positions. Finally, on the iteration for p γ (π) in which π k is the middle element (this iteration must take place because an appropriate 123 copy must exist), π k will be dropped. The resulting strings at this point for p γ (π) and p γ (σ) will be order-isomorphic, so the final permutations p γ (π) and p γ (σ) will be equal. Now, we can put a condition on equivalency involving p γ : Lemma 16. Under 123 ↔ γ, we have π ≡ σ if and only if p γ (π) = p γ (σ).
Now we have enough to show that p γ (π) is the primitive permutation of π: Lemma 17. Under 123 ↔ γ, p γ (π) is the primitive permutation of π.
We restate the definition of the primitive permutation without using of p γ (π) so that we can include 123 ↔ * 23.
Theorem 18. For β = 12 * , 1 * 3, * 23, the primitive permutation of π under 123 ↔ β is the result of repeatedly applying to π the replacement 123 → β on any choice of a 123 pattern until none exist.
For β = * 23, we use the reverse complement symmetry: the theorem statement is true for β = 12 * , and the reverse complement of the statement is the statement itself, so it is true for β = * 23.
Proof. Note that for each τ avoiding 123, τ itself along with all other permutations whose primitive permutation is τ will be equivalent by Definition 9, and thus are in the same class.
Suppose now there exists another permutation σ that is in the same class as π, but has primitive permutation ω different than τ . However, this is a contradiction because both ω and τ are defined to be the unique permutation of shortest length equivalent to π.
Note that while the above statement of the equivalence classes is the same for all three possible replacements, the classes themselves are different. This is because the primitive permutations can be different for different β.

Shift Right and Shift
Left: 123 ↔ * 12 and 123 ↔ 23 * We now deal with the replacements that shift two elements of a 123 pattern to the left or right and drop the third. We may immediately characterize the classes with the following theorem. In the proof, we draw inspiration from the stooge sort, in a manner similar to the proof of Proposition 2.17 in [6]. Proof. Note that the two replacements are reverse complements of one another, and the reverse complement version of the theorem's statement is the same as the statement, so we only work with 123 ↔ * 12.
It is not possible to apply either direction of the replacement 123 ↔ * 12 to a reverse identity, so each reverse identity must not be equivalent to any other permutation and is thus isolated.
On the other hand, we claim that the permutations that are not reverse identities are equivalent. Note that immediately we have 12 ≡ 123. Therefore, for n ≥ 2 we may transform the first two elements of id(n) into 123 so that id(n) ≡ id(n + 1). Thus, id(2) ≡ id(3) ≡ id(4) ≡ . . . . Now, we will prove that all non-reverse identity permutations of length n are equivalent to id(n) by inducting on n ≥ 3. (The cases for n = 0, 1, 2 are trivial.) The base case of n = 3 may be checked computationally. Now, assume the statement is true for n = k − 1, and suppose π = rid(n) is some given permutation of length n. If the first n − 1 elements of π are not order-isomorphic to rid(n − 1), we apply the inductive hypothesis to the first n − 1 elements, then the last n − 1 elements, and finally the first n − 1 elements again; the result is id(n). If the first n − 1 elements of π are orderisomorphic to rid(n − 1), then we instead apply the inductive hypothesis on the last n − 1 elements, the first n − 1 elements, and finally the last n − 1 elements. (We can not have both the first n − 1 elements and the last n − 1 elements of π order-isomorphic to rid(n − 1), because then π = rid(n).) The result of this procedure is again id(n), so that π ≡ id(n), as desired.
Because all permutations that are not reverse identities are equivalent to the identity of the same size, and all identities that are not also reverse identities are equivalent, we have that all non-reverse identity permutations are equivalent, completing the proof for 123 ↔ * 12.
Note that taking the reverse complements of each permutation in the classes described above results in exactly the same classes, so the result for 123 ↔ 23 * is the same.
By using this mechanism we may swap any two elements that are not left-to-right minima: Lemma 22. Suppose a permutation π and two of its non-left-to-right minimum elements are given. Order these two elements in decreasing order then drop the rightmost one, and call the result π ′ . Under 123 ↔ 13 * , π ≡ π ′ .
While non-left-to-right minima can be manipulated as shown, there are two properties of the set of non-left-to-right minima that must remain unchanged, in addition to the set of left-to-right minima: Lemma 23. Under 123 ↔ 13 * , two permutations π and σ are equivalent only if they have the following equal: • the number of left-to-right minima, • the position of the leftmost non-left-to-right minimum, and

• the largest value (relative to the left-to-right minima) of non-left-to-right minima.
Proof. To show that π ≡ σ only if the they share the three above properties, it suffices to show that 123 ↔ 13 * preserves these properties; moreover, only one direction is necessary to prove because then the reverse must also preserve them. Thus, we consider the 123 → 13 * direction applied to the elements φ 1 < φ 2 < φ 3 (from left to right) of an arbitrary permutation φ to produce φ ′ . Also, call k 1 the position of φ 1 and k 2 that of φ 2 when counting from the left.
We will undertake the first property by breaking the permutations at the k 1 -th position. The substrings of the first k 1 elements of φ and φ ′ are order-isomorphic, so the two substrings contain the same number of left-to-right minima. On the other hand, the left-to-right minima to the right of φ 1 in φ and to the right of φ ′ 1 in φ have values less than φ 1 and φ ′ 1 . Furthermore, the substring of φ consisting of all elements except those to the right of and greater than φ 1 is order-isomorphic to the corresponding substring of elements of φ ′ that are not both to the right of and greater than φ ′ 1 . Therefore, the numbers of left-to-right minima to the right of the k 1 -th element in each of φ and φ ′ are the same. We conclude that 123 → 13 * preserves the number of left-to-right minima.
To prove the second property we will use the fact that the first k 2 − 1 elements of φ and φ ′ are order-isomorphic. The leftmost non-left-to-right minimum of φ is at a position of at most k 2 , because φ 2 is a non-left-to-right minimum. Similarly, the leftmost non-left-to-right minimum of φ ′ has position at most k 2 . If φ 2 is indeed the leftmost non-left-to-right minimum, then φ ′ 3 will be the leftmost non-left-to-right minimum in φ ′ at the same position. Otherwise, the leftmost non-left-to-right minimum is in the first k 2 − 1 elements and thus in the same position in φ and φ ′ .
For the third property, it should be noted that when discussing a value relative to those of left-to-right minima we are discussing the number of left-to-right minima less than (or greater than) that value; such a notion is only valid when the number of left-to-right minima is constant (which was shown above). Consider the greatest nonleft-to-right minimum in φ and φ ′ , which we will call φ i and φ ′ i respectively. Note that φ i can not be φ 2 because φ 3 is a greater non-left-to-right minimum. Then, the relative order of values of the set of elements from φ consisting of all left-to-right minima and φ i is the same as that of the set of elements from φ ′ consisting of all of its left-to-right minima and φ ′ i , as desired.
In terms of three properties we may exactly characterize the equivalence classes: Theorem 24. Under 123 ↔ 13 * , there exists a distinct equivalence class for every triple of integers (m, p, v), with 1 ≤ p, v ≤ m, consisting of all permutations π with the following properties: • π has m left-to-right minima, • the position (from the left) of the leftmost non-left-to-right minimum is p + 1 • the value of the largest non-left-to-right minima is less than those of v left-to-right minima In addition, each reverse identity permutation is in a class only containing itself. There are no other classes.
Proof. Note that if π is a reverse identity permutation, then it can not undergo either direction of 123 ↔ 13 * , so it must be isolated. For the remainder of the theorem it suffices to show that, given two non-reverseidentity permutations π and σ, π ≡ σ if and only if they have the same triple (m, p, v). The only if direction was shown in Lemma 23. We will prove the other direction through the use of a primitive permutation.
Suppose both π and σ have triple (m, p, v). From Lemma 23, any permutation equivalent to π must have the same number of left-to-right minima. Also, it must have at least one non-left-to-right minimum. Thus, the shortest permutation equivalent to π must have at least m + 1 elements. In fact, there is exactly one permutation of this length: the permutation of length m + 1 whose (p + 1)-th element has value v + 1 and remaining elements are in decreasing order. We can indeed construct this permutation by applying Lemma 22 repeatedly to any pair of non-left-to-right minima until the resulting permutation τ has length m + 1.
In a similar manner, we may construct the primitive permutation of σ, which must also be τ because it has the same (m, p, v) triple. Thus, π and σ have the same primitive permutation and must be equivalent.
The remaining replacements 123 ↔ 1 * 2 and 123 ↔ 2 * 3 (which are reverse complements) have similar equivalence classes. Following logic analogous to Lemma 21, Lemma 22, Lemma 23, and Theorem 24, we may find that equivalence under 123 ↔ 1 * 2 implies and is implied by equivalence under 123 ↔ 132, with which we can identify three properties that are necessary and sufficient to infer equivalence. The result classifying the equivalence classes under 123 ↔ 1 * 2 is stated below: Theorem 25. Under 123 ↔ 1 * 2, there exists a distinct equivalence class for every triple (m, p, v), with 1 ≤ p, v ≤ m, consisting of all permutations π with the following properties: • π has m left-to-right minima, • the value of the smallest non-left-to-right minima is greater than those of v leftto-right minima • the position (from the right) of the rightmost non-left-to-right minimum is p + 1 In addition, each reverse identity permutation is isolated. There are no other classes.
The results for 123 ↔ * 13 and 123 ↔ 2 * 3 can be found by taking the reverse complement of each statement in Theorems 24 and 25, respectively. In particular, all instances of left-to-right minima become right-to-left maxima. Table 1 summarizes the characterization of the equivalence classes for each of the 18 considered replacements. For replacements whose classes are described in the form {π | π ≡ τ } for a certain τ , refer to their respective sections for algorithms that produce the τ corresponding to a given π.