# Using Collect to group derivatives together

Is there a way to combine derivatives that are a result from the product rule back together using Collect.

For example, I'd like to collect

x Dt[y,b] + y Dt[x,b]


back to

Dt[x y,b]


I can do this with a rule:

Rule = {x Dt[y,b] + y Dt[x,b] -> Dt[xy,b]};
x Dt[y,b] + y Dt[x,b]/.Rule


But this forces me to use a new variable: xy instead of the actual product of x and y. Moreover, I have many different rules to follow so typing all those out would be taxing. Has anyone else tried doing this and succeeded?

• Welcome to Mathematica.SE! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign!
– user9660
Commented Mar 9, 2016 at 17:23
• Note that Rule is a built-in Protected symbol. You shouldn't/can't use it as a variable. Commented Mar 9, 2016 at 17:36
• Thanks for the comment. I don't actually call it "Rule" in my code but I know that Mathematica warns about protected names. Commented Mar 9, 2016 at 17:42

Dt, by its nature, will apply the derivative rules until it can't. You could make it Inactive.

rule = {x Dt[y, b] + y Dt[x, b] -> Inactive[Dt][x y, b]};
x Dt[y, b] + y Dt[x, b] /. rule
(*  Inactive[Dt][x y, b]  *)


Some generic transformations:

With[{dt = Inactive[Dt]},
byparts = # /. Plus[f_ dt[g_, v_], rest___] :> Simplify[dt[f g, v] + rest - g dt[f, v]] &;
sum = # /. Plus[dt[f_, v_], dt[g_, v_], rest___] :> dt[f + g, v] + rest &;
];
pauseDt = Inactivate[#, Dt] &;


Example

Simplify[
Dt[x, b] + y Dt[x, b] + x Dt[y, b] // pauseDt,
TransformationFunctions -> {byparts, sum, Automatic}]
(*  Inactive[Dt][x (1 + y), b]  *)


Check:

Expand@Activate[%]
(*  Dt[x, b] + y Dt[x, b] + x Dt[y, b]  *)

• This is really useful. Do you know if there is a way to also combine Dt[x,a] and Dt[y,a] into Dt[x+y,a] so that I might do x+y->z, for example. Commented Mar 9, 2016 at 17:41
• @LuisNegrete Can you not do it in the same way? You may find Inactivate[expr, Dt] and Activate[] helpful if you're dealing with complicated expressions. Commented Mar 9, 2016 at 17:45