If you're hitting the beach this August, you may find yourself indulging in one of those characteristic treats of America's boardwalks: saltwater taffy.

Part of the draw of saltwater taffy is watching it being spun on those outlandish Rube Goldbergian machines strategically placed in storefront windows. These machines aren't just for show -- taffy isn't taffy until it's been bent and folded over on itself thousands of times, each fold pressing microbubbles of air into the sugary mix to give taffy it's characteristically silky-chewy texture.

This process is conventionally known as "pulling" taffy. But if you're a fluid dynamics professor at the University of Wisconsin, you might prefer to characterize it as "mixing" -- mixing air with sugar, essentially. And you might start to get curious about the mesmerizing spirograph patterns traced by the rods on those taffy machines, and wonder, above all else, if there isn't a more efficient way to achieve that silky result. ** **

That was the position Jean-Luc Thiffeault found himself in last summer before he fell down the rabbit hole of historic patent applications, Supreme Court decisions, advanced mathematics and one homemade taffy-pulling machine that led him to write his latest research paper: "A mathematical history of taffy pullers." In the paper, Thiffeault investigates the folding patterns of several machines to see which ones produced taffy with more "mathematical efficiency." That is, counting each full rotation of the machine's components, which machine would stretch out the taffy most?

Thiffeault had been using taffy pullers as examples in some of his lectures on fluid dynamics -- the math and physics of how stuff mixes together. As a researcher with a background in topology -- the study of the geometry of mathematical structures -- he was interested in the shapes that a rope of taffy made when folded back on itself dozens of times by a taffy pulling machine.

Taffy machines are a relatively new invention, appearing in America's beachtowns only around the turn of the 20th century. Before that, taffy was pulled by hand -- hoisted up on a hook, folded over on itself, stretched, and hoisted up again.

It was a laborious, time-intensive and often unhygienic process, as outlined by Chief Justice (and former U.S. President) William Howard Taft in the 1921 Supreme Court decision in Hildreth v. Mastoras, which settled a patent dispute over then-newfangled taffy pulling machines.

"Until the beginning of this century," Taft wrote, "candy was pulled only by hand. It required much strength. Candy pullers were hard to get. The work was strenuous, and produced perspiration and uncleanliness. It was done with the bare hands, and it was impossible to avoid danger from eczema and abrasions of the skin of the hands. It was neither appetizing nor sanitary."

Given these conditions, and the demand for taffy in America's beach resorts, the taffy pulling process was ripe for some mechanical disruption. In the course of his research, Professor Thiffeault found close to 200 U.S. patents involving taffy pulling machines and processes, most from the early 20th century.

Mathematically speaking, the simplest possible taffy-puller would involve three rods rotating around each other in a kind of figure 8 pattern. The left side of the diagram below shows, from the side, how a section of taffy** **would be stretched and folded in on itself by such a puller. The three colored dots represent the rods, while the dark grey mass around them is the taffy. The rods take turns rotating and swapping position, shown by the arrows, and pulling the taffy along with them.

This was called the Nitz taffy puller.** **When Professor Thiffeault stumbled across the patent for it, registered in 1918, he had a kind of Eureka moment: It was built to produce exactly the type of warped, folded shape that mathematicians in his field had been studying for decades. In the early 1970s, for instance, a couple mathematicians named William Thurston and Dennis Sullivan drew a mural on the wall of the University of California, Berkeley's math department of a shape that just happens to look exactly like the shape that Nitz's taffy puller would produce.

Mathematicians would think of that diagram as that of a loop winding around points on a Riemann Sphere, a representation of the infinite two-dimensional plane as the surface of a sphere. Similar constructions are used algebraically to generate equations for common finger print patterns.

Thurston and Sullivan probably knew nothing about taffy, of course -- they just happened to derive an equation for a highly complex shape that taffy manufacturers had been creating for decades.

In the 200 or so patents that Professor Thiffeault found**, **there were a lot of early-2oth century variations on taffy machines. One common design -- the precursor to what you usually see today in taffy shops -- involved four rods that rotated around each other.

Some of these patents contain beautiful, highly intricate diagrams of exactly the kind of folding process produced by the machines.

As the years went on, manufacturers began to turn to more baroque, almost unworkable designs. Some contained spinning rods attached to spinning rods, producing ornate, Spirograph-like folding patterns.

Still others involved intricate combinations of spinning rods, fixed rods, oscillating levers, and more.

Of the taffy machines above, Thiffeault writes "this is the most baroque design we’ve encountered: it contains a reciprocating arm, rotating rods, and fixed rods. The inventors did seem to know what they were doing with this complexity."

Much of this innovation was likely spurred by inventors' desire to get around the limitations set by other patents. They take an existing design, add some changes and voila -- a brand-new patent to potentially make money on.

"Mathematically, a lot of these were exploiting clever ways of moving rods around, trying to avoid other patents," Thiffeault said in an interview.

The study of topology provided Thiffeault with what he calls** **"an elegant mathematical framework that allows you to compute the rate of growth of taffy." In his paper, he lays out** **all the equations he ran on the various taffy machines. Here, I'm going to skip those details -- those so inclined can read about them in voluminous detail in his paper -- and get right to the punchline: Did the explosion of taffy innovation in the early-20th century produce more efficient taffy pulling machines?

"It isn't clear that there was that much progress, to be honest," Thiffeault told me.

Despite their varying degrees of complexity, the different taffy pullers all stretched taffy out by similar amounts. Innovators, for all their innovation, didn't really improve much on the standard four-rod taffy puller still in use in beach towns all over the U.S.

Well, you know what they say: If you want something done right, you've gotta do it yourself. Thiffeault was convinced he could come up with a more mathematically perfect taffy puller.

So that's exactly what he did. With the help of undergraduate student Alex Flanagan, he constructed a prototype of a six-rod taffy puller that roughly doubles the mathematical efficiency of the standard four-rod puller.

Here's what that prototype looks like in action, powered for the moment by hand:

It's surprisingly simple and elegant in its design -- the kind of thing you'd expect a mathematician to come up with. To the standard four-rod puller he adds two static rods which, in essence, provide two more points for the taffy to get hooked over and folded.

Now, Thiffeault isn't running a Kickstarter campaign on this thing any time soon. "I would not want somebody whose business critically depends on this machine" to give it a spin, he told me. Mathematical efficiency, after all, is a different beast than engineering efficiency. Those two extra rods may put more strain on the machine's motors, or otherwise make real-world use of the machine impractical.

But Thiffeault says he learned a lot from his taffy-making quest anyway. "Making candy is really difficult," he told me. The process was "a revelation into how complicated it is."

He also found that the expansion of taffy produced by many of the early 20th-century machines could be described by the so-called "golden ratio" that shows up over and over again in mathematics. Still others followed the lesser-known "silver ratio."

Taffy pullers "end up with these special numbers because they are fundamentally based on the idea of recurrence," Thiffeault says. Each new fold will contain within itself every previous fold, an endless braid of taffy stretching off into infinity.

That mathematical recurrence may explain some of the machines' lasting visual appeal. "There's something about taffy pullers that looks so natural and intuitive, in a way," Thiffeault says.

It doesn't hurt that their end product tastes pretty good too.