The first “Treehouse of Horror” episode appeared in the second season of "The Simpsons," and since then they have become an annual Halloween tradition. These special episodes usually consist of three short stories that are allowed to break the conventions of life in Springfield, with storylines that can include anything from aliens to zombies.

David S. Cohen, one of the writers most dedicated to getting mathematics into "The Simpsons," wrote the final part of “Treehouse of Horror VI” (1995), a segment titled “Homer 3.” This is, without doubt, the most intense and elegant integration of mathematics into "The Simpsons" since the series began a quarter of a century ago.

The storyline begins quite innocently with Patty and Selma, Homer’s sisters-in-law, paying a surprise visit to the Simpsons. Keen to avoid them, Homer hides behind a bookcase, where he encounters a mysterious portal that seems to lead into another universe. As the dulcet tones of Patty and Selma get louder, Homer hears that they want everyone to help clean and organize their collection of seashells. In desperation, he dives through the portal, leaving behind his two-dimensional Springfield environment and entering an incredible three-dimensional world. Homer is utterly perplexed by his new extra dimensionality and notices something shocking: “What’s going on here? I’m so bulgy. My stomach sticks way out in front.”

Instead of being drawn in the classic flat-animation style of "The Simpsons," scenes set in this higher dimension have a sophisticated* *three-dimensional appearance. In fact, these scenes were generated* *using cutting-edge computer animation techniques, and the cost of* *generating them, even though they lasted less than five minutes, was* *far beyond the budget of an entire normal episode. Fortunately, a* *company named Pacific Data Images (PDI) volunteered its services,* *because it realized that "The Simpsons" would provide a global platform* *for showcasing its technology. Indeed, PDI signed a deal with DreamWorks later that year which led directly to the production of "Antz" and "Shrek," thereby kick-starting a revolution in film animation.

When Homer approaches a signpost indicating the *x*, *y*, and *z *axes in his new three-dimensional universe, he alludes to the fact that he is standing within the most sophisticated animated scene ever to have appeared on television: “Man, this place looks expensive. I feel like I’m wasting a fortune just standing here. Well, better make the most of it.”Homer makes another pertinent comment when he first encounters his new environment: “That’s weird. It’s like something out of that twilighty show about that zone.” This is a nod to the fact that “Homer 3” is a tribute to a 1962 episode of "The Twilight Zone" titled“Little Girl Lost.”

In “Little Girl Lost,” the parents of a young girl named Tina become distraught when they enter her bedroom and cannot find her. Even more terrifying, they can still hear her voice echoing around them. Tina is invisible yet still audible. She is no longer in the room, but she seems just a breath away. Desperate for help, the parents call upon a family friend named Bill, who is a physicist. Having pinned down the location of a portal by chalking some coordinates on the bedroom wall, Bill declares that Tina has slipped into the fourth dimension. The parents struggle to understand the concept of a fourth dimension, because they (like all humans) have trained their brains to cope with our familiar three-dimensional world.

Although Homer leaps from two to three dimensions, not from three to four dimensions, exactly the same sequence of events takes place in “Homer 3.” Marge cannot fathom what has happened to Homer, because she can hear him but not see him, and she also receives advice from a scientist, Professor John Nerdelbaum Frink, Jr.

Despite his comically eccentric personality, it is important to not underestimate Professor’s Frink’s genius. Indeed, his scientific credentials are made clear in “Frinkenstein,” a story from “Treehouse of Horror XIV” (2003), when he receives a Nobel Prize from none other than Dudley R. Herschbach, who won his own Nobel Prize in 1986 and who voices his own character.*

Just like the physicist in *The Twilight Zone*, Frink draws a chalk outline around the portal, watched by Ned Flanders, Chief Wiggum, Reverend Lovejoy, and Dr. Hibbert, who have all come to offer support. Frink then begins to explain the mystery: “Well, it should be obvious to even the most dimwitted individual, who holds an advanced degree in hyperbolic topology, that Homer Simpson has stumbled into . . . *the third dimension*.”

Frink’s statement suggests that the characters in "The Simpsons" are trapped in a two-dimensional world, and therefore they struggle to imagine the third dimension. The animated reality of Springfield is slightly more complicated than this, because we regularly see Homer and his family crossing behind and in front of each other, which ought to be impossible in a strictly two-dimensional universe. Nevertheless, for the purposes of this “Treehouse of Horror” segment, let us assume that Frink is correct in implying the existence of only two dimensions in "The Simpsons," and let us see how he explains the concept of higher dimensions as he draws a diagram on the blackboard:

Professor Frink: Here is an ordinary square.

Chief Wiggum: Whoa, whoa! Slow down, egghead!

Professor Frink: But suppose we extend the square beyond the two dimensions of our universe along the hypothetical

z-axis . . . There.Everyone: [gasps]

Professor Frink: This forms a three-dimensional object known as a

cube, or aFrinkahedronin honor of its discoverer.

Frink’s explanation illustrates the relationship between two and three dimensions. In fact, his approach can be used to explain the relationship between all dimensions. If we start with zero dimensions, we have a zero-dimensional point. This point can be pulled in, say, the *x *direction to trace a path that forms a one-dimensional line. Next, the one-dimensional line can be pulled in the perpendicular *y *direction to form a two-dimensional square. This is where Professor Frink’s explanation picks up, because the two-dimensional square can be pulled in the *z *direction, which is perpendicular to its face, to form a three-dimensional cube (or Frinkahedron).

Finally, it is mathematically, if not physically, possible to go one step further by dragging the cube into another perpendicular direction (labeled the *w *dimension) to form a four-dimensional cube. Cubes in four (or more) dimensions are known as *hypercubes*.

The diagram of a four-dimensional hypercube is a mere sketch, the equivalent of a stick figure drawing being used to capture the essence of Michelangelo’s statue of David. Nevertheless, the stick-figure hypercube suggests an emerging pattern that helps explain the geometry of shapes in four and even higher dimensions. Let us consider the number of endpoints or corners (known as *vertices*) that each object possesses as we move from dimension to dimension. The number of vertices follows a simple pattern: 1, 2, 4, 8, 16, .. .. In other words, if *d *is the number of dimensions, then the number of vertices equals 2*d*. Hence, a ten-dimensional hypercube would have 210 or 1,024 vertices.

Despite Professor Frink’s deep understanding of higher dimensions, the bad news is that he is unable to save Homer, who is left to wander across his new universe. This leads to a bizarre series of events that ends with a visit to an erotic cake store. During this adventure, Homer encounters several fragments of mathematics which materialize in the three-dimensional landscape.

For example, soon after Homer travels through the portal, an apparently random series of numbers and letters floats in the far distance: 46 72 69 6E 6B 20 72 75 6C 65 73 21. The letters, in fact, are actually *hexadecimal *(or base 16) digits. Hexadecimal numbers are expressed using the usual digits 0 to 9, plus six others, namely A = 10, B = 11, C = 12, D = 13, E = 14, and F = 15. Together, each pair of hexadecimal digits represents a character in ASCII (American Standard Code for Information Interchange), which is a protocol for converting letters and punctuation into numbers, largely for the benefit of computers. According to the ASCII protocol, 46 represents “F,” 72 represents “r,” and so on. Translated, the entire sequence reads as a bold proclamation in praise of geeks: “Frink rules!”

A few moments later, a second mathematical tidbit appears in the three-dimensional landscape, courtesy of writer David S. Cohen:

1,78212 + 1,84112 = 1,92212

This is yet another false solution to Fermat’s last theorem, just like the one created by Cohen for “The Wizard of Evergreen Terrace,”which was discussed in chapter 3. The numbers have been carefully chosen so that the two sides of the equation are almost equal. If we match the sum of the first two squares to the sum of the third square, then the results are accurate for the first nine digits, as shown in bold:

1,025,397,835,622,633,634,807,550,462,948,226,174,976 (1,78212)

+ 1,515,812,422,991,955,541,481,119,495,194,202,351,681 (1,84112)

= 2,541,210,258,614,589,176,288,669,958,142,428,526,657

2,541,210,259,314,801,410,819,278,649,643,651,567,616 (1,92212)

This means that the discrepancy in the equation is just 0.00000003 percent, but that is more than enough to make it a false solution. Indeed, there is a quick way to spot that 1,78212 + 1,84112 = 1,92212 is a false solution, without having to do any lengthy calculations. The trick is to notice that we have an even number (1,782) raised to the twelfth power added to an odd number (1,841) raised to the twelfth power supposedly equaling an even number (1,922) raised to the twelfth power. The oddness and evenness are important because an odd number raised to any power will always give an odd result, whereas an even number raised to any power will always give an even result. Since an odd number added to an even number always gives an odd result, the left side of the equation is doomed to be odd, whereas the right side of the equation must be even. Therefore, it should be obvious that this is a false solution:

even12 + odd12 even12

Blink and you will miss five other nods to nerdiness that flash past Homer in his three-dimensional universe. The first is a rather ordinary looking teapot. Why is this nerdy? When pioneering graphics researcher Martin Newell at the University of Utah wanted to render a computer-generated object in 1975, he chose this household item; it was relatively simple, yet also offered challenges, such as a handle and curves. Ever since, the so-called Utah teapot has become an industry standard for demonstrating computer-graphic software. This particular style of teapot has also made cameo appearances in a tea party scene in "Toy Story," in Boo’s bedroom in "Monsters, Inc.," and in several other films.

The second nod is a flyby by the numbers 7, 3, and 4, a coded reference to Pacific Data Images, who produced the computer graphics.

These digits on a telephone dialing pad are associated with the letters *P*, *D*, and *I*.

Third, we glimpse a cosmological equation (ñm0 > 3*H*0 2/ 8p*G*) that describes the density of Homer’s universe. Provided by one of Cohen’s oldest friends, the astronomer David Schiminovich, the equation implies a high density, which means that the resulting gravitational attraction will ultimately force Homer’s universe to collapse. Indeed, this is exactly what happens toward the end of the segment.

Just before Homer’s universe disappears, Cohen dangles a particularly intriguing mathematical morsel for the discerning viewer. In the scene shown on page 152, a slightly unusual arrangement of Euler’s equation is visible over Homer’s left shoulder. This equation also appears in “MoneyBART.”

Finally, in the same image, the relationship P = NP can be seen over Homer’s right shoulder. Although the majority of viewers would not have noticed these three letters, let alone given them a second thought, P = NP represents a statement about one of the most important unsolved problems in theoretical computer science.

P = NP is a statement concerning two types of mathematical problems. P stands for *polynomial *and NP for *nondeterministic polynomial*. In crude terms, P-type problems are easy to solve, while NP-type problems are difficult to solve, but easy to check.

For example, multiplication is easy and so is classified as a P-type problem. Even as the numbers being multiplied get bigger, the time required to calculate the result grows in a relatively modest fashion.

By contrast, *factoring *is an NP-type problem. Factoring a number simply means identifying its divisors, which is trivial for small numbers, but rapidly becomes impractical for large numbers. For example, if asked to factor 21, you would immediately respond 21 = 3 × 7. However, factoring 428,783 is much harder. Indeed, you might need an hour or so with your calculator to discover that 428,783 = 521 × 823. Crucially, though, if someone handed you the numbers 521 and 823 on a slip of paper, you could check within a few seconds that these are the correct divisors. Factoring is thus a classic NP-type problem: hard to solve for large numbers, yet easy to check.

Or . . . is it possible that factoring is not as difficult as we currently think?

The fundamental question for mathematicians and computer scientists is whether factoring is genuinely hard to accomplish, or whether we are missing a trick that would make it simple. The same applies to a host of other supposedly NP-type problems—are they all genuinely hard, or are they merely hard because we are not smart enough to figure out the way to solve them easily?

This question is of more than mere academic interest, because some important technologies rely on NP-type problems being intractable.

For example, there are widely used encryption algorithms that depend on the assumption that it is hard to factor big numbers. However, if factoring is not inherently difficult, and someone discovers the trick that makes factoring simple, then it would undermine these encryption systems. In turn, this would jeopardize the security of everything from personal online purchases to high-level international political and military communications.

The problem is often summarized as “P = NP or P ≠ NP?”, which asks the question: Will apparently difficult problems (NP) one day be shown to be just as easy as simple problems (P), or not?

Finding the solution to the mystery of P = NP or P ≠ NP? is on the mathematicians’ most wanted list, and there is even a prize on its head. The Clay Mathematics Institute, established in Cambridge, Massachusetts, by the philanthropist Landon Clay, listed this puzzle as one of its seven Millennium Prize Problems in 2000, offering a $1 million reward for a definitive answer to the question P = NP or P ≠ NP?

David S. Cohen, who explored P-type and NP-type problems while studying for his master’s degree in computer science at the University of California, Berkeley, has a hunch that NP-type problems are indeed much easier than we currently think, which is why P = NP appears behind Homer in his 3-D universe.

However, Cohen holds a minority view. When William Gasarch, a computer scientist at the University of Maryland, polled one hundred researchers in 2002, only 9 percent thought that P = NP, while 61 percent favored P ≠ NP. He repeated the poll in 2010, and this time 81 percent favored P ≠ NP.

Of course, truth in mathematics is not decided by a popularity contest, but if the majority turn out to be right, then Cohen’s positioning of P = NP in the landscape of “Homer 3” will look somewhat incongruous. This, however, should not prove to be an issue in the short term, as half of the mathematicians polled did not think that the problem would be resolved during this century.

Finally, there is one more mathematical reference in “Homer 3” that deserves a mention. More accurately, the reference does not actually appear in the “Homer 3” segment, but rather in the credit sequence for the whole “Treehouse of Horror VI” episode. By tradition, the credits in the Halloween episodes of "The Simpsons" have always been quirky. For example, Matt Groening is credited variously as Bat Groening, Rat Groening, Matt “Mr. Spooky” Groening, and Morbid Matt Groening.

This tradition was inspired by a comic book titled "Tales from the Crypt," which regularly contained mutant credits for its writers and* *artists. Its publisher, EC Comics, became notorious after the Senate* *Subcommittee on Juvenile Delinquency ran comic book hearings in* *1954 that concluded that "Tales from the Crypt" and its other titles were* *partly responsible for corrupting the nation’s youth. This resulted in* *the removal of zombies, werewolves, and their ilk from all comics,* *and in turn these constraints forced the discontinuation of "Tales from the Crypt" in 1955. Nevertheless, "Tales from the Crypt" still has many* *fans, most of whom were not even born when it went to an early* *grave. Al Jean is one these fans, and it was his suggestion to pay homage* *to the comic by mimicking the idea of mutant credits in “Treehouse* *of Horror” episodes.

All of which explains why the credits for “Treehouse of Horror VI” include Brad “the Impaler” Bird, Lycanthropic Lee Harting, and Wotsa Matta U. Groening. And, if you look very carefully, you will spot a charming reference to the Pythagorean theorem and the writer of “Homer 3”:

*DAVID *2 + *S.*2 = *COHEN *2

* The awarding of the Nobel Prize is witnessed by Frink’s resurrected father, who is voiced by the legendary comic actor Jerry Lewis. This resulted in a voice circle. Lewis based his voice for Frink Sr. on Hank Azaria’s voice for Frink Jr., which in turn was based on Lewis’s lead character in "The Nutty Professor."

*Excerpted from "The Simpsons and Their Mathematical Secrets" by Simon Singh. © 2013 by Simon Singh. Used with permission by Bloomsbury USA.*

## Shares