Problem with `Derivative`/`Series` and `InverseFunction`
The problem with using an anonymous pure function inside of InverseFunction
is that you get nested anonymous pure functions when evaluating the second derivative. Compare the following 2 TracePrint
outputs:
TracePrint[InverseFunction[Function[x, Log[x]+Exp[x]]]'', Derivative[1][_]];
TracePrint[InverseFunction[Log[#]+Exp[#]&]'', Derivative[1][_]];
((1/(Function[x,Log[x]+Exp[x]]^[Prime])[InverseFunction[Function[x,Log[x]+Exp[x]]][#1]]&)^[Prime])
((1/((Log[#1]+Exp[#1]&)^[Prime])[InverseFunction[Log[#1]+Exp[#1]&][#1]]&)^[Prime])
Notice how the the first trace output has a mixture of x
and #1
, while the second trace output replaces x
with #1
. The latter trace is an example of a nested pure function using anonymous pure functions, which is why it doesn't work. The issue of nested anonymous pure functions has come up before, see:
- Is anonymous pure function a scoping construct?
- Pure function inside another pure function
Addendum
You also ask:
So, what's the best way to get the
Series
of that (and other similar) function?
Instead of taking the series of the inverse function, you can apply InverseSeries
to the series expansion of the function. For example:
InverseSeries @ Series[Log[x]+Exp[x], {x, 1, 2}] //TeXForm
$1+\frac{x-e}{1+e}-\frac{(e-1) (x-e)^2}{2 (1+e)^3}+O\left((x-e)^3\right)$
Series[
InverseFunction[Function[x, Log[x]+Exp[x]]][x],
{x, E, 2}
] //TeXForm
$1+\frac{x-e}{1+e}+\frac{(1-e) (x-e)^2}{2 (1+e)^3}+O\left((x-e)^3\right)$
For clarity, I used an expansion point of 1 for the function, which corresponds to an expansion point of E
for the inverse function. To get the expansion of the inverse function around 1 you could do:
pt = x /. First @ Solve[Log[x] + Exp[x]==1 && 0<x<1, x];
Simplify[
InverseSeries @ Series[Log[x] + Exp[x], {x, a, 1}],
Exp[a]+Log[a]==1
] /. a->pt //TeXForm
$\operatorname{Root}\left[\left\{e^{\#1}+\log (\#1)-1\&,0.51222243303322994816075176697026116734`20.304437036448245\right\}\right]+\frac{x-1}{e^{\operatorname{Root}\left[\left\{e^{\#1}+\log (\#1)-1\&,0.51222243303322994816075176697026116734`20.304437036448245\right\}\right]}+\frac{1}{\operatorname{Root}\left[\left\{e ^{\#1}+\log (\#1)-1\&,0.51222243303322994816075176697026116734`20.304437036448245\right\}\right]}}+O\left((x-1)^2\right)$
which yields the same result:
Series[
InverseFunction[Function[x, Log[x]+Exp[x]]][x],
{x, 1, 1}
] //TeXForm
$\operatorname{Root}\left[\left\{e^{\#1}+\log (\#1)-1\&,0.5122224330332299481607867201842576827690521506497275993993`30.\right\}\right]+\frac{x-1}{e^{\operatorname{Root}\left [\left\{e^{\#1}+\log (\#1)-1\&,0.5122224330332299481607867201842576827690521506497275993993`30.\right\}\right]}+\frac{1}{\operatorname{Root}\left[\left\{e^{\#1}+\log (\#1)-1\&,0.5122224330332299481607867201842576827690521506497275993993`30.\right\}\right]}}+O\left((x-1)^2\right)$
InverseFunction
and Derivative[1]
operate on functions. So, supply them with functions:
h=.
f = InverseFunction[h];
f'[x]
Derivative[1][h][InverseFunction[h][x]]^(-1)
In your case, this leads to:
h = x \[Function] Log[x] + Exp[x];
f'[x]
1/(E^InverseFunction[Function[x, Log[x] + Exp[x]]][x] + 1/ InverseFunction[Function[x, Log[x] + Exp[x]]][x])
Now also Series
works. I use machine precision numbers in order to make the output readible:
Series[f[x], {x, 1., 4}] // TeXForm
$$0.512222+0.276146 (x-1.)+0.0225572 (x-1.)^2-0.0123554 (x-1.)^3-0.0000787926 (x-1.)^4+O\left((x-1.)^5\right)$$