RE: Rule parameter passing

*To*: mathgroup at smc.vnet.net*Subject*: [mg34871] RE: [mg34855] Rule parameter passing*From*: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>*Date*: Tue, 11 Jun 2002 05:00:37 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

> -----Original Message----- > From: TerryH [mailto:tharter at attglobal.net] To: mathgroup at smc.vnet.net > Sent: Sunday, June 09, 2002 11:11 AM > Subject: [mg34871] [mg34855] Rule parameter passing > > > Hi All: > > What is the best way in which to write a rule in which the rule's > parameters > may vary? I'm trying to do some symbolic replacements in > various matrix > expressions, > in which sometimes the variables are say aA and Subscript[ \[Delta] , > \[aA] ], and > at other times the variables can be dD (say). > I have been able to do this by applying succesive rules, as in > > matrix /. aA-> aA + Subscript[ \[Delta] , \[aA] ] /. x_Subscript-> > fcn[ /[Delta], bB] /.aA-> bB > > where the function 'fcn' is: fcn[y_,sub_] := ysub > > However, I need to embed this code inside a Module, and > have not been > able to successfully pass > variables into the successive transformation rules listed avove. > > Anybody got any ideas on how to do this efficiently? Is the onlty way > to do this is to write a Package? > Unfortunately, I have no experience in writing a package. Thanks in > advance to all who may reply! > ....Terry > > Terry, rules are no different from other Mathematica expressions. To introduce parameters you can e.g. use them at the rhs of a definition. Perhaps this example might help (Just copy this into a notebook, convert the cell to text and then to input and execute; or else copy each line and execute): Attributes[dsplc] = {HoldAll}; Attributes[delta] = {HoldAll}; \!\(delta[x_] := \[Delta]\_x\) dsplc[x_] := HoldPattern[x] :> x + delta[x] expr = Normal[Series[ArcCos[x], {x, 0, 5}]] ((expr /. dsplc[x]) - expr)/delta[x] // Expand Series[D[ArcCos[x], {x, 1}], {x, 0, 4}] expr = Normal[Series[Exp[y], {y, 0, 10}]] (((expr /. dsplc[y]) - expr)/delta[y] // Expand) /. delta[y] -> 0 -- Hartmut