MathGroup Archive 1996

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Replacement

  • To: mathgroup at
  • Subject: [mg4458] Re: Replacement
  • From: wagner at (Dave Wagner)
  • Date: Mon, 29 Jul 1996 02:37:15 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at

In article <4shud7$g7n at>,
Sergej Gerassimov <ges at> wrote:
>x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y //. Sqrt[a^2+b^2]->r
>      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?

The reason what you're doing doesn't work is that the Sqrt in the denominator
is represented internally as Power[a^2+b^2, -1/2], which doesn't match the

As somebody in this forum once said, "Pattern matching is relentlessly
syntactic."  (Please take credit for this, whoever said it.)

A general solution to this type of problem is to introduce a dummy
variable and use Solve:

    Solve[{dummy==x/Sqrt[a^2+b^2]+Sqrt[a^2+b^2]/y, r==Sqrt[a^2+b^2]},

	  x         r
    ------------- + -
	  2    2    y
    Sqrt[a  + b ]

The arguments to Solve tell it to solve for dummy and to attempt to eliminate
a and b.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at


  • Prev by Date: Re: ListPlot the output of Print
  • Next by Date: Re: Replacement
  • Previous by thread: Re: Replacement
  • Next by thread: Re: Replacement