Search This Blog

Showing posts with label group theory. Show all posts
Showing posts with label group theory. Show all posts

Sunday, 11 December 2011

Pick a Card, Any Card

The standard way to mix a deck of playing cards—the one used everywhere from casinos to rec rooms—is what is known as a riffle (or "dovetail") shuffle. You begin by splitting the deck into two roughly equal stacks. Then you flick the cards with your thumbs off the bottoms of the piles in alternating fashion, interleaving the two stacks.

For games like blackjack or poker to be truly fair, the order of the cards must be completely random when the game begins. Otherwise a skilled cheat can exploit the lack of randomness to gain an advantage over other players.

How many riffle shuffles does it take to adequately mix a deck of 52 playing cards?
MAGIC7
Francesco Abrignani/Alamy
As it turns out, you have to shuffle seven times before a deck becomes truly scrambled. Not only that, the cards become mixed in a highly unusual way: The amount of randomness in the deck does not increase smoothly. The first few shuffles do little to disturb the original order, and even after six shuffles, you can still pick out distinctly non-random patches.

But right around the seventh shuffle something remarkable happens. Shuffling hits its tipping point, and the cards rapidly decay into chaos.

Magical Mathematics

By Persi Diaconis and Ron Graham
Princeton, 244 pages, $29.95

The seven-shuffles finding applies to messy, imperfect riffle shuffles. The deck might not be divided exactly in half, for instance, or the cards might be riffled together in a haphazard way. Far from undesirable, a little sloppiness is actually the key to a random shuffle.

A perfect (or "faro") shuffle, meanwhile, wherein the deck is split precisely in half and the two halves are zippered together in perfect alternation, isn't random at all. In fact, it's completely predictable. Eight perfect shuffles will return a 52-card deck to its original order, with every card cycling back to its starting position.
And this doesn't just work for 52 cards. A deck of any size will eventually return to its starting order after a finite sequence of faro shuffles, although the number of faros required isn't always eight—and doesn't increase linearly. If you have 104 cards, for instance, it takes 51 faros to restore the deck. For a thousand cards, it takes 36.

These findings are among the many fascinating results explored in "Magical Mathematics," a dazzling tour of math-based magic tricks. The authors, Persi Diaconis and Ron Graham, are distinguished mathematicians with high-powered academic pedigrees. Both are also accomplished magicians who have taught courses on mathematical magic at Harvard and Stanford.

Mr. Diaconis has an especially unusual résumé for a mathematician. In 1959, at age 14, he ran away from home to study with the great 20th-century sleight-of-hand master Dai Vernon—a man who once fooled Harry Houdini with a card trick. After spending 10 years under Vernon's tutelage, Mr. Diaconis returned home to New York and enrolled in night school, eventually earning a full ride to a Ph.D. program in mathematics at Harvard.

The book's title may strike some people as odd in its pairing of magic and math, but the two subjects share a common lineage that goes back centuries. In fact, some of the earliest recorded magic tricks were based in math. Fibonacci's 1202 manuscript "Liber Abaci," the foundation of modern arithmetic, contains a number of magic tricks, including several versions of the famous three-object divination, wherein a spectator mentally selects one of three objects and the magician correctly identifies the spectator's choice.

The earliest recorded card tricks, meanwhile, appear in a math text written around 1500 by a Tuscan friar who was close friends with Leonardo da Vinci. And one of the first magic manuals was compiled in the 17th century by Claude Gaspard Bachet de Méziriac, an early number theorist.
MAGIC8
Player/Alamy

But mathematical magic truly came of age in the 20th century, with the growth of magic as a mainstream hobby. "In the past hundred years, a revolution has taken place," the authors write, citing the thousands of math-based magic tricks now in circulation.

In their breezy yet authoritative book, Messrs. Diaconis and Graham showcase some of the genre's best creations as well as many new ones of their own devising. Included are tricks with coins and cards (the reader will want to have a deck handy), a divination routine that employs the I Ching—the 5,000-year-old Chinese fortune-telling book—and, my personal favorite, a gambling demonstration in which the spectator shuffles a deck of cards but somehow still manages to deal himself a royal flush in spades.

This last effect exploits something known as the Gilbreath Principle, a beautiful property discovered in the 1950s by a mathematician who worked for many years at the Rand Corp. Take a deck of cards and arrange it in alternating red-black order. Now deal half of the deck facedown into a pile—thus reversing its order—and riffle shuffle the two piles together. Finally, deal the cards face up in pairs.

Each pair will contain one red and one black card (though not necessarily in alternating order). This is the Gilbreath Principle. This same idea applies to any repeating pattern of cards. If, for instance, the deck is arranged so that the cards cycle through the four suits—clubs, hearts, spades, diamonds, clubs, hearts, spades, diamonds, and so on throughout the deck—and the same procedure is executed, then every four cards dealt off the top will contain a complete set of suits. This result, combined with a few clever subtleties, is the basis of the royal-flush effect.

All the tricks in "Magical Mathematics" are of the "self-working" variety—meaning they require little or no physical skill—and while a grasp of the underlying mathematics is helpful, it is by no means a necessity. Even math-phobes will be able to astound audiences by simply following the directions and consulting the many full-color illustrations provided throughout the text.

The mixing of magic and math is more than just a means to new tricks. It has also spawned a host of major mathematical breakthroughs. "Some magic tricks use 'real mathematics' and lead to questions beyond the limits of modern mathematics," the authors write. "Sometimes, we have been able to solve the math problems."

The seven-shuffles result is one such solution. Mr. Diaconis became interested in the math of shuffling after he encountered a card trick published in the early part of the 20th century by Charles Jordan, a chicken farmer and champion puzzle solver who invented several groundbreaking card tricks. In this particular effect—called "Long Distance Mind Reading," because it could be performed through the mail—the spectator shuffles before and after picking a card, but the magician still finds his selection.

Mr. Diaconis realized that for the trick to work shuffling had to be less effective than people generally assumed. While at Harvard, he teamed up with a mathematician named David Bayer and the two undertook a theoretical analysis, building on work done at Bell Labs in the 1950s. Their landmark 1992 paper—"Trailing the Dovetail Shuffle to its Lair"—rigorously proved that anything less than seven shuffles is inadequate. Not only that, their results had implications for a wide class of "mixing" phenomena—from stirring cake batter to compounding chemicals.

Similarly, the remarkable "looping" property of perfect shuffles is a facet of group theory—a branch of abstract mathematics that deals with, among other things, symmetric structures. Group theory has applications to chemistry, biology and, most notably, physics, where it provides the mathematical framework for the Standard Model—the overarching theory of subatomic particles and forces.

There's also a deep link between the perfect shuffle and the binary number system—the universal language of modern computing. To appreciate the connection, you first have to understand that there are two ways to do a faro. You can either weave the cards together so that the top and bottom cards stay in place—this is called an "out-faro"—or you can do what is known as an in-faro, in which the top and bottom cards each move inward by one card.

Now let's say that the ace of spades is on top, and you want to move 25 cards above it, so that the ace will be 26th from the top. The sequence of faros required to bring about this arrangement can be found by writing the number 25 in binary notation, like this: 11001. For each 1, you do an in-faro, and for each 0 you perform an out-faro. In this case, you would do two in-faros (11), followed by two outs (00) and, lastly, one more in (1).

Shuffling is one example of something seemingly ordinary that subtends an elegant mathematical structure. Juggling is another. "Mathematics is often described as the science of patterns," Messrs. Diaconis and Graham (a former president of the International Jugglers' Association) write. "Juggling can be thought of as the art of controlling patterns in time and space. Both activities offer unbounded challenges."

The central challenge in the mathematical study of juggling is to figure out which sequences of throws are possible and to categorize them according to the number of balls they require and their length—or period. Toward that end, mathematicians have developed a notation, called "siteswap," that uniquely describes all possible throwing sequences.

A siteswap pattern consists of a string of numbers, each of which specifies how much time one ball—or club, or chainsaw, or banana—spends in the air. The classic three-ball cascade, for instance, is denoted 333, because each ball is aloft for the same amount of time (three beats), and the sequence repeats after every third throw.

The remarkable thing about siteswap is that it allows jugglers to devise new patterns on paper and determine whether they're juggleable with a few simple calculations, all without tossing a single ball. What's more, the average of the digits in a pattern tells you the number of objects needed to juggle it—3 in the case of 441, for example, since the average of 4, 4 and 1 is 3.

Siteswap has led to the discovery of hundreds of unknown throwing sequences, many with just three or four balls. "Once the connection has been made between juggling (sequences) and mathematics, all kinds of doors, both mathematical as well as juggling, are thrown wide open," the authors note. "Many jugglers have been working hard to master the almost unlimited number of new patterns suggested by siteswaps."

Throughout the book, Messrs. Diaconis and Graham shuttle back and forth between magic and math, probing each trick for hidden mathematical insights and developing new magic based on what they find. In the process, they encounter a number of unsolved problems, some of which have prize money attached to them. It's a fun ride, even if you don't follow the nuances of every theorem and proof, and a refreshing change from the bombastic sort of magic one typically encounters on television.

Lovers of recreational mathematics, and especially fans of the late Martin Gardner, who contributed the foreword, will find many pleasures in "Magical Mathematics." And while exposing magic secrets in a book intended for the general public may raise hackles among some old-guard magicians, exploring the math behind these tricks will, in truth, only deepen the mystery. For, as the authors remind us, sometimes the methods are as magical as the tricks themselves.
 
—Mr. Stone is the author of the forthcoming "Fooling Houdini: Magicians, Mentalists, Math Geeks, and the Hidden Powers of the Mind."