4
$\begingroup$

Run codes below

InverseFunction /@ {InverseFunction, List, Reverse, RotateLeft, RotateRight, Sequence}

and one is returned with

{InverseFunction^(-1), #1 &, #1 &, #1 &, #1 &, #1 &}

For the first one, at least a formal answer is given (even though I hoped it gave something like InverseFunction itself); however for the rest it does not make sense that an identity function is obtained.

Ideally, Reverse is the inverse function of itself, and RotateRight and RotateLeft are inverse functions to each other.

Is it a bug?

$\endgroup$
1
  • $\begingroup$ Since this behavior also appears in Mathematica 10.1 I am removing the version tag. $\endgroup$
    – Mr.Wizard
    Jul 25, 2018 at 6:55

1 Answer 1

2
$\begingroup$

I have never considered applying InverseFunction to Symbols such as these so I appreciate the question.

I hypothesize that, without a specifically defined inverse, the Symbol is tested on an arbitrary argument, e.g. Reverse[foo]. Since each of these heads do not actually do anything in such a case (other than issue a Message) they appear inert, and # & is a reasonable inverse of an inert function I suppose. Why this evaluation takes place rather than returning e.g. InverseFunction[Reverse] I don't know.

This idea seems plausible based the TracePrint, e.g.

InverseFunction[Reverse]; // TracePrint

(Reverse^(-1))

InverseFunction

Reverse

Reverse

Reverse[Solve`InvFVar[0]]

Reverse

Solve`InvFVar[0]

Solve`InvFVar

0

Solve`InvFVar[0]

Solve`InvFVar

0

#1&

Function

Wherein Solve`InvFVar[0] looks like the arbitrary argument I supposed.

$\endgroup$
4
  • $\begingroup$ Will it be possible to incorporate it as built-in functionality that, say, InverseFunction[RotateLeft] returns RotateRight in the future? $\endgroup$ Jul 26, 2018 at 6:46
  • $\begingroup$ @ΑλέξανδροςΖεγγ I am not a Wolfram Research developer, so if you are asking about "from the factory" functionality I have no idea. If you mean can one modify InverseFunction so that it will return that, yes, easily, but it may not be wise to do so. Try this if you care to: Unprotect[InverseFunction]; InverseFunction[RotateLeft] := RotateRight; InverseFunction[RotateRight] := RotateLeft; Protect[InverseFunction]; $\endgroup$
    – Mr.Wizard
    Jul 26, 2018 at 9:17
  • $\begingroup$ Wizard Is it possible to use something like UpSet or TagSet? $\endgroup$ Jul 26, 2018 at 9:38
  • $\begingroup$ @ΑλέξανδροςΖεγγ For Protected functions like RotateRight you would need to them (RotateRight) to use TagSet, but if you prefer that to unprotecting InverseFunction it's certainly an option. $\endgroup$
    – Mr.Wizard
    Jul 26, 2018 at 9:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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