21
$\begingroup$

Consider an $n$-tuple $\left(a_1, a_2, \ldots, a_n\right)$ of real numbers. We are allowed to perform the following two moves:

  • S-moves: We pick two adjacent entries $a_i$ and $a_{i+1}$ satisfying $a_i > a_{i+1}$ and swap them (i.e., replace them by $a_{i+1}$ and $a_i$, respectively).

  • P-moves: We pick two adjacent entries $a_i$ and $a_{i+1}$ satisfying $a_i > a_{i+1}$ and replace them by $a_{i+1}+1$ and $a_i+1$, respectively (i.e., we swap them and then we add $1$ to each of them).

It is well-known ("bubblesort") that if we keep applying S-moves to our $n$-tuple (in succession), then we eventually end up with a weakly increasing $n$-tuple, so that our process terminates. Moreover, it terminates after at most $\dbinom{n}{2}$ many steps, and the exact number of steps it takes to terminate is the number of inversions of $\left(a_1, a_2, \ldots, a_n\right)$ (that is, pairs $\left(i,j\right)$ that satisfy $i < j$ and $a_i > a_j$).

A surprisingly apocryphal result says that

if we keep applying P-moves to our $n$-tuple (instead of S-moves), then the process also terminates after at most $\dbinom{n}{2}$ steps.

It appears logical to look for a similar semiinvariant as the number of inversions for S-moves that would prove this result, but I have not found one for now. Thus the first question:

Question 1. What is a good (more or less explicitly defined) nonnegative integer semiinvariant of an $n$-tuple $\left(a_1, a_2, \ldots, a_n\right)$ that decreases whenever we apply a P-move?

Note that the proof of termination I know (inspired by the solution to Tournament of Towns problem 23/3/6 in Mednikov's and Shapovalov's book) does not use such a semiinvariant; instead it imagines that each entry of our $n$-tuple is drawn on a card (and these cards are swapped along with the respective numbers during an P-move), and then shows that two cards cannot be swapped more than once (the proof is by minimal counterexample, arguing that if two cards get swapped twice, then there must be two other cards that get swapped twice in between these two swaps). It is not a very difficult argument, but rather surprising and somewhat finicky.

P-moves are subtler than they appear at first. Using the diamond lemma and termination, it is not hard to show that they are confluent (i.e., the final result does not depend on the specific moves taken) when the entries $a_1, a_2, \ldots, a_n$ are integers. But they are not confluent in general; a counterexample is the triple $\left(1,1/2,0\right)$, which results in either $\left(1,1,3/2\right)$ or $\left(2,5/2,3\right)$ depending on which path you take.

But there is yet another question that the above definitions lend themselves to asking:

Question 2. If the $n$-tuple $\left(a_1, a_2, \ldots, a_n\right)$ consists of integers, and if we are allowed to make both S-moves and P-moves, then will the process necessarily terminate?

What I know is that it will not terminate if we allow non-integer entries; a simple counterexample is $\left(0,1/3,-1/3\right) \to \left(0,-1/3,1/3\right) \to \left(2/3,1,1/3\right)$ (note that $\left(2/3,1,1/3\right)$ is just the initial triple $\left(0,1/3,-1/3\right)$ with each entry incremented by $2/3$, so that the sequence will go on forever). It is also easy to see that the moves will not be confluent (even for integers). Finally, the number of moves until termination might be larger than $\dbinom{n}{2}$ (for instance, the $6$-tuple $\left(2,1,0,2,0,0\right)$ needs $26$ moves in one of the possible paths).

$\endgroup$
2
  • $\begingroup$ The S-move mapping $(x,y)\mapsto(\min(x,y),\max(x,y))$ satisfies the Yang-Baxter equation, and every solution to the Yang-Baxter equation induces an action of the positive braid monoid. For the P-move, we do not have a solution to the Yang-Baxter equation, but the positive braid monoid $B_n^+$ still acts on $\mathbb{Z}^n\cup\{\#\}$ by setting $(x_1,\dots,x_n)\cdot\sigma_i=\#$ whenever $x_i\leq x_{i+1}$, $(x_1,\dots,x_n)\cdot\sigma_i=(x_1,\dots,x_{i-1},x_{i+1},x_i,x_{i+2},\dots,x_n)$ whenever $x_i<x_{i+1}$, and $\#\cdot\sigma_i=\#$. $\endgroup$ Commented Oct 23, 2023 at 16:08
  • 1
    $\begingroup$ @JosephVanName: This is why confluence follows from termination for P-moves in the case of integers. $\endgroup$ Commented Oct 23, 2023 at 16:11

1 Answer 1

10
$\begingroup$

Question 1:

I don't see any very elegant ones, but here is one that gives something: Let $(a_1, \ldots, a_n)$ be a sequence.

We recursively define that $a_i$ is a barrier for $a_j$ iff $$a_j + \#\{j<k<i|a_k \text{ is not a barrier for } a_j \} \\ \leq a_i + \#\{j<k<i|a_k \text{ is a barrier for } a_j \}$$ Then $\#\{(j<i)|a_i \text{ is not a barrier for } a_j\}$ is strictly decreasing:

When we make a $P$-move interchanging $a_i$ and $a_{i+1}$, generally things that used to be non-barriers may become barriers, but not the other way around: To stop being a barrier, either the number of barriers between $a_k$ and $a_l$ has to decrease or $a_k$ has to increase. After assuming a barrier relation of minimal distance became non-barrier, only the second case can occur, which means it's enough to consider for $a_k$ one of the swapped elements.

For $a_i$ no relations to the right ($a_i \sim a_l, l\ge i+2$) changed. This can be seen by noting that $a_{i+1}$ was not a barrier for $a_i$ before the move, so the left side of the definition did not change ($a_i$ increased by one, but the cardinality went down by one), and neither did the right.

For $a_{i+1}$, no relation to the right ($a_{i+1} \sim a_l, l\ge i+2$) changed either. In this case, both sides of the definition increased by one.

Thus no barrier can become a non-barrier. To see the number of barriers strictly increases, note that $a_{i+1}$ was not a barrier for $a_{i}$ before the move, but $a_i$ is one for $a_{i+1}$ after (For neighbors, barrier is the same as $\ge$).

While not incredibly computable, this invariant does give the optimal $\binom{n}{2}$ bound on runtime, though I do not believe it computes the runtime (as number of inversions does for bubblesort) even for integer sequences.

Question 2: the answer is yes, any such process on integer sequences must terminate:

Let $f(n)$ be the longest runtime possible on a sequence of length $n$. Then $f(1)=0$.

Now, for any series of moves on a vector of length $(n+1)$, the leftmost element needs to be swapped at least every $f(n)+1$ moves. Since the entries are integers, whenever the leftmost entry is swapped either the new entry is smaller than the one before or it is equal, but the entry that used to be there is now one larger (and in position 2). In particular, the number of entries smaller than the leftmost one goes down. This implies the leftmost vector can change at most $n$ times, so $f(n+1)<(n+1)(f(n)+1)<\infty$.

$\endgroup$
6
  • $\begingroup$ Nice proof for Question 2!! Translated into a language I like a bit more, this is really an induction on the Lehmer code. For any $n$-tuple $w = \left(w_1, w_2, \ldots, w_n\right)$, we define the Lehmer code of $w$ to be the $n$-tuple $\left(\ell_1\left(w\right), \ell_2\left(w\right), \ldots, \ell_n\left(w\right)\right)$, where $\ell_i\left(w\right)$ denotes the number of entries of $w$ to the right of $w_i$ but smaller than $w_i$. This Lehmer code is an element of the $n!$-element set $\prod_{i=1}^n \left\{0,1,\ldots,n-i\right\}$, which is totally ordered by lexicographic order. ... $\endgroup$ Commented Oct 24, 2023 at 1:03
  • $\begingroup$ ... Now what you argue is essentially that any P-move and any S-move decrease the Lehmer code of $w$ with respect to this lexicographic order, as long as $w$ consists of integers. Thus, the moves cannot continue for more than $n!$ steps. $\endgroup$ Commented Oct 24, 2023 at 1:04
  • $\begingroup$ @darijgrinberg one of the sets has a 'not' in it and the other doesn't $\endgroup$ Commented Oct 24, 2023 at 2:35
  • $\begingroup$ For Question 1: In the definition of "$a_i$ is a barrier for $a_j$", do you suppose $i < j$? $\endgroup$ Commented Oct 24, 2023 at 3:38
  • $\begingroup$ You should rather suppose $i>j$. The idea is that if $a_i$ is a barrier for $a_j$, then $a_j$ will never be able to end up to the right of $a_i$ along any path of $P$-moves. $\endgroup$ Commented Oct 24, 2023 at 20:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .