“Jokes are just a disruption of logic,” Keith says. Kenny takes their explanation one step further. “A joke is basically syllogistic,” he states, referencing the form of reasoning that goes: All dogs are animals, all animals have four legs, therefore all dogs have four legs. “Its premise and then the punchline would be conclusion. It’s the same shit.”
It's hard to know how strictly one should take such an equation, but this would suggest that the incongruity of the joke is its middle term, which would make sense; and it would also explain why there are so many analogies and overlaps between sophisms and jokes (e.g., see Julia Nefsky's discussion from 2005).