A deterministic card table

Eight Perfect Shuffles

A perfect out-shuffle is the opposite of random: it sends every position through a fixed doubling rule. Shuffle the live deck and watch all 52 cards return after eight exact out-shuffles, trace any card through the formula, then use binary in/out instructions to steer the top card to any requested position. A 24-card packet exposes the deeper surprise and a correction: its out-shuffle returns after 11, while the much larger group generated by both perfect shuffles is a cited theorem whose order arithmetic is checked live.

I · The returnCut exactly. Interlace exactly.

An out-shuffle splits the deck in half and alternates the cards while leaving the top and bottom cards outside the weave. Press once. The colors are original positions, so the interlacing is visible before the labels are readable.

Live 52-card deck

0 out-shuffles

top · position 0position 51 · bottom

Computing the return length…

Computing the position map…
Open the complete one-shuffle position map

Label positions from the top, starting at zero. For every card except the bottom one, the out-shuffle is multiplication by two modulo one less than the deck size. The bottom card is fixed separately. Repeating the shuffle repeats the multiplication. The deck returns when a power of two first leaves every position unchanged.

The in-shuffle changes which half contributes first. Its clean coordinate is one more than the visible position, so the modulus becomes one more than the deck size. Switch the control above and the page rebuilds the whole permutation. The longer return is not animated by assertion. You can run it.

II · The steering wheelWrite the destination in binary

The obvious dismissal is that eight is a cute coincidence about one deck size. Alex Elmsley's deeper observation turns the same doubling into control. Read a target's binary digits from left to right. A one means in-shuffle. A zero means out-shuffle. Each move appends that digit to the tracked card's position.

zero-indexed, top is 0

Binary instruction tape

Position register

0

What the last instruction did

The register is empty. The tracked card is at position 0.

Preparing the binary instruction…

Checking every possible target…

Checking every even deck…

Watch the position register while it runs and the trick stops being a trick. The out-shuffle reduces 2p modulo 51 and the in-shuffle reduces 2p+1 modulo 53, but on a legal target neither modulus ever fires: the running position is always small enough that both values land short of it. So every instruction is simply p → 2p + digit, and that is what appending a binary digit means. The tracked card's position does not end up equal to the number you typed. It is that number, spelled one digit at a time. The deck is a shift register.

That reading is worth more than the demonstration. The first green line under the panel does what it always did: it constructs and simulates the binary instruction for every legal target of this 52-card deck, on complete decks, every time the page loads. The second line runs the same check across every even deck from 4 to 120 cards, and also counts how many times a modulus fired along the way. That count is zero, which is the shift-register claim restated as a measurement. The general law, for every even deck and every legal target at once, is proved below rather than sampled.

The rule does need the deck to be even, and that is not a technicality about card stock. Deal five cards and it breaks at exactly one position: the last. Target 4 spells 100, and the second out-shuffle doubles 2 onto the modulus itself, which wraps to zero, so the card you aimed at the bottom arrives back on top. Across every odd deck from 5 to 201 cards it fails at that one target and nowhere else. That is the price of the evenness assumption, and it is exactly one position.

III · The exceptional packetTwenty-four cards do something else

The group generated by both perfect shuffles is much richer than the return time of either generator. A 24-card packet is an exceptional case in the classification by Persi Diaconis, Ronald Graham, and William Kantor. First, test the packet's plain out-shuffle.

The brief's suggested eight-shuffle test does not restore this packet. The modulus is 23. The page computes the residue after eight and keeps going to the first actual return. This is a useful correction: the famous count belongs to 52 cards, not to perfect shuffles in general.

Live 24-card packet · out-shuffle only

0 shuffles

Computing…

Computing the packet return…

Now add the in-shuffle and consider every arrangement reachable by any finite word in the two moves. That set is the shuffle group. Diaconis, Graham, and Kantor identify the 24-card case as a semidirect product involving the sporadic simple Mathieu group M12. The identification is their theorem. The live arithmetic below checks the resulting order, not the theorem that names the group.

Cited structure211 : M12 M12 orderComputing… Shuffle-group orderComputing…

Computed here

The two position permutations, their return times for every even deck up to 120 cards, every Elmsley landing of every one of those decks, the shortest-instruction search, the route census behind uniqueness and its collapse at one spare instruction, both 24-card residues, and the multiplication of the cited factors.

Cited, not reproved

The identification of the 24-card shuffle group with 2^11 : M12, and the published order of M12.

The check · rebuilt in this browser

These rows are filled only after the page constructs the permutations and runs the finite checks. The same algorithms live in the dependency-free Node verifier.

52-card out
Computing…
Out cycles
Computing…
52-card in
Computing…
Elmsley
Computing…
Elmsley, every even deck
Computing…
In-shuffle law
Computing…
Shortest instruction
Computing…
Only one shortest word
Computing…
A wrap costs a deck
Computing…
24-card correction
Computing…
Group arithmetic
Computing…

Uncertainties and free choices

Handed to the kernel · five laws, proved for every deck

The checks above instantiate the return law: they build the actual 52-card and 24-card permutations and read off their cycle order. But a permutation built at one size only ever settles that one deck. The claim underneath is universal, and it is exactly the modular-order lemma this page cites to DGK. So it is now handed to a proof assistant, which checks it for every even deck at once, with no search, in Lean 4, with zero imports, so the only thing trusted is the kernel.

The return theorem. A perfect out-shuffle of a deck of m+1 cards sends the card at position p to 2p mod m (the last card stays). The deck is restored after k shuffles exactly when 2k ≡ 1 (mod m). So the number of shuffles that restores it is the multiplicative order of 2 modulo m = (deck size − 1).

The whole proof is one observation: iterating the shuffle just doubles the position, so k shuffles send p to 2k·p mod m (theorem outIter_mobile). The deck is back iff that equals p for every card; taking p = 1 forces 2k ≡ 1, and that one congruence returns all of them. Through this law, the two numbers on the page fall to the kernel as decidable facts: a 52-card deck returns after 8 and no fewer (deck52_returns_after_eight, deck52_no_fewer); the 24-card packet is not restored at 8 and returns after 11 (deck24_not_after_eight, deck24_returns_after_eleven), the page's correction to the tempting "eight is universal", now machine-checked.

Eight is the period, not just the first return. The deck is in order after k shuffles if and only if 8 divides k (deck52_period; deck24_period for eleven). It is home at 8, 16, 24, and at no other count. Not home after 12. This needs no group theory: the restoring counts are closed under addition and ordered subtraction, so by a Euclidean argument (least_restorer_dvd) they are exactly the multiples of the least.

That closes a gap the concrete counts leave open. "No fewer than eight" tells you 8 is the first return; it does not tell you the deck stays scrambled at 9, 10, 11, 12 and springs back only at 16. The period theorem does, for every deck at once.

Three further claims on this page were, until now, settled the way the return count once was: by simulating a single deck. They are now proved for every deck.

The in-shuffle law. The page's other control sends position p to (2p+1) mod (m+2), so no card is fixed and the modulus is the deck size plus one. Read it one coordinate to the left, at p+1, and it is pure doubling again (inStep_shift). Everything above then transfers: the deck returns after k in-shuffles exactly when 2k ≡ 1 (mod m+2) (in_return_iff), which is 52 for a 52-card deck against 8 for the out-shuffle, and 52 is the period rather than merely the first return (deck52_in_period).

The page already said this in words: the in-shuffle's clean coordinate is one more than the visible position. That sentence was the entire proof, and it is now a theorem instead of a remark.

Elmsley steering, for every even deck. Running the binary digits of any legal target t ≤ m, most significant first, in-shuffle for a one and out-shuffle for a zero, brings the original top card to exactly position t (elmsley). The proof is the fact the position register makes visible: while the running position stays inside the deck, neither modulus can fire, so each instruction is only p ↦ 2p + digit and the position is the number (steer_valFrom). The live audit reaches fifty-two of these facts by simulating fifty-two decks; deck52_steer_all reaches all fifty-two in one line, and the theorem above reaches every deck size at once.
The hypothesis is sharp, and the word is shortest. Evenness is load-bearing, not decoration: on a five-card deck the rule fails (odd_deck_5_fails), and it fails at exactly one target. And since k instructions can only ever spell a k-digit binary number, no word shorter than the target's own binary expansion can reach it (no_shorter_word, bits_shortest). Elmsley's rule is not just a route to the target. It is a shortest route.
A wrap costs a whole deck. Run any instruction word from any legal position. The card either finishes on exactly the number the word spells, or it finishes at least a full deck below it (steer_dichotomy). There is no near miss and no creeping back, because the moment a modulus fires it takes a whole deck away, and every later instruction doubles that deficit instead of healing it. This is the lemma the uniqueness proof is really about, and the check panel measures it directly.
Elmsley's word is the only shortest word. A word of k instructions spells a number below 2^k; if it wrapped, the number it spells is at least t + m. At minimum length those two facts collide, since 2^k is at most 2t, which is at most t + m because the target is on the deck. So a shortest word cannot have wrapped, it reads its own value, and a binary numeral of fixed length is unique. Hence elmsley_unique: for every even deck and every legal target, the binary expansion is not merely a shortest route but the only one. This is the claim that until 2026-08-02 this page could only measure.
And uniqueness is exactly a minimum-length phenomenon. Give the magician one spare instruction and it collapses at once (deck52_two_routes_at_seven). On a 52-card deck, target 32 takes six instructions and at six the word is unique; at seven there are two, and the second wrapped its way there, spelling 85 rather than 32. Notice where that falls: 2^6 = 64 is within 32 + 51, but 2^7 = 128 is not, so the seven-instruction case is precisely the one the theorem declines to cover.

What is measured rather than proved is still named as such. The one uncertainty that remains on the steering claims is the shape of the bound rather than the result: the fitting condition is sufficient and never fails, but it is not the exact boundary of uniqueness, and the caveat above gives the count. The two-hundred-million-element group claim below likewise stays cited.

Footprint: #print axioms reads [propext] for the out-shuffle return theorem and every concrete out-shuffle return (no List.Perm, so tighter than usual), and no axioms whatever for valFrom_append, deck52_steer_37 and odd_deck_5_fails, which are pure computation. The rest additionally carry Quot.sound, from the omega and division reasoning that closes their arithmetic. No sorry, no Classical.choice, no native_decide, across 42 audited theorems. The Node verifier cross-checks this Lean model against the engine across 59 even decks for both shuffles, all 3,658 legal (deck, target) steering pairs, 99 odd decks for the sharpness, and, for the uniqueness result, 1,001,000 (deck, target) pairs over 1,000 even decks by a route census that shares no code with the kernel, plus 2,030,624 runs confirming the whole-deck gap. Seven deliberate corruptions of those checks were tried and all seven were caught (mutate-uniqueness.mjs). It then typechecks the file live and asserts the footprint. Proof: research/eight-perfect-shuffles/lean/PerfectShuffle.lean.

Sources and reproducibility

Repository check: node research/eight-perfect-shuffles/verify-eight-perfect-shuffles.mjs. It rebuilds the permutations, decomposes every out-shuffle orbit, simulates all target instructions on full decks, and fails on any mismatch. It also cross-checks the Lean model against the engine across 59 even decks for both shuffles, runs all 3,658 legal (deck, target) steering pairs while counting modular wraps, sweeps 99 odd decks to price the evenness hypothesis, searches the shuffle graph for a shorter instruction than the binary word, and, when lean is present, typechecks research/eight-perfect-shuffles/lean/PerfectShuffle.lean and asserts its axiom footprint. To run the kernel proof directly: bash research/eight-perfect-shuffles/lean/verify.sh (install once with install-lean.sh).