so is there a formula that can be automatically applied to restore the original colors? at least some reasonable approximation, based on the painting's age?

I seriously doubt it. Degradation would be in some part related to the conditions the painting was held in, which would be nearly impossible to backtrack outside of one-off case studies. Imagine a painting that was stuck in a room full of smoke -- or was put on some less than good backing paper/framing.

There has been some research on what causes degradation on paper/pigment but as far as I know much of it ends up as a mystery, a fact of time...

I would like to know that formula also. this can be an interesting tool to reveal true colors of paintings as the painters intended...