I recently tried figuring out the math behind Gimp's Colour Erase blend mode (basically the same as the Colour to Alpha filter), and this is what I ended up with:
[C++ Code]
[Detailled explanations of how it works.]
The gist of it is: With a fully opaque bottom layer, Normal Blend is just a linear interpolation. With both layers fully opaque, Colour Erase is the inverse operation of that Normal Blend.
In your colour space of choice, trace a line that passes through both the Top and Bottom colours. Starting from Bottom, walk that line away from Top until it you meet the border of the unit cube (i.e, the limit your colour gamut). That point is your resulting colour. Its opacity is the proportion of the distance top-bottom, compared to the distance top-result.