The Simpsons reference that refutes one of history’s greatest mathematicians

In one famous episode of The Simpsons, Homer finds a counterexample to Fermat’s last theorem

A screengrab of an episode of the Simpsons, with Homer Simpson writing mathematical equations on a chalkboard

Homer refuting Fermat’s last theorem in “The Wizard of Evergreen Terrace.”

Disney+

This article is from Proof Positive, our friendly newsletter that explores the joys and peculiarities of math. Sign up today for a weekly math essay and puzzle in your email inbox.


The plot of “The Wizard of Evergreen Terrace” seems like that of a typical Simpsons episode. In it, Homer struggles with a midlife crisis. Disappointed by a lack of accomplishments in his life, he decides to emulate famous inventor Thomas Edison and in turn tries to develop technical innovations, which of course all end in disaster. But if you follow the episode carefully, which was first broadcast in 1998, you’ll be in for a surprise—at least if you know anything about mathematics.


On supporting science journalism

If you're enjoying this article, consider supporting our award-winning journalism by subscribing. By purchasing a subscription you are helping to ensure the future of impactful stories about the discoveries and ideas shaping our world today.


In one particular scene, Homer stands pensively at a fully scribbled blackboard. Next to the obligatory drawings of doughnuts, which are not only Homer’s favorite food but also critical to the field of topology, there is a seemingly harmless equation: 3,98712 + 4,36512 = 4,47212. Type it into a calculator and it appears correct. But amazingly, it contradicts one of the most established theorems of mathematics.

The Great Theorem of Fermat: A Centuries-Old Mathematical Riddle

This story dates back to the 17th century. It starts with the equation xn + yn = zn. If you choose n = 1, then this equation will always be satisfied: no matter how one chooses the values for x and y, z will always be a positiveinteger result. For example, 3 + 6 = 9.

For n = 2, it gets a bit trickier because the equation becomes quadratic: x2+ y2 = z2. This formulation feels familiar, particularly if you like geometry—it’s the Pythagorean theorem. Still, there are some quirks: if x and yhave integer values, z is not necessarily an integer. For example, for x = 1 and y = 2, the formula 12 + 22 = 5. But 5 is not a square number.

Look at the equation again when n = 3 and things get strange. You cannot find a solution that is an integer for x3 + y3 = z3. That means you cannot divide a cube with integer side lengths z into two smaller cubes that have integer side lengths x and y. The same is true for all other values of n.

Seventeenth-century French scholar Pierre de Fermat recognized this, too—and claimed to have discovered a proof for the statement that there are no three positive integers x, y and z that can satisfy xn + yn = zn when n is greater than 2. The catch: he wrote about achieving this mathematical wizardry in a note in the margins of a book by an ancient scientist, Diophantus of Alexandria, and he didn’t actually spell out the proof.

Fermat left similar scribbles behind frequently. And all of them—except this one—were successfully proved by later experts. So this mystery proofbecame known as Fermat’s last theorem.

Generations of scholars took a crack at it until finally, more than 350 years later, in 1994, mathematician Andrew Wiles solved the puzzle. His impressive work made waves: he developed novel methods that led to further groundbreaking discoveries in the field. For this, among other things, he was honored in 2016 with the Abel Prize, one of the highest honors in mathematics.

For Wiles’s proof, you have to leave the algebra you know from school and enter more branched mathematical areas. In fact, you have to enter into the esoteric realms of elliptic curves and modular forms—concepts developed in the 1980s.

Nobody seriously doubts that Wiles’s approach is correct. His technical paper has been reviewed by many experts, especially because some of his techniques are repeatedly revisited to reveal other mathematical relationships. This reduces the probability that an error could have crept in somewhere.

But Fermat could not have known about elliptic curves and modular forms. So that creates new questions: Had the scholar been joking? Had he miscalculated? Or does a substantially simpler proof exist? The debate goes on.

Homer Simpson versus Pierre de Fermat

Fortunately, the Homer Simpson mystery is easier to solve. Yes, 3,98712 + 4,36512 = 4,47212 represents an integer solution of the equation xn + yn = zn for n = 12. But the problem here is in the conventional calculator.

The numbers 3,98712 + 4,36512 are enormously large values consisting of 44 digits. Ordinary calculators typically provide only 10 digits, which is why they round the numerical values up or down. With a more accurate calculator or computer program, you will find that 3,98712 + 4,36512 does not actually equal 4,47212.

In fact, what “The Wizard of Evergreen Terrace” proves is that many of the creators of The Simpsons have a surprisingly deep knowledge of mathematics. Many of its writers have had backgrounds in computer science, mathematics or physics, including David X. Cohen, who was responsible for the Fermat joke. He had written a computer program specifically to spit out a near solution for this purpose. That he chose Fermat’s great theorem may not have been pure coincidence: in fact, as a student, Cohen attended lectures by mathematician Ken Ribet, who had done some of the preliminary work for Wiles’s proof.

And that’s far from the only Simpsons episode with a slyly placed nerdy Easter egg. In his book The Simpsons and Their Mathematical Secrets, mathematician Simon Singh presents many more examples. If nothing else, the show invites you to take a closer look during a cozy evening TV viewing—and perhaps make a mathematical discovery in the process.

This article originally appeared in Spektrum der Wissenschaft and was reproduced with permission. It was translated from the original German version with the assistance of artificial intelligence and reviewed by our editors.

It’s Time to Stand Up for Science

If you enjoyed this article, I’d like to ask for your support. Scientific American has served as an advocate for science and industry for 180 years, and right now may be the most critical moment in that two-century history.

I’ve been a Scientific American subscriber since I was 12 years old, and it helped shape the way I look at the world. SciAm always educates and delights me, and inspires a sense of awe for our vast, beautiful universe. I hope it does that for you, too.

If you subscribe to Scientific American, you help ensure that our coverage is centered on meaningful research and discovery; that we have the resources to report on the decisions that threaten labs across the U.S.; and that we support both budding and working scientists at a time when the value of science itself too often goes unrecognized.

In return, you get essential news, captivating podcasts, brilliant infographics, can't-miss newsletters, must-watch videos, challenging games, and the science world's best writing and reporting. You can even gift someone a subscription.

There has never been a more important time for us to stand up and show why science matters. I hope you’ll support us in that mission.

Thank you,

David M. Ewalt, Editor in Chief, Scientific American

Subscribe