2
$\begingroup$

I want to build a table of InverseFunctions, f.e.:

Table[InverseFunction[Head[foo][#] &][x], {foo, {Sin[x], Log[x], Sqrt[x]}}]

{ArcSin[x], E^x, Power(-1)[x]}

I' m frustrated by the fact that Sqrt[x] evaluates to Power ... instead of x^2. As a temporary fix I have written:

Table[InverseFunction[(Head[foo] /. Power -> Sqrt)[#] &][x], {foo, {Sin[x], Log[x], Sqrt[x]}}] 

which gives the desired result:

{ArcSin[x], E^x, x^2}

I would like to find a more general and reliable way to prevent this kind of "Head-Substitution". I tried many things with HoldForm etc., but to no avail.

Thanks for your ideas

$\endgroup$
4
$\begingroup$

If you use ToString, make sure you specify InputForm (compare ToString[1/x] v.s. ToString[1/x, InputForm]).

Why not something like this?

pureify[f_, x_] := Function @@ {f /. x -> #}

Table[InverseFunction[pureify[foo, x]][x], {foo, {Sin[x], Log[x], Sqrt[x]}}]

(* {ArcSin[x], E^x, x^2} *)
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ Magnificent and exactly what I was hoping for :) $\endgroup$ – eldo Aug 6 '14 at 18:12
1
$\begingroup$

Thanks to @hieron suggestion to start with the "pure" heads I found this solution:

GetHeads[fun_] := ToExpression@First@StringSplit[ToString[fun], "["]

f = GetHeads /@ {Sin[x], Log[x], Sqrt[x]}

{Sin, Log, Sqrt}

Table[InverseFunction[foo[#] &][x], {foo, f}]

{ArcSin[x], E^x, x^2}

| improve this answer | |
$\endgroup$
1
$\begingroup$

Without "Head-Substitution", you may achieve it:

inv = InverseFunction /@ {Sin, Log, Sqrt}
x // inv // Through

out:

{ArcSin[x], E^x, x^2}

Edit1:

Yes, to get rid of the arguments I just wanted to suggest you

inv = InverseFunction /@ 
  ToExpression /@ (StringTake[#, {1, -4}] & /@ToString /@ {Sin[x], Log[x], Sqrt[x]})
x // inv // Through

But I was not so happy with StringTake, you got the more general way finally

| improve this answer | |
$\endgroup$

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.