Grandmasters decline with age. That's a given. There is nothing special about the age of 40, but age eventually takes its toll. That much is clear. Beyond that, it's about how long you can put off the effects and compensate for them. Mistakes will crop in, but you try to compensate for them with experience and hard work.
The broader the chess player you are, the easier it is to be competitive, and the same seems to be true of mathematics - if you can find links between different branches of mathematics, it can help you resolve problems. In both mathematics and chess, you study existing theory and use that to go forward.