Sometimes, you just feel like you're more 'on it' than normal: you're in the zone, you're on the ball, you're in the flow of whatever it is you're doing at the time, whether it's working late in the office or working out at the gym.

Now scientists have come up with a mathematical formula that represents this state of flow, which could potentially be applied in everything from developing artificial intelligence in machines to personal coaching for humans.

"Our theory says that the more informative a means is, the more flow someone will experience while performing it," says social psychologist David Melnikoff from Northeastern University in Massachusetts.

"The formula is a way of mathematically quantifying exactly how informative a particular means happens to be."

There are three variables in this formula: M (the means, the successful action achieved in the hopes of reaching a goal), E (the ends, the outcome of pursuing the goal), and I (the mutual information, the degree to which using the means reduces the uncertainty of the ends).

Put together, that looks like I(M;E). The researchers say that our flow is maximized when the mutual information we have about how the means will affect the ends is highest – in other words, when we know more about how our actions will impact our goals.

If you're completely lost at this point, here's an example. Say your goal (ends) is losing weight, and the way you want to do it (means) is jogging – the mutual information part is to do with how often you jog and how far you run.

If you have more information about how the means will affect the ends – so precisely how much jogging will shed how much weight, in this case – you're more likely to be fully immersed and fully engaged in what you're doing.

Or, take a game of darts: Imagine having to hit a bullseye (the means) to win a game (the ends). When the mutual information is highest (you know a hit will win the game), you're more likely to be in the zone; when it's lower (a hit may or may not win the game), you're less likely to be.

Consider the Peloton treadmills and exercise bikes, which bombard you with information about means and ends. You get detailed readouts of your performance through the supplied software, as well as links to leaderboards that show how you're doing compared to everyone else who's online at the same time.

"There are thousands of positions on the leaderboard where a rider could finish – thousands of possible end states – and the rider's performance reveals which of these end states will occur," says psychologist Ryan Carlson from Yale University in Connecticut.

"That is a lot of information, far more than you'd normally get from a workout. When is the last time exercising allowed you to rule out literally thousands of possible end states?"

The team behind the formula says it could potentially enhance flow in any task, whether that's creating a work of art, playing a sport, or trying to get through a mountain of paperwork before the end of the working day.

Of course, personal interest, talent, and skills still play an important role. Someone who has no knack for gardening and no interest in it won't suddenly become a master gardener because they have more information about the means and ends, for example.

The researchers say their computational theory of flow might be helpful in a variety of scenarios: Bosses wanting to maximize employee performance perhaps, or software developers looking to build machines that are as efficient as humans are in flow states.

"These principles underlying flow may be unconscious but they are not random – and work within a biological system that can be described in mathematical terms," says Melnikoff.

The research has been published in Nature Communications.