Reputation: 331
Input:
f[x_] := Sqrt[x^2 + y^2]
f'[x]
Output:
x / Sqrt[x^2 + y^2]
How do I get Mathematica to replace the denominator by f[x]
itself? (Note: this is a simple example of a more complicated differentiation problem, in which the function itself is complicated but shows up a lot in the derivative.)
That is, desired Output is:
x / f[x]
I tried
Simplify[f'[x], TransformationFunctions -> {f}]
but to no avail. Any help is appreciated!
Upvotes: 0
Views: 1014
Reputation: 4976
I think you can do it like this:
Clear[f,g]
g[expr_]:=expr/.(x_^2+y_^2):> (f[x])^2
Simplify[D[Sqrt[x^2+y^2],x],TransformationFunctions->{Automatic,g},Assumptions->f[x]>0]
it will give x/f[x]
as a result.
Upvotes: 1
Reputation: 1242
I think it's very hard to do this in general; in your specific example one can use a rule such as
rules = {z_^2 + y^2 -> Hold[f[z]^2]};
and then
f'[x] /. rules
(* x/Sqrt[Hold[f[x]^2]] *)
f''[x] /. rules
(* -(x^2/Hold[f[x]^2]^(3/2)) + 1/Sqrt[Hold[f[x]^2]] *)
Working with the square root is more difficult and I think one rule is not enough, the basic reason being :
Sqrt[x^2 + y^2] // FullForm
1/Sqrt[x^2 + y^2] // FullForm
Upvotes: 1