6
$\begingroup$

Here is the Mathematica code I'm asking about:

fn = InverseFunction[ Log@#+Exp@#& ];
Print[  fn'                 [1.]]
Print[  D[fn[x],x]      /.x->1. ]
Print[  D[fn[x],{x,2}]  /.x->1. ]
Print[  fn''                [1.]]
Print[  D[D[fn[x],x],x] /.x->1. ]
Print[ Normal @ Series[fn@x, {x, 1., 1}] ]
Print[ Normal @ Series[fn@x, {x, 1., 2}] ]

Try it online!

As you can see:

fn is a function defined using InverseFunction. We can assume that this function has no closed-form.

It has first-order and second-order numerical derivative at the point 1, being 0.27614597273176456 and 0.04511431748742336 respectively.

However, calculate double derivative using Derivative (fn''[1.]) or Series (degree $\geq 2$) does not behave as expected, resolves to InverseFunction' object.

So, what's the best way to get the Series of that (and other similar) function?

$\endgroup$
  • $\begingroup$ Answers about the bug in particular (and whether is that a bug) is also welcome. $\endgroup$ – user202729 Dec 3 '17 at 14:18
4
$\begingroup$

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)$$

$\endgroup$
  • $\begingroup$ In conclusion: Anonymous function (#&) doesn't work, while explicit function (Function[y,y]) does work. Why? Is that a bug? They are both functions. $\endgroup$ – user202729 Dec 3 '17 at 14:00
  • $\begingroup$ Also the wrap around InverseFunction is unnecessary - just InverseFunction[...] instead of Function[x, InverseFunction[...][x]] works, InverseFunction is supposed to return a function. $\endgroup$ – user202729 Dec 3 '17 at 14:02
  • $\begingroup$ I have cleaned it up a bit. To my own surprise, lambda calculus seems not work. As a mathematician, I prefer Function anyway. It was actually the one thing that convinced me to use Mathematica... $\endgroup$ – Henrik Schumacher Dec 3 '17 at 14:06
  • $\begingroup$ If I were you, I would file that as a bug to Wolfram support. My impression used to be that lambda calculus and Function are supposed to be equivalent... $\endgroup$ – Henrik Schumacher Dec 3 '17 at 14:09
  • 1
    $\begingroup$ Moreover, I'd like to say that it would be more transparent for others if you would simply copy small code snippets directly into StackExchange... $\endgroup$ – Henrik Schumacher Dec 3 '17 at 14:32
5
$\begingroup$

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:

  1. Is anonymous pure function a scoping construct?
  2. 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)$

$\endgroup$
  • $\begingroup$ Thanks! - So it's Mathematica implementation (use pure function to represent derivatives) that makes this impossible? $\endgroup$ – user202729 Dec 3 '17 at 16:38
  • 1
    $\begingroup$ Isn't this a bug with handling pure functions by Derivative? $\endgroup$ – Alexey Popkov Dec 3 '17 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.