implementing mma's InverseFunction

50 views
Skip to first unread message

Kelvin Li

unread,
Apr 12, 2011, 1:43:25 PM4/12/11
to sage-devel
Hello Sage Devs!

Is anybody working on implementing something similar to mathematica's
InverseFunction? Or is there already a trac ticket out there? If there
is interest and it is not on trac, I can open a ticket.

Here is the link to mma's docs on InverseFunction:

http://reference.wolfram.com/mathematica/ref/InverseFunction.html

The question of finding the inverse to a given callable symbolic
function has popped up a few times. In the cases that I have seen, it
seems that Sage does not have this sort of feature. Here is one
instance from AskSage:

http://ask.sagemath.org/question/502/can-sage-compute-the-inverse-of-a-function

Anybody know what is being done (or has been done)?

-- Kelvin

Burcin Erocal

unread,
Apr 14, 2011, 4:03:22 AM4/14/11
to sage-...@googlegroups.com
Hi Kelvin,

I don't think anybody is working on this. Feel free to open a ticket
and give the link to the MMA documentation in the description. A full
solution to this would probably require adding an attribute to all
symbolic functions to point to their inverses.

Are you interested in working on this? I could try to explain how to go
about this in more detail if there is interest.

Cheers,
Burcin

Kelvin Li

unread,
Apr 14, 2011, 4:09:10 PM4/14/11
to sage-devel
On Apr 14, 1:03 am, Burcin Erocal <bur...@erocal.org> wrote:
> Hi Kelvin,
>
> On Tue, 12 Apr 2011 10:43:25 -0700 (PDT)
>
>
>
> Kelvin Li <ltwis...@gmail.com> wrote:
> > Is anybody working on implementing something similar to mathematica's
> > InverseFunction? Or is there already a trac ticket out there? If there
> > is interest and it is not on trac, I can open a ticket.
>
> > Here is the link to mma's docs on InverseFunction:
>
> >http://reference.wolfram.com/mathematica/ref/InverseFunction.html
>
> > The question of finding the inverse to a given callable symbolic
> > function has popped up a few times. In the cases that I have seen, it
> > seems that Sage does not have this sort of feature. Here is one
> > instance from AskSage:
>
> >http://ask.sagemath.org/question/502/can-sage-compute-the-inverse-of-...
>
> > Anybody know what is being done (or has been done)?
>
> I don't think anybody is working on this. Feel free to open a ticket
> and give the link to the MMA documentation in the description. A full
> solution to this would probably require adding an attribute to all
> symbolic functions to point to their inverses.

This is now #11202 (http://trac.sagemath.org/sage_trac/ticket/11202).

> Are you interested in working on this? I could try to explain how to go
> about this in more detail if there is interest.

Thanks Burcin, I will give it a shot. I have never hacked Sage before
(or any large software project, for that matter), so expect lots of
mistakes from me. :-)

Is there something I should be aware of before I dive into the
symbolics code? I am imagining adding an `inverse` method to the
symbolic functions classes, wherever that may be. In the end, I also
imagine being able to find the inverses of vector functions (but both
input and output must have the same number of dimensions).

Would it be okay to call Sage's `solve` function to find the inverse,
or would there be problems with that?

> Cheers,
> Burcin

Kelvin Li

unread,
Apr 23, 2011, 4:22:47 AM4/23/11
to sage-devel
This thread has been dormant for a while, but I thought it would be
worth mentioning that I found a way to find the inverse of symbolic
expressions in one variable, using the "roots" method. See my latest
answer at:

http://ask.sagemath.org/question/502/can-sage-compute-the-inverse-of-a-function

Even with this, I would like to find inverses of vector functions
(i.e. more than one variable). Not sure if this is possible yet with
the same approach of using "roots". The relevant Trac ticket is #11202
(http://trac.sagemath.org/sage_trac/ticket/11202).

Ideas? Comments?

-- Kelvin

Kelvin Li

unread,
Apr 23, 2011, 4:38:10 AM4/23/11
to sage-devel
> http://ask.sagemath.org/question/502/can-sage-compute-the-inverse-of-...
>
> Even with this, I would like to find inverses of vector functions
> (i.e. more than one variable). Not sure if this is possible yet with
> the same approach of using "roots". The relevant Trac ticket is #11202
> (http://trac.sagemath.org/sage_trac/ticket/11202).
>
> Ideas? Comments?
>
> -- Kelvin

A quick look at the code for the "roots" method shows that it simply
calls Maxima's "solve". Therefore, finding the inverse of vector
functions should be relatively easy to implement, using the same
approach.

Updating Trac ticket #11202 again...

-- Kelvin

Benjamin Jones

unread,
Apr 23, 2011, 1:44:48 PM4/23/11
to sage-devel
The `symbolic_inverse` function you posted on ask.sagemath looks good.
I might suggest catching the RuntimeError when no roots are found and
raising a more informative error, e.g. "Sage could not find a symbolic
inverse" ...

--
Benjamin Jones
benjami...@gmail.com

Kelvin Li

unread,
Apr 23, 2011, 5:17:34 PM4/23/11
to sage-devel
On Apr 23, 10:44 am, Benjamin Jones <benjaminfjo...@gmail.com> wrote:
> The `symbolic_inverse` function you posted on ask.sagemath looks good.
> I might suggest catching the RuntimeError when no roots are found and
> raising a more informative error, e.g. "Sage could not find a symbolic
> inverse" ...

I am thinking about directly using "solve()", rather than "roots()",
to implement "inverse()". That way I can raise my own exception.

Another consideration is whether we want to let "inverse()" itself be
representable as a symbolic expression. I need to learn about how this
works in Sage, but I am referring to the behavior of "integral()" when
it can't integrate something. For example:

sage: Ei(x).integral(x)
integrate(Ei(x), x)
sage: Ei(x).integral(x).diff(x)
Ei(x)

In the case of "inverse()", this might look like:

sage: f(x) = x + sin(x)
sage: f.inverse(x)
inverse(x + sin(x), x)
sage: f(f.inverse(x))
x + sin(x)

Then this can be used to allow Sage to apply the inverse function
theorem[1], for example.

I have a lot to learn about how symbolics works in Sage before I can
work on this. Maybe the easier route would be not to let inverse() be
representable as a symbolic expression and simply raise an exception
if Maxima's "solve()" fails. Later down the line, I might be able to
do something fancier.

I would like to know whether letting inverse() "play" with the
symbolics as outlined above is desirable.

[1] http://en.wikipedia.org/wiki/Inverse_function_theorem

-- Kelvin
Reply all
Reply to author
Forward
0 new messages