Re: Rule Writing for x and 1/x
- To: mathgroup at christensen.cybernetics.net
- To: mathgroup at christensen.cybernetics.net
- Subject: [mg838] Re: [mg785] Rule Writing for x and 1/x
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Tue, 25 Apr 1995 02:19:24 -0400
D Reece writes >Is there a way to write a single rule in MMA which will turn J/s >into W and s/J into 1/W? Here is one solution In[1]:= {s/J,J/s}//.{a:(s/J) |(J/s) :> (a/.J->s W)} Out[1]= 1 {-, W} W But for complicated expressions you might find it better to use AlgebraicRules, or my package AlgebraicRulesExtended (on MathSource). In[2]:= {Sin[5 + a s^2/J],Sqrt[J]/s/ b, s/J, J/s}/. AlgebraicRulesExtended[ J/s == W] Out[2]= a s Sqrt[s W] 1 {Sin[5 + ---], ---------, -, W} W b s W Or, if you prefer J to s In[3]:= {Sin[5 + a s^2/J],Sqrt[J]/s/ b, s/J, J/s}/. AlgebraicRulesExtended[ J/s == W,{s,J}] Out[3]= a J W 1 {Sin[5 + ---], ---------, -, W} 2 b Sqrt[J] W W Allan Hayes hay at haystack.demon.co.uk