“Without doubt, the most mathematically sophisticated television show in the history of primetime broadcasting is The Simpsons. This is not a figment of my deranged mind, which admittedly is obsessed with both The Simpsons and mathematics, but rather it is a concrete claim backed up in a series of remarkable episodes.

The first proper episode of the series in 1989 contained numerous mathematical references (including a joke about calculus), while the infamous “Treehouse of Horror VI” episode presents the most intense five minutes of mathematics ever broadcast to a mass audience. Moreover, The Simpsons has even offered viewers an obscure joke about Fermat’s last theorem, the most notorious equation in the history of mathematics.

These examples are just the tip of the iceberg, because the show’s writing team includes several mathematical heavyweights. Al Jean, who worked on the first series and is now executive producer, went to Harvard University to study mathematics at the age of just 16. Others have similarly impressive degrees in maths, a few can even boast PhDs, and Jeff Westbrook resigned from a senior research post at Yale University to write scripts for Homer, Marge and the other residents of Springfield.

When they moved from academia to Fox Studios, these writers retained their passion for numbers and they have secretly planted mathematical references in dozens of episodes. Until now, only extreme geeks have been aware that the writers have been smuggling mathematics into their scripts while the rest of the planet has been oblivious to the numerous nods to number theory and geometry.

The 2006 episode “Marge and Homer Turn a Couple Play”, for example, contains a triple dose of secret mathematics. The storyline revolves around Marge and Homer’s efforts to help baseball star Buck Mitchell and his wife Tabitha Vixx, who are experiencing marital difficulties. The episode climaxes with Tabitha appearing on the Jumbo Vision screen at the Springfield stadium, where she publicly proclaims her love for Buck. More important, just before she appears on the screen, it displays a question that asks the baseball fans in the crowd to guess the attendance.

The Jumbo Vision screen from ‘Marge and Homer Turn a Couple Play’, showing a perfect number, a narcissistic number and a Mersenne prime number.

The screen displays three multiple choice options; 8,128, 8,208 and 8,191. These digits might seem arbitrary and innocuous, but in fact they represent a perfect number, a narcissistic number and a Mersenne prime.

8,128 is called a perfect number, because its divisors add up to the number itself. The smallest perfect number is 6, because 1, 2 and 3 not only divide into 6, but they also add up to 6. The second perfect number is 28, because 1, 2, 4, 7 and 14 not only divide into 28, but they also add up to 28. The third perfect number is 496, and the fourth one is 8,128, which appears in this episode. As René Descartes, the 17th-century French mathematician (and philosopher) pointed out: “Perfect numbers, like perfect men, are very rare.”

8,208 is a narcissistic number because it contains 4 digits, and raising each of these digits to the 4th power generates four numbers that add up to itself: 84 + 24 + 04 + 84 = 8,208.

The fact that 8,208 can recreate itself from its own components hints that the number is in love with itself, hence the narcissistic label. Among the infinity of numbers, fewer than 100 exhibit narcissism.

8,191 is a prime number, because it has no divisors other than 1 and the number itself, and it is labelled a Mersenne prime because another 17th-century French mathematician, Marin Mersenne, spotted that 8,191 was equal to 213 – 1. More generally, Mersenne primes fit the pattern 2p –1, where p is any prime number.”

The Simpsons’ secret formula: it’s written by maths geeks – Guardian