Simplifying expression involving total derivatives

I'm trying to simplify expressions involving partial derivatives of an abstract functions. To obtain the human readable result, I would like to gather terms of total derivatives and hold on differentiation

$$\frac{\partial f(x,y)}{\partial y}g(x,y) + f(x,y)\frac{\partial g(x,y)}{\partial y} = \partial_y\left(f(x,y)g(x,y) \right).$$

I've tried to define transformation function

transform[expr_, var_] :=
With[{int = Integrate[expr, var]}, Defer[D[int, var]]]


which, when applied to some simple cases does exactly what is expected, e.g.

D[f[x, y] g[x, y], y] //
Simplify[#,
TransformationFunctions -> {transform[#, x] &, transform[#, y] &}] &

(* ===> D[f[x, y] g[x, y], y] *)


For a slightly more complicated expression (which is of my interest here) this approach fails

D[f[x, y] g[x, y], y] + D[f[x, y] g[x, y], x] //
Simplify[#,
TransformationFunctions -> {transform[#, x] &, transform[#, y] &}] &

(* ===> D[g[x, y], x]*f[x, y] + D[g[x, y], y]*f[x, y] +
D[f[x, y], x]*g[x, y] + D[f[x, y], y]*g[x, y] *)


Is there any other way to deal with such expression simplification? I'm aware of (22029) (22014), but posted answers do not give the full answer in this particular case.

-
The examples all look like you want nothing at all to happen. I don't understand your goal. E.g., what about D[(f[x, y] g[x, y])^2, y]? Do you want that to stay unevaluated, too? –  Jens Jul 23 at 0:11
Just have a look on nontrivial case (the second example). –  mmal Jul 23 at 6:50
add comment

2 Answers

Are you looking for this result:

D[f[x, y] g[x, y], y] + D[f[x, y] g[x, y], x] // Simplify[#,
TransformationFunctions -> {Automatic, transform[#, x] &,
transform[#, y] &}] &


TransformationFunctions replaces the internal rules, so if you want to preserve them you have to add Automatic into the list. Hoping this helps.

-
This only factors out derivative terms (D[g[x, y], x] + D[g[x, y], y])* f[x, y] + (D[f[x, y], x] + D[f[x, y], y])* g[x, y], I would like to get D[f[x, y] g[x, y], y] + D[f[x, y] g[x, y], x] in this example. –  mmal Jul 23 at 15:07
add comment

Would it be acceptable to simplify the expression without evaluating the derivatives in the first place?

SetAttributes[simp, HoldFirst]
simp[expr_] := Block[{D}, Defer @@ {Simplify@expr}]

simp[x^2 + 2 x + 1 + D[f[x, y] g[x, y], y]]
(*  (1 + x)^2 + D[f[x, y]*g[x, y], y]  *)

simp[x^2 + 2 x + 1 + D[f[x, y] g[x, y], y] + D[f[x, y] g[x, y], x]]
(*  (1 + x)^2 + D[f[x, y]*g[x, y], x] + D[f[x, y]*g[x, y], y]  *)


I included the polynomial term to demonstrate that Simplify is working as expected on parts of the expression which are not derivatives.

-
Unfortunately no, simply because expression under consideration has evaluated derivatives yet :/ –  mmal Nov 11 at 16:35
@mmal, I'm not sure what you're trying to do. In both of your examples your desired result is exactly the same as the input. It would be useful to include an example where the transformation actually changes the expression. –  Simon Woods Nov 11 at 19:27
add comment