I was captain of the high school math team and a proud member of the state math team. This got me into Harvard but didn’t get me any dates, so I dropped math for comedy. This change of direction still didn’t get me any dates, but it did get me a job: I’ve been writing for The Simpsons for thirty years. There are quite a few math majors on the writing staff, and there have been enough math jokes on the show to fill a book. That book is Mathematical Secrets of “The Simpsons” by Simon Singh, and it was an international best-seller.I’ve never figured out the connection between math and comedy—if there is one—but I have noticed a certain subset of jokes structured like algebra. I’m not talking about jokes based on algebra, like the mathematician who told his kids, “If I’ve told you n times, I’ve told you n + 1 times . . .”I’m not even counting jokes that have an algebraic underpinning, like this kiddie favorite:Kids intuitively get this joke, even though it involves math they haven’t learned yet: ($1 × n) – ($1 × n) = 0, for any number n of watermelons. The guys will earn nothing no matter how big the truck is. It’s similar to another joke kids tell: In equation form, 6 × 1/6 Pizza = 8 × 1/8 Pizza.These are literally algebraic jokes. I’m more interested in jokes that are structured like algebra equations that must be “solved” to be enjoyed. The punchline is x; it’s not in the joke; it is the solution to the joke. It’s easier to describe by example: “A comedian says, ‘The towels in this hotel are so thick, I can hardly close my luggage.’” The comedian, of course, is stealing towels; that’s the funny part, although it’s stated nowhere in the joke. You have to deduce it.Here’s another one. “A bartender says, ‘What’ll you have?’ A time traveler walks into a bar.” For you to get the joke—for it to even be a joke—you have to solve it: the time traveler began at the start of the joke, but traveled ahead a few seconds to end the joke. It’s remarkable: all the pieces are there, and yet the explanation, which you mentally construct, is longer than the joke itself.If this thread is getting too heady, let’s return to basics with a Henny Youngman joke:The implied punchline is: “I beat her to death because I couldn’t poison her with mushrooms, as I did my first two wives.” It is exceedingly grim material for a joke, except that none of it is stated outright: murder is nowhere mentioned in the joke itself. The joy of discovery ostensibly mitigates the horror of the story. That’s why Henny got away with telling it for decades.This would qualify as “sick humor,” and quite a few algebra jokes fall into this category. It’s not a coincidence: a characteristic of the algebra joke is that nothing is said outright; the delight of the sick humor version is in how much depravity can be hidden in plain sight. Here are two examples so dark that I present them without explication:The algebra joke structure can conceal a dirty joke as well as a sick one. I’ll cite this one from The Simpsons, which I consider the cleverest of the seventy thousand plus jokes that have appeared on the show: “A sign on a store reads ‘Sneed’s Feed & Seed. Formerly Chuck’s.’” It seems so bland; you wouldn’t give it a second look in real life—that’s certainly how it slipped past the Fox censors. But the implication, purely by extending the joke pattern, is that the store was called “Chuck’s Fuck & Suck.” That accounts for “formerly,” which hides the smutty solution right out in the open.Once you’re aware of the form, you’ll notice many algebra jokes out there, ranging from the mild to the macabre, cute to crude. Let me close with one of the trickiest. Hardly anyone figures it out immediately; I’d call it advanced algebra: “A skeleton walks into a bar and says, ‘I’d like a beer and a mop.’”