# For six block counts in every 144, a fixed order can pass a three-entry shuffle test

One way to test a shuffle is to pick three entries, read them from left to right and see how often each of their six possible orders occurs. In a uniform shuffle all six are equally likely. Could the test give the same result if whole blocks stay in a fixed order and only their contents are shuffled? Previous work ruled out most block counts and found examples that pass, but left open which of the remaining counts work.

We prove that every count allowed by the arithmetic works. For exactly six block counts in every 144, there is a fixed order for which all six triple frequencies approach $1/6$ as the blocks grow. The number of blocks leaves remainder 0, 1, 17, 64, 80 or 81 when divided by 144. This settles a conjecture of Khovanova and Zhang [2]. At every such length, the fixed order can even have a plot that looks the same after a quarter-turn.

## How blocks affect the test

A permutation lists the ranks $1,\ldots,n$ in some order. A triple consists of entries at three distinct positions. Its order records their relative ranks: for instance, $5,9,2$ has order 231 because the middle rank comes first, the largest second and the smallest last. The frequency of an order is the fraction of all triples that give it.

To enlarge a fixed permutation, called the seed, replace each entry with a block of $b$ consecutive ranks. A higher seed entry gets a block whose ranks all exceed those of a lower entry's block. Shuffle the ranks within a block using a uniformly random permutation of length $b$, and use a copy of that same permutation in every block. This is *random inflation*. A seed is *3-inflatable* if, with probability one, all six triple frequencies tend to $1/6$ as $b$ grows.

The test on the enlarged permutation translates into exact counts in the seed. In the large-block limit, drawing three entries gives three independent, uniformly distributed block labels before the entries are sorted by position. If all triple orders are equally frequent, a randomly chosen pair must be increasing half the time. A pair drawn within one block already has that probability. For pairs drawn from distinct blocks, the seed determines the order, so half its pairs must also be increasing. The required count for each pair order is therefore $M=\binom n2/2$, where $\binom nr$ counts the ways to choose $r$ of $n$ positions.

Now consider a particular triple order, and let $C$ be its count in the seed. There are $n^3$ equally likely ways to draw three block labels. The contribution to the triple frequency depends on how many labels are distinct.

*Three distinct blocks.* Each occurrence in the seed accounts for six draws, one for each way to draw its labels. Together these contribute $6C/n^3$.

*Two distinct blocks.* For the order 123, both blocks must form an increasing pair. Either block can supply the repeated label. For 132, the pair must again increase, but only the higher block can repeat. In general there are $k=2$ choices for which block repeats for a monotone order (increasing or decreasing), and $k=1$ for each other order. There are $M$ seed pairs of the required order, three placements of the repeated label in the draw, and probability $1/2$ that its entries have the required internal order.

*One block.* There are $n$ choices of label, and each order has limiting probability $1/6$ within that block.

Adding these contributions gives the limiting frequency
$$
 \frac{1}{n^3}\left(6C+\frac{3kM}{2}+\frac n6\right).
$$
A monotone order gets a larger contribution from draws with two distinct blocks, so it needs fewer occurrences in the seed. Setting the frequency to $1/6$ gives the counts derived by Khovanova and Zhang [2, Theorem 13] for $n\ge3$:
$$
 T=\frac{n(n-1)(2n-7)}{72}\quad\text{for each of 123 and 321},\qquad
 S=\frac{n(n-1)(4n-5)}{144}\quad\text{for each other order}.
$$

These counts must be integers. That requirement gives the six possible remainders above [2, Lemma 15]. Length one works directly; length two cannot balance its pairs. Khovanova and Zhang found examples at lengths 17, 64, 80, 81, 144 and 145 and showed that the product of two lengths that work also works. This gave infinitely many examples but left gaps, including 161. Their Conjecture 18 says that every length with one of the six remainders works.

## A quarter-turn reduces six counts to one

Plot each seed entry as a point with position on the horizontal axis and rank on the vertical axis. A 90-degree rotation turns an increasing pair into a decreasing pair. It exchanges the orders 123 and 321 and cycles through the other four triple orders. If the rotation leaves the whole plot unchanged, the two pair counts must be equal. The two monotone triple counts must also match, as must the other four counts. It is enough, then, to build a plot with this symmetry and exactly $T$ increasing triples: every triple belongs to one of the six orders, and $2T+4S=\binom n3$.

![Permutation plot with 80 points in four squares; rotating the three descending runs in the leftmost square generates the other three squares.](results/quarter-turn.png)

Figure 1. A seed of length 80. In the leftmost square, the points descend in runs of 4, 7 and 9. Each run lies above the preceding one. Rotating this square gives the other three. The seed has 13,430 triples of each monotone order and 13,825 of each other order. After random inflation all six frequencies tend to the same value.

To build such a plot, divide $n$ by four and write $n=4m+e$. The six permitted remainders ensure that $e$ is either 0 or 1. Each square will hold $m$ points, with a point at the center if $e=1$. Choose a permutation $\sigma$ of length $m$ to determine the order within the leftmost square. Number both positions and ranks from zero and plot the points $(i,m+\sigma(i))$ for $0\le i<m$. Add the three successive rotations of these points using the quarter-turn $R(x,y)=(n-1-y,x)$. The four squares use disjoint intervals on each axis. For odd $n$, only the center coordinate remains on either axis; add the point $(2m,2m)$. Beniamini, Lavee and Linial [3] used this geometry to make all six counts equal before inflation. Here the inflated plot must have equal frequencies, so the seed needs the two distinct counts $T$ and $S$. For lengths from 400,000 onward we choose the order within the first square by a single rule. For the shorter lengths we verify explicit seeds.

To choose the order within the first square, we need to know how it affects the count in the full plot. Let $A$ be the number of increasing pairs in $\sigma$, and $U$ its number of nonmonotone triples. The number of increasing triples in the full plot is
$$
 N_{123}=2\left[\binom m3-U\right]+2m\left[\binom m2+A\right]+e(m^2+2A).
$$
The three terms count increasing triples by where their points lie. The first counts triples entirely within a square. Two squares preserve the increasing triples of $\sigma$ and two turn its decreasing triples into increasing ones.

For triples that cross between squares, read the heights of the four squares from left to right. Their order is 2413. No three squares are in increasing order. The first and last squares each have two partners with which they form an increasing pair of squares. Each of these outer squares offers $A$ increasing pairs to go with any of the $m$ points in a partner. The other two squares each have one partner and offer $\binom m2-A$ pairs. This accounts for the second term, as in [3, Lemma 3.6] for even lengths.

The last term applies only at odd lengths. An increasing triple containing the center uses two points southwest of it, two northeast, or one in each square. These choices contribute $2A+m^2$.

## Adjusting the increasing-triple count

Start with all $m$ points in the first square in increasing order. The full plot then has the following number of increasing triples:
$$
 B=2\binom m3+4m\binom m2+e\left(m^2+2\binom m2\right).
$$
We must remove $B-T$ increasing triples by rearranging the first square and rotating its new order into the others. Count the reduction in units of two triples, so the target is $D=(B-T)/2$. This is an integer: $16$ divides $n(n-1)$ on the six residues, making the integer $T$ even. For odd admissible $n$, $4$ divides $m$, so $B$ is even in both cases.

Within the first square, divide $\sigma$ into consecutive groups of positions. Give each group higher ranks than its predecessor, as in Figure 1. We use these inner blocks to adjust the triple count in known amounts. Suppose one block of length $j$ has $I$ inversions (decreasing pairs) and $u$ nonmonotone triples of its own. It removes $I$ from $A$ and contributes $u+(m-j)I$ to $U$: any one of the $m-j$ outside points makes a nonmonotone triple with an inversion in the block. No other triple crossing blocks is nonmonotone. Thus this block contributes $(2m+e-j)I+u$ to the reduction $D$, and the contributions add.

In a descending run of length $j$, all $\binom j2$ pairs are inversions and all triples are monotone. Writing $H=2m+e-2$, its contribution is
$$
 c(j)=(2m+e-j)\binom j2=H\binom j2-3\binom j3 .
$$
In other words, each inversion contributes $H$ units before a discount of three units per internal triple. For a fixed total number of inversions, the discount from descending runs is always a multiple of three. By contrast, 2413 has three inversions and four nonmonotone triples, giving $3H-2$. Its discount is two units. Using zero, one or two such blocks lets us select any remainder on division by three. A block of one point (a singleton) contributes zero, so it can fill unused positions.

## Why the corrections fit at every large length

For $m\ge100{,}000$, we can reach the exact reduction $D$ in two steps. One long descending run supplies most of it. Shorter blocks supply the rest. The long run must leave both a large enough reduction for those corrections to work and enough positions to hold the blocks.

Let $a$ be the largest run length at most $m$ with $c(a)\le D$. Stop one point short, at length $L=a-1$. This leaves more than $0.3m$ positions free and a remaining reduction $d=D-c(L)$, by the following bounds:
$$
 m/2\le L<0.7m,\qquad 0.45m^2<d<2m^2. \tag{1}
$$
To prove these bounds, substitute $n=4m+e$ into the formulas for $B$ and $T$. This gives $144D=40m^3-72m^2+20m$ in the even case and $144D=40m^3-24m^2-4m$ in the odd case. Thus $0.27m^3<D<0.28m^3$. At $j=\lceil m/2\rceil+1\le0.501m$, we have $c(j)<0.26m^3$; at $j=\lfloor0.7m\rfloor$, we have $j-1\ge0.699m$ and $c(j)>0.31m^3$. The increment
$$
 \Delta_j=c(j+1)-c(j)=j\left(2m+e-(3j+1)/2\right)
$$
is positive for $1\le j<m$, locating $L$ as claimed. For $j=L,L+1$ the increment lies between $0.45m^2$ and $m^2$, by $m/2\le j\le0.7m$. Since $\Delta_L\le d<\Delta_L+\Delta_{L+1}$, (1) follows.

A run of length 48 supplies 46 units of discount per inversion, since $3\binom j3=(j-2)\binom j2$. We use this run as a reference: if every correction run had this length, each inversion would supply $h=H-46$ units of reduction. Choose a total of
$$
 P=\lfloor d/h\rfloor-1
$$
inversions for all the correction blocks. At the reference rate these inversions fall short by $s=d-hP$, where $h\le s<2h$ because we rounded down and subtracted one. We make up the difference by putting some inversions in shorter runs: a smaller discount means a larger reduction per inversion. The required total discount is $HP-d=46P-s$.

Choose $t\in\{0,1,2\}$ so $2t\equiv HP-d\pmod 3$, and use $t$ copies of 2413. The descending runs must now supply a total of
$$
 Q=(HP-d-2t)/3=(46P-s-2t)/3
$$
internal triples. This is a nonnegative integer: (1) and $2m-48\le h<2m$ give $0.22m<P<1.01m$, hence $46P>s+2t$. Allocate these $Q$ triples to runs, starting with as many runs of length 48 as possible. Each uses $\binom{48}3$ triples. Repeat with the remaining triples at lengths 24, 12, 6 and 3, in that order. A run of length 3 uses a single triple, so this accounts for $Q$ exactly.

This choice meets the discount target. Two checks remain: can we complete the inversion count with descending pairs, which carry no discount, and can all the blocks fit in $m$ positions?

For the first check, compare the inversions in each run with the number it would take to supply the same internal triples using runs of length 48. A 48-run uses exactly $3/46$ inversions per internal triple; every smaller run uses more. Write the total inversion count of the runs as $3Q/46+E$. The excess $E$ is bounded by all the inversions in the runs of length below 48. After allocating runs of a given length, too few triples remain for another run of that length. Thus the counts of runs of lengths $(24,12,6,3)$ are at most $(8,9,10,19)$ respectively. Together these use at most 3,009 inversions and 417 positions. The remaining inversion count is therefore
$$
 r=P-3t-3Q/46-E=(s+2t)/46-3t-E .
$$
It is at least $h/46-6-3009>0$ and less than $(2h+4)/46$.

Second, the $r$ descending pairs and all earlier blocks must fit in the inner permutation. Since the inversion budget holds, the 48-runs occupy at most $2P/47$ positions: each uses $\binom{48}2$ inversions in 48 positions. Adding the leading run, the special blocks, the 48-runs, the smaller runs and the final pairs uses fewer than
$$
 0.7m+8+2(1.01m)/47+417+2(4m+4)/46 < m
$$
positions for $m\ge100{,}000$. Fill the rest with singletons. The correction blocks have exactly $P$ inversions and discount $3Q+2t$, so they contribute $HP-3Q-2t=d$. The leading run supplies the rest of $D$. This proves existence for every admissible $n\ge400{,}000$.

## Exact verification below 400,000

For each of the 16,667 permitted positive lengths below 400,000, the [list of seeds](results/witnesses.txt.gz) gives an explicit example. Each example serves as a certificate: its counts can be checked without searching for a permutation. Each line gives the length and either the full seed or a list of inner blocks with multiplicities. D followed by a number denotes a descending run of that length; other digits give a block in rank order. A colon precedes the multiplicity. The list is sorted by block type, but the blocks can be placed in any order provided each uses higher ranks than all preceding blocks. Their contributions add, so reordering them preserves the required count. The two full seeds are marked with an exclamation point and use letters for ranks above nine.

We verified the certificates independently of the reduction formula. For each inner block we selected one, two or three positions at a time and counted how often each relative order occurred. When we combined blocks, selections lying entirely in one block kept their order. For two occupied blocks we multiplied the local counts and read the order from the relative heights of the blocks. Three occupied blocks contribute the product of their lengths to their own triple order. We combined the inner blocks this way, rotated the resulting counts and combined the four squares, including the center at odd lengths. For the two seeds given in full, we checked rotation directly. Every certificate met the required counts, and the list of lengths agreed exactly with the list obtained by testing the integer divisibilities. As a check on this counting method, we expanded all 27 seeds through length 640 and enumerated their pairs and triples individually.

Length one is immediate. The seed at length 17 is $(4,12,13,17,3,2,10,7,9,11,8,16,15,1,5,6,14)$ from the [Khovanova–Zhang archive](https://github.com/ekzhang/inflatable/blob/e4345558cdf3379da2ce4b77a750922e5931661c/search/inflatable_list17.txt). Table 1 gives examples of the block lists, including cases that use blocks other than descending runs and 2413.

Table 1. Inner permutations for seven finite certificates. Place the additional block first, then the indicated descending runs, each on ranks higher than all preceding blocks. A parenthesis gives the number of copies.

| Seed length | Additional block | Descending run lengths |
|---:|:---:|:---|
| 64 | 87531246 | 7, 1 |
| 81 | 7531264 | 11, 2 |
| 144 | 7642153 | 21, 4, 2 (×2) |
| 161 | 87543216 | 24, 2, 1 (×6) |
| 224 | 53124 | 35, 4, 2, 1 (×10) |
| 225 | 641352 | 35, 4, 2, 1 (×9) |
| 640 | none | 78, 55, 4, 3 (×3), 1 (×14) |

Together the verified seeds and the construction cover every positive length that passes divisibility. At each one, the three-entry test can miss a fixed block order even when the seed has quarter-turn symmetry.

Using four entries changes what the test can detect. Král’ and Pikhurko [1] proved that uniform limiting frequencies for all four-entry orders force *quasirandomness*. In particular, when both axes of the plot are scaled to the unit interval, the limiting fraction of points in each rectangle must equal its area. For a seed of length greater than one, the first block occupies only one of the $n$ rank intervals. Pair its position interval with any other rank interval and the resulting rectangle has area $1/n^2$ but contains no points. Triples are therefore the last case in which an inflation of such a seed can pass.

## References

1. D. Král’ and O. Pikhurko (2013). [Quasirandom permutations are characterized by 4-point densities](https://doi.org/10.1007/s00039-013-0216-9). *Geometric and Functional Analysis*.
2. T. Khovanova and E. Zhang (2021). [Limit densities of patterns in permutation inflations](https://doi.org/10.37236/8234). *Electronic Journal of Combinatorics*.
3. G. Beniamini, N. Lavee and N. Linial (2025). [How balanced can permutations be?](https://doi.org/10.1007/s00493-024-00127-x). *Combinatorica*.
