The secret to The Simpsons' ability to predict the future may be linked to the creators' affinity for mathematics.

From the invention of autocorrect and smartwatches, to the presidency of Donald Trump, it would be reasonable to wonder if someone in the writers' room secretly moonlights as a time traveller.

Fans, particularly the maths whizzes among them, often spot plenty of Easter eggs and hidden references in shows that are all to do with numbers.

This is due to the fact that many of people involved in the production of The Simpsons are huge maths buffs, the Mirror reports.

In fact, the first-ever episode of the series in 1989 had plenty of mathematics references with jokes about calculus. And if your worst nightmare is maths then it seems fitting that the Halloween special “Treehouse of Horror VI” featured a pretty intense five minutes of maths.

In one scene, the letters P and NP can be seen over Homer’s right shoulder, which might not mean anything to most viewers, but it’s actually an unsolved theoretical computer science problem. The puzzle has a reward of \$1million for whoever solves the mystery.

As previously reported by The Guardian, many of The Simpsons writers have a pretty impressive mathematical background. Al Jean, who is now the executive producer, worked on the first series and studied mathematics at Harvard University at the age of just 16.

Jeff Westbrook was a writer and a producer for The Simpsons, and he’s a former academic and algorithms researcher at Yale University.

• Inside mysterious octagonal castle believed to be hiding codes and messages

Get this, in the TV show they even suggested that Homer had solved the historical Fermat’s last theorem by 17th century French mathematician Pierre De Fermat. On the Treehouse of Horror VI, Homer seems to challenge the claim when he writes: 1,782¹² + 1,841¹² = 1,922¹².

For all the geniuses out there, if you actually work out what Homer has written on your calculator, you’ll learn that his solution is ever so slightly incorrect with a small imbalance in the equation. It still takes a calculator to work this out though, so basically writer Joel Cohen is playing a Halloween prank on viewers – gotcha.

That’s not all of it though, in the 2006 episode “Marge and Homer Turn a Couple Play” there’s a triple dose of secret mathematics. It’s all about Marge and Homer’s efforts to help baseball star Buck Mitchell and his wife Tabitha Vixx, who are experiencing marriage difficulties.

At the end of the episode, Tabitha appears on the Jumbo Vision screen at the Springfield stadium, but before she does, there is a question asking the baseball fans to guess the attendance.

The screen then displays multiple choice options of 8,128, 8,208 and 8,191, which may seem like random numbers, but they’re actually not. They represent a perfect number, a narcissistic number and a Mersenne prime.

There are so many mathematical references in The Simpsons, and a lot of them are through Lisa, certified maths nerd and trigonometry lover.

Let’s take a look at another example, in “Colonel Homer” (1992) you see the first appearance of the local movie theatre. Clever viewers noticed that the movie there is called “Googolplex”, and to understand this reference, you have to know about Edward Kasner, an American mathematician.

In 1938, he said to his nephew Milton that it would be useful to have a label to describe the number (or 10,000,000,000,000,000,000,000,000,000,000,000,000, 000,000,000,000, 000,000,000,000, 000,000,000,000,000,000,000,000,000,000,000,000,000). This is where Milton suggested the word googol. If you know you know – right?

Long story short, brain-box writers have packed in plenty of mathematics references, so give yourself a pat on the back if you spot any.