Re: [Q] Implementing identities as rules
- To: mathgroup at smc.vnet.net
- Subject: [mg18714] Re: [mg18608] [Q] Implementing identities as rules
- From: Carl Woll <carlw at u.washington.edu>
- Date: Sat, 17 Jul 1999 02:36:36 -0400
- Organization: Physics Department, U of Washington
- References: <199907130501.BAA09558@smc.vnet.net.>
- Sender: owner-wri-mathgroup at wolfram.com
Kevin, I've seen some other responses to your question, but I have a different approach which I think is more general. The basic idea is to give rules for the derivatives of your function, rather than defining the function itself. For your example we have Derivative[1,0][f][x_,y_]:=2x f[x,y] Derivative[0,1][f][x_,y_]:=2y f[x,y] Now, we can try things like In[32]:= D[f[x,y],x] D[f[x,y],y] D[f[x,y],x,y] D[f[x,y],x,x] D[f[x,y],{x,2},{y,3}] Out[32]= 2 x f[x, y] Out[33]= 2 y f[x, y] Out[34]= 4 x y f[x, y] Out[35]= 2 2 f[x, y] + 4 x f[x, y] Out[36]= 2 3 24 y f[x, y] + 48 x y f[x, y] + 16 y f[x, y] + 2 3 32 x y f[x, y] Now, admittedly, one could get the same answers using the methods proposed by the other respondents in this case. However, as a trivial example, suppose your function is something like E^(x^2 +y^2)+x? Now, the application of rules like E^(x^2+y^2)+x -> f[x,y] will not work (although you can get around this by using the rule E^(x^2+y^2) -> f[x,y]-x). Did you have a more complicated situation in mind then the example you provided? If so, and if none of the proposed methods are able to help you, please feel free to share it. Carl Woll Dept of Physics U of Washington Kevin Jaffe wrote: > During symbolic manipulations it often important to be able to use > both sides of an identity or definition. For example, let f be a > function defined by > > In[1]:= f = Function[{x, y}, Exp[x^2 + y^2]]; > > Its partial derivative with respect to x is: > > In[2]:= D[f[x, y], x] > > 2 2 > x + y > Out[2]= 2 E x > > Now, I want to recast this result in the form 2 x f[x, y], i.e. I want > to revert to the "left-hand side" of the original definition of f[x, > y]. How does one do this in Mathematica? I know that if I try the > rule > > In[3]:= %2 /. Exp[a_^2 + b_^2] :> f[a, b] > > 2 2 > x + y > Out[3]= 2 E x > > I get the original expression, because when the pattern is replace, > f[a, b] is immediately evaluated to reproduce the original expression. > (I know that the replacement occurs because if instead I use a rule > whose right hand side cannot be evaluated further > > In[4]:= %2 /. Exp[a_^2 + b_^2] :> g[a, b] > > Out[4]= 2 x g[x, y] > > I get the desired result.) > > Is there a way to instruct Mathematica not to evaluate the expression > after the replacement has been made? > > Thanks, > > kj0 at mailcity.com > > Get your FREE Email at http://mailcity.lycos.com > Get your PERSONALIZED START PAGE at http://my.lycos.com -- Carl Woll Dept of Physics U of Washington
- References:
- [Q] Implementing identities as rules
- From: "Kevin Jaffe" <kj0@mailcity.com>
- [Q] Implementing identities as rules