Palo Alto, Ca.

Persi Diaconis's unlikely scholarly career in mathematics began with a disappearing act.

He was 14 years old and obsessed with magic, spending much of his free time in or around Tannen's Magic Store, on Times Square, where sleight-of-hand masters regularly gathered to show off tricks and to gossip. There, one of the most influential magicians of the past century, a card maestro named Dai Vernon, saw Diaconis's prodigious trick dealing and invited the young man to leave New York and join him on the road.

Diaconis vanished from his regular life, dropping out of school and cutting ties with his family. "I packed a little bag—I took some decks of cards and some socks," remembers Diaconis, now 66 with unruly tufts of white hair, in his office at Stanford University, where he is a professor of mathematics and statistics. "I was sort of his assistant." And his student. Vernon, then in his 60s, promised that if his apprentice advanced far enough in his studies, he would reveal secrets of magic he had never shared with anyone else.

It was this search for the hidden workings of magic that led Diaconis to math. During a few years on the road doing his own magic act, he came to think of the hearts, diamonds, spades, and clubs in a deck of cards as variables that followed predictable formulas as he shuffled them. He could code the cards as binary numbers in his head and perform mental calculations as audience members cut the deck, so that when they picked a card, any card, Diaconis could name it.

This month the magician-turned-mathematician reveals some secrets in a new book, *Magical Mathematics: The Mathematical Ideas That Animate Great Magic Tricks* (Princeton University Press). The unusual work is part math textbook, part magic primer, and part history book, tracing how magic and math have long traveled under the same cape. Diaconis wrote the book with a colleague, Ron Graham, a professor of mathematics and computer science at the University of California at San Diego, who once worked as a professional juggler and trampoline acrobat.

The audience Diaconis imagined as he wrote the new book is his own teenage self. As he puts it, "I hope I corrupt a couple of high-school kids into thinking math is interesting."

He long ago gave up performing magic, but his background doing card tricks has inspired his most innovative scholarship. Perhaps his best known mathematical finding is that it takes seven shuffles of a standard deck of cards to randomly mix them. The conclusion turns out to have implications far beyond card tables: Someday it may help manufacturers determine how much mixing is necessary in industrial processes, or give spies a better way to tell how complex their secret codes need to be.

Back in the mid-1970s, when Diaconis first came to Stanford, where he has spent most of his scholarly career, he planned to keep his magic background a secret from his academic colleagues. His fear was that they wouldn't take seriously a man of hocus-pocus who did research on card shuffling.

Then he stumbled upon a book in the Stanford library that changed his mind. It described an experiment by one of his intellectual heroes, the French mathematician Paul Lévy, analyzing the phenomenon known as perfect shuffling—in which a standard deck of cards is carefully shuffled eight times and ends up returning precisely to its starting arrangement. "I let out a whoop," Diaconis says. "I thought, If Paul Lévy can study perfect shuffling, I can say I study perfect shuffling. So I wrote up my work on perfect shuffling, and it got on the front page of *The New York Times.*"

That was in 1990. Now quirky research equipment shows up in his office here in the statistics department. For a time, he had a craps table so he and his graduate students could study the odds of dice rolls. For another experiment, he had the physics department build a robot arm that could flip coins with precisely the same force and angle every time, so he could analyze their trajectories.

"He has a strong taste for applied things," says Charles Radin, a mathematics professor at the University of Texas at Austin, noting that Diaconis extrapolates the workings of a small system, like a deck of cards, to broader principles, to produce "imaginative results."

Despite accolades for his card-based scholarly work—he won a Mac-Arthur Fellows "genius" grant in 1982—Diaconis still worries about being associated too closely with his magic activities. He sees himself first and foremost as someone attempting to solve the toughest problems of mathematics. His friends and colleagues say he is unusually focused on that work, devoting much of his free time to talking out math problems and seeking collaborators in other fields who might know an intellectual trick he could use.

Yet he maintains ties to the magic community, and occasionally designs tricks for friends to perform in their acts. Some magicians he knows have expressed concern about his latest book, fearing that he is sharing too many trade secrets.

On a recent afternoon, Diaconis sits in his office with a deck of cards, working on his latest shuffling experiment. His goal is to analyze just how thoroughly cards get mixed when using an unusual shuffling method popular in the casinos of Monte Carlo—laying cards face-down on the table and pushing them around. He calls the technique "smushing" and suspects that it doesn't randomize the cards as well as casino owners might think.

That's just a hunch, though. To get actual data, he has numbered each card in the deck with a felt-tip marker, from 1 to 52, and he and a research assistant have spent hours smushing cards and recording in what order those numbers wind up each time. "We gather them up, and then we start calling them out—OK, 20, 18, 5, 23," he says, continuing until the complete order is noted. He sets out all the cards again, smushes for another minute, and the researchers again record their numerical order. (To see a video of the experiment, visit chronicle.com.)

It's time-consuming, but even more difficult is devising mathematical formulas to predict how well the cards are mixed, since they are moving in three dimensions. "It's kind of beyond science right now," says Diaconis. His hope is that his experiment will help crack a puzzle in fluid dynamics called the Navier-Stokes equations, identified by the Clay Mathematics Institute as one of the seven most important open problems in mathematics. The equations are used to predict weather patterns and to model ocean currents, among other applications, but they have never been proved to hold true for all situations. The institute has offered a million-dollar prize for a solution to the equations.

One key insight at the core of Diaconis's work is that at a certain point, any additional stirring of a group of items changes it very little. "Suppose I had a big glass bowl and have black beads and white beads in it, and I take a canoe paddle to mix them," he explains. For a while, the bowl would contain clear swaths of white and black. "Then all of a sudden it turns gray," he says. "In many systems, there's a sharp cutoff from order to chaos."

In a casino, gamblers stand to benefit from any scraps of order in card shuffling. If they know of a sudden increase in the likelihood of a face card, for instance, they can bet with more confidence. Diaconis himself has no taste for gambling—he prefers to work for the house, and has, in fact, consulted with casinos to help spot card counters and has advised a manufacturer of a card-shuffling machine still used in many casinos.

The smushing experiment is a challenge more daunting than his earlier research on standard shuffling. The math is technically outside of Diaconis's areas of expertise, which include statistics and a subdiscipline of math called combinatorics, which draws on algebra, geometry, and probability theory. So in recent months he has been trying to give himself a crash course in fluid dynamics, a subfield of physics that would take years of formal study to earn a degree in. "I'm just like a first-year graduate student now, or worse," he says. "I collect people who are good at explaining things, and I'm supposed to be good at explaining things, and we know about each other, and so when we're stuck and when we need help in an area, we can ask."

Lauren Bandklayder, who is volunteering as his research assistant while applying to graduate programs in math, says this ability to discipline-hop is one of Diaconis's unusual traits among math scholars. "I couldn't figure out what he focused on," she says. "He really does try and focus just on the math behind everything."

Mathematicians like to joke that they aren't the most social bunch, so Diaconis's gregariousness also makes him unusual. "He brings groups of people together who weren't talking to each other," says David Aldous, a statistics professor at the University of California at Berkeley. "He straddles statistics and mathematical probability and pure mathematics—and he's one of the few people who straddles all of these things."

Diaconis's journey into math began through his tendency to seek answers across disciplines. When he was a boy hanging out in the magic shop, a friend suggested that the best way to understand cards was to read a classic textbook by William Feller, *An Introduction to Probability and Its Applications *(1950)*.* Diaconis tracked down a copy, but it was like a foreign language to him. "I couldn't read it," he recalls. "But I could tell it was interesting."

When he decided to stop performing and go to college, his main drive was to be able to understand that book. At 22, he enrolled in the City College of New York and majored in math.

Degree in hand, Diaconis was now devoted to his new discipline and finally able to grasp the content of Feller's book. He dreamed of heading to Harvard University for graduate school, but knew it was a long shot. "My teachers at City College wouldn't write letters for me," he says. "They said, 'Nobody from the math department at City College has ever gotten into Harvard, and so it's a waste of time. You shouldn't do that.'"

Through his connections in the world of magic, though, he met someone who could help: Martin Gardner, whose "Mathematical Games" column in *Scientific American* had inspired many young people to study math and thus had a sizable following among academics. Gardner knew that a Harvard statistics professor at the time, Frederick Mosteller, was a magic enthusiast, so he wrote Mosteller a letter praising the young man's skills with cards and asking if the Harvard professor could help.

"It worked," wrote Gardner in his autobiography. "Fred wrote back at once to ask if Persi would be willing to major in statistics. Persi said of course. He visited Fred for an interview which I suspect most of the time was spent with a deck of cards. Soon Persi was at Harvard, where he obtained a doctorate in statistics."

Diaconis describes his childhood home as unhappy. His mother was a music teacher and his father was a mandolin player who worked as a cook and a housepainter. Diaconis himself played violin so well as a child that he won a scholarship to an after-school program at Juilliard. But after fleeing his home with hardly a trace, he never touched the violin again. Ten or fifteen years ago, he realized that he does not even remember how to read sheet music.

When he was starting graduate school, at age 27 or so, Diaconis did reconnect with his parents. He hoped they might still have some of his magic books from his childhood, and he called them up and visited for "a very uncomfortable lunch and dinner." He had little contact with them after that. "The magic community was my family," he says. "And mathematics became a family in the same way."

Back when Diaconis made a living as a magician, he went by the name Persi Warren, using his easier-to-pronounce middle name. He would wear a black turtleneck and a blazer. He spent a couple of years performing on cruise ships in the Caribbean, and even doing a few gigs in Europe and South America.

Here's a trick that he developed for his act: He took a deck of cards held together by a rubber band, and tossed it to a random audience member. He asked the volunteer to cut the deck at any point and pass it to an adjacent spectator, who also cut the deck. The process was repeated until five spectators had been involved. At that point, the fifth volunteer was asked to take the top card, but not to show it to anyone, then pass the deck to the other four volunteers, each of whom removed the next top card in turn.

"The performer now asks, 'This may sound strange, but would each of you please look at your card, make a mental picture, and try to send it to me telepathically?" writes Diaconis in his book, which explains the trick. "As this is done, the performer concentrates and appears confused: 'You're doing a great job, but there is too much information coming in for me to make sense of. Would all of you who have a red card please stand up and concentrate?"

From that information—knowing which of the five volunteers have red cards—Diaconis discerned the exact card held by each volunteer. How? The answer relies on a mathematical concept called de Bruijn sequences. (See the box on this page for a more detailed explanation.)

To understand Diaconis's approach to magic, and to math, it helps to know a bit about his mentor, Dai Vernon. That magician, known as the Professor, spent much of his career not only performing magic but traveling the country talking with card cheats and others who knew novel ways of handling cards. He also scoured books on magic and gambling, trying to refine old tricks and develop new ones. (Diaconis himself has a collection of more than 10,000 books and articles on magic, and scours rare book catalogs for new additions.)

On posters for his act, Vernon called himself "the man who fooled Houdini," because he once won a challenge issued by the famous performer. But Vernon was critical of Houdini's emphasis on showmanship and frowned upon a growing trend toward spectacle in magic acts. He felt that magic should appear effortless, delivered with a simple elegance rather than lovely assistants and light shows. Vernon, though far less famous than Houdini, is the man behind the versions of many standard tricks performed by magicians today, including a routine with cups and balls, and one with interlinking metal rings.

When Diaconis hit the road with Vernon, the elder magician was working on an annotated version of a guide to card magic first published in 1902 by an unknown author who used the pseudonym S.W. Erdnase. Diaconis served as a key researcher and wrote the introduction, an experience that he says helped give him the ability to explain complicated technical concepts to a general audience.

Quarrels between Vernon and Diaconis led them to go their separate ways after about two years, though they remained friends until Vernon's death, in 1992. But the mentor's devotion to magic as a pure exercise helped shape his young disciple.

At times Diaconis has felt tensions between magic and math.

He was advised by Mosteller, the professor at Harvard who dabbled in magic, not to do any tricks in the classroom. "He said, 'The kids end up thinking you're a performer, and they stop believing you're a scholar.'"

His own experience has confirmed that. When Diaconis gives talks to other academics explaining the math behind perfect shuffling, he begins with equations and theory. Then he takes out a deck of cards and demonstrates—a trick that is so hard to do that in his book he says fewer than 100 people in the world can manage it. It involves cutting the deck exactly in half and interweaving the two halves precisely. When he fans the cards out, demonstrating that after eight shuffles they return to their original order, his colleagues applaud. After that, the questions get more skeptical. "Now the hostility level of the audience triples. Someone will say, 'Was that N or N-1,' in an angry voice. Suddenly people think there's not a mathematician up there."

When I take out a deck of cards and ask Diaconis to demonstrate, he refuses, and asks that the questions return to the topic of his mathematics research. "I'm not going to do perfect shuffles now," he says.

Meanwhile, his magician friends have complained to him about his new book, which has been in the works for decades. Early in the project the publisher suggested the subtitle, "Revealing the Secrets of the World's Great Magic Tricks," which might have sold more books but might also have upset more magicians. "Persi was getting pushback because magicians don't reveal," says Graham, his co-author.

One person reportedly concerned about the project is Ricky Jay, a well-known magician and historian of magic who also apprenticed with Dai Vernon. "Some of the tricks in there, he does," says Diaconis of his friend Jay. "He was sort of heartbroken." (Jay could not be reached for comment.)

Diaconis says his goal is to educate rather than to make a buck off of his knowledge of magic. The new book can help show the public a serious side of magic not often in the spotlight, he told Jay. The idea, as he puts it, is "to try to show people that tricks have a lot of substance in them—that magic is an art, and it has its own depth and breadth."

Diaconis wasn't always so open to sharing his techniques. In fact, some magicians say the professor is notoriously reluctant to share material, especially from his time with Vernon. A review of the book published in the September issue of *Genii, The Conjurors' Magazine* refers to his reputation "as an infamous 'black hole' repository, where magic secrets enter and from which they never escape." It notes that the book leaves out long-held secrets among magicians, and that it avoids giving away any sleight-of-hand tricks.

*Magical Mathematics* will probably end up in more textbook aisles than hobby shops, since it is packed with tough equations, moving quickly through high-level math theory. Mathematicians may nod in recognition, but lay readers may have to take a refresher course in advanced math before trying the tricks for their friends.

That's why one magician, William Kalush, director of the Conjuring Arts Research Center, in New York City, says he expects that most magicians will not view the book as a threat. "You've got to do some work to understand what Professor Diaconis is explaining," he says. "And once you've done that, you're allowed entry into our world a little."