Sunday 24 September 2017

Do you know the maths secrets hidden in 'The Simpsons'?

In one of many mathematical gags, Homer's second equation appears to disprove Fermat's last theorem Photo: Fox
In one of many mathematical gags, Homer's second equation appears to disprove Fermat's last theorem Photo: Fox

Tom Chivers

‘Comedy,” says Al Jean, “is very mathematical. Especially animation, with its precision and control.” I bow to his expertise on both subjects – he’s a graduate in mathematics from Harvard University but, more famously, he’s also one of the original writers of the longest-running and most successful animation of all time, The Simpsons, which has its 25th anniversary in December.

You can see the analogy – although he doesn’t call it an analogy; he uses the mathematical term isomorphism. Good comedy, like a mathematical problem, has a complicated set-up and then a satisfying, unexpected reveal: “Coming up with a good joke is often like doing a proof,” says Jean.

That, at least, is the explanation Jean gives for the fact that the writing staff of The Simpsons, and of its sister show Futurama, is crammed with maths geniuses, and for the related fact that both shows are equally crammed with highbrow mathematical concepts; one contains an apparent disproof of Fermat’s Last Theorem, while the other contains the proof of an original theorem, the only one ever published in a cartoon rather than an academic journal. “We’re subconsciously oozing our nerdiness into the script,” Jean says.

David X Cohen, one of Jean’s former colleagues on The Simpsons, another Harvard graduate and now the head writer on Futurama, explains further. “We have a healthy team of nerds,” he says. “I have a master’s in theoretical computer science, and my undergraduate is in physics. Those credentials place me somewhere in the middle in the Futurama writing staff.” There are three PhDs, one in chemistry, one in computer science, and one in applied maths; Cohen describes himself as “pretty mediocre” by comparison.

Can you spot the 'Mersenne prime', the 'perfect number' and the 'narcissistic' number? (Fox)
Can you spot the 'Mersenne prime', the 'perfect number' and the 'narcissistic' number? (Fox)

We’re talking about the mathematical secrets of The Simpsons because, this year, a book was published called The Simpsons and their Mathematical Secrets, and Cohen and Jean are coming to London’s Science Museum to talk about it. The book is written by Simon Singh, one of Britain’s most respected science writers and the holder of a PhD in particle physics.

“Usually these books are the writer inserting their own ideas into the show,” says Cohen. “This is someone digging up ideas that we’ve stuck in the show.” Jean gives an example: one 2006 episode features a baseball game. At one point, the crowd is asked to guess the attendance, and three numbers come up: 8,128, 8,208 and 8,191. For most viewers they’re three arbitrary numbers but, for maths nerds, they’re not. The first, 8,128, is a so-called “perfect number”: the numbers that it divides into also add up to it. Then, 8,208 is a “narcissistic number”: it has four digits and, if you multiply each one by itself four times, the results add up to 8,208. And 8,191 is a “Mersenne prime”, named after a 17th-century French mathematician. A prime number is one that can be divided only by itself and one; for many prime numbers, if you double them and add one, it makes a new prime number, a Mersenne. “You wouldn’t know just looking at the sign,” says Jean. “That’s my favourite thing; it encourages digging, and repeat viewing.”

 “I can top that,” laughs Cohen. In the 1995 Halloween special, “Treehouse of Horror VI”, some equations float past in the background. One reads 398712 + 436512 = 447212. If you are a mathematician, that will make your eyes pop out.

If you aren’t a mathematician, some explanation is required. Most people know Pythagoras’s theorem: “the square of the hypotenuse (the long side of a right-angled triangle) is equal to the sum of the squares of the other two sides”. In mathematical notation, that is: x2 + y2 = z2. Sometimes x, y and z can be whole numbers: three threes (9) plus four fours (16) equal five fives (25). But for thousands of years, mathematicians have wondered: if it works for some square numbers (x2), does it work for any cubed numbers (x3)? Or any higher powers than that?

After millennia of looking, mathematicians decided that it didn’t; that for the equation xn + yn = zn, where n is a whole number greater than two, there are no whole-number solutions. But they couldn’t prove it. Then another 17th-century French mathematician, Pierre de Fermat, wrote in the margin of a book of ancient Greek maths, “I have discovered a truly marvellous proof of this, which this margin is too narrow to contain.” This was discovered by his son after his death, and, for the next 300 years, mathematicians struggled to find this proof. In 1994, a British mathematician, Andrew Wiles, finally did.

But there on the screen in The Simpsons, it said 398712 + 436512 = 447212! Or: xn + yn = zn! And if you take a calculator and enter those numbers, you’ll find that it works. Had The Simpsons disproved the famous theorem?

No; it was a trick. Most calculators can display only eight digits; if you tried the equation on a better calculator, you’d find it almost worked, but almost is still a miss. “I wrote a computer programme to find a near counter-example. This was just after Wiles proved it,” says Cohen, sounding a little sheepish. “I want to point out that this was a hot topical reference at the time.

These “jokes” are on screen for only a second or two. They’re known as “freeze-frame gags”: The Simpsons began around the time the VCR player was becoming standard in American homes. Suddenly, they could stick in bonus gags for committed fans. “We hate to have unused real estate,” says Jean. Every time, within hours of the episode airing, someone would have found it, solved it, and posted it on a discussion board. “There’s never been something we put in there that hasn’t been found in a couple of hours,” says Jean; Cohen finds it reassuring that their fans are as nerdy as they are. Not that the jokes are only maths-related; in Futurama, there’s a joke about a (real) British spy in the American Revolutionary War who shares a surname with one of the main characters, and both shows are stuffed with historical and scientific references. “The first time we did it, we thought it’d be literally just of interest to our old college room-mates,” says Cohen.

 It was among those old college room-mates that both Cohen and Jean began their comedy-writing careers seriously. Both wrote for The Harvard Lampoon, a comedy magazine that has acted as a career kick-starter for many of Hollywood’s top writers. “That was where quite a few people who were going to make a positive contribution to the world derailed and went, ‘Hey, there are careers to be had in comedy writing,’ ” says Cohen. Jean was involved in The Simpsons from the first episode; Cohen joined four years later, and moved to Futurama when that began. Cohen, by the way, only tentatively agrees with Jean about the maths-comedy isomorphism: he says the main reason there are so many maths nerds in The Simpsons is because a few happened to join early, and they did well and employed like-minded people. In a suitably scientific analogy, he says it grew “like a crystal”.

The Simpsons is written almost as a radio show: a full script, and then recording, with animation added only near the end. It’s during the first rough version of the animation, according to Cohen, that the writers think, “Oh, look, there’s room for a gag.” “You see that the animators have put a car in the background, so you think, ‘Let’s throw a funny licence plate in there.’ ”

But sometimes the writers let their maths-geekery take centre stage. “When we get called out for nerdiness, we tend to double down,” says Jean. So one episode, a parody of the film Moneyball, revolves around the statistical analysis of baseball results. A future episode, according to Jean, has Lisa on a maths team, and features “the most complicated math jokes we can think of”. But the greatest came in Futurama.

“We were using a traditional storyline, a brain-swapping machine,” says Cohen, “and we wanted to make it a bit more complicated.” They decided that if two people had already had their brains swapped, they couldn’t be swapped back; they could swap only with new people. But then they realised that they didn’t know if it would be possible to swap people back to their original bodies. “We kind of got stumped.” The following morning, Ken Keeler, the maths PhD, said he’d proved “that for any group of people whose brains have been switched, as long as you bring in two new people you can always get everyone’s brains back to where they started. That’s a mathematical proof in the area of ‘group theory’.” The proof is displayed by a pair of mathematical basketball players – don’t ask – for a second at the end. (Keeler also wrote the script for that episode. His first draft opened with a four-page discussion of the proof: “We were all thinking, ‘Oh no, how are we going to tell Ken we can’t use this?’ ” says Cohen. Then they turned to page five, where the real script began. “He got us,” says Cohen, ruefully.)

Jean hopes that both the gags and the book will encourage young Simpsons and Futurama fans to go into maths. “I hope we’re encouraging exploration, because it’s a wonderful discipline. Even though I fled it at the first opportunity.”

He tells me of his own “brush with fame”, as though as a Simpsons writer he’s not famous in his own right. “As a student I had a class by Andrew Wiles. I doubt he’d remember me. But I got a B+.”

The Simpsons, Weekdays at 6pm, Channel 4. Season 26 will start on Sky 1 in early November.

Telegraph.co.uk

Editors Choice

Also in Entertainment