2
$\begingroup$

So, I have my function, such as

f[x_,y_]:=(1-x/y)^(1/2);

This function enters a big expression that contains variables x and y, as well as the function f. Now I have to differentiate that expression with respect to either x or y (or both). Evaluating the result, Mathematica will substitute each occurrence of f[x,y] with the definition above. For this particular function, its derivative will involve the factor of

(1-x/y)^(-1/2),

i.e.

1/f[x,y].

When simplifying the result, how can I tell Mathematica to use this fact? I know there options to Simplify like TransformationFunctions, ExludedForms, ComplexityFunction, but the information and examples of the beginner-level on these options are rather scarce.

ADDENDUM

I think first I should have asked a simpler question.

In[1]:= Simplify[G m/r^2, G m == A]

Out[1]= A/r^2

But:

In[2]:= Simplify[G m/r^2, G m/r^2 == A]

Out[2]= G m/r^2

Why is output not simply A?

$\endgroup$
  • 1
    $\begingroup$ very closely related: 3822 $\endgroup$ – yohbs Nov 6 '17 at 15:18
4
$\begingroup$

Instead of giving a DownValues for f, you could give definitions for it's derivative:

Clear[f];
f /: Derivative[1, 0][f] = -1/(2 f[#1, #2] y)&;
f /: Derivative[0, 1][f] = x / (2 f[#1, #2] y^2)&;

Then, the following derivatives use f[x, y] in the output:

D[f[x, y], x] //TeXForm

$-\frac{1}{2 y f(x,y)}$

D[f[x, y], y] //TeXForm

$\frac{x}{2 y^2 f(x,y)}$

D[f[x, y] y + f[x, z] x + f[y, x] z, x] //TeXForm

$\frac{x z}{2 y^2 f(y,x)}-\frac{x}{2 y f(x,z)}-\frac{1}{2 f(x,y)}+f(x,z)$

$\endgroup$
  • $\begingroup$ Interesting that you get the higher derivatives for free; D[f[x, y], {x, 2}]. $\endgroup$ – Edmund Nov 6 '17 at 21:57
  • $\begingroup$ Is there a more general way? I gave a particular example, but I need a general solution, when I have f[x_, y_]:=whatever function of x and y, and I want to replace in a given expression each combination of x and y that yields this function with the symbol f. $\endgroup$ – ThisGuy Nov 7 '17 at 3:54
3
$\begingroup$

You can define f this way

frule = {f -> (Sqrt[1 - #1/#2] &)}

Then use it in any expression, such as

D[f[x, y], x] + f[x, y] /. frule
(*Sqrt[1-x/y]-1/(2 y Sqrt[1-x/y])*)
$\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.