# How to define a function like 1/f(x)

I'm trying to define a function f(x) such that 1/f(x) = 1/R - A/B. I know that I can just work the RHS out so that f(x) = C/D and then define it like that, but I was wondering if there was a way to directly define the function without simplification. In some cases it may be very difficult to simplify it to get a f(x) = form.

• Your code-formatted bits are not Mathematica code -- just to confirm, you want to do this is in the software Mathematica? Apr 22, 2021 at 0:59
• f[x_]:=1/(1/R - A/B) ? Apr 22, 2021 at 14:27
• @MichaelE2 yes its in Mathematica Apr 22, 2021 at 15:42
• @murray yes like I mentioned, this might not be simple to do in other situations so I wanted a way to define it directly Apr 22, 2021 at 15:42
• Are you looking for a function inverse or a reciprocal? Apr 23, 2021 at 0:18

You can use InverseFunction for this so long as your LHS is of the form g[f[x]]:

g[y_] := 1/y;
f[x_] := InverseFunction[g] @ (1/R[x] - A[x]/B[x])
f[x]


If InverseFunction[g] can be computed symbolically, then it might be more efficient to use immediate assignment for f instead (i.e, f[x_] = ) so that the inverse does not have to be re-computed each time you call f, but you'll need to be careful that x is not already defined then. You can use Block or Module to ensure this, if necessary:

Block[{x},
f[x_] = InverseFunction[g] @ (1/R[x] - A[x]/B[x])
]


If you don't like defining an axillary function g, you can use pure functions instead (e.g., InverseFunction[1/# &]).