Re: Getting the Derivative of an HoldForm Expression

*To*: mathgroup at smc.vnet.net*Subject*: [mg127895] Re: Getting the Derivative of an HoldForm Expression*From*: David Bailey <dave at removedbailey.co.uk>*Date*: Thu, 30 Aug 2012 04:10:47 -0400 (EDT)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*Delivered-to*: l-mathgroup@wolfram.com*Delivered-to*: mathgroup-newout@smc.vnet.net*Delivered-to*: mathgroup-newsend@smc.vnet.net*References*: <k16jfv$bep$1@smc.vnet.net> <k1a28l$icg$1@smc.vnet.net> <k1i0nc$4n5$1@smc.vnet.net>

On 28/08/2012 09:49, nitgun at gmail.com wrote: > Thank you for your reply. > Unfortunately I made my example a bit confusing. Because actually I need the replacement the other way round. I want to replace common subexpressions. Some occur after some fancy calculations and others I can avoid by substituting right at the beginning (as my given example). That's why I want to include the terms for the replacement in the notebook as well so that others can understand the calculations. Otherwise nobody would know what a[t] stands for, unless he finds the replacement in the end. But maybe it works when I put it into such a replacement list. > Replacing common subexpressions will work too. For example: In[4]:= a[2 t] + b[t] + c[2 t] + d[ t] /. c[x_] + a[x_] -> g[x] Out[4]= b[t] + d[t] + g[2 t] Some cases are trickier In[5]:= (a + b)/Sqrt[c + d] /. Sqrt[c + d] -> g[c, d] Out[5]= (a + b)/Sqrt[c + d] You sometimes need to know a bit about how expressions are represented internally in Mathematica: In[6]:= (a + b)/Sqrt[c + d] /. (c + d)^p_. -> g[c, d]^(2 p) Out[6]= (a + b)/g[c, d] Note that Mathematica is automatically aware that additions and subtractions can be shuffled into any order (likewise for multiplications), and that divisions and roots are expressed internally in power notation. Assignments are far more useful inside pieces of actual code, but they can be quite dangerous in hand explorations of equations, because a left over assignment (say m=1) messes up expressions like (m c^2), and in a large expression that might not be instantly obvious! Replacement rules are extremely powerful, and it is well worth exploring them in depth. David Bailey http://www.dbaileyconsultancy.co.uk