Re: "Transparency" with respect to differentiation

*To*: mathgroup at smc.vnet.net*Subject*: [mg74055] Re: "Transparency" with respect to differentiation*From*: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>*Date*: Thu, 8 Mar 2007 04:31:45 -0500 (EST)*Organization*: The Open University, Milton Keynes, UK*References*: <es909c$2c5$1@smc.vnet.net> <eslrt9$ptl$1@smc.vnet.net>

Martin Schoenecker wrote: > Regarding the object quat with the following properties > >> quat[a_+b_]:=quat[a]+quat[b] >> quat/:D[quat[fun_],var__]:=quat[D[fun,var]] > > The unwanted behaviour was that differenciation was carried out before > distribution: > >> In[8]:= D[quat[f[x] + g[x]], x] >> Out[8]= f'[x] quat'[f[x]] + g'[x] quat'[g[x]] > > I found out with the help of the Mathematica Reference Guide, A.2.7 that > UpValues have a higher precedence than DownValues, which explains this > behaviour. Trying to give the needed rule explicitly results in > > > quat /: D[quat[(a_) + (b_)], var__] := > D[quat[a], var] + D[quat[b], var] > > $Failed > TagSetDelayed::"tagpos":" .... too deep for an assigned rule to be found. > > Now the question, reformulated, is: how could I define the mentioned > properties so that they would be carried out in the right order? > > Thanks, > Martin > Does something like the following meet your needs? In[1]:= quat[(a_) + (b_)] := quat[a] + quat[b]; quat /: D[quat[fun_], var__] := quat[D[fun, var]]; Unprotect[D]; D[quat[(a_) + (b_)], var__] := D[quat[a], var] + D[quat[b], var]; Protect[D]; In[6]:= quat[f[x] + g[x] + h[x]] D[quat[f[x] + g[x]], x] (D[#1, x] & ) /@ quat[f[x] + g[x]] D[quat[f[x] + g[x]], x] D[quat[f[x]], x] Out[6]= quat[f[x]] + quat[g[x]] + quat[h[x]] Out[7]= quat[Derivative[1][f][x]] + quat[Derivative[1][g][x]] Out[8]= quat[Derivative[1][f][x]] + quat[Derivative[1][g][x]] Out[9]= quat[Derivative[1][f][x]] + quat[Derivative[1][g][x]] Out[10]= quat[Derivative[1][f][x]] Regards, Jean-Marc