It’s no secret that the longest-running American sitcom is also one of the smartest. Academics have pored over The Simpsons for its insights into philosophy and psychology, but it took physicist Simon Singh, the author of previous books about cryptography, the Big Bang, and Fermat’s Enigma, to tap a vein of knowledge that runs even deeper in the animated world of Springfield: math. In the engaging (and educational) The Simpsons and Their Mathematical Secrets, Singh delves into the academic backgrounds of some of the most poindextrous Simpsons writers -- Al Jean, J. Stewart Burns, Jeff Westbrook, and David X. Cohen among them -- who are equipped with advanced degrees in math and science. Naturally, they’ve been using their platform to advance what Cohen calls "a decades-long conspiracy to secretly educate cartoon viewers." Hoyvin-glavin! Click through the gallery above for some key Simpsons moments of witty math infusion. Above: "Treehouse of Horror VI: Homer3" (1995) Simon Singh calls this segment "the most intense and elegant integration of mathematics into The Simpsons since the series began" – no small praise from someone who combed through the entire run in search of math content. In the very meta storyline, Homer leaves behind 2-D Springfield when he enters a portal to the abstract and mysterious third dimension, which is rendered with then-cutting-edge computer animation. Homer’s stunned family can hear but not see him as he wanders along a z-axis, and eccentric genius Professor Frink is the only one who can explain the concept of depth: "This forms a three-dimensional object known as a cube, or a Frinkahedron in honor of its discoverer."

"The Wizard of Evergreen Terrace" (1998) Some of the most elaborate mathematical concepts on The Simpsons are distilled into freeze-frame gags, and this one is particularly dense. Among Homer’s scribbles during an inventing fervor, elite math nerds (or those reading Singh’s explanations) will recognize playful equations for very complex mathematical problems: the long-elusive mass of the Higgs boson (which 14 years later is no longer speculative), Fermat’s last theorem, the density of the universe, and how to transform a doughnut into a sphere according to the rules of topology. Image via The Simpsons and Their Mathematical Secrets, Nicole Gastonguay and Na Kim

"They Saved Lisa’s Brain" (1999) Dr. Stephen Hawking makes a guest appearance in this episode, intervening to save Lisa from an angry mob after Springfield’s power-hungry Mensa chapter runs amok. In the last scene, Hawking offers Homer some seemingly ridiculous praise: “Your theory of a doughnut-shaped universe is intriguing ... I may have to steal it." In fact, that structure has serious cosmological support, though mathematicians prefer to call the three-dimensional shape a torus. Mmm... all-encompassing torus of unfathomable size...

"Bye Bye Nerdie" (2001) Bumbling Professor Frink struggles to bring order to a raucous crowd of scientists at Springfield’s 12th Annual Big Science Thing, before he shocks the room to silence by yelling, "Pi is exactly three!" The obvious joke is that only such a preposterous inaccuracy could quiet a group of math geeks, but there’s another layer. Writer Al Jean based the line on an actual attempt to legislate an official value for pi, known as the Indiana Pi Bill of 1897, in which an amateur mathematician suggested "squaring the circle" by rounding π to 3.2. The baffled state House of Representatives allowed the measure to pass, but luckily a Purdue University math professor intervened before the Senate ratified the absurdity into law."

"Marge in Chains" (1993) When Marge goes on trial for shoplifting, sketchy lawyer Lionel Hutz tries to discredit the memory of convenience store owner Apu Nahasapeemapetilon in court. Unfortunately, the Kwik-E-Mart proprietor has a savant’s memory: "In fact, I can recite pi to 40,000 places. The last digit is 1." Apu’s claim is a reference to the pi-reciting record holder at the time, mnemonist Hideaki Tomoyori (the current record for reciting the infinite decimal from memory is 67,890 places, set by Chao Lu in 2005). However, punctuating the punch line with the actual 40,000th digit of pi was a challenge for the writers, since in 1993, they couldn’t simply Google the known digits. NASA mathematician David Bailey saved the day by mailing a printed copy of the first 40,000 decimal places of pi to confirm that the last digit is, in fact, 1.

"Girls Just Want to Have Sums" (2006) In a nod to the public firestorm provoked by Harvard President Lawrence Summers’ 2005 comments about why women are underrepresented in academia, Principal Skinner triggers a hate campaign when he suggests that girls are inherently inferior to boys in “the real subjects,” math and science. In a questionable effort to fight sexism at Springfield Elementary, an education reformer separates girls to learn a supposedly more feminine form of math. Lisa chafes at the lack of actual problem-solving, and sneaks into the male half of the school to excel in math under cover. The writers found no easy way to resolve the controversy in the episode – just as Lisa is about to offer her opinion about why women continue to be underrepresented in STEM fields in a climactic speech, Martin Prince interrupts with a flute solo.

"$pringfield (Or, How I Learned to Stop Worrying and Love Legalized Gambling)" (1993) Wearing Henry Kissinger’s glasses (the former secretary of state dropped them in the toilet while touring Springfield’s nuclear power plant) seems to endow Homer with his intellect. So he spouts an impressive-sounding geometric formula – “the sum of the square roots of any two sides of an isosceles triangle is equal to the square root of the remaining side” – that turns out to be totally false. Back to proofs, Simpson. The scene references The Wizard of Oz, when the Scarecrow, emboldened by the brains supposedly endowed by his new diploma, spouts the same bastardized version of the Pythagorean theorem.

“Bart the Genius” (1990) In the first regular Simpsons episode, math-infused sequences underscore a plot about Bart’s academic frustration. When an aptitude test is foisted on the class, Bart’s visualization of a classic trains-traveling-at-different-speeds problem devolves into a numerical nightmare. Fed up, he swaps his answer sheet with that of the brainy Martin – and finds himself fast-tracked to a school for gifted students.