We all knew the writing staff of Futurama was brainy, but this is something else. To work out the ridiculous brain switching plot line from last night’s hilarious episode, writer Ken Keeler (who also just happens to have a PhD in mathematics) ended up writing and proving an entirely new theorem. This is probably the most impressive bit of side work from a TV writer since a writer of Desperate Housewives discovered a new species or the staff of Full House developed a vaccine for a specific strain of syphilis.

In the episode “The Prisoner of Benda,” the Professor and Amy use a new invention to switch bodies. Unfortunately, they discover that the same two brains can’t switch twice and have to come up with some equation to prove that, with enough people switching, eventually everyone will end up in their rightful form. This, of course, leads to much hijinks as well as the grossest sex scene the show has ever done (take that, Prof. Farnsworth and Mom!).

Of course, Keeler decided to go the hard route and come up with a suitable equation himself. It was first teased in an interview that head writer and executive producer David X. Cohen gave to the American Physical Society:

“In an APS News exclusive, Cohen reveals for the first time that in the 10th episode of the upcoming season, tentatively entitled “The Prisoner of Benda,” a theorem based on group theory was specifically written (and proven!) by staffer/PhD mathematician Ken Keeler to explain a plot twist. Cohen can’t help but chuckle at the irony: his television-writing rule is that entertainment trumps science, but in this special case, a mathematical theorem was penned for the sake of entertainment.”

Now that the episode has aired, we can check out the theorem in full. Well, I won’t. I suck at math. But the people over at the Futurama wiki The Infosphere have. If there’s anyone as smart as Futurama writers, it’s Futurama fans.

Now, if you’ll excuse me, I have to go continue to clean that sex scene out of my brain.

(photo via)

Have a tip we should know? tips@themarysue.com