In a top-to-random shuffle one takes the top card of a deck of cards and inserts it into a position chosen uniformly at random. This is not a practical way to shuffle: as in the coupon collector problem, it takes about shuffles to have a good chance of having moved every card, so one expects at least this number to be necessary to get good mixing. In fact, a careful analysis shows that it takes shuffles for the probability distribution on arrangements of the cards to be exponentially close by (up to a small error term) to the uniform distribution. So for 52 cards we need about 200 shuffles. By contrast, a famous result, also due to Diaconis, says that 7 riffle shuffles suffice to get good mixing on a deck of 52 cards. However, there is at least one sense in which top-to-random still wins: if we count each top-to-random shuffle as moving one card (i.e. thinking physically, and ignoring that, mathematically, an insertion into position induces a -cycle on the top cards) then the snail-paced top-to-random shuffle achieves its mixing by moving only 200 cards, whereas each riffle shuffle moves (in the same physical sense) 52 cards each time.

The top-to-random shuffle is also related to the optimal Knuth shuffle: at time do a card-in-position--from-top-to-any-position-weakly-below shuffle. After steps the deck is uniformly mixed. Convincing anyone closely watching proceedings that this is true is left as an exercise for the shuffler.

In this paper with John Britnell we defined several generalized Stirling and Bell numbers related to the top-to-random shuffle. They’ve now been submitted to OEIS. The purpose of this post is to make a record of the numbers and record one curious observation.

The first batch of sequences, including the two already present, are, in the notation of the paper:

- A048993 : number of set partitions of into exactly parts. (A Stirling number of the second kind.)
- A102661 : number of set partitions of into at most parts. (A generalized Bell number.)
- A261139 : number of set partitions of into exactly parts such that no part contains two consecutive numbers, or both 1 and .
- A261137 : number of set partitions of into at most parts with the same conditions as A261139.

The connection with shuffling is most easily explained by using the inverse random-to-top shuffles. Take a deck of cards, with card 1 at the top and card at the bottom, and a set partition of into exactly parts, say . There is a unique way to assign a card number to each part such that is the set of times when card is lifted to the top by a sequence of random-to-top shuffles that overall leave the deck invariant. To see this, observe that the final card lifted must be card 1. Hence the part containing must get label 1. Now continue inductively, assigning label to the part containing the greatest number not already labelled by 1 up to . It is not hard to see that counts the analogous sequences where the identity permutation is forbidden.

The second batch of sequences deals with top-to-random (or random-to-top) shuffles that may flip the card moved. The corresponding sequences were all new to OEIS.

- : number of set partitions of into exactly parts with an even number of elements in each part distinguished by marks. (Not submitted, since its just a scaling of the usual Stirling number.)
- A261275 : number of set partitions of into at most parts with an even number of elements in each part distinguished by marks.
- A261318 : number of set partitions of into exactly parts, with an even number of elements in each part distinguished by marks, and such that no part contains two consecutive numbers (each unmarked), or both 1 and (each unmarked).
- A261319 : number of set partitions of into at most parts with the same conditions as A261318.

Now for the curious observation. By Equation (5) in Section 6 of the paper, we have

It easily follows by summing two series that the exponential generating function for the primed Stirling numbers is

.

Let be the number of set partitions of into exactly parts, each of size at least two. The exponential generating function for these numbers is

.

(The only way I can recommend to prove this is to read Chapter 3 of Wilf’s wonderful book generatingfunctionology until it becomes obvious.)

Observe that on setting , the two e.g.f.s become equal to . Hence

where is the generalized Bell number corresponding to . So, in some asymptotic sense, set partitions satisfying the `no-cyclically-consecutive numbers’ restriction behave like set partitions into parts of size at least two.

This can be made more precise as follows. The e.g.f. for the primed Stirling numbers may be written as

where . Similarly the e.g.f. for the Stirling numbers for parts of size at least two may be written as

where . Now, since

whenever , we have

for all . Letting we recover the equality already seen. The identity above seems surprisingly unobvious analytically, but maybe I’m missing an easy argument.