I'll tell you an open secret: Focusing very intently on difficult maths for an extended period of time can make almost anyone begin to experience aspects of mental illness.

The physics community has dealt with this, DOD code breakers deal with it, the manhattan project, etc. It's a well studied phenomena because of how it related to the war effort and much of the research documentation is declassified, in the public domain, and is a matter of the historical record.

My point is software development is just another domain where this research applies. This information is generally recognized by the pop culture as evidenced by the fact that there are several blockbuster movies about it, for example the film 'Pi' by Darren Aronofsky and 'A beautiful mind'. However this phenomena is generally not accepted by the startup community. I assume that the reason for this is because recognizing it could theoretically lead to a rise in insurance cases by engineers who developed serious mental illness over time due to prolonged exposure to what were known to be unsafe working conditions. In my opinion it should be thought of as a high risk job akin to scuba instructor, or roofer.

So the whole thing is swept under the rug. Never the less I will give my recommendations as a developer who works all the time and has wrestled with this phenomena in the past:

- Force yourself to hike/walk/bike outdoors for at least an hour per day. I'm convinced that merely jogging on a tread mill or gym excercise does not have the same benefit. Think of the outdoors (and the sun) as a relief valve for the "cabin fever" effect.

- A daily Zazen practice (15 minutes+) This is the kind of meditation from Japanese buddhism where you're not trying to accomplish or "do" anything, you just sit, in a good posture. I think of this as putting your overclocked CPU in hibernate mode long enough for the heat sync to do it's thing. I think this can provide a similar effect to having had a couple extra good hours of sleep, and all it costs is a few minutes of your day. The more you practice it, the better it works.

- healthy diet and exercise

- yoga (or just plain stretching)

- Do not under-estimate prolonged caffeine consumption as a likely co-factor for many symptoms. Always eliminate this as a possibility whenever you can

- As a relaxation excercise take a break during your day and spend a few minutes in a quiet place directing your attention to any area of your back, neck, shoulders, or even your face whereever you expereince a sensation of pressure or weight. Sometimes just stopping to pay attention that these muscle groups are becoming tense is enough to help them relax some.

- super mellow music at a low volume even if it's not what you prefer generally can help when writing software. Classical music, downtempo, ambient, chill-out, atomospheric drum and bass, even unusual stuff like gregorian chant. It can be slow and boring, after all it's less about entertainment and more about the cumulative effect it has on your brain when used as background music.

example of downtempo genre: https://www.youtube.com/watch?v=tYdebVcZDPw

soma.fm/groovesalad plays a good mix imho. There's good studies on this on mice. A good rule of thumb is asking yourself this question "could this song be characterized as 'intense' in any way ?" if so then save it for some other activity