Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

Topic: Re: [mg4433] Replacement
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  
Allan Hayes

Posts: 1,508
Registered: 12/6/04
Re: [mg4433] Replacement
Posted: Jul 30, 1996 2:58 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

ges@vsnhdd.cern.ch (Sergej Gerassimov)
[mg4433] Replacement
writes

> I have something like
> x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y
> and I'd like to substitute Sqrt[a^2+b^2] by r.
>
> x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y //. Sqrt[a^2+b^2]->r
> gives:
>
> x r
> ------------- + -
> Sqrt[a^2+b^2] y
>
> (replace one only in the numerator)
> How to replace Sqrt[a^2+b^2] by r everywhere in the expression?


Serge:
Two suggestions

x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y /.
{Power[(a^2+b^2), p:1/2|-1/2]->r^Sign[p]}

x r
- + -
r y

x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y /.
{Sqrt[a^2+b^2]->r,1/Sqrt[a^2+b^2] ->1/r}

x r
- + -
r y

The reason is that what Mma sees is

FullForm[x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y]

Plus[
Times[Power[Plus[Power[a, 2], Power[b, 2]], Rational[-1, 2]], x],
Times[
Power[Plus[Power[a, 2], Power[b, 2]], Rational[1, 2]],
Power[y, -1]
]
]

The Sqrt has gone.

Allan Hayes
hay@haystack.demon.co.uk







Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.