Researchers from University College London developed the equation after observing a group of study participants play a game involving monetary risks and rewards. They then used the equation to analyze data from more than 18,000 people around the globe, collected through a smartphone app.

The data was all about what made these people happy on a moment-by-moment basis, including how they felt and what they were thinking before feeling happy. And the equation the researchers constructed, they believe, was able to successfully predict the factors leading to their a significant percentage of the time.

And here it is:

After all the complex analyses, it really all comes down to what we expect and how strongly we expect it.

According to cognitive and computational Robb Rutledge, lead author of the study, sometimes happiness results from following the ’s maxim: Keep your expectations low, and if they’re exceeded then you’ll be pleasantly surprised.

“Life is full of expectations," he says. "It would be difficult to make good decisions without knowing, for example, which restaurant you like better. It is often said that you will be happier if your expectations are lower. We find that there is some truth to this: Lower expectations make it more likely that an outcome will exceed those expectations and have a positive impact on happiness.”

On the other hand, Rutledge says, sometimes we feel happy well before we know the outcome: “If you have plans to meet a friend at your favorite restaurant, those positive expectations may increase your happiness as soon as you make the plan. The new equation captures these different effects of expectations and allows happiness to be predicted based on the combined effects of many past events.”

The research team combined their analysis with results of functional MRI scans of the original study participants’ brains, in an attempt to correlate happiness-resulting decisions with activity in certain brain areas. They found significant activity in two brain areas known to play a major role in seeking rewards and feeling strong emotion—the ventral striatum and the insular cortex.

Expectations are really just the business end of our brain’s reward-targeting shotgun. Both the setting of expectations and their achievement triggers a whole lot of (the so-called “reward neurotransmitter”) to cascade through tightly packed receptors in the brain’s reward center—of which the ventral striatum is a central part.

That understanding jibes nicely with this study’s findings that merely thinking about an expectation sparks elevated feelings. Achieving or exceeding the expectation leads to even more dopamine activity, and, consequently, even higher emotion.

And, somehow, all of that can be captured in an equation. Who said math isn’t useful?

The study was published in the Proceedings of the National Academy of Sciences.

You can find David DiSalvo on Twitter @neuronarrative and at his website The Daily Brain. His latest book is Brain Changer: How Harnessing Your Brain’s Power To Adapt Can Change Your Life.