The Simpsons is arguably the most successful television show in history. Inevitably, its global appeal and enduring popularity have prompted academics (who tend to overanalyze everything) to identify the subtext of the series and to ask some profound questions. What are the hidden meanings of Homer's utterances about doughnuts and Duff beer? Do the spats between Bart and Lisa symbolize something beyond mere sibling bickering? Are the writers of The Simpsons using the residents of Springfield to explore political or social controversies?

One group of intellectuals authored a text arguing that The Simpsons essentially provides viewers with a weekly philosophy lecture. The Simpsons and Philosophy, edited by William Irwin, Mark T. Conard, and Aeon J. Skoble, claims to identify clear links between variousepisodes and the issues raised by history's great thinkers, includingAristotle, Sartre, and Kant. Chapters include "Marge's Moral Motivation," "The Moral World of the Simpson Family: A Kantian Perspective,"and "Thus Spake Bart: On Nietzsche and the Virtues of BeingBad."

By contrast, Mark I. Pinsky's The Gospel According to The Simpsons focuses on the spiritual significanceof The Simpsons. This is surprising, because many charactersappear to be unsympathetic toward the tenets of religion. Regularviewers will be aware that Homer consistently resists pressure to attendchurch each Sunday, as demonstrated in "Homer the Heretic"(1992): "What's the big deal about going to some building every Sunday?I mean, isn't God everywhere? . . . And what if we've picked the wrong religion? Every week we're just making God madder and madder?"

Even President George H. W. Bush claimed to have exposed the real message behind The Simpsons. He believed that the series was designed to display the worst social values. This motivated the most memorable sound bite from his speech at the 1992 Republican National Convention, which was a major part of his re-election campaign: "We are going to keep on trying to strengthen the American family to make American families a lot more like the Waltons and a lot less like the Simpsons."

The writers of The Simpsons responded a few days later. The next episode to air was a rerun of "Stark Raving Dad" (1991), except the opening had been edited to include an additional scene showing the family watching President Bush as he delivers his speech about the Waltons and the Simpsons. Homer is too stunned to speak, but Bart takes on the president: "Hey, we're just like the Waltons. We're praying for an end to the Depression, too."

However, all these philosophers, theologians, and politicians have missed the primary subtext of the world's favorite TV series. The truth is that many of the writers of The Simpsons are deeply in love with numbers, and their ultimate desire is to drip-feed morsels of mathematics into the subconscious minds of viewers. In other words, for more than two decades we have been tricked into watching an animated introduction to everything from calculus to geometry, from pi to game theory, and from infinitesimals to infinity.

"Homer 3," the third segment in the three-part episode "Treehouse of Horror VI" (1995) demonstrates the level of mathematics that appears in The Simpsons. In one sequence alone, there is a tribute to history's most elegant equation, a joke that only works if you know about Fermat's last theorem, and a reference to a $1 million mathematics problem. All of this is embedded within a narrative that explores the complexities of higher-dimensional geometry.

"Homer 3" was written by David S. Cohen, who has an undergraduate degree in physics and a master's degree in computer science. These are very impressive qualifications, particularly for someone working in the television industry, but many of Cohen's colleagues on the writing team of The Simpsons have equally remarkable backgrounds in mathematical subjects. In fact, some have PhDs and have even held senior research positions in academia and industry. Here is a list of degrees for five of the nerdiest writers:

J. Stewart Burns

BS Mathematics, Harvard University MS Mathematics, UC Berkeley

David S. Cohen

BS Physics, Harvard University

MS Computer Science, UC Berkeley

Al Jean

BS Mathematics, Harvard University

Ken Keeler

BS Applied Mathematics, Harvard University

PhD Applied Mathematics, Harvard University

Jeff Westbrook

BS Physics, Harvard University

PhD Computer Science, Princeton University

In 1999, some of these writers helped create a sister series titled Futurama, which is set one thousand years in the future. Not surprisingly, this science fiction scenario has allowed them to explore mathematical themes in even greater depth, with references to Moebius strips, Klein bottles, taxicab numbers and numerous nods to binary arithmetic.

If you remain dubious about my claim that The Simpsons and Futurama are essentially mathematical textbooks hidden within an animated sit-com format, then I will leave you with a brief description of one particular episode that should dispel any doubts.

A Futurama episode entitled "The Prisoner of Benda" (2010) has a storyline that includes a mind-switching machine that can transfer the mind of one person into the body of a second person, and vice versa. Various characters – including Fry, Bender, Leela, and Professor Farnsworth – indulge in an orgy of mind-switching, before they realise that two people who have switched minds cannot switch back. Hence, two people who have switched can only restore their minds via switches with third parties, who act as intermediate vessels for minds trying to find their rightful owners. This raises an interesting mathematical question; "How many intermediate people are required in order to guarantee that people can return to their own minds, regardless of the number of people and the number of previous switches?"

Ken Keeler, a Futurama writer who has a doctorate in applied mathematics, took up the challenge of investigating mind-switching and developed a proof which demonstrates that introducing two fresh people into any group, regardless of the group's mind-switching history, is sufficient to unmuddle all the minds. The full proof appears on a blackboard in one of the final scenes of the episode. Known as Keeler's theorem or the Futurama theorem, this curious and credible piece of mathematics has subsequently inspired other mathematicians to explore related mind-switching mysteries.

This proves that the writers behind The Simpsons and Futurama have a unique set of mathematical talents, as no other sitcom can boast the creation of a genuinely innovative and bespoke piece of mathematics. Indeed no other series in the history of primetime television has included so many mathematical references.

This excerpt has been adapted from the introduction to The Simpsons and Their Mathematical Secrets by Simon Singh. Copyright (c) 2013 by Simon Singh. Used by permission of Bloomsbury USA