Author and TV presenter Simon Singh may well be best known for his work on Fermat's Last Theorem, but these days he's investigating the mathematics of America's most famous family.

"I suppose the biggest surprise is that 'The Simpsons' is in any way mathematical," says Simon Singh. Sitting in his kitchen in Richmond, we're trying to work out the process by which one of the most celebrated authors of popular science books should have progressed to adding a title on an animated TV sitcom to his list of publishing achievements. Isn't it something of a surprise that a post-graduate in particle physics should take the long-running critique of blue-collar America so seriously? "Well it would be, I suppose. But another big surprise is how many of the writers on 'The Simpsons' are heavyweight mathematicians."

Singh's latest contribution to the genre is 'The Simpsons and Their Mathematical Secrets', a book that bursts with satisfyingly geeky observations about the programme. Those thinking that 'The Simpsons' would soon have any investigator scraping the barrel for intellectual ballast will not have reckoned on Singh, who has form as a getter of great stories from unlikely sources. Singh first came to the public's attention with his enormously successful 'Fermat's Last Theorem', which later became an award-winning TV documentary. He has also written books on cryptography and the origins of the universe.

'The Simpsons' is arguably the most successful television show in history. For most of us, the series probably operates as a social satire centred on a dysfunctional family. And yet, for the mathematically minded it provides a rare opportunity to become almost casually reacquainted with Euler's Identity or Fermat's Last Theorem on mainstream TV. "All these references are embedded in episodes written by people with PhDs in applied maths, with degrees from Harvard, professors from Yale, and so on."

Despite it being "a very obvious book for me to write", Singh explains how his latest is getting on for a decade late in hitting the shops. He first started "writing to the writers" of 'The Simpsons' in 2005, but simultaneously "got angry and annoyed about alternative medicine". This meant his attention was deflected towards another writing project, 'Trick or Treatment: Alternative Medicine on Trial', effectively shelving the 'Simpsons' idea. 'Then, I got sued for libel in 2008 and so things had to wait for a few more years. Finally, I returned to 'The Simpsons' in 2011. But it's an idea I've been wanting to work on for some time."

Singh has been a fan of the show since the earliest episodes way back in 1989. "But it was a few years before I realised that this was an animated sitcom rather than a kids' cartoon." The author also loves TV. He worked in the medium for six years and remembers with affection how as a child he watched "endless TV". The roll-call of his favourite "science boffins of the 1970s" trips off the tongue with nostalgic fluency and precision: Magnus Pyke, Patrick Moore, James Burke. "They left such a lasting impression."

#### Maths in 'The Simpsons'

Singh's favourite mathematics cameo in 'The Simpsons' is that of Fermat's Last Theorem – "because I've written a book about it" – which appears in the episode 'Treehouse of Horror VI'. Eagle-eyed viewers will remember the equation 1782^{12} + 1841^{12} = 1922^{12} appearing on a blackboard over Homer's shoulder.

"Now that shouldn't exist," says Singh. "Fermat's Last Theorem says that it cannot be true. And yet this has cropped up. I thought I'd check that with the calculator on my phone and, sure enough, it works." Singh says that there is something very odd going on here, because "here is an equation that should not exist – and certainly not in 'The Simpsons'! – and yet it seems to shatter what Fermat told us."

And yet there is no mistake. The apparent irregularity in the internal mathematics of the 'Simpsons' universe is explained by the fact that phone calculators do not resolve to sufficient decimal places to illustrate the slight imbalance in what's called a 'near-miss' Fermat solution. Singh describes this moment in 'The Simpsons' as "a very nice bit of mathematics", before describing a similar joke that appears in an episode called 'The Wizard of Evergreen Terrace'.

Another example Singh particularly likes centres on a scoreboard at a baseball game, displaying possible answers for a multiple-choice quiz to determine the game's attendance. Is it: a) 8,191, b) 8,128, c) 8,208 or, d) No way to tell? To most of us, these will be perfectly innocuous and realistic numbers for a ballgame with an attendance of just over 8,000, and if we notice them at all, they will represent no more than incidental background detail. "But each number has a very specific mathematical significance," says Singh. He's not wrong. The first is a Mersenne prime; the second is a perfect number, while the third is a narcissistic number. Singh describes the last of these as a number that is "in love with itself", where, if each digit were raised by the power corresponding to the number of digits in the original number and then combined, you get back to where you started (i.e. 8,208 = 84 + 24 + 04 + 84 = 4,096 + 16 + 0 + 4,096). "You don't find that in Coronation Street," says Singh. (Has anyone checked?! 'Ed)

These are in-jokes that even most technically literate are unlikely to get instantly. But what is interesting here is that 'The Simpsons' took off at around the point where ownership of VHS videocassette recorders was at its height. In 1989, 60 per cent of American households owned a VCR. The significance of this for Singh is that here is the first moment in history where the audience could collectively "freeze programmes, watch them again and check things. The fans of the series – the nerds and the geeks (and I use those terms affectionately) – would look out for these things and share them online. And the writers put these things into The Simpsons in the hope that one or two people would pick them up."

#### Homeric numeric

In the introduction to his new book, Singh states that there are, of course, many books about 'The Simpsons'. Critics and academics have written about the show in relation to theology, psychology and philosophy. "All of these things pop up in various plotlines, while relationships between the characters can be used to illustrate whatever point you want them to, frankly." He goes on to say that if you wanted to write a book about 'The Simpsons' in relation to technology and engineering you could do that, too: after all, Homer Simpson is a safety worker in a nuclear power plant and Lisa has a highly-developed obsession with science.

But for Singh the mathematics angle is fundamental. "There aren't seven or eight theologians or psychologists writing the scripts. But there are seven or eight accomplished mathematicians. You'll find personal relationships and even faith popping up in 'Coronation Street' or 'Eastenders'. But you don't find Fermat's Last Theorem in these programmes. And so the link between 'The Simpsons' and mathematics isn't fabricated. It is there because of the writers who have a tremendous passion for mathematics."

Given that there is such a high proportion of mathematicians working together on the programme, the question arises as to how or why they chose the format of a 22-minute cartoon comedy to display their message to the world. Why are mathematicians linked to comedy, muses Singh, before reeling off a list of stand-up comedians with a mathematical background, culminating with one of the most successful satirists of the 20th century, Tom Lehrer, who taught mathematics at MIT and at the University of California.

"I asked the writers about this, and it seems that a lot of their theories stem from the fact that mathematicians love logic, while a lot of humour derives from illogic. I then asked them why they weren't working on a live sitcom, or was there something about animation that appeals to the mathematician?" Scriptwriter Al Jean's response to Singh was that as a mathematician he enjoyed the complete control that the discipline allowed him in terms of the flow of the narrative argument. Jean further developed his response by saying that he found science and engineering difficult because of their involvement with reality. For Singh these present interesting parallels. "When you deal with the real world on TV there are actors who fluff lines or want to bring their own ideas to the table. Or there are variables such as the weather that get in the way of what you want to do. When you are an animator, everything on your storyboard will appear as you want it. Mathematics and animation are similar, controllable disciplines."

#### Thriller by numbers

Although mathematics might be regarded an unlikely source for best-selling books, Singh is no stranger to success in this area. In 1997, the small narrative non-fiction specialist 4th Estate published Singh's squat tome 'Fermat's Last Theorem' – a book that was to make him, if not a household name, then at least absurdly popular with the more enquiring of literary commuters.

The end of the 20th century was a time when books such as Dava Sobel's 'Longitude' were topping the best-seller lists, and the public wanted more of these 'strange but true' yarns. It didn't matter that the subject might be arcane or abstruse. It fact it helped. As long as obscurity didn't tip over into impenetrability, and so long as there were a few decent heroes and villains, subjects once thought geeky would finally have their place in the sun. Singh's first book seemed to have everything right.

Singh had been a producer and director on such TV programmes as 'Tomorrow's World' and 'Horizon' with an eye and an ear for what made a good story. As he says, "people know what scientists do. They try to understand the universe. People know what engineers do. They go out and build stuff. But they don't really know what mathematicians do." If they thought anything about it, "they kind of thought that maybe they help engineers, or they become accountants or teachers. But nobody really understood what it is they actually do. They certainly didn't seem to know that you can do mathematics for its own sake."

Singh explains how Fermat's Last Theorem provided an opportunity – "perhaps for the first time" – to explain how people can become passionate about such a seemingly inaccessible and abstract subject as mathematics in the same way they can about science. "The reason you could take people on this journey was because it was such an extraordinary story. Here was a guy in the 17th century, Pierre de Fermat, who discovers a proof, but never tells us what that proof is, and then dies. He leaves us with this buried treasure; except we don't have a map and we have no idea where the treasure is buried. We have no idea of what the proof is or what it might be composed of."

Singh then launches into the now well-known tale of three centuries of obsessive questing for the proof, the repeated failure and the increasing desperation in the face of a tantalising goal and the subsequent successful end to the journey. As he retells the story it occurs to me that probably the only reason people outside the mathematics community know anything at all of the 17th century French lawyer with a flair for calculus is the man sitting opposite me.

Of course, there is no need for Singh to do a PR job on 'The Simpsons'. But by the time his latest book has done the rounds of the engineering community, he may well be the man to thank for alerting us to one of the geekiest and funniest lines in cartoon history. When his precocious daughter constructs a perpetual motion machine in her spare time, Homer, that cartoon icon best known for slacking off and eating doughnuts, berates her: "Lisa, in this house we obey the laws of thermodynamics!"