We’ve all met people who have managed to be happy after a loss, or been through what appears to be an unbearable situation—a long illness in the family, for instance, or a forced separation. When such people share the details about how they hung on to happiness, or reclaimed it, each reaches for the tools of their craft. Filmmakers make films. Masterful writers like Joan Didion and Julian Barnes write haunting, leveling memoirs.

It’s fitting then that Mo Gawdat, chief business officer at Google X, the tech giant’s “moonshot factory,” and an engineer to the core, turned to an equation when his 21-year-old son, Ali, died unexpectedly during a routine appendectomy. Now he’s sharing his model with the world, not only the bereaved, in a hybrid memoir and self-help book, Solve for Happy. His personal moonshot goal is to make 10 million people happier, as a tribute to his son.

As he writes in the book, Gawdat had struggled with depression even before 2014, when Ali died at a hospital in Dubai, the Egyptian family’s adopted home. (A needle of carbon dioxide, usually used to create space in the abdominal cavity, was pushed too deeply into the young man’s body, entering a main artery.) Years before that, Gawdat had made efforts to learn from psychology experiments, books, and documentaries why happiness was eluding him, even as he earned fortunes as an engineer and software developer, and started a family. This part of his story is familiar: like others, he learned through experience what surveys have already demonstrated, that after a person’s needs are met, more wealth won’t lead to more happiness. If anything, the causal relationship is reversed: being happy makes people more productive and successful, he notes, citing research from the University of Warwick.

One day, in a conversation about his persistent depression with his mother, Gawdat recognized a flaw in his thinking about happiness. He had been using the wrong parameters in his approach; happiness wasn’t something that a person arrived at as a sum of other accomplishments. He explains:

In algebra, equations can be solved in many ways. If A = B + C, for example, then B = A– C. If you try to solve for A, you would look for the values of the other two parameters— B and C— and if you tried to solve for B, you would be taking different steps. The parameter you choose to solve for drastically changes your approach to the solution. The same is true when you decide to solve for happy.

The equation that Gawdat came to—working with Ali, as he told The Guardian— was this: “happiness is greater than or equal to your perception of the events in your life, minus your expectation of how life should behave.”

Courtesy Inkwell Management Mo Gawdat

In brief, Gawdat believes that our default emotion (again, when we’re not hungry and not in danger) is happiness. However, as we mature, life conspires to gum up our data processors—our brains—with elaborate illusions about what we should be doing, what happiness would look like, what matters. “Parental or societal pressure, belief systems, and unwarranted expectations come along and overwrite some of the original programming,” he proposes.

This leads to confusion, unhappiness, and pain, a state of affairs that Gawdat says can be essentially “debugged” through clearer thinking and a Zen-like understanding of the “now” we’re always within. His happiness equation allows a person to clearly identify the ill-conceived expectations that are casting shadows on what life is actually like. In fact, Solve For Happy doesn’t discuss happiness directly, he explains; instead, it’s a manual for ending suffering so a person can return to a natural state of deeper, foundational happiness.

Like Sheryl Sandberg, who recently wrote about the grief of losing her husband, he sees happiness, or the reduction of suffering, as a choice, and he chose to refocus on the happiness equation when his son died. The pain he feels for his lost son will always last, he writes, but he doesn’t live with thoughts that circle and deepen that anguish. He calls this tactic a commitment, and one that takes continuous effort, in the same way we need exercise to stay in top form. The work is in constantly solving the happiness equation, literally comparing expectations to what’s real every day, and, hopefully, in time, reaching a state of calmness and wellbeing.

[Joy] emerges, first and foremost, from a deep understanding of the exact topology of life. It comes as a result of having analyzed the Happiness Equation from a 20,000-feet view and completely grasped that life, with its mighty wheels of motion, always behaves as it always has and always will.

The way the book is packaged—with its cute illustrations, arrows, and captions that shout “remember this!” —may not suit everyone’s taste. But Gawdat’s thinking and methodic analysis of our brain’s design and blind spots, divine intervention (or lack of any), the possibility of an afterlife, and what he calls the five ultimate truths, is compelling and convincing. He pulls from a range of schools of thought and faiths, including Taoism, Islam, and philosophy and metaphysics, to construct his arguments.

The writing itself is strongest, however, when Gawdat is remembering Ali, and when he relays the internal conversations he still has with his son, a sometimes teasing teacher. Here, we see Gawdat’s pain, and how the equation is applied (the italics are his and indicate Ali’s imagined voice):

No one should die at such a young age. Is that true? Youngsters die by the thousands every hour of every day.

My life will stop with yours. Oh, is that true? Life stops for nobody. You’re here until it’s your time to go. You’d better behave with that in mind.

And later: