Fed up with jet lag when you fly long distances? University of Michigan mathematicians have your back. They’ve developed a free app, available today, based on mathematical models that can tell you when to go outdoors and when to stay in bed to avoid the sleepiness and other side effects of crossing multiple time zones quickly.

Jet lag occurs when you fall out of sync with your circadian rhythm, a biological cycle that lasts about 24 hours in humans and determines when we wake, sleep and eat, amongst a host of other things. The misalignment not only causes fatigue, it can also alter mood and impair performance. Repeated or chronic disturbances in the rhythm—as occurs in pilots and shift workers—have been linked to depression, heart diseases and diabetes. Minimizing the time you’re off schedule reduces those risks.

Advice on how to avoid jet lag abounds, although not all of it has been verified experimentally. What is certain is that light controls the circadian clock to a great extent. (The effect is mediated by special cells in the retina that are distinct from the eye’s rods and cones and tell the brain what time it is.) And exposure to light at different times can speed up or slow down the circadian clock. So knowing when to walk out in the daylight and when to envelop yourself in darkness will help you change your internal schedule to match the new time zone.

But how can you figure out exactly when those times are?

“That’s a question that can only be answered by mathematics,” says Daniel Forger, a mathematical biologist at the University of Michigan who studies biological clocks. Unlike an experiment in the lab, a mathematical model can test infinite possibilities to determine what to do to sync up as quickly as possible.

To calculate the best schedules for 1,000 possible trips, Forger and then-undergraduate Kirill Serkh combined two well-tested models of the effect of light on the human circadian system and then applied optimal control theory, a mathematical method to find ideal situations.

They found that you don’t need to take random naps or flash lights in your eyes, as some popular tips suggest. Surprisingly, you only need to alter the timing of what your eyes and brain perceive as dawn and dusk, results published today in the journal PLOS Computational Biology.

“We thought the answer would be extremely complicated: At 3:40, you need to get this much light, and at this time, you need to get this much,” says Forger. Instead, shifting your clock quickly just requires a new bedtime and long periods of bright light or complete darkness. These schedules significantly outperformed previous suggestions. Using this method, it takes only four days to fully sync after a 12-hour time zone shift. With other methods, it takes seven to 13 days or more. Even better, this method helps you “partially” sync in two days, which means you can sleep just fine.

Olivia Walch, a graduate student at the University of Michigan, then developed an iPhone app with the model, called Entrain, which allows users to set tailored schedules. First, you enter your normal sleep schedule and then choose the area you’re traveling to and the type of light you’ll be encountering on your trip (Are you hiking outdoors? Or attending an indoor conference?). The app then provides a custom schedule, telling you when you should be in the light or in the dark as well as how many days it will take to fully adjust.

Of course, you may not be able to head to bed when the app tells you to. But that’s okay, because it can automatically adapt its suggestions given your schedule. You tell it when you actually went to sleep and the kind of light exposure you had that day, and the app updates your future optimal dawn and dusk times.

The app also offers an opportunity for citizen science: Users can submit their data anonymously to the University of Michigan and answer survey questions about how well it worked and what symptoms of jet lag they experienced. The data would allow Forger and his team to see what people are actually doing when they go into different time zones and whether the schedules work in the real world. If users do so, “We’ll have a study of jet lag that has never been done before,” says Forger, who is now leading a project exploring the possible links between sleep deprivation and bipolar disorder.