2
$\begingroup$

Let's say I have a function $f$ and it's inverse $f^{-1}$

Say I don't know how to define either explicitly but I know one thing, and that is that $f$ is it's own inverse.

$$f( f(x) ) = x$$

Mathematica is quite capable of manipulating expressions where functions are only referred to by name, but I wish it to also use the above information when doing so.

How do I define such to Mathematica?

$\endgroup$

2 Answers 2

5
$\begingroup$

Why not just this:

f[f[x_]] := x

Whenever f[f[something]] is encountered, it's replaced by something.

f[1]
(* f[1] *)

f[f[1]]
(* 1 *)

f[f[f[1]]]
(* f[1] *)

f[f[x_]] := x is a rule to replace f[f[x_]] by x whenever this pattern occurs.

$\endgroup$
-1
$\begingroup$

Example:

f[x_] := x^2;

fInverse[y_] := Solve[f[x] == y, x]

fInverse[y]

{{x -> -Sqrt[y]}, {x -> Sqrt[y]}}

f[fInverse[x]]

(* {{(x -> 0)^2}, {(x -> 1)^2}} *)

Or

x /. f[fInverse[x]][[2, 1, 1]]

(* 1 *)

(There is no unique inverse when $x^2 = (-x)^2$.)

but you can try the above with f[x_]:= 3 x + 8, for example.

$\endgroup$
1
  • 1
    $\begingroup$ The function $f(x) = x^2$ is not its own inverse. $\endgroup$
    – march
    Commented Feb 25, 2017 at 4:55

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.