# The composition of the logit function and its inverse is not numerically invariant to decimal places

I've defined the two following functions:

logit[x_] := Module[{},
Log[x/(1 - x)]
];
invLogit[x_] := Module[{},
E^x/(1 + E^x)
];


One is the inverse of the other. However,

In[37]:= logit[invLogit[34.55555]]

Out[37]= 34.6574


Is there a way to increase the precision of the calculations?

• logit[invLogit[34.5555520]]. – AccidentalFourierTransform Dec 2 '18 at 14:46
• @AccidentalFourierTransform thanks for the comment. However, if these functions have to receive a variable, how would I do then? e.g. logit[invLogit[s]], where s is some value computed in another function. – An old man in the sea. Dec 2 '18 at 14:48
• The inverse relationship is only valid for real values of x. Evaluate logit[invLogit[2 + 8 I]] // Simplify – Bob Hanlon Dec 2 '18 at 16:10

logit[x_] := Module[{}, Log[x/(1 - x)]];

The issue is that the gradient of logit approaches zero for large arguments. Therefore there is a loss of precision in evaluating it. Enforcing a larger precision calculation helps get back to where you started.
• Mikado, thanks for your answer. In the set precision command, is the $MaxExtraPrecision the best numerical approximation we can have in general terms in mathematica? – An old man in the sea. Dec 2 '18 at 15:22 • From the help for $MaxExtraPrecision` I don't think that it is relevant here. I think you can specify as many extra digits of precision as you need. – mikado Dec 2 '18 at 15:36