Seven shuffles Image: Johnny Blood (CC BY-SA 2.0)

Seven shuffles

Cut a deck roughly in half, hold one half in each hand, and let the cards fall together with the thumbs so that the two halves interleave. That is a riffle shuffle, and the question of how many of them it takes to mix a deck has a precise answer, published in 1992 by Dave Bayer and Persi Diaconis under the title Trailing the Dovetail Shuffle to its Lair. The answer for 52 cards is seven. Fewer, and a card player who pays attention can still exploit the order; more, and the gain is small. The New York Times put the result on its front page, which does not happen to many theorems about the symmetric group.

A shuffle is a permutation

Number the cards 1 to 52 from the top of a fresh deck. After any shuffle, the deck is in some order, and that order is a permutation of \(\{1, \ldots, 52\}\) in the sense of Unit 6: a rearrangement, one of \(52!\) possible ones, which is about \(8 \times 10^{67}\). A perfectly mixed deck is one in which every one of the \(52!\) orders is equally likely. The question is how close a few riffle shuffles come to that.

To answer it one needs a mathematical model of what a riffle shuffle does, and the one Bayer and Diaconis used goes back to Edgar Gilbert and Claude Shannon at Bell Labs in 1955 and, independently, to Jim Reeds in 1981. Cut the deck at a position chosen according to the binomial distribution, which puts the cut near the middle most of the time, exactly as hands do. Then drop cards from the two halves one at a time, and at each drop let the probability of dropping from a half be proportional to the number of cards left in it. A larger half drops cards faster, which is also what hands do. The model matches measurements of real shuffles by real people well, apart from the few who shuffle very badly or very well.

Rising sequences

The key to the analysis is to look at the deck after the shuffle and count its rising sequences. A rising sequence is a maximal set of cards that are in increasing order and consecutive in value: in the arrangement 1, 4, 2, 5, 3, 6, the cards 1, 2, 3 form one rising sequence and 4, 5, 6 form another, because each sequence can be read off from left to right skipping the other. A fresh deck has one rising sequence. One riffle shuffle produces at most two, since each half keeps its own order as the cards interleave. Two shuffles produce at most four, and \(k\) shuffles at most \(2^k\). That already shows that five shuffles cannot mix the deck: \(2^5 = 32\) is less than 52, so after five shuffles the arrangement 52, 51, 50, ..., 1, which has 52 rising sequences, has probability zero, and so do most of the \(52!\) arrangements.

Bayer and Diaconis proved an exact formula. After \(k\) riffle shuffles of \(n\) cards in the Gilbert-Shannon-Reeds model, the probability of ending in a particular arrangement with \(r\) rising sequences is

\[ \frac{1}{2^{kn}} \binom{2^k + n - r}{n}. \]

The formula depends on the arrangement only through \(r\), which is what makes the problem tractable: instead of tracking \(52!\) probabilities one tracks 52 of them, one for each possible number of rising sequences, together with the count of arrangements having each \(r\), which is a classical quantity called the Eulerian number.

The table

How far a deck is from perfectly mixed is measured by the total variation distance, which is the largest difference between the probability a card player assigns to some event, such as "the ace of spades is above the king of hearts", under the true distribution and under the uniform one. It runs from 1, meaning that some event is certain to happen when it should happen only with probability 0, down to 0, meaning that no bet can tell the difference. For 52 cards the distances after \(k\) shuffles are, to three places:

1 shuffle, 1.000; 2 shuffles, 1.000; 3, 1.000; 4, 1.000; 5, 0.924; 6, 0.614; 7, 0.334; 8, 0.167; 9, 0.085; 10, 0.043.

Through four shuffles, nothing: there are arrangements of probability zero, and an event can be found that distinguishes the deck perfectly. At five the distance is still above 0.9. Then it falls by about half with every shuffle. The rule of thumb "seven shuffles" marks the point at which the distance first drops below one half, and after that each further shuffle buys less. The sharp drop between five and eight is called a cut-off, and it is the phenomenon Diaconis spent much of his career studying in other random processes: a system that is far from mixed for a long time and then mixes almost all at once. For a deck of \(n\) cards the cut-off sits at about \(\frac{3}{2}\log_2 n\) shuffles, which for \(n = 52\) is about 8.5; the seven comes from where one chooses to draw the line on the curve.

Why it matters to anyone

A bridge club is the easy case. Four shuffles is common at the table, and after four shuffles the deck remembers a great deal of its previous order, which in bridge is the previous hand sorted into suits. Players who know this can predict distributions better than chance, and some tournament bridge clubs switched to computer-dealt hands partly for that reason. Casinos are the serious case: a blackjack dealer who shuffles a six-deck shoe too few times leaves a structure that a trained player can follow, and the Bayer-Diaconis analysis is one reason why shuffling machines and specified shuffling procedures became standard.

Magicians knew parts of the story long before the theorem. The fact that one riffle shuffle creates at most two rising sequences is the basis of card tricks a century old, in which a spectator shuffles once and the magician still finds the chosen card. Diaconis left home at fourteen to travel with the magician Dai Vernon and came to mathematics through tricks of this kind, which is why his papers, unusually, give the trick as well as the proof.

The algebra in it

The probability formula above is a statement about the symmetric group \(S_{52}\), and the techniques behind it come from the representation theory of symmetric groups and from the combinatorics of descents, which is the study of where a permutation goes down. The same riffle shuffle structure turned out to govern other objects that have nothing to do with cards: the carries that occur when long numbers are added in a column, which Diaconis and Jason Fulman connected to shuffling in 2009, and certain random walks on groups of Lie type. In the masterclass, permutations and their cycle types are the subject of Unit 6, where the riffle shuffle appears as the standard example of a random permutation, and the counting of orbits that the formula relies on is the method of Unit 10. The research spotlight of Unit 6 presents work of Diaconis and his coauthors on how shuffles mix, which is where this article's question is asked at research level. The full list of units is in the curriculum.

One practical note. A riffle shuffle done perfectly, with the deck cut exactly in half and the cards alternating one by one, is not random at all. It is a fixed permutation, and eight perfect shuffles of the kind that keep the top card on top return a 52-card deck to its starting order. Perfect shufflers exist, and they have been banned from more than one card room. The theorem is about the imperfect shuffle, the one that ordinary hands produce, and it is the imperfection that does the mixing.

Study algebra properly

The Algebra Masterclass: weekly units, quizzes, a final exam, and a certificate.
About the program