Re: ? D[f,{x,n}]
- To: mathgroup at smc.vnet.net
- Subject: [mg25561] Re: [mg25495] ? D[f,{x,n}]
- From: Carl Woll <carlw at u.washington.edu>
- Date: Sat, 7 Oct 2000 03:36:09 -0400 (EDT)
- References: <200010060350.XAA24795@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Jack, It seems to me that your definition for D[f_,x_] should work for both D[f,x] and D[f,{x,n}], since the pattern matcher can match x to {x,n}. So why do you need an additional definition for D[f_,{x_,n_}]? For example, I ran the following test: In[1]:= flag=True; In[2]:= Unprotect[D]; D[f_,x_]/;flag:=Block[{flag=False},D[mySimplification[f],x]] Protect[D]; In[5]:= mySimplification[f_]:=(Print[f];f) In[6]:= D[Cos[x],x] Cos[x] Out[6]= -Sin[x] In[7]:= D[Cos[x],{x,2}] Cos[x] Out[7]= -Cos[x] The From In[6] and From In[7] lines correspond to the print statements in the mySimplification command. So, a single definition of D[f_,x_] is all you need. You don't mention what your package does, but I don't think I would have chosen to overload D with additional definitions as you have chosen to do. What exactly are you trying to do in this package? Carl Jack Goldberg wrote: > Hi folks, > > I am touching up a package I have worked on for a number of years. > Rather than send it off as is, I keep tweeking it to improve its > usefulness. I should know better... My latest tweek leads me to > a problem with D[f,{x,n}]. Here's the story: > > In my package I define a constant "flag" which I set true: flag = True. > > Then I Unprotect D: Unprotect[D]: I want to modify f before the built-in > D fires so I write a little program: > > D[f_,x_]/;flag := Block[ {flag=False}, > D[ mySimplification[f],x] > ] > > So, what I think happens is this. Since flag = True and since Mathematica uses > my definition of D before its own, this little snippet fires. Block sets > flag = False, mySimplification[f] fires, and my definition of D does not > fire again (or I would be caught in a loop) so Mathematica's definition of D > now works and I have accomplished my aim which is to simplify f before > taking the derivative. This seems to work. However, this idea fails to > work for D[f,{x,n}]! Here's my code: > > D[f_,{x_,n_}]/;flag := Block[ {flag=False}, > D[ mySimplification[f],{x,n} ] > ] > > (Of course, the nature of mySimplification should be irrelevant.) > > While trying to work out this problem, I discovered that I don't > understand the difference between D[f,x] and D[f,{x,1}]. If I > alter the definition of D[f,x] have I also altered the definition > of D[f,{x,1}]? How about the other way around? If I alter the > definiton of D[f,{x,1}] does this alter the definition of D[f,x]? > It seems as though they should be linked internally but if so, > I can find no reference to this linkage. This not a mute point since > I found that in trying to use mySimplification in both D[f,x] and > D[f,{x,n}] it is necessary to know what happens if a user chooses to > write D[f,x] in the form D[f,{x,n}]. > > Help is needed. Thanks. >
- References:
- ? D[f,{x,n}]
- From: Jack Goldberg <jackgold@math.lsa.umich.edu>
- ? D[f,{x,n}]