WorksMathematics
Exact diameter of the symmetric group with LX generators
Abstract
We prove an exact formula for the diameter of the directed Cayley graph for the symmetric group with generators (left cyclic shift) and (exchange of the first two elements). For every , we show that the diameter equals for even and for odd . This resolves a longstanding question first proposed in the 1960's and refined in more recent work. The proof is AI-assisted and is based on a variety of combinatorial arguments. We also describe the agentic system we developed that led to this proof and looks highly promising for attacking other questions of this type. An accompanying Lean 4 formalization rigorously verifies the result.
Introduction
In this paper we study the following problem. Consider a permutation of the integers , and consider two operations: , a left cyclic shift, and , exchange of the first two elements. How many operations does it take to sort the sequence, in the worst case? Despite its elementary formulation, this combinatorial problem is far from trivial. In group theory terms, it provides the diameter of the directed Cayley graph of the permutation group when generated by elements and (notice the graph is directed here because we do not include the inverse generator).
This question was first proposed in the 1960’s in [1], while a precise conjecture for the result was stated recently in [2] (a more detailed review of the literature is given in the next section). Here we prove this conjecture and thus resolve this longstanding open question. Ultimately, one of our motivations is attacking the celebrated Babai-type conjecture of establishing a polynomial bound on the diameter with arbitrary generators [3, 4, 5, 6, 7] which is however far beyond the scope of the present work.1
Initially we attempted to attack the problem by usual LLM tools – direct conversations with LLMs such as GPT Astra or Claude Fable 5.1/Opus 5.5. In our experiments we found that this approach does not lead to success (or perhaps would require a huge token budget). This highlights the difficulty of this problem. For example, the models typically get stuck at pursuing microscopic improvements of known upper bounds for the desired quantity (diameter) rather than developing new ideas.
Remarkably, we were able to circumvent this obstacle and indeed obtain a proof – by developing an LLM-powered agentic system. We describe it in more detail in the next subsection. We also provide a Lean formalization of the result, see section 19. While currently we have not understood the proof in detail, we hope that, together with a description of our workflow, it will still be of use to the community.
Our agentic system has shown itself to be quite powerful while staying at reasonable amounts of token spend and compute. It is this system that obtained the proof we present (with relatively minor human intervention that mainly amounted to agent orchestration rather than mathematical input). We already have evidence of its high efficiency in obtaining proofs of other conjectures of this type. We hope to explore its highly promising full capabilities in the future.
Agentic system
To obtain the proof presented in this paper we used an agentic system developed primarily by one of the authors (S. Uskov) and available at the public GitHub repository (link). It establishes a ‘Research Team’ consisting of several agents powered by an LLM (we mainly used GPT Astra in this work). The system provides skills and instructions including reasoning frameworks that encourage the agents to use a range of reasoning strategies and tricks – such as looking for counterexamples, trying to reformulate the problem in different ways, etc. Overall it is a prototype platform for coordinating AI-assisted research in mathematics, under human supervision. It combines a web interface, a Go server, and a persistent database to organize conjectures, lemmas, dependencies, research tasks, and attempts at problems. Configurable agents – including Codex, Claude Code, OpenCode, and Coddy Agent – take on distinct tasks such as finding proofs, searching for counterexamples, formalizing arguments in Lean, and reviewing results. A planner proposes overall research strategies, while execution and repair cycles advance approved tasks. Lean code is used to check candidates against a fixed formal statement, and the human operator provides final acceptance of the results in some cases. The system also records versioned evidence, reviews, failed approaches, and reusable accepted lemmas, allowing research results to accumulate across attempts (and, when enabled, across projects). Full technical details can be found at the repository linked to above.
AI statement
Section 1 of the paper is mostly human-written, while the subsequent text and figures, including the proof, are AI-generated with minor human edits. The proof was obtained by our agentic system with relatively minor human intervention that amounted mostly to workflow orchestration. We mainly used GPT-6 Astra (with reasoning level from Medium to Ultra) within the agentic system as well as within OpenAI Codex. We also used Opus 5.5 for minor checks and editing.
Related work
The original problem and earlier bounds. The two-generator LX problem goes back to Glushkov’s work on ‘completeness of operation systems’ in computers [1]. The historical account by Glukhov and Zubov [9 pp. 20–21] records Glushkov’s upper bound , Pogorelov’s subsequent quadratic bounds in 1973 [10], and Zubov’s asymptotic result , attributed there to 1979. Zubov’s later paper treats diameter bounds for a complete cycle and a transposition [11]. His subsequent work studies representations using generalized inversions and sorting using circular inversions [12, 13]. These early results do not specify the parity-dependent constant terms in the exact formula proved here.
The precise conjecture and computations. The exact formula for the diameters was conjectured very recently by Chervov and collaborators in their CayleyPy growth paper [2]. They report exhaustive diameter computations through . Thus the attribution distinguishes Glushkov’s original problem from this later precise conjecture. The directed diameter sequence is recorded as OEIS A039745 [14]. Moreover, OEIS A378881 records computational examples of permutations at maximum directed distance [15]. The present argument proves the conjectured formula uniformly for all .
Related questions. The CayleyPy reinforcement-learning study [16] supplies pathfinding methods and diameter bounds chiefly for the three-generator system , where also costs one move. Its bounds therefore concern a different metric from the directed metric of this paper. Kuppili and Chitturi [17] use the same two moves, calling them , but study sorting the reversed permutation rather than the maximum distance over all permutations.
The same directed graph is also called the sigma–tau graph. Williams’ preprint [18] and the later work of Sawada and Williams [19] concern Hamilton paths and cycles in that graph. Their objective is to visit every permutation, rather than to determine the longest shortest path. Adin, Alon, and Roichman [20] determine the adjacent-swap diameter for circular permutations, where cyclic rotations identify arrangements. That problem does not charge shifts or specify a final starting marker, whereas both are essential to the constants in the present formula.
The proof below includes its combinatorial estimates explicitly. For background on comparing ordinary inversion count with total absolute displacement, see Diaconis and Graham [21].
Note added: we learned that after our proof was completed A. Guerrieri also independently obtained [22] the proof of several related conjectures from [2] (though not specifically the one we prove here).
The moves
We will describe the setting of the problem in the following way. We start with cards labelled , where is the number of cards. All labels are distinct. We have the following and moves:
Shift L: Left cyclic shift. Equivalently, we remove the first card and place it at the end. Swap X: exchange the first and second cards. Figure 1 shows both operations applied to the same row.

Figure 1. Two operations on five cards. The shift moves card 2 to the end; the swap exchanges cards 2 and 0.
The target row is . A backward shift is not a single permitted move: moving the last card to the front using L requires shifts.
For each starting row, take the length of a shortest solution. The maximum of these lengths is the diameter, denoted by . For example, asserts both that every row of five cards can be sorted in at most 11 moves and that some row cannot be sorted in 10 moves.
The same diameter governs transitions between arbitrary pairs of rows. Given a target row, rename its first card 0, its second card 1, and so on. The target becomes the increasing row. Renaming cards changes neither operation and therefore preserves the length of every shortest transition.
The exact formula
For , the result is
Write for the appropriate right-hand side. To prove , we prove that every row has a solution of length at most , and that some row has no solution shorter than . These are the upper and lower bounds.
For six and seven cards, respectively,
| 5 | 6 | 7 | 8 | 9 | 10 | |
| 11 | 18 | 25 | 35 | 45 | 58 |
Table 1.
This is the formula of [2 Conjecture 11]. The formulas for the even and odd cases differ only in their constant terms. A function given by different polynomials for different residue classes is called a quasipolynomial; here the residue class is the parity of .
An explicit route proves only an upper bound for its starting row. Proving that a route is shortest requires excluding every shorter solution.
Eleven moves on five cards
Consider the row .
| Step | Operation | Row after the operation |
| 0 | – | |
| 1 | L | |
| 2 | L | |
| 3 | L | |
| 4 | L | |
| 5 | X | |
| 6 | L | |
| 7 | L | |
| 8 | X | |
| 9 | L | |
| 10 | X | |
| 11 | L |
caption:
:::
There are eight shifts and three swaps. After step 10, the circular order is already correct. The last shift makes the row begin with 0, and it must be included in the exact move count.
For five cards, all minimum distances can be checked by finite enumeration. Start at the increasing row. At each stage, construct predecessors of rows already found by applying X or moving the last card to the front. The backward shift is used to find a predecessor; it is not an allowed forward move in a solution.
Record each new row only when it first appears. The stage at which a row first appears is its minimum distance to the target using the permitted operations. The resulting counts are
| Distance | Rows | Distance | Rows |
| 0 | 1 | 6 | 15 |
| 1 | 2 | 7 | 20 |
| 2 | 3 | 8 | 22 |
| 3 | 5 | 9 | 19 |
| 4 | 8 | 10 | 11 |
| 5 | 12 | 11 | 2 |
Table 1 (PDF p. 6).
The counts sum to 120 = , so they cover every permutation of five cards. The example first appears at stage 11. Its solution is therefore shortest, and . This enumeration applies only to five cards.
Cards on a circle and the starting marker
Arrange the positions on a circle and label them . Add a marker indicating where the row currently starts.
Under L, the cards remain in their circular positions and the marker advances by one position. Under X, the cards at the marker and at the next position are exchanged. After shifts, the marker returns to its starting position.
To distinguish full turns, repeat the circle along an infinite line. After positions , put positions , then another copy, and continue. The line also extends to negative coordinates.
The displacement from coordinate 2 to coordinate 7 is +5, whereas that from 2 to 12 is +10. Both return to circular position 2, but they use different numbers of turns. Integer coordinates must therefore be retained when estimating the number of moves.

Figure 2. Unrolling a circle with five positions. Coordinates 2, 7, and 12 represent the same circular position on different turns.
Move conventions and position labels
We distinguish three quantities:
the label written on a card;
the card’s initial position, before any move;
the card’s target coordinate on the unrolled line.
Let be the label of the card initially at position . The symbol denotes the entire starting row: means that position 2 initially contains card 4.
Let be the target coordinate of the card initially at position . The index always refers to that initial position. The displacement of this card is
A positive displacement is to the right and a negative displacement is to the left. Displacement is final coordinate minus initial coordinate. A card that moves back and forth can travel farther than the magnitude of its displacement.

Figure 3. Card 4 starts at position 2. Assigning target coordinate 4 gives displacement +2. The card’s label and its initial position differ.
For example, the row permits targets without additional turns:
| Initial position | 0 | 1 | 2 | 3 | 4 | |
| Card label | 2 | 0 | 4 | 1 | 3 | |
| Target | 2 | 0 | 4 | 1 | 3 | |
| Displacement | +2 | −1 | +2 | −2 | −1 |
Table 1 (PDF p. 7).
The displacements sum to zero. A swap moves one card one position right and the other one position left. In the circular model, L moves only the marker and leaves the card coordinates unchanged.
More generally, the marker may finish at circular position . Card must then occupy position modulo . The unrolled targets satisfy
The first condition specifies the target modulo a full turn; the second specifies zero total displacement. Residues alone do not determine the move count, since different numbers of turns can require different routes.
Constructing a sorting scan
Fix target coordinates. At the marker, compare the targets of the two adjacent cards. If the left target exceeds the right target, apply X. Otherwise apply L and advance to the next comparison. The same operations take place in every periodic copy.
An inversion is a pair in the wrong target order. On a finite line, the left card should end to the right of the right card. On the periodic line, pairs from different copies must also be counted.
To obtain a finite count, take initial positions within one period. For each pair, count the copies of card that are on the wrong side of card relative to their targets. The contribution is
The floor rounds down to an integer, and the outer bars take the absolute value. With , a target difference of gives floor and contribution 1. A difference of 6 also contributes 1: a copy of card from the preceding turn is on the wrong side of card .
Summing over gives the number of periodic inversions. Pairs of copies are counted up to a common translation by a multiple of . Each swap of an inverted adjacent pair decreases this number by one; a shift of the marker leaves it unchanged.
The scan terminates. If an inversion remains, some adjacent pair is inverted: otherwise every adjacent target, and hence every sequence of targets, would be increasing. Within shifts the marker encounters such a pair and a swap decreases the nonnegative integer inversion count. There can be only finitely many decreases.
After the last swap, the targets are increasing along the line. Every integer target occurs exactly once, since labels are distinct and copies repeat every positions. Consecutive targets therefore differ by one; a missing integer would have no place in the increasing sequence. Every card’s target differs from its current coordinate by the same constant. The sum of remaining displacements over one period is zero, so that constant is zero. All cards have reached their targets. Some final shifts may still be needed to put the marker at the required start of the increasing row.
The total length is
Both terms matter. Even when swaps are already minimal, the next required swap may lie just behind the marker and require almost a full turn to reach.
For the upper bound we choose targets and estimate the scan length. If a row has no solution of length at most , every scan we construct must be longer than . These inequalities will restrict the starting row.
Why the scan uses no more shifts than another solution
Fix the targets and compare the scan, which swaps every inverted pair when it first reaches it, with any other swap schedule for the same targets.
Choose an integer threshold . Call a card small if its target is at most , and large otherwise. The scan always puts a small card before a large one when it compares them.
At each boundary, count the small cards to its right. This count is finite: sufficiently distant copies on the right have targets greater than . A smaller count means that more small cards have passed to the left. For two adjacent positions, let be the number of small cards starting at the left position, and the number strictly after the right position. After ordering the pair, the number starting at the right position is
If the pair contains zero small cards, the answer is ; if it contains one, that card goes on the left and the answer is again ; if it contains two, the answer is . The formula gives all three values.
The function is nondecreasing in both variables. Thus inequalities between all such counts for two schedules survive the next comparison. Ordering the pair also gives the smallest possible count at the boundary inside it. Skipping the swap, or swapping a correctly ordered pair, cannot produce a smaller count.
Apply this argument successively at every comparison. After any given number of shifts, the scan has no more small cards to the right of any boundary than an arbitrary schedule. This holds for every threshold .
If the other schedule has finished, no card to the right of position has target at most . The same is true for the scan. Each scan card then has target at least its current position. The remaining displacements sum to zero, so they all vanish: the scan has also finished.
Consequently, for fixed targets the scan uses no more shifts than any other schedule. Its swap count is the inversion count, a lower bound for every schedule. If a final marker is required, append only the necessary residual shifts. The total length still does not exceed that of the other schedule. A lower bound for the scan with fixed targets is therefore a lower bound for every solution with those targets.
A table of backward-arrow counts
The following tables are auxiliary calculations. The permitted puzzle moves remain L and X. Write for the residue of in ; for example, and . For each in that set, put
An arrow of is . It is backward if its endpoint is less than its start. Thus is backward, whereas and are not. A position with is a fixed position of the table. This describes a table entry; card motion during sorting is counted separately.
Let be the number of backward arrows in , called the table’s height. For example, take
Subtracting 2 modulo 7 gives
Only and are backward, so . All seven heights are
| Subtracted value | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
| Height | 4 | 3 | 2 | 4 | 3 | 2 | 3 |
Table 1 (PDF p. 9).
The original table need not be the table with zero in its first position. Here , whereas and begins with zero and has height 2.
We call the initial offset, and the initial height: it is the height of the table whose first entry is zero. The original row itself has height . This example illustrates the calculation and is not assumed to be a counterexample.

Figure 4. Heights for one row of seven cards. Two heights are 2 and two are 4; the mean, marked by the dashed line, is 3.
Counting heights, swaps, and shifts
Rule 1: the sum of all heights is constant. For a fixed position , the value runs through every residue once as does. Exactly of those values are less than . Thus the arrow starting at is backward in exactly tables. Summing,
In the seven-card example the sum is .
Rule 2: height decreases by at most one in a single step. The offset of position is . For instance, the arrow for has offset . An offset occurs at exactly when . Let be its number of occurrences.
Passing from to decreases every table entry by one modulo . A fixed arrow with becomes backward. The arrow ending at 0, if it starts at a positive position, ceases to be backward when its end wraps to . If 0 is at position 0, both changes are absent: does not become backward, and no backward arrow ending at 0 disappears. In either case,
The index is cyclic. Since , the decrease is at most one. Two consequences will be used:
An absent offset has , so the next height is one lower.
A minimum height occurs at an offset that is present; otherwise the next height would be lower than the minimum.
The same rule can be summed over consecutive columns. If is subtracted modulo from every entry of a table , let count its relative offsets that are less than . Then
In particular, equal heights imply . For , the relative offsets are . Three are below 2, so subtracting another 2 changes the height from 2 to , taking to .
For an offset , its backward gap is . This is for and 0 for . With , offset 5 has gap 2.
From table height to a swap bound
Fix a table of height . At position , first choose the forward target if , and otherwise. Then decrease every target by . The added turns sum to , and decreasing targets by subtracts . The resulting displacements are balanced and lie between and . We prove the following bound on the inversion, hence swap, count:
Let be the ordinary inversion count of , and let be the sum of backward-arrow lengths over . The quantity is Spearman’s footrule; comparisons between that statistic and inversion count were studied by Diaconis and Graham [21]. We give the bound needed here explicitly. First,
Partition the positions into backward and other positions. There are pairs between the classes. Moving backward targets to the next turn changes each such pair’s contribution by one: up if the pair was not an ordinary inversion, down if it was. Pairs within a class are unchanged.
There are exactly inversions between the classes. To see this, for each backward position , subtract the number of later values less than from the number of earlier values greater than . The difference is , since exactly values are less than . Sum over backward positions. An inversion between two backward positions cancels, appearing once with each sign. A later nonbackward position satisfies and contributes no negative term. The remaining terms are exactly the between-class inversions. This proves the identity for .
Next we show . Temporarily allow swaps of arbitrary positions in the finite row, solely to count . These are not additional puzzle moves. Until the row is increasing, find with and . Such a pair exists: take the rightmost with and follow the values starting at . To the right of , arrows cannot go forward. A fixed position cannot occur along this path, since it would already receive an arrow from a distinct position, contradicting injectivity. The path decreases until it reaches a number at most ; its last position before that step can serve as .
Swapping positions brings both cards toward their labelled positions and decreases by exactly . Repeat until the row is increasing. If there are swaps, their distances sum to the original . A swap at distance can be implemented with adjacent swaps, by carrying one card across and restoring the intermediate cards. Thus the construction uses adjacent swaps. Since their minimum number is , we have .
Each chosen swap decreases the number of backward positions by at most one. That number starts at and ends at zero, so . Hence , and substitution gives
Define the nonnegative reserve
A scan with shifts has total length .
What a card’s backward-swap count means
For the card initially at , count the cards to its left on the unrolled line whose targets exceed , including copies from preceding turns. Call them its backward predecessors, and write their number as . During the scan, the card must let each predecessor pass by moving one position left. Thus counts its necessary backward swaps and is also called its depth. Depth differs from displacement, since the card may also take part in rightward swaps.
A displacement table is balanced if its entries sum to zero. For a balanced table with for every , all depths satisfy . This can be proved without analysing a complete route. Choose a card of maximum depth. If it has a forward crossing with another card, the other card has strictly greater depth: every larger target that the first card must let pass also exceeds the smaller target of the other card, and the first card itself supplies an additional predecessor. This contradicts maximality. The chosen card therefore has no forward crossings. Its displacement is minus its depth, and the lower bound on displacement bounds that depth by . All other depths are no larger.
For the targets constructed from a table of height , the lower displacement bound is exactly . Depth occurs precisely at the fixed positions of . A card of depth has no forward crossings and therefore displacement , which in this construction corresponds to a fixed position. Conversely, displacement requires at least backward swaps, and more than are impossible.
A fixed position here means in the auxiliary table. The card starting there is assigned displacement during the scan. The completion estimates distinguish depths , , and smaller depths. Encountering the third kind early saves a turn: in Estimate 2 below, is replaced by .
How many shifts the swap queue requires
After the first sweep, the front card has the greatest target among those seen. It has no backward predecessors, so its depth is zero. The other cards form a queue of positions.
Suppose the next card has depth . If , a swap decreases that depth by one and moves the zero-depth card one position forward. After , the front depth is zero again and the processed card goes to the back of the queue. If , no swap is needed.
Each shift processes one queue position. A card of depth visits the front of the queue times, with shifts between visits. If its initial position after the zero-depth front is , its last swap occurs no later than shift
The maximum of these quantities over positive depths bounds completion of the whole queue.
During the first sweep, a card moved left by a comparison loses one unit of depth. If the next target is a new maximum, the old maximum enters the queue with depth equal to the least depth in the prefix already seen. The same comparison count will be used for the initial delay in § 17.
We use two consequences.
Estimate 1. If the front depth is less than and all depths are at most , the scan finishes by shift . After the first sweep, every queue depth is at most ; substitute that bound in the last-swap formula.
Estimate 2. Suppose the front depth is less than , all positions of depth are at most , and some position between 0 and has depth less than . Then completion occurs by shift
After the first sweep, depth can remain only on a former depth- card or on the card that carried the maximum until the first depth below appeared. The former depth- cards started at positions at most ; the card that carried the maximum started at a position at most . Every other depth is at most , so the queue formula gives the estimate.
The last swap may precede the required final marker. To finish at residue , append the necessary shifts. The completion times below are always rounded up to a number with the required residue.
An arrow of almost maximum depth
Let have height , and let a card at have depth and relative offset . Its displacement is . Displacement equals rightward swaps minus leftward swaps, so its number of rightward swaps is
At each such swap, a smaller-target card moves left. That card has greater depth, hence depth , and its initial position is fixed in . All these fixed positions lie on the open circular arc from to . That arc has positions, exactly the number of rightward swaps. A pair contributes at most one such crossing because all displacements lie in a band of width less than . Therefore every position passed over by an arrow of depth is fixed.
Suppose every depth in an initial segment is at least , with and . Every nonfixed arrow in that segment goes forward. Indeed, a backward arrow with nonzero endpoint would pass through position 0 along its circular arc and require . A backward arrow ending at 0 would require all subsequent positions to be fixed. Any earlier backward arrow would then also have to end at 0, contradicting distinct endpoints. Only one backward arrow would remain, contrary to .
How many initial positions can be fixed
Let count unit backward arrows in . Retain the notation for total backward length and for ordinary inversions. Add one modulo to every entry, and let be the original position of label . Direct counting gives
For , each length changes by one and the single label wraps. For , that label loses inversions and gains . A backward arrow can cease to be backward only if its length was one, which gives the last inequality.
Use , proved above. Substitution cancels and yields
At a minimum height, . The neighbouring-height formula shows that the frequency of the preceding offset is at most one; every unit backward arrow has that offset.
If the first positions are fixed, remove them and renumber the others from zero. The quantities , , , are unchanged, and the row length becomes . Since , we obtain
There is a related bound for a prefix of almost maximum depth. If its first depths are at least and , then (assuming also )
To prove it, follow arrows starting at 0. Each goes forward and passes over fixed positions only. Replace consecutive links by and make fixed. The quantities , , are unchanged, while increases by one: changes involving intermediate fixed positions cancel, leaving the pair of link endpoints. Thus does not increase.
Repeat until positions are fixed. Move the origin from 0 to 1, changing position numbers and labels together. The quantities and are unchanged. The number of unit backward arrows cannot increase except possibly through an arrow from 0 to . Such an arrow would pass over all intermediate positions and, together with the backward arrow ending at 0, give height at most one. The hypothesis excludes it.
There are now fixed initial positions, so the preceding count gives the second bound. In particular, a depth below occurs by position .
Which minimum heights remain
In this subsection is the minimum height, so . An offset attaining that height will be called a minimum offset: its height is minimum, not necessarily its numerical value.
If , the first backward position is at most , since backward positions must fit in the remaining row. A backward position has depth below . Move the marker there, run the scan, and finish at the required start. Estimate 1 and the swap bound give at most
moves. If with , the difference between and this bound is
Thus already admits a route within the required bound. If , the auxiliary table is increasing and at most shifts suffice.
For even , we must also exclude . Let be the gap of the chosen offset. Allowing one extra turn, the scan finishes at shift , giving the total bound
A counterexample therefore requires . If some position has depth below , start there and finish at shifts; the length is then less than . Consequently positions must all be fixed. The fixed-prefix bound gives , or , a contradiction.
For even , only remains. For odd , the possibilities are and . In the latter case the minimum equals the mean, so all heights are equal. We handle it next.
Odd size with all heights equal
Let , , and suppose every height equals . The neighbouring-height rule gives for every : all offsets are distinct. Each auxiliary table has one fixed position, backward arrows, and forward arrows.
There is a forward arrow starting at with length at least and gap at least 3. Otherwise the distinct forward lengths could only come from the following possibilities:
lengths , at most choices;
length , at most one choice;
an arrow starting at 0, at most one choice.
Length can occur only from 0 and is already included. This gives at most choices, a contradiction. The chosen arrow has .
In its table, . An arrow of depth passes over fixed positions only. As there is just one fixed position, its offset is at most 2. Offsets 0, 1, 2 each occur once, so at most three cards have depth at least . Among the first positions there is a depth below . Estimate 2 gives at most
moves. If , the required bound follows. It remains to treat .
We show that zero reserve makes the starting row a circular reflection. The equality means . The arbitrary-swap construction above gave and , so .
Decompose the arrows of into cycles. Swapping two positions either joins two cycles or splits one cycle in two, changing the number of cycles by one. Sorting therefore takes at least the number of positions minus the number of cycles. Every nontrivial cycle has at least one forward arrow, so the number of backward arrows is no larger than that same difference.
There is one fixed position and nonfixed positions. The equality leaves exactly nontrivial cycles. Each contains at least two positions, so all are transpositions.
Draw these pairs as arcs above the row. For , their contributions relative to the sum for the individual pairs are
| Pairs | Correction to the inversion count |
| and | 0 |
| and | 0 |
| and |
Table 1 (PDF p. 15).

Figure 5. Separate and nested pairs contribute no correction. Crossing pairs reduce the sum of the individual inversion counts by 2.
Comparing the four endpoint values proves the table. For all pairs,
Thus excludes crossings.
Cut the circle at its unique fixed position. The remaining positions are joined by noncrossing arcs. If there were two separate groups of nested arcs, each group would contain an innermost arc between adjacent positions. Those two pairs would have the same offset 1, contradicting distinct offsets. The same argument excludes branching within a group. All arcs are therefore nested. The first position after the cut is paired with the last, the second with the next-to-last, and so on. Restoring the original labels gives a reflection for some .
For a reflection, find a forward arrow of length at least with gap between 3 and . The following starting position works:
| Value of | Choice of |
| 1 | |
| 2 | |
Table 2.
Substitution in verifies both conditions. The scan bound is
Equal heights thus also satisfy the odd bound. Any odd counterexample must have minimum height , hence .
Finishing a scan at a minimum-height table
Let , where . Choose a minimum offset distinct from the initial offset, and let be its last occurrence. Put and . The terms in account for the chosen position and the final shifts to the required marker. Only and are possible.
If some position has depth below , Estimate 2 permits completion at
shifts. This number has the required final residue .
First suppose . Every fixed position is at most . Start at a depth below no later than , and finish at shifts. The total is at most whenever
If this fails, the prefix bound supplies a depth below by . Use the shorter deadline . Since , the deadline together with the swap bound again gives the desired length.
Thus a last-occurrence arrow that goes forward or ends at 0 already gives a solution of length at most : these are exactly the arrows for which .
If , a depth below occurs before , since one exists among the positions. The length is at most , so the same condition suffices.
We obtain a restriction on a counterexample: a minimum offset distinct from the initial one has a backward last-occurrence arrow with nonzero endpoint. Its gap is greater than 2 for even , or greater than for odd $n.
Even size: incompatible values of the second card
Let be even and put
Assume a row cannot be sorted in moves or fewer; call it a counterexample. We shall prove the following lemma.
First-two-cards lemma. If a row of even size has no solution of length at most , its first card is 0 and its second card is .
First apply the lemma. Define the reflection , which exchanges 0 and 1. For ,
| 0 | 1 | 2 | 3 | 4 | 5 | |
| 1 | 0 | 5 | 4 | 3 | 2 |
Table 3.
The inverse permutation specifies where a labelled card stands; for example, is the position of card 1. Form the new row
The minimum solution lengths for and are equal. Invert a sequence of operations: reverse their order, replace L by a backward shift, and leave X unchanged. Then reflect by . Reflection reverses shift direction, turning the backward shift into the allowed L. It exchanges positions 0 and 1, so X remains the same swap. The sequence length is unchanged. Applying the transformation twice returns to the original row, so it works in both directions.
The row is also a counterexample, and the lemma gives . Since ,
Only 1 is mapped to 0 by , so , or . But the lemma for gives . These values differ for , which is impossible at one position. The lemma therefore proves the even upper bound. With six cards, it would require the second card to be both 1 and 5.
Why the first card must be zero
We now prove the lemma using the height tables. Let be the minimum height. The scan estimates leave only
Let be the set of minimum offsets. For a counterexample, ; if the initial offset is not minimum, this improves to . Here is the arrow count underlying these bounds.
A minimum offset distinct from 0 and must be represented by a backward arrow with nonzero endpoint; otherwise the scan ending at its last occurrence is already short enough. Choose the largest minimum offset . Every backward arrow with smaller offset stays backward when is subtracted from the labels. If , there is also a backward arrow ending at 0, starting at the position of card .
Indeed, a backward arrow with smaller offset satisfies
Thus , and its new endpoint is . The additional arrow ending at 0 was not counted: its original endpoint is .
The minimum-height table has only backward arrows. Count itself separately and, when necessary, also the initial offset. This gives at most minimum offsets; if the initial offset is not minimum, the latter exception disappears and the bound is . If 0 is minimum, use the original table for the same count: count offset 0 separately and omit the arrow ending at 0 from the other representatives.
The mean height is , so the total excess above is . There are at least nonminimum columns, each exceeding by at least one. Hence there are exactly of each kind and every nonminimum height is . We have proved:
exactly offsets have height ;
exactly offsets have height ;
the initial offset has height , since otherwise there would be at most minimum columns.
A present offset of height occurs exactly once: two occurrences would make the next height at least .
Every original backward arrow with nonzero endpoint must have a minimum offset. Suppose one at position did not. Remove from the possible representatives of minimum offsets, and also remove the position of card 0 if it is backward. The remaining count is
| Case | Backward positions | Exceptions | Total |
| at most | 0 only | at most | |
| , offset 0 minimum | at most | 0 and | at most |
| , offset 0 not minimum | at most | only | at most |
Table 1 (PDF p. 17).
In the first two cases the original height is . In the third it is at most and two distinct backward positions were removed. This leaves at most representatives for minimum offsets, a contradiction.
Consider offset , whose gap is 2. A minimum height with gap 1 or 2 would give a solution of length at most . For noninitial offsets this was proved in Section 10. For an initial offset there are at most two fixed positions, since otherwise the next height would exceed . A depth below then occurs by position 2 and Estimate 1 again gives a short enough route. Consequently . Offset is present; otherwise would be minimum with gap 1.
Let be its unique occurrence. Its original arrow goes forward or ends at 0, since backward arrows with nonzero endpoint have minimum offsets.
Suppose . The initial offset is minimum and therefore is neither nor , so . The table for offset adds 2 to the labels. Its first arrow ends at , and it has only one fixed position, .
An arrow of depth passes over fixed positions only. The first arrow would pass over positions 1 and 2 and require at least two fixed positions. Thus the first card has depth at least two below the maximum. This saves a turn. At height and gap 2, the route has at most
moves. The required bound for is , so this is a contradiction. Therefore .
Why the second card must be
Return to position of offset . Its arrow cannot end at 0: card 0 is already at position 0 and . Hence and
Since and , this requires and . The first two cards are indeed , completing the lemma.
Restrictions on an odd counterexample
Let be odd. Suppose a row has no solution of length at most
Let be the minimum height. The last occurrence of an offset is its greatest position index in the original row. For an offset , write for its backward gap. Thus for and . For an arrow this is the forward circular distance from its endpoint back to its start .
The scan restrictions can be collected as follows.
Odd-counterexample lemma. A counterexample satisfies all of the following conditions.
A. Three heights. We have , , and every height is , , or .
B. The initial card. We have with or 2, and . Every present offset of height with positive gap has gap at least .
C. Minimum height. If , then . At the last occurrence of , the original arrow satisfies .
D. One exceptional offset. Consider a present offset with and . If its last-occurrence arrow goes forward or ends at 0, then equals a single value .
Such a exists. For some occurrence of , put and . Then
The original arrow at goes forward or ends at 0.
We prove the lemma from the absence of a route of length at most . § 13 and § 14 will then use A–D to bound one and the same count both above by and below by .
Why at most one offset is exceptional
Suppose two distinct exceptional offsets have positive gaps $1 \le V < G \le h + 3$. Both tables have height and a nonzero first entry.
Take the table of gap . All its fixed positions are at most : its last fixed position satisfies . If a depth below occurred between 0 and , Estimate 2 would give at most
moves, the required odd bound for . All those depths are therefore at least . Their nonfixed arrows go forward and pass over fixed positions only.
Put . Subtracting from the entries of gives the table of gap with the same height, so exactly relative offsets of are below .
For each , its arrow cannot end after ; otherwise position would have to be fixed. Its offset is therefore at most
Equality is impossible, since it would make fixed in the gap- table, whose last fixed position is at most . All positions therefore have offsets below , and they exhaust all such offsets.
The offset at 0 is at least and cannot equal , since the other table also has a nonzero first entry. The first arrow ends after , hence at least at 2, making position 1 fixed. Its offset is zero, below , but excludes it from the positions already counted. This contradiction proves uniqueness.
A preliminary window count without a height bound
For now, heights may exceed . Call a column high if its height is at least . Let count high columns, count minimum columns, and be the sum of the excesses above . The total-height identity gives
The minimum-offset count from § 11 gives . That count used minimum-height scan bounds and did not depend on parity.
Let be the window of offsets with gaps from 1 to ; it has elements. A minimum offset in this window can only be the initial offset , since all other short minimum gaps have been excluded.
If is minimum and belongs to the window, let its gap be and its frequency be . If , a depth below would appear by and a scan would fit within . Thus . On passing from to offset 0, at least zero relative offsets are counted and is subtracted, so .
Thus the minimum-offset set can meet the window only in . At the same time, the high column at offset 0 lies outside their union. The overlap on the left of a count can be cancelled against this extra high column on the right.
An offset in the window falls into one of the following categories:
height at least ;
the initial offset ;
the preceding offset modulo , when the initial height is minimum;
the unique exceptional offset of height , if it exists;
a backward arrow with nonzero endpoint and height .
To check completeness, a minimum height must be . For a present offset of height , take its last occurrence. It is initial, exceptional if the arrow goes forward or ends at 0, or in the last category. An absent offset has next height one lower, hence minimum. The next gap lies between 0 and , so the next offset is and the absent one is .
Define three events:
: the initial height is minimum, or is with positive initial gap in the window;
: the initial height is minimum and belongs to the window;
: an exceptional offset exists, and another offset of the same height has a smaller positive gap.
An event has indicator 1 when it holds and 0 otherwise. We claim
First suppose a present height- offset lies in the window. Choose one with smallest positive gap and call its offset . Every other window offset of that height is numerically less than . Noninitial minimum offsets are also less than , since their gaps exceed the entire window.
Select backward arrows whose offsets are below . They remain backward after subtracting . If , the new table also has a backward arrow ending at 0. Hence at most arrows were selected, where if and otherwise.
Count separately. Together with the initial offset, it requires at most places; a coincident needs no second place. The preceding offset requires at most places. The exceptional offset needs an additional place only if its gap exceeds the smallest chosen gap, which is exactly event ; at equality it is already . Including the overlap cancellation gives
Use to obtain the claim.
If no present height- offset lies in the window, high columns and the initial and preceding offsets cover the window. Then . Since , the same claim follows, with absent.
Excluding heights above
The preliminary bound gives . If , then and all three events hold. In particular, the initial height is minimum and its gap lies between 0 and . Gap 0 means . We show that under these conditions .
Take threshold modulo . If , the absence of a short scan gives , where is the frequency of . Since every height is at most , the next-height formula gives , hence .
The height at is at most , since the next column is the initial minimum . It cannot be : it is noninitial and has gap , whereas noninitial minimum gaps exceed . Thus , and is absent.
Every present height- offset is strictly below . Indeed, between and the end of the scale there are fewer than offsets. Passing to any of them counts at least offsets and subtracts fewer than , giving height at least . The offset has height , and is absent. If , take ; the neighbouring-height argument again gives height and absence, and all present offsets are below numerically.
Repeat the window count at this threshold. At most selected backward arrows have offsets below , since the height- table also has an arrow ending at . Count , , and a possible exceptional separately, with the same high-column cancellation. Then
so . This gives , contradicting . The only possible heights are , , .
Geometry of an exceptional table
For an exceptional table , let be its number of fixed positions, its gap, and . Its height is , so
The maximum height gives . At least one fixed position exists, namely the last occurrence of , so .
A depth below by position would give a short scan by Estimate 2. Thus every depth in is at least . A depth- arrow contains as many fixed positions as its offset minus one, so that offset is at most . Depth- cards are fixed and have offset zero. All these prefix offsets are therefore below .
Subtracting from the labels increases height by at most one, from to at most . The height rule gives at most offsets below . The prefix supplies such positions, whence .
The first arrow contains fixed positions, so . All fixed positions lie between and , so . We have proved
In particular . No assumption about the initial height being was needed.
Excluding a minimum initial height
First exclude event . Under , the initial height is minimum and or : for , combine with ; for , . Thus is either or .
The repeated threshold count at , now with , shows that an exceptional exists. Take its table , gap , first target , and fixed-position count .
Suppose the initial height is minimum. Subtracting from takes height to , so exactly offsets of are below . All fixed positions are counted, and every position is fixed because the first arrow passes over it. Consequently
and there are no other offsets below .
If , position belongs to the high-depth prefix and is nonfixed, since it receives the arrow from . All fixed positions are less than , so its arrow must go to . This supplies offset below , contradicting the completed count. Thus . But and , so and the original first label is . This contradicts . Event is impossible.
With , the preliminary count now gives , so both and hold. If the initial height were still minimum, the geometry just proved would give . Event supplies another height- offset with positive gap . Between these equal heights, exactly relative offsets are below . But all zero offsets are already counted, so , contrary to . The initial height is therefore and its positive gap lies in the window.
Why the initial gap is 1 or 2
The exceptional-table bounds imply
The value would give , and would give . Both are excluded. Hence is , , or , so and .
We refine the bound on . Since
subtracting from gives the initial table with the same height. Exactly relative offsets of are below . All fixed positions are counted, and the first arrow fixes , so
If , those are all the fixed positions. The next two prefix arrows must be and , since longer arrows would contain additional fixed positions. Since , we have . The two unit arrows have offset below ; together with the zero offsets, they give at least offsets below , a contradiction. Therefore , and gives
There are fixed positions before , while itself is nonfixed, as it receives the arrow from . The last, th fixed position is therefore after . Thus
Why the initial gap is smallest at height
For , no smaller positive integer gap exists. Suppose . Then and the last fixed position is or ; all other fixed positions are .
If , the arrow at goes to . If , the arrow at goes to . Either case supplies an offset . If , this offset together with the zero offsets would give more than offsets below . Hence .
Offset now occurs at least twice: on the first arrow and on the unit arrow just found. There is also one fixed position with offset , so at least three offsets are below . Gap corresponds to subtracting from this table’s entries and would have height
Thus no gap has height ; the initial gap is indeed smallest among positive gaps of that height.
Conditions A, B, and D of the lemma are proved. Condition C follows from the minimum-height scan bound in Section § 10. The initial height is larger than the minimum, so there is no initial exception: every minimum gap exceeds , and its last arrow is backward with nonzero endpoint. This completes the structural lemma.
Let count offsets of height and those of height . The mean height is . Each minimum column is one below that mean, each height- column is one above, and all others equal it. Therefore
Selecting positions: an upper bound on their number
Write . Select positions satisfying both
: the original arrow is backward with nonzero endpoint;
the offset at is less than .
Let be the number selected. For example, with and , the arrow qualifies, since its offset is . The arrow does not qualify, since it ends at 0.
We prove . A selected position satisfies
The table adds modulo to the labels. There is no wrap at a selected position because , so
Each selected position therefore gives a backward arrow in , whose height is by condition B.
There is one more backward arrow not in the selection. Take from condition D. Its offset implies , so
Since , the residue is already , and
The position was not selected: its original arrow went forward or ended at 0.

Figure 6. How an additional backward arrow can appear. An arrow ending at 0 is excluded from the original selection; after adding 1, contributes to the height. This illustrates a local step, not a complete counterexample.
The selected positions and yield at least backward arrows, but the height is . Therefore
Counting offsets: the opposite bound
Now count distinct values of offsets. Multiple occurrences of one value count only once. Take two sets:
, the offsets of height ;
, the last nonzero residues.

Figure 7. Offset values and position numbers are different sets of indices. The arrow from position 8 to position 2 has offset 5.
Call the window. For , , it consists of the seven values . Window gaps lie from to , while minimum gaps exceed by condition C. Thus and are disjoint, with altogether
distinct values. We cover them by categories whose sizes can be bounded.
Minimum offsets are represented by selected positions. By C, the last occurrence has a backward arrow with nonzero endpoint. Its gap exceeds , hence exceeds , so its offset is . Both selection conditions hold.
Window offsets of height . There are at most , since there are only such values in the entire height table.
Window offsets of height $h + 1. First suppose is present and take its last occurrence.
If , count one exception.
If and its arrow goes forward or ends at , condition D gives , a second exception.
Otherwise the arrow is backward with nonzero endpoint. By B its gap is at least . Equality would give , already counted. Hence the gap exceeds , the offset is below , and the position is selected.
If a window value is absent, Rule 2 gives next height and next gap between and . Condition C excludes such a minimum height, including the cyclic transition from to . Height is itself impossible in the window. The categories are complete.
| Category | Number of values |
| Height | at most |
| Initial offset | at most 1 |
| Exceptional offset | at most 1 |
| Offsets of selected positions | at most |
Table 7.
The last entry is an upper bound because different selected positions can share an offset. Therefore
Since ,
§ 13 gave for the same set of positions. The two bounds are incompatible. For example, would require at most four and at least five positions.
The odd-counterexample lemma therefore proves the odd upper bound. The finite case was handled in § 5.
Permutations that attain the bound
Computational examples of extremal rows appear in [15]. For each , we now construct a row whose every solution has length at least and prove that lower bound uniformly. Start with the reflected row
For even , exchange positions 1 and 2. For this gives
For odd , take the reflected row’s card at position and put it at position 2, moving the intervening cards at positions one place right. This defines a starting row; it is not claimed to be an allowed puzzle move. For , , the row becomes
We separately bound swaps and shifts from below. Swaps are counted by pairs whose order must change. Shifts are counted by repeated leftward moves of a card, between which the marker must travel almost a full turn.
Counting swaps with two colours
Let be the original position in the reflected row from which the card now at was taken. Its label is
For even size, just exchanges 1 and 2. For odd size, it puts index at position 2. Take any solution of and retain every card’s unrolled target. For some common integer , the targets have the form
where specifies the copy of the final position occupied by the card initially at . Colour blue if is even and orange if is odd.
Suppose have the same colour and . Then is even and
The parenthesized difference is between 1 and , so is odd and nonzero. This pair contributes at least one periodic inversion.
As in § 8, a pair contributes
This counts order violations including periodic copies. Each adjacent swap changes the total by one, up or down. Eliminating all violations requires at least the initial inversion count in swaps.
If positions are blue, the number of same-colour pairs is
Exceptions can occur only at ordinary inversions of , where . There is one such pair for even size and for odd size, since the relocated card crosses cards.
Same-colour pairs are fewest when the colour classes are as equal as possible. For the minimum is ; for it is . For six positions, a split into three of each colour gives pairs. Subtracting the possible exceptions gives
| Number of cards | Necessary swaps |
| at least | |
| at least |
Table 1 (PDF p. 26).
This applies to every choice of turns . It does not assume that cards use the nearest copies of their target positions.
A lower bound on shifts
Follow a card that must move left. After a swap moving it one place left, the marker is at the card’s new position. To move the same card left again, the marker must reach the preceding circular position. As it only advances, this takes shifts.
For an arbitrary route, count the first time the card reaches each new position to the left of its start. Extra rightward motion does not remove the need to cross those positions. The same count therefore bounds routes with backtracking.
For example, a card going from position to coordinate must cross , , and . With , the marker can be at the starts of these successive crossings no earlier than unrolled coordinates , , and . A final shift may still be needed for the required start.
Let be the total number of shifts. If the card initially at ends at , counting leftward crossings and the final marker gives
The last term is the number of shifts from the last crossing under consideration to the nearest allowed final marker; it depends on the card’s label .
For the nearly reflected rows, apply this to cards with the smallest displacements. Sometimes two cards give the same bound, so changing the turns of one leaves a restriction supplied by the other. The exact constants require an additional analysis of initial swaps and all possible turns. We prove the following lemma.
Move-count lemma for nearly reflected rows. Every solution of the rows in § 15 uses at least
moves in total.
We first state the bounds for individual cases, then prove them and check that all possible targets are covered.
For even size, potentially short routes reduce to two cases:
| Targets | Swaps at least | Shifts at least | Total at least |
| Ordinary | |||
| Exceptional |
Table 2 (PDF p. 26).
The exceptional case requires one more swap but permits one fewer shift; the total is unchanged. For , these are and .
For odd , , the residue of the total shifts must be considered. Each case gives at least moves. For example, if and , one target case gives
Consequently
For this is the desired ; for it is larger by . The other target cases give at least the same bound, as we now prove. The case already follows from Section 5.
Which turns are possible in a solution shorter than
Start with any purported solution shorter than the bound. Keep each card’s unrolled displacement , and let be the total shifts modulo . Then
If some , its repeated leftward crossings alone require at least shifts. Together with the two-colour swap bound, this reaches the required total. A shorter solution must therefore satisfy
For each , choose the least displacement in each residue class that is at least . For our rows the resulting table is
Each lies in consecutive integers starting at , so every other admissible displacement is
with integer . Balance gives
For the nearly reflected rows, . Only two balanced possibilities remain:
, and every ;
, and exactly one .
If the sum is positive, balance is impossible. It suffices to check the base table and, when its sum is , tables obtained by adding to one coordinate. This restriction follows from the assumption of a short solution; it is not imposed in advance.
For example, with , , ,
The sum is , so exactly one coordinate must receive . Adding to one coordinate or to two coordinates would give sum instead of .
To prove the sum bound, first use the unmodified reflection, replacing by . Its table is
For odd , step visits every residue, so each occur once and . Modifying the reflection decreases the expression at position by and increases those at by one. These changes sum to zero, so only wraps at the ends of the chosen band affect the total:
position 2 receives if ;
a position in loses if . There is at most one such position, since the values of are distinct.
Thus . More precisely, with ,
| Values of | |
| 0 and 1 | |
Table 1 (PDF p. 28).
In the middle range, for instance, , so no is added. The value occurs in the modified segment only when is even, at . The sum is then ; otherwise it is 0.
For even , the unmodified reflection visits every residue of the appropriate parity twice. Its sum is . Swapping positions 1 and 2 decreases one expression by one and increases the other by one. The lower-end wrap adds only at , and the upper-end wrap subtracts only at . Hence
In the case subtracting , , so the sum is again at least .
What changes when one turn is added
Adding to one target affects only the pairs containing that card. Each contribution changes by or . If decrease, then
Here equals the card’s backward-crossing count before the added turn. For a balanced table with every displacement at least , § 10 bounds this count by .
If has sum , first add one to every displacement. The result is balanced, and target differences and inversion count are unchanged. All displacements are at least , so take . Adding a turn to any one coordinate therefore increases the inversion count by at least one for , and at least two for .
Even size: excluding the bottom of the band
Let and suppose a displacement is . At a position , the label is modulo . Substitute in the shift bound:
Combining with gives
which exceeds the desired . Position 0 also gives a sufficient bound. In a purported shorter route, can therefore occur only at position 1 or 2.
At both positions, . The residue condition for gives . The base sum is then , so one turn must be added to one coordinate. Its base inversion count is , and adding a turn increases it by at least one:
The card at position 1 or 2 gives
Together these yield
Thus a shorter route has no displacement , leaving the narrower band
Even size: ordinary and exceptional final markers
Choose residue representatives from to :
Their sum is nonnegative. Balance permits no added turns, so necessarily .
For the unmodified reflection, the expressions decrease by two, visiting each residue of the required parity twice. Their representatives in this band sum to if is odd and to if it is even. The swap at positions 1 and 2 changes only two terms; it can decrease the sum by a full period only at . Precisely,
where . The positive correction is the wrap of modified position 1 through the lower end, and the negative one is the wrap of position 2 through the upper end.
Residue gives positive sum and is excluded. All others allow only two cases:
and have the same parity;
.
In the first case, displacement occurs at position 0 or at a position . To verify this, solve
At unchanged positions , so . The two solutions differ by . If one lies at a modified position 1 or 2, the other remains near the end; the boundary case gives position 0.
For , the shift bound gives
Position 0 gives at least as much. Adding yields
In the second case the displacement table is explicit:
| Position | Displacement |
| 0 | |
| 1 and 2 | |
Table 4.
Here . The first three cards delay the subsequent swap queue. Counting that delay gives at least shifts before the swaps finish. Yet the total shift count must have residue . The preceding number already has that residue but is one too small. The next allowed count adds :
Again . The required final residue turns a shortage of one shift into the need for an extra full turn.
For , the table is . Finishing the swaps requires at least seven shifts. The final residue is 0, so the next admissible shift count is 12; with six swaps this gives 18 moves.

Figure 8. For six cards, six shifts cannot suffice, since the swaps require at least seven. The final marker requires a multiple of six, so at least twelve shifts are necessary.
Odd size: all final residues
Let , . The base table remains
Partition the possible into three disjoint ranges:
outer: or ;
middle: ;
the remaining value .
In the outer range balance permits only the base table. For , must be even; for , it must be odd. In either case, a position has displacement :
Substitution in the shift bound gives . Thus
two moves above the required bound.
In the middle range put . The base inversion count satisfies
To obtain the improvement over the general two-colour bound, observe that position 2 has turn number zero in the base table. Each position with
has turn number 1: the expression is negative but greater than , so taking its residue adds exactly . There are
such positions.
Each pair is reversed by the modification of the reflection, since . These positions have different colours, with turns 0 and 1. The coarse bound subtracted one for every reversed pair, even a different-colour pair that had contributed zero before subtraction. Here the actual contribution is at least one: for opposite colours and reversed order, the floor of the target difference divided by is an odd integer. We can replace the coarse contribution by , an improvement of two for each of the pairs. Hence
The equality follows by checking the two parities of .
There are two distinct positions with displacement . One is in the modified segment:
The other is if , and position 0 in the boundary case. Both follow by substituting into .
If no turn is added, the second position gives
The total is at least
If a turn is added, balance is possible only for . The swap count increases by at least two:
Only one coordinate receives the turn, so at least one of the two coordinates just found is unchanged. Even the weaker shift bound gives
and therefore
Finally, at , the base table is balanced:
| Position | Displacement |
| 0 | |
| 1 | |
| 2 | 0 |
Table 1 (PDF p. 31).
No turn can be added, since it would make the sum positive. The first two cards give a delay of at least shifts before the swaps finish. The preceding count already has the required residue . Another full period is needed:
Together with this gives . All final residues have now been covered.
Why the first cards delay the entire scan
Consider the first cards, initially at , and suppose each needs at least backward swaps (we assume ). Assume the next target, at position , exceeds all the preceding targets. We prove that the scan cannot finish before shift
During the first sweep, the scan carries the largest target seen so far to the right. Call its card the carried card. After inspecting the first cards, the carried card’s remaining backward count is the minimum of those cards’ initial backward counts.
This is checked one comparison at a time. If the next target is smaller, the carried card moves right and the smaller card performs one backward swap. The carried card’s backward count is unchanged. If the next target is greater, its card becomes the carried card. A card with the greater adjacent target has no more backward predecessors. Each step therefore preserves the minimum of the counts seen so far.
At the boundary before , the next target exceeds all preceding ones. The old carried card remains at and still needs at least leftward swaps. The marker is already at , comparing with the right neighbour. To perform the first leftward swap, it must reach the previous circular position, taking shifts. Each further backward swap costs at least another shifts. This gives .
Backtracking or skipped swaps cannot produce earlier completion, because § 8 compares the scan with every schedule for the same targets.
Apply this to the two exceptional tables. In the even case take , . Cards 1 and 2 have displacement , so each needs at least backward swaps. Card 0 has at least backward predecessors, supplied by copies of the last targets from the preceding turn. The target at position 3 exceeds the first three. The delay is .
In the odd case take , . Card 1 has displacement . Card 0 has at least backward predecessors from copies of the last targets on the preceding turn. The target at position 2 is 2 and exceeds the first two. The delay is .
Counting inversions in the exceptional tables
For even size the targets form three blocks:
the first three are , , ;
the next decrease from to 3 in steps of one;
the last decrease from to in steps of one.
The first block has two inversions. Every pair within either decreasing block is an inversion. Every pair from the first and last blocks has target difference at least and less than , contributing one. All other between-block pairs contribute zero. Thus
For odd size the first targets are , , 2, followed by two decreasing blocks of cards each. Contributions come from one inversion among the first three, all within-block pairs, and pairs of the first two targets with the last block:
For the even boundary table , every displacement is one less than in the exceptional table. A common shift leaves target differences unchanged, so its inversion count is also .
A complete seven-card example
For the row we have . The seven possible final residues give the following cases:
| Displacements | Moves at least | |
| 0 | Balance impossible in the chosen band | – |
| 1 | Base table | 27 |
| 2 | Base table | 25 |
| 3 | One coordinate increased by 7 | 26 |
| 4 | Base table | 25 |
| 5 | Exceptional table | 26 |
| 6 | Base table | 27 |
Table 5.
“Balance impossible” does not prohibit sorting with that final residue. It means that such a route has already been excluded from the class of putative solutions shorter than 25 moves. Every route therefore uses at least 25 moves.
In each case the swap and shift bounds apply to the same target table, so their sum bounds the length of that solution.
Combining the bounds
For even , the upper bound from § 11 and the lower bound from § 17 agree:
Substituting gives
For odd , § 12–§ 14 and the lower bound give
Substituting gives
The upper bound applies to every starting row. The lower bound applies to every solution of the rows in § 15. Their agreement proves the diameter formula for every . § 5 supplies $n = 5.
Formalization and computational provenance
An accompanying code [23] in Lean 4[24], using Mathlib [25], proves the exact directed diameter. The source version cited here is commit
9e04062fc06c6c1009295a8047e0ca52dd017456.
Its toolchain is Lean 4.34.0 with Mathlib v4.34.0.
The public entry point is LX/SharpDiameterAll.lean. The commands
lake build LX
lake env lean VerifyLXExact.lean
check the development and the full public theorem types. The axiom audit at this commit checks 4593 project theorems, including generated auxiliary declarations, and permits only propext, Classical.choice, and Quot.sound.
Acknowledgements
We thank the members of the CayleyPy collaboration for useful related discussions. F.L.-M. also thanks A. Guerrieri for discussions. The work of F.L.-M. was supported by the STFC grants APP69281 and ST/C004225/1. F.L.-M. is grateful to Anthropic for access to their models through the Claude Team plan for scientists. I. L. thanks V. Kirova for computations using equipment of the National Research Nuclear University MEPhI high-performance computing cluster.
References
- [1]V. M. Glushkov. Completeness of a system of operations in digital computers. Cybernetics, 4(2):1–4, 1968. English translation of Kibernetika 4(2) (1968), 1–5. doi:10.1007/BF01073731.
- [2]A. Chervov, D. Fedoriaka, E. Konstantinova, et al. CayleyPy Growth: Efficient growth computations and hundreds of new conjectures on Cayley graphs (Brief version), 2025. Version 2, 1 April 2026. Section 4.1, Conjecture 11. URL: https://arxiv.org/abs/2509.19162v2, arXiv:2509.19162.
- [3]L. Babai and Á. Seress. On the diameter of Cayley graphs of the symmetric group. Journal of Combinatorial Theory, Series A, 49(1):175–179, 1988. doi:10.1016/0097-3165(88)90033-7.DOI
- [4]L. Babai and Á. Seress. On the diameter of permutation groups. European Journal of Combinatorics, 13(4):231–243, 1992. doi:10.1016/S0195-6698(05)80029-0.DOI
- [5]L. Babai, R. Beals, and Á. Seress. On the diameter of the symmetric group: polynomial bounds. In Proceedings of the Fifteenth Annual ACM-SIAM Symposium on Discrete Algorithms (SODA 2004), pages 1108–1112. SIAM, 2004.DOI
- [6]E. Breuillard, B. Green, and T. Tao. Approximate subgroups of linear groups. Geometric and Functional Analysis, 21(4):774–819, 2011. doi:10.1007/s00039-011-0122-y.DOI
- [7]H. A. Helfgott and Á. Seress. On the diameter of permutation groups. Annals of Mathematics, 179(2):611–658, 2014. doi:10.4007/annals.2014.179.2.4.DOI
- [8]A. Chervov, F. Levkovich-Maslyuk, A. Smolensky, et al. CayleyPy-4: AI-holography. Towards analogs of holographic string dualities for AI tasks, 2026. URL: https://arxiv.org/abs/2603.22195, arXiv:2603.22195.
- [9]M. M. Glukhov and A. Yu. Zubov. On the lengths of symmetric and alternating permutation groups in various generating systems (a survey). In Matematicheskie Voprosy Kibernetiki, volume 8, pages 5–32. Nauka, Moscow, 1999. In Russian. URL: https://keldysh.ru/papers/1999/mvk/mvk1999_5.pdf.
- [10]B. A. Pogorelov. On a problem of V. M. Glushkov. Kibernetika, (5):141–143, 1973. In Russian. English translation: A problem of V. M. Glushkov, Cybernetics 9 (1973), 895–899, doi:10.1007/BF01069732. Historical results and this bibliographic record are also given in [9, pp. 20–21 and reference 48].
- [11]A. Yu. Zubov. On the diameter of the group S_N with respect to a system of generators consisting of a complete cycle and a transposition. In Trudy po Diskretnoi Matematike, volume 2, pages 112–150. TVP, Moscow, 1998. In Russian. URL: https://www.mathnet.ru/eng/tdm22.
- [12]A. Yu. Zubov. On the representation of substitutions as products of a transposition and a full cycle. Journal of Mathematical Sciences, 166(6):710–724, 2010. Russian original: Fundamentalaya i Prikladnaya Matematika 15(1) (2009), 31–51. doi:10.1007/s10958-010-9887-z.DOI
- [13]A. Yu. Zubov. Circular inversions of permutations and their use in sorting problems. Prikladnaya Diskretnaya Matematika, (1(31)):13–31, 2016. In Russian. URL: https://www.mathnet.ru/eng/pdm540, doi:10.17223/20710410/31/2.DOI
- [14]D. desJardins and contributors. A039745: Diameter of symmetric group Sₙ when generated by (1, 2) and (1, 2, 3, . . . , n). The On-Line Encyclopedia of Integer Sequences. Accessed 29 October 2026. URL: https://oeis.org/A039745.
- [15]K. Ryde and contributors. A378881: Irregular triangle listing permutations of {1, . . . , m} which are at maximum distance from the identity permutation under steps rotate left (L) or exchange first two elements (E). The On-Line Encyclopedia of Integer Sequences, 2024. Accessed 29 October 2026. URL: https://oeis.org/A378881.
- [16]A. Chervov, A. Soibelman, S. Lytkin, et al. CayleyPy RL: Pathfinding and reinforcement learning on Cayley graphs, 2025. Version 3, 15 May 2026. URL: https://arxiv.org/abs/2502.18663v3, arXiv:2502.18663.
- [17]S. S. Kuppili and B. Chitturi. Exact upper bound for sorting Rₙ with LE. Discrete Mathematics, Algorithms and Applications, 12(3):2050033, 2020. 12 pp. Author-hosted manuscript: https://bpb-us-e2.wpmucdn.com/sites.utdallas.edu/dist/f/1052/files/2023/03/LE.pdf. doi:10.1142/S1793830920500330.DOI
- [18]A. Williams. Hamiltonicity of the Cayley digraph on the symmetric group generated by σ = (1 2 · · · n) and τ = (1 2), 2013. Version 3, 6 July 2017. URL: https://arxiv.org/abs/1307.2549v3, arXiv:1307.2549.
- [19]J. Sawada and A. Williams. Solving the Sigma-Tau problem. ACM Transactions on Algorithms, 16(1):11:1–11:17, 2020. Article 11; published online 15 November 2019. doi:10.1145/3359589.DOI
- [20]R. M. Adin, N. Alon, and Y. Roichman. Circular sorting, 2025. Version 2, 6 August 2025. URL: https://arxiv.org/abs/2502.14398v2, arXiv:2502.14398.
- [21]P. Diaconis and R. L. Graham. Spearman’s footrule as a measure of disarray. Journal of the Royal Statistical Society, Series B, 39(2):262–268, 1977. doi:10.1111/j.2517-6161.1977.tb01624.x.DOI
- [22]Andrea Guerrieri. In preparation.
- [23]S. Uskov, A. Chervov, F. Levkovich-Maslyuk, I. Litvak, A. Smolensky, and A. Soibelman. Exact directed L/X diameter in Lean 4. https://github.com/snow-ghost/glushkov-lx-lean/releases/tag/v1.0.0, November 2026. Lean 4 formalization, version v1.0.0, commit 9e04062.
- [24]L. de Moura and S. Ullrich. The Lean 4 theorem prover and programming language. In Automated Deduction – CADE 28, volume 12699 of Lecture Notes in Computer Science, pages 625–635. Springer, 2021. doi:10.1007/978-3-030-79876-5_37.
- [25]The mathlib Community. The Lean mathematical library. In Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs (CPP 2020), pages 367–381. ACM, 2020. doi:10.1145/3372885.3373824.DOI