This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

\ytableausetup

centertableaux

Deterministic stack-sorting for set partitions

Janabel Xia Department of Mathematics, Massachusetts Institute of Technology, Cambridge, MA [email protected]
Abstract.

A sock sequence is a sequence of elements, which we will refer to as socks, from a finite alphabet. A sock sequence is sorted if all occurrences of a sock appear consecutively. We define equivalence classes of sock sequences called sock patterns, which are in bijection with set partitions. The notion of stack-sorting for set partitions was originally introduced by Defant and Kravitz. In this paper, we define a new deterministic stack-sorting map ϕσ\phi_{\sigma} for sock sequences that uses a σ\sigma-avoiding stack, where pattern containment need not be consecutive. When σ=aba\sigma=aba, we show that our stack-sorting map sorts any sock sequence with nn distinct socks in at most nn iterations, and that this bound is tight for n3n\geq 3. We obtain a fine-grained enumeration of the number of sock patterns of length nn on rr distinct socks that are 11-stack-sortable under ϕaba\phi_{aba}, and we also obtain asymptotics for the number of sock patterns of length nn that are 11-stack-sortable under ϕaba\phi_{aba}. Finally, we show that for all unsorted sock patterns σaabaa\sigma\neq a\cdots aba\cdots a, the map ϕσ\phi_{\sigma} cannot eventually sort all sock sequences on any multiset MM unless every sock sequence on MM is already sorted.

1. Introduction

1.1. Stack-sorting algorithms

There is a long history of research on sorting with restricted data structures. In particular, Knuth first introduced the concept of a stack-sorting machine in The Art of Computer Programming [19], which uses a stack data structure to sort sequences. Given an input sequence, one can push elements from the input onto the stack and pop elements off the stack to the output subject to the constraint that the element being popped out of the stack must be the element that was most recently pushed onto the stack. Thus, the stack grants sorting power through choices between pushes and pops. A stack-sorting algorithm is a rule for deciding whether to push or pop at each step in the sorting process. There has since been much work on various stack-sorting algorithms inspired by Knuth’s stack-sorting machine, including West’s deterministic stack-sorting algorithm [4, 11, 13, 22], pop-stack-sorting [1, 2, 21], deterministic stack-sorting for words [14], sorting with pattern-avoiding stacks [3, 5, 6, 16], stack-sorting Coxeter groups [10, 12], and more.

In the setting where our sequences are permutations, we say that a sequence is sorted when it is the identity permutation. Given a stack-sorting algorithm, it is natural to ask how many passes through the stack are needed to sort the input object. We say that our input object is kk-stack-sortable if there is some stack-sorting algorithm that sorts the input in at most kk iterations. We say that our input object is kk-stack-sortable under ϕ\phi if it can be sorted by at most kk iterations of a given stack-sorting algorithm ϕ\phi. Knuth [19] characterized the permutations that are 11-stack-sortable as exactly the permutations that avoid the pattern 231231. This characterization launched the growing field of permutation patterns research that exists today. In general, the set of permutations that are kk-stack-sortable is closed under pattern containment. However, given the nondeterminism of Knuth’s stack-sorting machine, it is very difficult to characterize or enumerate such permutations when k2k\geq 2. For example, Pierrot and Rossin only recently proved that there is a polynomial time algorithm for deciding whether or not a given permutation is 22-stack-sortable [20]. This motivated West to define a deterministic stack-sorting algorithm [22], which uses 2121-avoiding stacks. West’s stack-sorting map is easier to analyze. For example, all permutations of length nn are (n1)(n-1)-stack-sortable under West’s stack-sorting map. Furthermore, we can explicitly characterize all permutations that require all (n1)(n-1) iterations of West’s stack-sorting map to become sorted.

Beyond the permutation setting, Defant and Kravitz recently generalized the notion of stack-sorting to set partitions [15]. In this paper, we continue the investigation of stack-sorting of set partitions. More generally, we define sock sequence to be a sequence of elements, which we refer to as socks, from a finite alphabet. We say a sock sequence is sorted if all occurrences of a sock appear consecutively in the sequence. We also define equivalence classes on sock sequences called sock patterns, which are in bijection with set partitions. We will study stack-sorting on sock sequences and sock patterns.

As in the permutation setting, one can characterize which sock patterns are 11-stack-sortable. Defant and Kravitz showed that a sock pattern pp is 11-stack-sortable if and only if there is a 231231-avoiding word representation of pp [15]. However, the nondeterminism of stack-sorting sock patterns makes analyzing the number of stacks needed to sort them difficult. This motivates us to look at deterministic stack-sorting algorithms, which we believe may shed light on the nondeterministic setting. Inspired by both West’s 2121-avoiding stack-sorting map and Defant and Zheng’s work on consecutive pattern-avoiding stacks [16], we define and study novel pattern-avoiding stack-sorting maps on sock sequences. Our notion of pattern avoidance is identical to Klazar’s notion of pattern avoidance for set partitions [17, 18]. However, our notion of pattern avoidance within the stack differs in that we do not only consider consecutive pattern avoidance. We formally define these pattern-avoiding stack-sorting algorithms in Section 2.

1.2. Main results

We give special attention to one such pattern-avoiding stack-sorting map for sock sequences. We define a foot-sorting map, denoted ϕaba\phi_{aba}, based on abaaba pattern avoidance in the stack. The name foot-sorting comes from Defant and Kravitz’s original paper on the topic [15], in which feet are used in place of stacks. We show that every sock sequence eventually becomes sorted under a finite number of iterations of ϕaba\phi_{aba}. Moreover, any sorted sock sequence stays sorted after applying ϕaba\phi_{aba}. Thus our map ϕaba\phi_{aba} is a noninvertible sorting operator.

When looking at any noninvertible combinatorial dynamical system, it is natural to ask how many objects require a given number of iterations to reach a periodic point. For sorting operators in particular, it is natural to ask how many objects become sorted after applying a fixed number of sorting operations. For example, Defant enumerated the 33-stack-sortable permutations [12, 9, 11], West enumerated the (n2)(n-2)- and (n3)(n-3)-stack-sortable permutations [22], and Claesson, Dukes, and Steingrimsson enumerated the (n4)(n-4)-stack-sortable permutations [7].

Thus, we begin by taking an enumerative approach to studying ϕaba\phi_{aba}. We state and prove an enumeration of sock patterns of length nn that are 11-stack-sortable under ϕaba\phi_{aba}, and we further extend this result to a refined enumeration that is parameterized by the number of distinct socks rr in the sock pattern. In particular, we have the following closed forms.

Theorem 1.1.

Let s(n)s(n) denote the number of sock patterns of length nn that are 11-stack-sortable under ϕaba\phi_{aba}. Let P(x):=n=1s(n)xnP(x):=\sum_{n=1}^{\infty}s(n)x^{n} be the corresponding generating function. Then we have

P(x)=(1+3x3x2)+16x+7x22x3+x44(x2x).P(x)=\frac{(-1+3x-3x^{2})+\sqrt{1-6x+7x^{2}-2x^{3}+x^{4}}}{4(x^{2}-x)}.
Theorem 1.2.

Let s(n,r)s(n,r) denote the number of sock patterns of length nn and containing rr distinct socks that are 11-stack-sortable under ϕaba\phi_{aba}. Let P[q](x):=n=1r=1s(n,r)xnqrP_{[q]}(x):=\sum_{n=1}^{\infty}\sum_{r=1}^{\infty}s(n,r)x^{n}q^{r} be the corresponding multivariate generating function. Then we have

P[q](x)=(q+(q2+2q)x(q2+2q)x2)+q12(q+2)x+(q2+2q+4)x22q2x3+q2x42(q+1)(x2x).P_{[q]}(x)=\frac{(-q+(q^{2}+2q)x-(q^{2}+2q)x^{2})+q\sqrt{1-2(q+2)x+(q^{2}+2q+4)x^{2}-2q^{2}x^{3}+q^{2}x^{4}}}{2(q+1)(x^{2}-x)}.

We then take a separate approach to studying these pattern-avoiding stack-sorting operators, namely through investigating periodic points for general patterns σ\sigma. In particular, we show in Proposition 5.2 that for any unsorted sock pattern σaabaa\sigma\neq a\cdots aba\cdots a and for any multiset of socks MM such that not all sock sequences on MM are already sorted, there always exists a sock sequence on MM that never gets sorted by ϕσ\phi_{\sigma}.

1.3. Outline of the paper

In Section 2, we provide background discussion on sock sequences and stack-sorting algorithms that we use throughout the paper. In Section 3, we describe the action of our foot-sorting map ϕaba\phi_{aba} and prove a tight upper bound on the number of iterations of ϕaba\phi_{aba} required to sort an arbitrary sock sequence. In Section 4, we prove the explicit enumerations of sock patterns that are 11-stack-sortable under ϕaba\phi_{aba} stated in Theorem 1.1 and Theorem 1.2. In Section 5, we study the behavior of general σ\sigma-avoiding stack-sorting maps through periodic points. In Section 6, we raise some natural future directions for the investigation of deterministic stack-sorting for set partitions.

2. Preliminaries

In this section, we provide definitions and notation for the discussion of stack-sorting sock sequences.

2.1. General notation for sock sequences

Fix an arbitrary infinite alphabet AA. Throughout, we will use the standard Latin alphabet a,b,c,a,b,c,\dots to refer to distinct elements of AA. We call these elements of AA socks. A sock sequence is a sequence p=p1pnp=p_{1}\cdots p_{n} of socks in AA. Let AA^{*} denote the (infinite) set of sock sequences on AA.

Let pp be a sock sequence. Let |p||p| denote the length of the sock sequence. We say that a sock sequence pp is empty if |p|=0|p|=0, and nonempty otherwise. Let x1x2x_{1}x_{2}\cdots denote the concatenation of sock sequences x1,x2,x_{1},x_{2},\dots (where xix_{i} is potentially empty). Let xmx^{m} denote the sock sequence xxx\cdots x consisting of mm occurrences of sock xAx\in A. Let C(p):=|SP(p)|C(p):=|{\operatorname{SP}}(p)| denote the number of distinct socks appearing in sock sequence pp.

2.2. Sock patterns as sequences

We first introduce the following definition, which will help us develop the notion of sock patterns.

Definition 2.1.

Let p=p1pnp=p_{1}\cdots p_{n} be a sock sequence on the alphabet AA. Then define Set(p):={p1,,pn}{\operatorname{Set}}(p):=\{p_{1},\dots,p_{n}\} as the set of distinct socks in pp.

We can now define an equivalence relation on sock sequences, where two sock sequences p=p1pnp=p_{1}\cdots p_{n} and q=q1qmq=q_{1}\cdots q_{m} are equivalent if and only if there exists a bijection f:Set(p)Set(q)f:{\operatorname{Set}}(p)\rightarrow{\operatorname{Set}}(q) such that q=f(p1)f(pn)q=f(p_{1})\cdots f(p_{n}). Thus, two sock sequences are equivalent if one can be obtained from the other by renaming the socks. For example, the sock sequences abaaabaa and cacccacc are equivalent. A sock pattern is an equivalence class on sock sequences under our equivalence relation. This also gives us a notion of pattern avoidance. We say that a sock sequence avoids a sock pattern σ\sigma if no subsequence of socks forms a sock sequence in the class σ\sigma.

We can also introduce the following notion of standardization to obtain a natural representative of each equivalence class.

Definition 2.2.

The standardization of a sock sequence pp is an injective renaming of the socks in pp such that the socks appearing for the first time from left to right form the alphabetical sequence {a,b,c,}\{a,b,c,\dots\}.

Example 2.1.

Let p=bbadbp=bbadb. Then the standardization of pp is aabcaaabca.

We say that a sock sequence is standardized if it is equal to its own standardization. We see then that two sock sequences are equivalent exactly when they have the same standardization. When referring to a sock pattern, we will use the unique standardized sock sequence in the equivalence class as our representative.

In the traditional setting of stack-sorting permutations, one can think of permutations as sequences on the base set [n][n] for some n>0n\in\mathbb{Z}_{>0}. In the setting of sock sequences, we instead define our base set to be a multiset MM of socks. We can then think of sock sequences as sequences on the multiset MM.

Definition 2.3.

Let MM be a multiset of socks. Let S(M)S(M) be the set of sock sequences consisting of all socks in MM (equivalently, the set of sock sequences on MM).

Example 2.2.

Let M={a,a,b,b}M=\{a,a,b,b\}. Then S(M)={aabb,abab,abba,baab,baba,bbaa}S(M)=\{aabb,abab,abba,baab,baba,bbaa\}.

Note that it will often be natural to consider the entire set S(M)S(M) at once, as S(M)S(M) is closed under any stack-sorting map. For example, to study a stack-sorting map ϕ\phi, we can ask which sock sequences within S(M)S(M) get sent to each other, which sock sequences within S(M)S(M) eventually become sorted under repeated iterations of ϕ\phi, which sock sequences within S(M)S(M) are periodic points, etc.

Finally, the following notation will help us connect sock sequences to set partitions.

Definition 2.4.

Let pp be any sock sequence on MM. For any sock mMm\in M, define I(p,m):={ipi=m}I(p,m):=\{i\mid p_{i}=m\}, i.e. the set of indices ii at which sock mm occurs in pp.

2.3. Sock patterns as set partitions

Sock patterns of length nn are in bijection with set partitions on [n][n]. For example, the sock pattern represented by the standardized sock sequence p=aabacbp=aabacb corresponds to the set partition {{1,2,4},{3,6},{5}}\{\{1,2,4\},\{3,6\},\{5\}\}. Let 𝒳𝓃\mathcal{X_{n}} denote the set of all set partitions on [n][n]. Then the bijection is

SP(p):A\displaystyle{\operatorname{SP}}(p):A^{*} 𝒳\displaystyle\rightarrow\mathcal{X}
p\displaystyle p {I(p,m)mp},\displaystyle\mapsto\{I(p,m)\mid m\in p\},

where the subsets in the set partition SP(p){\operatorname{SP}}(p) correspond to the indices at which a fixed sock occurs in pp. Note that Klazar’s notion of pattern avoidance for set partitions [17, 18] corresponds to our notion of pattern avoidance for sock patterns.

2.4. A novel stack-sorting map

We define a deterministic stack-sorting algorithm for sock sequences based on pattern avoidance of sock patterns. This sorting algorithm is inspired by the consecutive pattern-avoiding stacks defined by Defant and Zheng [16]. Here, we consider pattern containment in a more general sense, where a pattern need not occur consecutively within the stack.

Definition 2.5.

Let ϕaba:AA\phi_{aba}:A^{*}\rightarrow A^{*} denote the stack-sorting map given by the following procedure. Suppose we are given an input sequence pp read from left to right. Throughout the procedure, we consider the sequence ss of socks obtained from reading the stack from top to bottom. At each point in time, we do one of the following operations:

  1. (1)

    If there are remaining socks to push and pushing the leftmost sock from our input sock sequence onto the top of the stack does not create an abaaba pattern in ss, then we do so.

  2. (2)

    Otherwise, we pop the topmost sock off of our stack.

The procedure continues until the output contains all socks in the original input. Let ϕaba(p)\phi_{aba}(p) denote the output sock sequence.

Example 2.3.

Let p=abcabp=abcab. Then the following diagram illustrates the state of the stack at each step in the algorithm. Our output sock sequence is ϕaba(abcab)=cbbaa\phi_{aba}(abcab)=cbbaa, which we note is sorted.

Refer to caption
Figure 1. Result of applying map ϕaba\phi_{aba} to the sock sequence p=abcabp=abcab

We can think about output sock sequences as belonging to the image of map ϕaba\phi_{aba}. Note that this sorting procedure preserves the multiset of socks, and therefore also induces a map ϕaba:S(M)S(M)\phi_{aba}:~{}S(M)\rightarrow S(M) for any multiset of socks MM. Furthermore, sorting with ϕaba\phi_{aba} and then renaming socks with a bijection ff yields the same sock sequence as renaming socks with a bijection ff and then sorting with ϕaba\phi_{aba}, so this sorting procedure also induces a map from sock patterns to sock patterns. We call this particular stack-sorting map a foot-sorting map, which we investigate in more detail in Section 3.

More generally, we can define analogous stack-sorting maps ϕσ\phi_{\sigma} for any pattern σ\sigma.

Definition 2.6.

Let ϕσ:AA\phi_{\sigma}:A^{*}\rightarrow A^{*} denote the stack-sorting map given by the following procedure. Suppose we are given an input sequence pp read from left to right. Throughout the procedure, we consider the sequence ss of socks obtained from reading the stack from top to bottom. At each point in time, we do one of the following operations:

  1. (1)

    If there are remaining socks to push and pushing the leftmost sock in our input sequence onto the top of the stack does not create a σ\sigma pattern in ss, then we do so.

  2. (2)

    Otherwise, we pop the topmost sock off of our stack.

The procedure continues until the output contains all socks in the original input. Let ϕσ(p)\phi_{\sigma}(p) denote the output sock sequence.

Again, this general sorting procedure preserves the sets of sock sequences S(M)S(M) for any multiset of socks MM and also induces a map from sock patterns to sock patterns.

3. The foot-sorting map ϕaba\phi_{aba}

In this section, we study the behavior of the foot-sorting map ϕaba\phi_{aba} introduced in Definition 2.5. We begin by presenting a quick but useful lemma that tells us what the action of our foot-sorting map ϕaba\phi_{aba} looks like recursively.

Lemma 3.1.

Let p=xl1s1xl2s2xlmsmxlm+1p=x^{l_{1}}s_{1}x^{l_{2}}s_{2}\cdots x^{l_{m}}s_{m}x^{l_{m+1}} be a sock sequence where l1,,lm>0l_{1},\dots,l_{m}>0 and lm+10l_{m+1}\geq 0 are integers, and s1,,sms_{1},\dots,s_{m} are nonempty sock sequences not containing xAx\in A. Then

ϕaba(p)=ϕaba(s1)ϕaba(s2)ϕaba(sm)xl1++lm+1.\phi_{aba}(p)=\phi_{aba}(s_{1})\phi_{aba}(s_{2})\cdots\phi_{aba}(s_{m})x^{l_{1}+\cdots+l_{m+1}}.
Proof.

We show directly what happens to input sock sequence p=xl1s1xl2s2xlmsmxlm+1p=x^{l_{1}}s_{1}x^{l_{2}}s_{2}\cdots x^{l_{m}}s_{m}x^{l_{m+1}}. By definition, we first push the first l1l_{1} occurrences of xx onto the stack. We then have the following for all i[m1]i\in[m-1]. We i) push all socks in sis_{i} onto the stack, which only contains l1++lil_{1}+\cdots+l_{i} occurrences of xx. This results in sis_{i} getting sorted by ϕaba\phi_{aba} independently, since sis_{i} contains no occurrences of xx and therefore does not interact with the occurrences of xx at the bottom of the stack. We then ii) must pop all remaining socks in sis_{i} in the stack before pushing the next occurrences of xx, to avoid having the pattern abaaba occur in the stack. Finally, we iii) push the next li+1l_{i+1} consecutive occurrences of xx in our input. After m1m-1 rounds of this process, we are left with smxlm+1s_{m}x^{l_{m+1}} in our input, ϕaba(s1)ϕaba(sm1)\phi_{aba}(s_{1})\cdots\phi_{aba}(s_{m-1}) in our output, and exactly l1++lml_{1}+\cdots+l_{m} occurrences of xx on our stack. Again, we push all socks in sms_{m} and independently sort them. If lm+1=0l_{m+1}=0, we finally pop all remaining socks in sms_{m} in the stack and all l1++lml_{1}+\cdots+l_{m} occurrences of xx at the bottom of the stack, giving us ϕaba(s1)ϕaba(sm)xl1++lm\phi_{aba}(s_{1})\cdots\phi_{aba}(s_{m})x^{l_{1}+\cdots+l_{m}} as our final output. If lm+1>0l_{m+1}>0, we pop all remaining socks in sms_{m} in the stack before pushing the next lm+1l_{m+1} occurrences of xx, and finally pop all l1++lm+1l_{1}+\cdots+l_{m+1} occurrences of xx in the stack to obtain ϕaba(s1)ϕaba(s2)ϕaba(sm)xl1+lm+1\phi_{aba}(s_{1})\phi_{aba}(s_{2})\cdots\phi_{aba}(s_{m})x^{l_{1}+\cdots l_{m+1}}. Thus our output always becomes ϕaba(s1)ϕaba(s2)ϕaba(sm)xl1++lm+1\phi_{aba}(s_{1})\phi_{aba}(s_{2})\cdots\phi_{aba}(s_{m})x^{l_{1}+\cdots+l_{m+1}}, as desired. ∎

Given how our foot-sorting map ϕaba\phi_{aba} acts on sock sequences, we can provide an upper bound on the number of iterations of ϕaba\phi_{aba} required to sort any sock sequence. In the permutation setting, we have that any permutation of length nn is (n1)(n-1)-sortable under West’s stack-sorting map, which is linear in the number of distinct elements of the permutation sequence, and furthermore this bound is tight. It turns out that any sock sequence on nn distinct socks is nn-sortable under ϕaba\phi_{aba}, which is also linear in the number of distinct elements appearing in our sequence. We also show that this bound is tight.

Theorem 3.2.

Let pp be any sock sequence on multiset MM. Let nn be the number of distinct socks in MM. Then pp is nn-sortable under ϕaba\phi_{aba}. Furthermore, for any n>2n>2 there exists a sock sequence pp such that pp is not (n1)(n-1)-sortable under ϕaba\phi_{aba}.

Proof.

Say that a sock is clumped if all occurrences of that sock appear consecutively. Then we can see that any sock that is clumped stays clumped under ϕaba\phi_{aba}; if we can push one of the clumped socks onto the stack and avoid the pattern abaaba, then we can push all of them onto the stack. Likewise, once we must pop a clumped sock out of the stack, then all of the socks can constitute the last sock in the pattern abaaba, so they must all be popped out together.

We claim that each application of ϕ\phi adds at least one more clumped sock. In particular, if the first sock xx is not clumped, then by Lemma 3.1, one application of ϕaba\phi_{aba} clumps together all occurrences of sock xx and sends them to the back of the output sock sequence. If the first sock xx is already clumped, then we have p=xxqp=x\cdots xq where qq is some sock sequence. Then ϕaba(p)=ϕ(q)xx\phi_{aba}(p)=\phi(q)x\cdots x, and we can use the same argument on qq. Thus, the first sock that is not already clumped becomes clumped under ϕaba\phi_{aba}. Because socks that are clumped stay clumped in any subsequent application of ϕaba\phi_{aba}, we need at most nn stacks to sort pp.

To show that this bound is tight for any nn, consider the sock sequence p=a1ana1anp^{*}=a_{1}\cdots a_{n}a_{1}\cdots a_{n} where aia_{i} is a sock for all i[n]i\in[n] and pp^{*} contains exactly two copies of each distinct sock aia_{i}. We will show that pp^{*} is not (n1)(n-1)-sortable under ϕaba\phi_{aba}. To do so, we claim that the after kk iterations of ϕaba\phi_{aba} for, our sock sequence becomes X1qX2qX3X_{1}qX_{2}qX_{3} where qq is a sock sequence of length |q|=nk|q|=n-k containing only single occurrences of socks, and X1,X2X_{1},X_{2}, and X3X_{3} are sock sequences of lengths |X1|=2k3,|X2|=2k+13|X_{1}|=2\left\lfloor\frac{k}{3}\right\rfloor,|X_{2}|=2\left\lfloor\frac{k+1}{3}\right\rfloor and |X3|=2k+23|X_{3}|=2\left\lfloor\frac{k+2}{3}\right\rfloor. We prove this by induction on kk.

Our base case is easily verifiable; ϕaba((a1an)2)=ana2ana2a1a1)\phi_{aba}((a_{1}\cdots a_{n})^{2})=a_{n}\cdots a_{2}a_{n}\cdots a_{2}a_{1}a_{1}), which we can rewrite in the form X1qX2qX3X_{1}qX_{2}qX_{3} where X1X_{1} and X2X_{2} are empty, X3=a1a1X_{3}=a_{1}a_{1}, and q=ana2q=a_{n}\cdots a_{2}, which are all of the correct form. Now we assume our hypothesis holds up to iteration kk, and show that it remains true after iteration k+1k+1. Indeed, if we write q=aqq=aq^{\prime}, we have

ϕaba(X1aqX2aqX3)=(X2¯q¯X3¯q¯aaX1¯),\phi_{aba}(X_{1}aq^{\prime}X_{2}aq^{\prime}X_{3})=(\overline{X_{2}}\ \overline{q^{\prime}}\ \overline{X_{3}}\ \overline{q^{\prime}}\ aa\ \overline{X_{1}}),

which we can rewrite as X1qX2qX3X_{1}^{\prime}q^{\prime}X_{2}^{\prime}q^{\prime}X_{3}^{\prime}, where X1=X2¯X_{1}^{\prime}=\overline{X_{2}}, X2=X3¯X_{2}^{\prime}=\overline{X_{3}}, and X3=aaX1¯X_{3}^{\prime}=aa\overline{X_{1}}. Then we can verify that |X1|=|X2|=2k+12|X_{1}^{\prime}|=|X_{2}|=2\left\lfloor\frac{k+1}{2}\right\rfloor, |X2|=|X3|=2k+22|X_{2}^{\prime}|=|X_{3}|=2\left\lfloor\frac{k+2}{2}\right\rfloor, |X3|=2+2k3=2k+33|X_{3}^{\prime}|=2+2\left\lfloor\frac{k}{3}\right\rfloor=2\left\lfloor\frac{k+3}{3}\right\rfloor, and q=nk1q=n-k-1, as desired.

Given the claim, we now have that X2X_{2} is nonempty for all sufficiently large kk. The X1qX2qX3X_{1}qX_{2}qX_{3} cannot be sorted until qq is empty, which takes at least nn iterations as desired. ∎

Note that this notion of nonconsecutive pattern avoidance for our deterministic stack-sorting maps ϕaba\phi_{aba} (and more generally ϕσ\phi_{\sigma}) is necessary for our maps to have nice properties like the above. Suppose, instead we defined an analogous stack-sorting map ϕaba\phi^{\prime}_{aba} (and more generally ϕσ)\phi^{\prime}_{\sigma}) that only considers consecutive pattern avoidance in the procedure given by Definition 2.6. Then one example of a sock sequence that never gets sorted by applying iterations of ϕaba\phi^{\prime}_{aba} would be abcabcabcabc (in fact, ϕaba(abcabc)=cbacba\phi^{\prime}_{aba}(abcabc)=cbacba and ϕaba(cbacba)=abcabc\phi^{\prime}_{aba}(cbacba)=abcabc). Moreover, for any σ\sigma, we have sock sequences that never get sorted by applying iterations of ϕσ\phi^{\prime}_{\sigma}. Indeed, we will see in Proposition 5.2 that for any pattern σaba\sigma\neq aba, there always exists an unsorted sock sequence pp that avoids σ\sigma and therefore alternates between pp and p¯\overline{p} under iterations of ϕσ\phi^{\prime}_{\sigma}, neither of which are sorted. Therefore, under the consecutive pattern avoidance regime, there would be no stack-sorting map ϕσ\phi_{\sigma} that eventually sorts any sock sequence.

4. Enumerating 11-stack-sortable sock patterns under ϕaba\phi_{aba}

In this section, we prove our main enumerative results. We first provide a proof of Theorem 1.1 and then derive asymptotics based on the closed form. Then we generalize our argument to prove Theorem 1.2.

We first discuss the notion of appending two sock patterns. Observe that under our notion of equivalence between sock sequences, even if sock sequences s1s_{1} and s1s_{1}^{\prime} are equivalent and sock sequences s2s_{2} and s2s_{2}^{\prime} are equivalent, it does not necessarily follow that the sock sequence s1s2s_{1}s_{2} is equivalent to the sock sequence s1s2s_{1}^{\prime}s_{2}^{\prime}. For example, suppose s1=aaba,s1=aaba,s2=bcabs_{1}=aaba,s_{1}^{\prime}=aaba,s_{2}=bcab, and s2=cbacs_{2}^{\prime}=cbac. Then we can have s1s2=aababcabs_{1}s_{2}=aababcab and s1s2=aabacbacs_{1}^{\prime}s_{2}^{\prime}=aabacbac, which are not the same sock pattern. The sock pattern pp is determined by how we explicitly assign sock names to the occurrence of s1s_{1} and the occurrence of s2s_{2}, up to standardization.

We are now ready to prove Theorem 1.1.

Proof of Theorem 1.1.

We use Lemma 3.1. Let p=xl1s1xl2s2xlmsmxlm+1p=x^{l_{1}}s_{1}x^{l_{2}}s_{2}\cdots x^{l_{m}}s_{m}x^{l_{m+1}} be a 11-stack-sortable sock pattern under ϕaba\phi_{aba} where xsix\notin s_{i} for any i[m]i\in[m]. Note that in order for

ϕaba(p)=ϕaba(s1)ϕaba(s2)ϕaba(sm)xl1++lm+1\phi_{aba}(p)=\phi_{aba}(s_{1})\phi_{aba}(s_{2})\cdots\phi_{aba}(s_{m})x^{l_{1}+\cdots+l_{m+1}}

to be sorted, we must have that for all i[m]i\in[m], each sis_{i} individually is a 11-stack-sortable sock pattern under ϕaba\phi_{aba}.

Then given any fixed sis_{i}, we only need to consider their relationship to each other in the full sock pattern. In particular, we claim that for any l1,l2>0l_{1},l_{2}>0 and nonempty sock patterns s1,s2s_{1},s_{2} that are each 11-stack-sortable under ϕaba\phi_{aba}, there are exactly two possible sock patterns xl1s1xl2s2x^{l_{1}}s_{1}x^{l_{2}}s_{2} that are 11-stack-sortable under ϕaba\phi_{aba}. To see this, we must have |C(si)C(si+1)|1|C(s_{i})\cap C(s_{i+1})|\leq 1, as otherwise the subsequence ϕaba(si)ϕaba(si+1)\phi_{aba}(s_{i})\phi_{aba}(s_{i+1}) in ϕaba(p)\phi_{aba}(p) contains either abababab or abbaabba as a subsequence and is not sorted. We then consider the following two cases:

  1. i)

    If |C(s1)C(s2)|=0|C(s_{1})\cap C(s_{2})|=0, then there is exactly one way to assign sock names to s1s_{1} and s2s_{2} up to standardization. Namely, we can assign any sock names such that the socks in s1s_{1} and s2s_{2} are disjoint, and then standardize.

  2. ii)

    If |C(s1)C(s2)|=1|C(s_{1})\cap C(s_{2})|=1, then again there is exactly one way to assign sock names to s1s_{1} and s2s_{2} up to standardization. Namely, we assign the same name to the last element that appears in ϕaba\phi_{aba} and to the first element that appears in ϕaba(s2)\phi_{aba}(s_{2}), and consider all other socks in s1s_{1} and s2s_{2} disjoint.

Then we can see that up to equivalence, pp is determined by the sock patterns sis_{i} together with the choice for 1im11\leq i\leq m-1 of whether or not sis_{i} and si+1s_{i+1} share a sock, for a total of 2m12^{m-1} choices. We can now consider the cases where m=0m=0 and m1m\geq 1 separately, which allows us to write the following relation on P(x)P(x):

(1) P(x)\displaystyle P(x) =x1x+m1(P(x)m2m1(l1,,lm>0lm+10xl1++lm+1))\displaystyle=\frac{x}{1-x}+\sum_{m\geq 1}\left(P(x)^{m}2^{m-1}\left(\sum_{\begin{subarray}{c}l_{1},\dots,l_{m}>0\\ l_{m+1}\geq 0\end{subarray}}x^{l_{1}+\cdots+l_{m+1}}\right)\right)
(2) =x1x+m1(P(x)m2m1(x1x)m(11x))\displaystyle=\frac{x}{1-x}+\sum_{m\geq 1}\left(P(x)^{m}2^{m-1}\left(\frac{x}{1-x}\right)^{m}\left(\frac{1}{1-x}\right)\right)
(3) =x1x+12(1x)m1(P(x)m2m(x1x)m)\displaystyle=\frac{x}{1-x}+\frac{1}{2(1-x)}\sum_{m\geq 1}\left(P(x)^{m}2^{m}\left(\frac{x}{1-x}\right)^{m}\right)
(4) =x1x+12(1x)2P(x)(x1x)12P(x)(x1x).\displaystyle=\frac{x}{1-x}+\frac{1}{2(1-x)}\cdot\frac{2P(x)\left(\frac{x}{1-x}\right)}{1-2P(x)\left(\frac{x}{1-x}\right)}.

To see why Equation 1 holds, we can consider the coefficient of xnx^{n} for any n0n\in\mathbb{Z}_{\geq 0}. On the left-hand side, this is s(n)s(n) by definition. On the right-hand side, we have two main terms. The first term x1x=n11xn\frac{x}{1-x}=\sum_{n\geq 1}1x^{n} counts the unique sock pattern with length nn that is 11-stack-sortable under ϕaba\phi_{aba} when m=0m=0, namely p=xxp=x\cdots x. The second term contributes a sum of 2m1s(n1)s(n2)s(nm)2^{m-1}s(n_{1})s(n_{2})\cdots s(n_{m}) over all possible lengths n1,,nm,l1,,lm+1n_{1},\dots,n_{m},l_{1},\dots,l_{m+1} with ni>0n_{i}>0 for i[m]i\in[m] and li>0l_{i}>0 such that n1++nm+l1++lm=nn_{1}+\cdots+n_{m}+l_{1}+\cdots+l_{m}=n. This counts the number of sock patterns that are 11-stack-sortable under ϕaba\phi_{aba} when m1m\geq 1, since we can take any nonempty sock patterns sis_{i} that are independently 11-stack-sortable under ϕaba\phi_{aba} and append them in 2m12^{m-1} ways.

Given Equation 4, one can now easily solve the quadratic in P(x)P(x) to obtain the closed form

P(x)=(1+3x3x2)+16x+7x22x3+x44(x2x),P(x)=\frac{(-1+3x-3x^{2})+\sqrt{1-6x+7x^{2}-2x^{3}+x^{4}}}{4(x^{2}-x)},

as desired. ∎

Corollary 4.1.

We have s(n)=Kcnn3/2+O(cnn5/2)s(n)=Kc^{n}n^{-3/2}+O(c^{n}n^{-5/2}), where K=0.34313K=0.34313\cdots is a constant and c=4.5464c=4.5464\cdots is the inverse of the smallest positive root x0x_{0} of 16x+7x22x3+x4=01-6x+7x^{2}-2x^{3}+x^{4}=0.

Proof.

For any power series ff and n0n\geq 0, let [xn]{f(x)}[x^{n}]\{f(x)\} denote the coefficient of xnx^{n} in the series f(x)f(x). We wish to find asymptotics for s(n)=[xn]{P(x)}s(n)=[x^{n}]\{P(x)\}.

Let P(x):=16x+7x22x3+x44(x2x)P^{*}(x):=\frac{\sqrt{1-6x+7x^{2}-2x^{3}+x^{4}}}{4(x^{2}-x)}. Note that to obtain asymptotics for s(n)s(n), it suffices to compute asymptotics for the coefficients of the power series of P(x)P^{*}(x) at x=0x=0, since we can verify that

P(x)P(x)=1+x+x24(x2x)=14n=1xnP(x)-P^{*}(x)=\frac{-1+x+x^{2}}{4(x^{2}-x)}=-\frac{1}{4}\sum_{n=-1}^{\infty}x^{n}

contributes only constant terms to s(n)s(n).

In particular, we define Q(x):=P(x0x)Q(x):=P^{*}(x_{0}x), where x0x_{0} is the smallest positive root of 16x+7x22x3+x4=01-6x+7x^{2}-2x^{3}+x^{4}=0 (and thus the singularity of P(x)P^{*}(x) with smallest magnitude). Then we have that the smallest singularity of Q(x)Q(x) occurs at x=1x=1, so we can write Q(x)=(1x)βR(x)Q(x)=(1-x)^{\beta}R(x) where β=12\beta=\frac{1}{2} and R(x)R(x) is analytic in some disk |x|<1+ε|x|<1+\varepsilon where ε>0\varepsilon>0. Let R(x)=j=0rj(1x)jR(x)=\sum_{j=0}^{\infty}r_{j}(1-x)^{j}. Then Darboux’s Theorem [8, 23] tells us that

[xn]{(1x)βR(x)}=[xn]{j=0mrj(1x)β+j}+O(nmβ2).[x^{n}]\{(1-x)^{\beta}R(x)\}=[x^{n}]\left\{\sum_{j=0}^{m}r_{j}(1-x)^{\beta+j}\right\}+O(n^{-m-\beta-2}).

Plugging in m=0m=0 and β=12\beta=\frac{1}{2} gives us

[xn]{(1x)1/2R(x)}=[xn]{r0(1x)1/2}+O(n5/2).[x^{n}]\{(1-x)^{1/2}R(x)\}=[x^{n}]\{r_{0}(1-x)^{1/2}\}+O(n^{-5/2}).

Note that r0=R(1)r_{0}=R(1), which is well-defined and computable. We can also compute [xn]{(1x)1/2}[x^{n}]\{(1-x)^{1/2}\} using Stirling’s approximation as follows:

[xn]{(1x)1/2}\displaystyle[x^{n}]\{(1-x)^{1/2}\} =(1)n1(12n)\displaystyle=-(-1)^{n-1}\binom{\frac{1}{2}}{n}
=(12)n13(2n3)n!\displaystyle=-\left(\frac{1}{2}\right)^{n}\frac{1\cdot 3\cdot\dots\cdot(2n-3)}{n!}
=(14)n12n3(2n)!(n!)2\displaystyle=-\left(\frac{1}{4}\right)^{n}\frac{1}{2n-3}\frac{(2n)!}{(n!)^{2}}
=(14)n12n3(2ne)2n2π(2n)((ne)n2πn)2(1+O(n1))\displaystyle=-\left(\frac{1}{4}\right)^{n}\frac{1}{2n-3}\frac{\left(\frac{2n}{e}\right)^{2n}\sqrt{2\pi(2n)}}{\left(\left(\frac{n}{e}\right)^{n}\sqrt{2\pi n}\right)^{2}}\cdot\left(1+O(n^{-1})\right)
=14πn3/2(1+O(n1))\displaystyle=-\frac{1}{\sqrt{4\pi}}n^{-3/2}\cdot\left(1+O(n^{-1})\right)
=14πn3/2+O(n5/2).\displaystyle=-\frac{1}{\sqrt{4\pi}}n^{-3/2}+O(n^{-5/2}).

Thus, we have

[xn]{Q(x)}\displaystyle[x^{n}]\{Q(x)\} =R(1)4πn3/2+O(n5/2)\displaystyle=-\frac{R(1)}{\sqrt{4\pi}}n^{-3/2}+O(n^{-5/2})
[xn]{P(x)}\displaystyle\Rightarrow[x^{n}]\{P^{*}(x)\} =(1x0)nR(1)4πn3/2+O((1x0)nn5/2)\displaystyle=-\left(\frac{1}{x_{0}}\right)^{n}\frac{R(1)}{\sqrt{4\pi}}n^{-3/2}+O\left(\left(\frac{1}{x_{0}}\right)^{n}n^{-5/2}\right)
s(n)\displaystyle\Rightarrow s(n) =Kcnn3/2+O(cnn5/2),\displaystyle=Kc^{n}n^{-3/2}+O(c^{n}n^{-5/2}),

where K=R(1)4π=0.34313K=-\frac{R(1)}{\sqrt{4\pi}}=0.34313\cdots is a constant, c=1x0c=\frac{1}{x_{0}}, and x0=12(18211)x_{0}=\frac{1}{2}\left(1-\sqrt{8\sqrt{2}-11}\right) is the smallest solution to 16x+7x22x3+x4=01-6x+7x^{2}-2x^{3}+x^{4}=0, as desired. ∎

We can extend the previous result to a more refined enumeration of the 11-stack-sortable sock patterns under ϕaba\phi_{aba} of a given length nn based on the number of distinct socks that appear. We can thus define a qq-analogue for the statistic C(p)C(p), and find a closed form for its generating function as stated in Theorem 1.2. Our proof is analogous to the proof of Theorem 1.1.

Proof of Theorem 1.2.

Let s(n,r)s(n,r) denote the number of sock patterns of length nn that are 11-stack-sortable under ϕaba\phi_{aba} and have rr distinct socks. Again, for p=xl1s1xl2s2xlmsmxlm+1p=x^{l_{1}}s_{1}x^{l_{2}}s_{2}\cdots x^{l_{m}}s_{m}x^{l_{m+1}} to be 11-stack-sortable, we must have that sis_{i} are individually 11-stack-sortable under ϕaba\phi_{aba} for all i[m]i\in[m] (where the sis_{i} are potentially nonempty). Furthermore, if pp has rr distinct socks, then we have to choose how to cover those rr socks across the mm sock patterns s1,,sms_{1},\dots,s_{m}.

We again split into two cases. When m=0m=0, we have that there is exactly one sock pattern of length nn that is 11-stack-sortable under ϕaba\phi_{aba}, namely p=xnp=x^{n}. This pattern contains one distinct sock, so we can capture these sock patterns in the sum n>0xnq1=qx1x\sum_{n>0}x^{n}q^{1}=\frac{qx}{1-x}.

Now suppose m>0m>0, so we have a nonzero number of nonempty sock patterns sis_{i}. Suppose sis_{i} has length ni>0n_{i}>0 and ri>0r_{i}>0 distinct socks for i[m]i\in[m]. For each nonempty sis_{i}, we can again either choose to i) have the first sock of ϕaba(si)\phi_{aba}(s_{i}) be the same as the last sock of ϕaba(si1)\phi_{aba}(s_{i-1}), or ii) have ϕaba(si)\phi_{aba}(s_{i}) (and therefore sis_{i}) have disjoint socks from ϕaba(si1)\phi_{aba}(s_{i-1}). In the former, the total number of distinct socks added by appending sis_{i} is ri1r_{i}-1, and in the latter, the total number of distinct socks added by adding sis_{i} is rir_{i}. Thus, our contributions to P[q](x)P_{[q]}(x) look like the product of either s(ni,ri)xniqris(n_{i},r_{i})x^{n_{i}}q^{r_{i}} or s(ni,ri)xniqri1s(n_{i},r_{i})x^{n_{i}}q^{r_{i}-1} terms over all i[m]i\in[m], which we can factor as P[q](x)m(1+q1)mP_{[q]}(x)^{m}(1+q^{-1})^{m}. We can thus write the following relation on P[q](x)P_{[q]}(x):

P[q](x)\displaystyle P_{[q]}(x) =qx1x+m1(P[q](x)m(1+q1)m1(l1,,lm>0lm+10xl1++lm+1q))\displaystyle=\frac{qx}{1-x}+\sum_{m\geq 1}\left(P_{[q]}(x)^{m}(1+q^{-1})^{m-1}\left(\sum_{\begin{subarray}{c}l_{1},\dots,l_{m}>0\\ l_{m+1}\geq 0\end{subarray}}x^{l_{1}+\cdots+l_{m+1}}q\right)\right)
=qx1x+m1(P[q](x)m(1+q1)m1(x1x)m(11x)q)\displaystyle=\frac{qx}{1-x}+\sum_{m\geq 1}\left(P_{[q]}(x)^{m}(1+q^{-1})^{m-1}\left(\frac{x}{1-x}\right)^{m}\left(\frac{1}{1-x}\right)q\right)
=qx1x+q(1+q1)(1x)m1(P[q](x)m(1+q1)m(x1x)m)\displaystyle=\frac{qx}{1-x}+\frac{q}{(1+q^{-1})(1-x)}\sum_{m\geq 1}\left(P_{[q]}(x)^{m}(1+q^{-1})^{m}\left(\frac{x}{1-x}\right)^{m}\right)
=qx1x+q(1+q1)(1x)P[q](x)(1+q1)(x1x)1P[q](x)(1+q1)(x1x).\displaystyle=\frac{qx}{1-x}+\frac{q}{(1+q^{-1})(1-x)}\cdot\frac{P_{[q]}(x)(1+q^{-1})\left(\frac{x}{1-x}\right)}{1-P_{[q]}(x)(1+q^{-1})\left(\frac{x}{1-x}\right)}.

We can now easily solve this quadratic in P[q](x)P_{[q]}(x) to get the closed form

P[q](x)=(q+(q2+2q)x(q2+2q)x2)+q12(q+2)x+(q2+2q+4)x22q2x3+q2x42(q+1)(x2x),P_{[q]}(x)=\frac{(-q+(q^{2}+2q)x-(q^{2}+2q)x^{2})+q\sqrt{1-2(q+2)x+(q^{2}+2q+4)x^{2}-2q^{2}x^{3}+q^{2}x^{4}}}{2(q+1)(x^{2}-x)},

as desired. ∎

After obtaining a closed form and asymptotics for the number of 11-stack-sortable sock patterns of a given length, it is natural to ask whether or not there is a simple way to describe what 11-stack-sortable sock sequences look like. It turns out that even though we know recursively what the map ϕaba\phi_{aba} behaves like, we cannot easily characterize the set of kk-stack-sortable sock sequences. The following example shows that sortability is not closed under containment, that is, there exist sock sequences pp and qq such that pp is contained in qq, pp is not 11-stack-sortable, and qq is 11-stack-sortable. Take p=abcabcp=abcabc and q=babcabcq=babcabc. Then ϕaba(p)=cbcbaa\phi_{aba}(p)=cbcbaa is unsorted and ϕaba(q)=aaccbbb\phi_{aba}(q)=aaccbbb is sorted. Therefore, the set of 11-stack-sortable sock sequences under ϕaba\phi_{aba} cannot be characterized as all sock sequences that avoid some fixed set of sock patterns. Note that this contrasts with the original nondeterministic setting that Defant and Kravitz introduced based on Knuth’s stack-sorting machine [15]. The lack of a pattern avoidance characterization of 11-stack-sortable sock patterns is due to the determinism of the stack-sorting procedure here. It is worth mentioning that the set of kk-stack-sortable permutations under West’s stack-sorting map is also not closed under permutation pattern containment when k>1k>1 [22].

5. General σ\sigma-avoiding stack-sorting algorithms

In this section, we study the behavior of ϕσ\phi_{\sigma} for general σ\sigma beyond the pattern abaaba. A natural question to ask is whether or not ϕσ\phi_{\sigma} will always sort any arbitrary sock sequence in AA^{*}. The following proposition tells us that ϕaba\phi_{aba} is the only such map.

Proposition 5.1.

The only σ\sigma for which ϕσ\phi_{\sigma} eventually sorts all sock sequences is σ=aba\sigma=aba.

Proof.

Note that for any σaba\sigma\neq aba such that |σ|3|\sigma|\geq 3, then ϕσ(aba)=aba\phi_{\sigma}(aba)=aba and thus will never sort abaaba. Thus, we only need to consider when |σ|2|\sigma|\leq 2. There are two patterns of length two, namely abab and aaaa. We can easily verify that the sock sequence abcabcabcabc gets taken to itself and to its reverse under ϕab\phi_{ab} and ϕaa\phi_{aa}, respectively. ∎

The question above is not particularly interesting, since we simply show that there exist short sock sequences that cannot be sorted by ϕσ\phi_{\sigma} when σ\sigma is sufficiently large. We would like to say something stronger. In the permutation setting, it makes sense to group permutations of a given length nn (since passes through the stack will never change the length of the input permutation) and say something about the existence of unsortable permutations for all nn. Similarly, in the sock sequence setting, we group sock sequences S(M)S(M) on a given multiset MM. Now we can ask for which (σ,M)(\sigma,M) do we have that any sock sequence within S(M)S(M) will eventually become sorted under ϕσ\phi_{\sigma}. We have the following proposition, which tells us that for an infinitely large class of σ\sigma, the map ϕσ\phi_{\sigma} cannot eventually sort all sock sequences in any S(M)S(M) (unless every sock sequence of S(M)S(M) is already sorted).

Proposition 5.2.

Let σ\sigma be an unsorted sock pattern that is not of the form aabaaa\cdots aba\cdots a. Then for any multiset of socks MM such that not all sock sequences in S(M)S(M) are sorted, there exists a sock sequence pS(M)p^{*}\in S(M) that is not kk-stack-sortable under ϕσ\phi_{\sigma} for any kk.

Proof.

It suffices to show that there exists an unsorted sock sequence pp such that pAv(σ,σ¯)p\in{\operatorname{Av}}(\sigma,\overline{\sigma}), as applying ϕσ\phi_{\sigma} to any sock sequence pp that avoids σ\sigma just reverses pp. Suppose that MM consists of distinct socks a1,a2,,ama_{1},a_{2},\dots,a_{m}. Without loss of generality, suppose there are at least two copies of a1a_{1}. We know that σ\sigma contains abaaba because it is unsorted. Thus we can consider the following cases for σ\sigma and in each case we explicitly construct a sock sequence pp^{*} that avoids both σ\sigma and σ¯\overline{\sigma}:

Case 1: σ\sigma contains abbaabba or abcaabca. Let p=a1a1a2a2ananp=a_{1}\cdots a_{1}a_{2}\cdots a_{2}\cdots a_{n}\cdots a_{n} be a sorted sock sequence. Consider the sock sequence

p=a1a1a2a1a2a2a3a3amamp^{*}=a_{1}\cdots a_{1}a_{2}a_{1}a_{2}\cdots a_{2}a_{3}\cdots a_{3}\cdots a_{m}\cdots a_{m}

obtained by swapping the last a1a_{1} and the first a2a_{2}. Then pp^{*} avoids both σ\sigma and σ¯\overline{\sigma} because the only occurrence of abaaba would either consist of the last two occurrences of a1a_{1} or the first two occurrences of a2a_{2}, both of which only contain one sock between them.

Case 2: σ\sigma contains abab,abacabab,abac or cabacaba. Then we consider the sock sequence

p=a1a1a2a2amama1.p^{*}=a_{1}\cdots a_{1}a_{2}\cdots a_{2}\cdots a_{m}\cdots a_{m}a_{1}.

This cannot contain an occurrence of σ\sigma because the only opportunity to contain abaaba as a pattern is to contain one of the occurrences of a1a_{1} at the beginning and the last occurrence a1a_{1}. Then there would be no more socks on either end of the sock sequence to represent the sock not equal to a1a_{1} in the pattern σ\sigma. For the same reason, pp^{*} cannot contain an occurrence of σ¯\overline{\sigma}.

Note that these cases are exhaustive, as we assume σ\sigma is not of the form aabaaa\cdots aba\cdots a. Therefore we have found a sock sequence pp^{*} that avoids σ\sigma and σ¯\overline{\sigma} for all possible σ\sigma, as desired. ∎

6. Further Directions

In this final section, we propose several questions and directions for future study. We hope that continued investigation of deterministic stack-sorting maps for sock sequences, whether based on pattern avoidance or not, is fruitful and yields implications for the nondeterministic setting. We provide possible directions along the lines of characterization and enumeration.

Recall that we have shown that the foot-sorting map ϕaba\phi_{aba} can sort any sock sequence on nn socks in at most nn iterations. Furthermore, we provided a construction p=(a1an)2p=(a_{1}\cdots a_{n})^{2} to show that this bound is tight. We may ask whether there are other sock sequences for which the bound is tight.

Question 1.

What are all sock sequences on nn socks that are not (n1)(n-1)-sortable under ϕaba\phi_{aba}?

It could be interesting to characterize the sock sequences on nn distinct socks that are not (n1)(n-1)-stack-sortable. Beyond (n1)(n-1)-sortable, it would also be interesting to characterize the sock sequences that are kk-stack-sortable and not (k1)(k-1)-stack-sortable for other values of kk. For example, while there is no pattern avoidance characterization of the 11-stack-sortable sock sequences, it would be interesting to see whether or not there is still some nice characterization.

Along the lines of characterization, it could also be interesting to characterize an alternate class of periodic points. When looking at ϕaba\phi_{aba}, we know that all sock sequences eventually get sorted, and thus the only periodic points are the sorted sock sequences, which are precisely those avoiding the sock pattern abaaba. Any sock sequence avoiding σ\sigma and σ¯\overline{\sigma} is a periodic point under ϕσ\phi_{\sigma} with period two. Recall that we have also shown in Proposition 5.2 that for almost all σ\sigma, we can find an unsorted periodic point avoiding σ\sigma and σ\sigma that has period two. It is natural to ask whether or not there are periodic points under ϕσ\phi_{\sigma} with period greater than two when σaba\sigma\neq aba. It could be interesting to determine for which σ\sigma there exist periodic points under ϕσ\phi_{\sigma} with period greater than two, and to characterize such periodic points.

Also recall that we have an enumeration of the sock patterns of length nn that are 11-stack-sortable under ϕaba\phi_{aba}. Because we do not have a nice way to understand what the 11-stack-sortable sock sequences look like, nor do we understand how to count the number of preimages in general, it is not immediately clear how to enumerate even 22-stack-sortable sock patterns.

Question 2.

How many sock patterns of length nn are kk-stack-sortable under ϕaba\phi_{aba} for k>1k>1?

Another line of investigation would be to look at other deterministic sorting algorithms, such as considering analogous sorting maps ϕσ1,,σi\phi_{\sigma_{1},\dots,\sigma_{i}} that avoid multiple sock patterns σ1,,σi\sigma_{1},\dots,\sigma_{i} at once. It could be interesting to investigate the behavior of alternative deterministic stack-sorting algorithms on sock sequences in general.

7. Acknowledgments

This work was done at the University of Minnesota Duluth with support from Jane Street Capital, the National Security Agency, and the CYAN Undergraduate Mathematics Fund at MIT. The author is grateful to Joe Gallian and Colin Defant for directing the Duluth REU program and for the opportunity to participate. The author is also grateful to Mitchell Lee, Noah Kravitz, Maya Sankar, and Yelena Mandelshtam for helpful discussions and their guidance throughout the research process.

References

  • [1] M. D. Atkinson and J.-R. Sack, Pop-stacks in parallel, Inform. Process. Lett. 70 (1999), 63–67.
  • [2] David Avis and Monroe Newborn, On pop-stacks in series, Utilitas Math. 19 (1981), 129–140.
  • [3] Katalin Berlow, Restricted stacks as functions, Discrete Math. 344 (2021), Paper No. 112571, 11.
  • [4] Miklós Bóna, A survey of stack-sorting disciplines, Electron. J. Combin. 9 (2003), Article 1, 16.
  • [5] Giulio Cerbai, Sorting Cayley permutations with pattern-avoiding machines, Australas. J. Combin. 80 (2021), 322–341.
  • [6] Giulio Cerbai, Anders Claesson, and Luca Ferrari, Stack sorting with restricted stacks, J. Combin. Theory Ser. A 173 (2020), 105230, 19.
  • [7] Anders Claesson, Mark Dukes, and Einar Steingrímsson, Permutations sortable by n4n-4 passes through a stack, Ann. Comb. 14 (2010), 45–51.
  • [8] G. Darboux, Mémoire sur l’approximation des fonctions de très-grands nombres, et sur une classe étendue de développements en série., Journal de Mathématiques Pures et Appliquées (1878), 5–56 (fre).
  • [9] Colin Defant, Counting 3-stack-sortable permutations, J. Combin. Theory Ser. A 172 (2020), 105209, 26.
  • [10] Colin Defant, Pop-stack-sorting for Coxeter groups, Comb. Theory 2 (2022), Paper No. 11, 30.
  • [11] Colin Defant, Stack-Sorting and Beyond, ProQuest LLC, Ann Arbor, MI, 2022, Thesis (Ph.D.)–Princeton University.
  • [12] Colin Defant, Stack-sorting for Coxeter groups, Comb. Theory 2 (2022), Paper No. 18, 49.
  • [13] Colin Defant, Troupes, cumulants, and stack-sorting, Advances in Mathematics 399 (2022), 108270.
  • [14] Colin Defant and Noah Kravitz, Stack-sorting for words, Australas. J. Combin. 77 (2020), 51–68.
  • [15] Colin Defant and Noah Kravitz, Foot-Sorting for Socks, November 2022, arXiv:2211.02021 [math].
  • [16] Colin Defant and Kai Zheng, Stack-sorting with consecutive-pattern-avoiding stacks, Adv. in Appl. Math. 128 (2021), Paper No. 102192, 33.
  • [17] Martin Klazar, Counting pattern-free set partitions. I. A generalization of Stirling numbers of the second kind, European J. Combin. 21 (2000), 367–378.
  • [18] Martin Klazar, Counting pattern-free set partitions. II. Noncrossing and other hypergraphs, Electron. J. Combin. 7 (2000), Research Paper 34, 25.
  • [19] Donald E. Knuth, The art of computer programming. Vol. 4A. Combinatorial algorithms. Part 1, Addison-Wesley, Upper Saddle River, NJ, 2011.
  • [20] Adeline Pierrot and Dominique Rossin, 2-stack sorting is polynomial, Theory Comput. Syst. 60 (2017), 552–579.
  • [21] Rebecca Smith and Vincent Vatter, A stack and a pop stack in series, Australas. J. Combin. 58 (2014), 157–171.
  • [22] Julian West, Permutations with forbidden subsequences, and, stack-sortable permutations, Thesis, Massachusetts Institute of Technology, 1990, Accepted: 2005-08-10T22:33:11Z.
  • [23] Herbert S. Wilf, generatingfunctionology, third ed., A K Peters, Ltd., Wellesley, MA, 2006.