1
$\begingroup$

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?

$\endgroup$
3
  • $\begingroup$ 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! $\endgroup$
    – user9660
    Commented Mar 9, 2016 at 17:23
  • $\begingroup$ Note that Rule is a built-in Protected symbol. You shouldn't/can't use it as a variable. $\endgroup$
    – Michael E2
    Commented Mar 9, 2016 at 17:36
  • $\begingroup$ Thanks for the comment. I don't actually call it "Rule" in my code but I know that Mathematica warns about protected names. $\endgroup$ Commented Mar 9, 2016 at 17:42

1 Answer 1

3
$\begingroup$

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]  *)

Mathematica graphics


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]  *)
$\endgroup$
2
  • $\begingroup$ 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. $\endgroup$ Commented Mar 9, 2016 at 17:41
  • $\begingroup$ @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. $\endgroup$
    – Michael E2
    Commented Mar 9, 2016 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.