The episode in question was the just aired "The Prisoner of Benda." Ken Keeler is a Futurama writer, and he actually has a PhD in mathematics as well.
The episode centers around an invention that allows characters to switch bodies. However, you can only switch bodies once between the same pair of people. Thus, when Amy and the Professor exchange bodies, they find they cannot switch back. The theorem (one in group theory) was designed to prove that by switching enough bodies, the original two could eventually end up in their proper bodies.
We find Futurama hilarious, and this episode was no different. It was very reminscent, however, of the Flintstones episode "Monster Fred." While that episode began with Fred being creamed by a bowling ball, it ended with Fred, Barney, Wilma, Betty, and even Dino getting their brains scrambled up, and it took several tries to get them all back in the correct bodies.
It's been a great season for Futurama, including an episode which mocked the iPhone (as the EyePhone). Episode 100, "The Mutants Are Revolting," is scheduled to be aired on Sept. 2nd.