In an episode of “The Simpsons,” mad scientist Professor Frink demonstrates his latest creation: a sarcasm detector.

“Sarcasm detector? That’s a really useful invention,” says another character, the Comic Book Guy, causing the machine to explode.

Actually, scientists are finding that the ability to detect sarcasm really is useful. For the past 20 years, researchers from linguists to psychologists to neurologists have been studying our ability to perceive snarky remarks and gaining new insights into how the mind works. Studies have shown that exposure to sarcasm enhances creative problem solving, for instance. Children understand and use sarcasm by the time they get to kindergarten. An inability to understand sarcasm may be an early warning sign of brain disease.

Sarcasm detection is an essential skill if one is going to function in a modern society dripping with irony. “Our culture in particular is permeated with sarcasm,” says Katherine Rankin, a neuropsychologist at the University of California at San Francisco. “People who don’t understand sarcasm are immediately noticed. They’re not getting it. They’re not socially adept.”

Sarcasm so saturates 21st-century America that according to one study of a database of telephone conversations, 23 percent of the time that the phrase “yeah, right” was used, it was uttered sarcastically. Entire phrases have almost lost their literal meanings because they are so frequently said with a sneer. “Big deal,” for example. When’s the last time someone said that to you and meant it sincerely? “My heart bleeds for you” almost always equals “Tell it to someone who cares,” and “Aren’t you special” means you aren’t.

“It’s practically the primary language” in modern society, says John Haiman, a linguist at Macalester College in St. Paul, Minnesota, and the author of Talk is Cheap: Sarcasm, Alienation and the Evolution of Language.

Sarcasm seems to exercise the brain more than sincere statements do. Scientists who have monitored the electrical activity of the brains of test subjects exposed to sarcastic statements have found that brains have to work harder to understand sarcasm.

That extra work may make our brains sharper, according to another study. College students in Israel listened to complaints to a cellphone company’s customer service line. The students were better able to solve problems creatively when the complaints were sarcastic as opposed to just plain angry. Sarcasm “appears to stimulate complex thinking and to attenuate the otherwise negative effects of anger,” according to the study authors.

The mental gymnastics needed to perceive sarcasm includes developing a “theory of mind” to see beyond the literal meaning of the words and understand that the speaker may be thinking of something entirely different. A theory of mind allows you to realize that when your brother says “nice job” when you spill the milk, he means just the opposite, the jerk.

Sarcastic statements are sort of a true lie. You’re saying something you don’t literally mean, and the communication works as intended only if your listener gets that you’re insincere. Sarcasm has a two-faced quality: it’s both funny and mean. This dual nature has led to contradictory theories on why we use it.

Some language experts suggest sarcasm is used as a sort of gentler insult, a way to tone down criticism with indirectness and humor. “How do you keep this room so neat?” a parent might say to a child, instead of “This room is a sty.”

But others researchers have found that the mocking, smug, superior nature of sarcasm is perceived as more hurtful than a plain-spoken criticism. The Greek root for sarcasm, sarkazein, means to tear flesh like dogs.

According to Haiman, dog-eat-dog sarcastic commentary is just part of our quest to be cool. “You’re distancing yourself, you’re making yourself superior,” Haiman says. “If you’re sincere all the time, you seem naive.”

Sarcasm is also a handy tool. Most of us go through life expecting things to turn out well, says Penny Pexman, a University of Calgary psychologist who has been studying sarcasm for more than 20 years. Otherwise, no one would plan an outdoor wedding. When things go sour, Pexman says, a sarcastic comment is a way to simultaneously express our expectation as well as our disappointment. When a downpour spoils a picnic and you quip, “We picked a fine day for this,” you’re saying both that you had hoped it would be sunny and you’re upset about the rain.

We’re more likely to use sarcasm with our friends than our enemies, Pexman says. “There does seem to be truth to the old adage that you tend to tease the ones you love,” she says.

But among strangers, sarcasm use soars if the conversation is via an anonymous computer chat room as opposed to face to face, according to a study by Jeffrey Hancock, a communications professor at Cornell University. This may be because it’s safer to risk some biting humor with someone you’re never going to meet. He also noted that conversations typed on a computer take more time than a face to face discussion. People may use that extra time to construct more complicated ironic statements.

Kids pick up the ability to detect sarcasm at a young age. Pexman and her colleagues in Calgary showed children short puppet shows in which one of the puppets made either a literal or a sarcastic statement. The children were asked to put a toy duck in a box if they thought the puppet was being nice. If they thought the puppet was being mean, they were supposed to put a toy shark in a box. Children as young as 5 were able to detect sarcastic statements quickly.

Pexman said she has encountered children as young as 4 who say, “smooth move, mom” at a parent’s mistake. And she says parents who report being sarcastic themselves have kids who are better at understanding sarcasm.

There appear to be regional variations in sarcasm. A study that compared college students from upstate New York with students from near Memphis, Tennessee, found that the Northerners were more likely to suggest sarcastic jibes when asked to fill in the dialogue in a hypothetical conversation.

Northerners also were more likely to think sarcasm was funny: 56 percent of Northerners found sarcasm humorous while only 35 percent of Southerners did. The New Yorkers and male students from either location were more likely to describe themselves as sarcastic.

There isn’t just one way to be sarcastic or a single sarcastic tone of voice. In his book, Haiman lists more than two dozen ways that a speaker or a writer can indicate sarcasm with pitch, tone, volume, pauses, duration and punctuation. For example: “Excuse me” is sincere. “Excuuuuuse me” is sarcastic, meaning, “I’m not sorry.”

According to Haiman, a sarcastic version of “thank you” comes out as a nasal “thank yewww” because speaking the words in a derisive snort wrinkles up your nose into an expression of disgust. That creates a primitive signal of insincerity, Haiman says. The message: These words taste bad in my mouth and I don’t mean them.

In an experiment by Patricia Rockwell, a sarcasm expert at the University of Louisiana at Lafayette, observers watched the facial expressions of people making sarcastic statements. Expressions around the mouth, as opposed to the eyes or eyebrows, were most often cited as a clue to a sarcastic statement.

The eyes may also be a giveaway. Researchers from California Polytechnic University found that test subjects who were asked to make sarcastic statements were less likely to look the listener in the eye. The researchers suggest that lack of eye contact is a signal to the listener: “This statement is a lie.”

Another experiment that analyzed sarcasm in American TV sitcoms asserted that there’s a “blank face” version of sarcasm delivery.

Despite all these clues, detecting sarcasm can be difficult. There are a lot of things that can cause our sarcasm detectors to break down, scientists are finding. Conditions including autism, closed head injuries, brain lesions and schizophrenia can interfere with the ability to perceive sarcasm.

Researchers at the University of California at San Francisco, for example, recently found that people with frontotemporal dementia have difficulty detecting sarcasm. Neuropsychologist Katherine Rankin has suggested that a loss of the ability to pick up on sarcasm could be used as an early warning sign to help diagnose the disease. “If someone who has the sensitivity loses it, that’s a bad sign,” Rankin says. “If you suddenly think Stephen Colbert is truly right wing, that’s when I would worry.”

Many parts of the brain are involved in processing sarcasm, according to recent brain imaging studies. Rankin has found that the temporal lobes and the parahippocampus are involved in picking up the sarcastic tone of voice. While the left hemisphere of the brain seems to be responsible for interpreting literal statements, the right hemisphere and both frontal lobes seem to be involved in figuring out when the literal statement is intended to mean exactly the opposite, according to a study by researchers at the University of Haifa.

Or you could just get a sarcasm detection device. It turns out scientists can program a computer to recognize sarcasm. Last year, Hebrew University computer scientists in Jerusalem developed their “Semi-supervised Algorithm for Sarcasm Identification.” The program was able to catch 77 percent of the sarcastic statements in Amazon purchaser comments like “Great for insomniacs” in a book review. The scientists say that a computer that could recognize sarcasm could do a better job of summarizing user opinions in product reviews.

The University of Southern California’s Signal Analysis and Interpretation Laboratory announced in 2006 that their “automatic sarcasm recognizer,” a set of computer algorithms, was able to recognize sarcastic versions of “yeah, right” in recorded telephone conversations more than 80 percent of the time. The researchers suggest that a computerized phone operator that understands sarcasm can be programmed to “get” the joke with “synthetic laughter.”

Now that really would be a useful invention. Yeah, right.