The longest climb of a shuffle
Worth reading first: The sequence that cannot avoid a staircase · Every crowd holds a bowl or a dome.
Any distinct numbers, in any order, contain a run of about of them that climbs or a run of that length that falls — a pigeonhole argument on two counters per number. That is Erdős and Szekeres’s theorem, and it is exact: there are orders in which no run, up or down, is any longer. It is a statement about the worst order. In 1961 Stanisław Ulam asked about a typical one. Shuffle a deck of cards thoroughly and deal them out; how long is the longest run of cards that increase?
The answer turned out to be one of the deepest results in probability of the last half-century. The longest increasing run of a random shuffle is almost exactly — twice the guarantee, and in both directions at once. How much it varies from shuffle to shuffle was settled only in 1999, and the answer connects card shuffles to the eigenvalues of random matrices, the growth of crystals and the edges of fluctuating interfaces.
The figure below is the problem in its most visual form. Four hundred points dropped at random in a square, and the longest chain of them that rises to the right in both coordinates: thirty-four points, where .
Points in a square
The square and the shuffle are the same object. Drop points at random, sort them left to right, and record the order of their heights: the result is a uniformly random shuffle of cards, because every order of heights is equally likely. A chain rising to the right in both coordinates is then an increasing subsequence of the shuffle, and the longest such chain is the longest increasing subsequence.
The square version, due to John Hammersley in 1972, makes one fact nearly obvious. Double the side of the square and keep the density of points the same: there are four times as many points, and a rising chain across the big square can be built from rising chains across two small squares placed corner to corner along the diagonal. So the length is at least additive along the diagonal, and a length proportional to the side — that is, to — is the natural scale. Hammersley proved that settles to a constant, and conjectured it was .
Why and not something else took five years and two independent proofs. In 1977 Benjamin Logan and Lawrence Shepp, and independently Anatoly Vershik and Sergei Kerov, proved it by identifying not just the longest run but the whole shape of a structure the shuffle determines — the same shape this essay ends with.
Patience sorting counts it
Finding the longest increasing run of a given shuffle does not require checking every subsequence. A card game does it in one pass.
Deal the cards one at a time. Put each card on the leftmost pile whose top card is larger, and if there is none, start a new pile on the right. The number of piles at the end is the length of the longest increasing subsequence.
Two facts make that true. No increasing run can put two of its cards on the same pile, because each pile decreases from bottom to top, so a run has at most as many cards as there are piles. And when a card is placed on pile , the top card of pile is smaller than it and was dealt earlier — otherwise the card would have gone there — so following those links back from any card on the last pile traces an increasing run through every pile. The game is a proof as well as an algorithm, and the chain-covering argument of Dilworth and Mirsky is the same proof in the language of ordered sets.
It is also fast. Finding the pile for each card is a binary search, so a million cards take about twenty million comparisons. Every length in the figures below was computed this way, and on the smaller cases checked against a search of every pair.
Two, approached very slowly
With patience sorting, the average longest run can be measured for shuffles of any reasonable size.
The ratio rises steadily and never reaches . At twenty-five cards it is about , at four hundred about , at six thousand four hundred about . The approach is slow because the correction shrinks only like — to halve the distance to the deck has to grow eightfold. The dashed curve is the leading correction that the 1999 theorem below implies, and the measured points sit a little above it, as a further, smaller correction says they should.
This is a place where small cases genuinely mislead. A reader who shuffled a hundred decks of a hundred cards would measure a ratio near and could reasonably guess the constant was or or . The limit is , and nothing short of a proof — or decks of millions of cards — would reveal it.
The worst order and a typical one
Erdős and Szekeres’s theorem has an extremal order, and it is worth setting beside a random one.
In the extremal order both the longest climb and the longest fall are about , the least the theorem allows. In a random order, the longest climb is about and so is the longest fall, since reversing a random shuffle gives another random shuffle. The random order has both, twice over, where the theorem promises one, once.
That gap between guarantee and typical is the same one the previous essay found for convex polygons, where random crowds hold far larger convex polygons than the worst crowds are forced to. Extremal orders are rigid and rare: the blocks must be arranged exactly, and a single misplaced card lengthens a run. Out of all orders, the ones with both runs close to are a vanishing fraction, and the probability that a random shuffle’s longest climb falls below decays like — faster than for almost any other statistic of a shuffle.
The comparison is worth setting against the rest of Ramsey theory, where randomness usually plays the opposite part. For the party problem, a random colouring is the best escape anyone knows: Erdős proved in 1947 that colouring each pair by a coin toss avoids a large one-coloured group far better than any explicit colouring does, and nobody has constructed colourings that match it. For sequences it is the other way round. A random order is a poor escape — its runs are twice as long as necessary — and the best escape is a rigid construction of blocks. Whether randomness helps or hinders escaping depends on whether the structure being avoided is rare, as a one-coloured group is, or everywhere, as a rising chain is.
Fluctuations of size n to the one-sixth
Knowing the average is not knowing how much a single shuffle can differ from it, and here the problem produced its biggest surprise.
If the longest run were a sum of many independent pieces, its fluctuations would be of size , which here is about . They are much smaller: of size , about three and a half cards when . A shuffle of two thousand cards almost always has a longest climb within a handful of cards of .
And the shape of the fluctuations is not the bell curve. In 1999 Jinho Baik, Percy Deift and Kurt Johansson proved that converges to a distribution Craig Tracy and Harold Widom had found five years earlier in a completely different place: the largest eigenvalue of a large random Hermitian matrix, rescaled at the edge of the spectrum. It is lopsided, with a thin tail to the right and a thinner one to the left, mean and spread . The histogram shows its lopsidedness at two thousand cards: the bars fall off more slowly on the right than on the left.
That a card game and a random matrix share a limit law is the surprising connection this essay turns on, and it has since spread. The same Tracy–Widom distribution describes the fluctuations of a growing crystal’s edge in certain models, the position of the fastest particle in a simple model of traffic in which cars hop forward only into empty spaces, and the interface of a turbulent liquid crystal measured in the laboratory in 2010. The shared structure is a random growth process in which each step depends on a maximum over earlier steps — which is exactly what the longest rising chain is.
The shape a shuffle grows
The 1977 proofs of the constant did not study the longest run alone. They studied a whole shape attached to the shuffle, of which the longest run is one measurement.
The Robinson–Schensted correspondence inserts the cards of a shuffle one at a time into rows, each card bumping the smallest larger card from its row down into the next. The result is a staircase-shaped arrangement of boxes — a partition of , drawn as a diagram — and Craige Schensted proved in 1961 that the length of its first row is the longest increasing subsequence, and of its first column the longest decreasing one. Curtis Greene later showed that the first rows together give the largest union of increasing subsequences, so the whole shape measures the shuffle’s increasing structure at every scale.
Scaled by and turned on its corner, the shape of a random shuffle’s diagram approaches a single curve,
meeting the two lines at . The first row of the diagram runs out along one of those lines, and it reaches to — which, undoing the scaling and rotation, is a row of length . The constant in the longest-run problem is where the limit curve touches the corner.
It is worth comparing with the shape a random partition takes, which is a different curve for a different reason. There, every partition of was equally likely. Here, a partition’s chance is the number of shuffles that produce it, which by the correspondence is the square of the number of ways to fill its diagram with increasing along rows and columns — the Plancherel weighting, which favours balanced shapes. Two natural ways of choosing a random partition, two different limit curves, and both found by solving a variational problem for the most likely shape.
Counting shuffles with random matrices
The link to random matrices is not only a coincidence of limit laws. There is an exact identity underneath it, found by Ira Gessel in 1990 and put in its sharpest form by Eric Rains in 1998.
Pick a unitary matrix at random — uniformly, in the sense that makes every rotation of complex -space equally likely — and take its trace, the sum of its diagonal entries. The trace is a complex number whose size fluctuates from matrix to matrix. Rains proved that the average of its size raised to the power is a whole number, and that the whole number is the count of shuffles of cards whose longest increasing run is at most :
For every shuffle qualifies and the average is . For only the fully decreasing order qualifies, and a unitary matrix is a point on the unit circle, whose size is one: the average is . In between, the identity turns a question about cards into an integral over a group of matrices, and the integral can be analysed by the same methods that describe how eigenvalues crowd together — which is how Baik, Deift and Johansson proved their theorem.
Matrix integrals counting combinatorial objects have appeared before: the Gaussian integral that counts ways to pair a polygon’s edges, organised by the genus of the surface each pairing makes. The shuffle identity is a relative. In both, an average over random matrices is secretly a sum over arrangements, and the matrix side is where the asymptotics are tractable.
A process that sorts itself
There is a way to watch the constant emerge rather than compute it, and it comes from turning the square on its side.
Sweep a vertical line across Hammersley’s square from left to right, and keep, at each moment, a set of marks on the line: one mark for each pile of the patience-sorting game run on the points passed so far, placed at the height of that pile’s top card. When the sweeping line meets a new point, the lowest mark above the point jumps down to it — the card goes on the leftmost pile whose top is larger — or a new mark appears if none is above. The number of marks when the line reaches the far side is the longest rising chain.
David Aldous and Persi Diaconis showed in 1995 that this system of jumping marks behaves, at large scale, like a fluid obeying a simple conservation law. The marks thin out as they are pushed downward and replenished from above, and solving the fluid equation for their density gives the answer: marks at the end. It is a proof by physics — a hydrodynamic limit — and it explains the constant as the solution of a differential equation rather than as the corner of a limit shape.
That two such different proofs give the same , one through the shape of a tableau and one through the flow of a fluid of marks, is part of why the answer is trusted as deeply as it is. Neither proof, though, gives the fluctuations, and it was the matrix identity above that finally did.
What sampling cannot settle
Every number in these figures is a sample. Two hundred shuffles at each size estimate the mean to about one per cent; fifteen hundred shuffles show the shape of the fluctuation law only roughly; one shuffle of two thousand five hundred cards shows the limit shape once. The claims that the ratio tends to exactly , that the fluctuations are exactly of order , and that their law is exactly Tracy–Widom’s are theorems, and the figures are consistent with them rather than evidence strong enough to have found them.
The finite sizes also hide how slowly everything converges. The histogram’s mean is at two thousand cards, not the limiting , and the difference is a correction of relative size , the same slowness the growth figure shows. Anybody estimating the constants from simulation would be misled in the same direction at every size they could afford.
And the pictures are all of the uniform shuffle. Shuffles that are not uniform — a deck given only a few riffle shuffles, or points concentrated along the diagonal of the square — have longest runs governed by other laws, and the rigidity of is a property of complete randomness.
Still open: the constant in higher dimensions
Hammersley’s square has a natural extension. Drop points at random in a -dimensional cube and ask for the longest chain rising in every coordinate at once. Its length is about , and Béla Bollobás and Peter Winkler proved in 1988 that the constant exists for every and that tends to as the dimension grows.
For the constant is , by the theorems above. For and every higher dimension, the value of is not known. It lies between known bounds, and simulations estimate it, but there is no Robinson–Schensted correspondence for three-dimensional orders, no limit shape to compute, and none of the algebraic structure that made the planar problem exactly solvable. The same question that has a closed answer in the plane has, one dimension up, only an estimate.
What links here
Computed from the collection, not written here: the essays that point at this one.
Named objects
A dashed tag is an object no other essay names yet.
FluctuationsLimit shapeLongest increasing subsequenceMonte CarloRandom matrixRandom permutationRobinson schenstedYoung tableau