MathGroup Archive 2002

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

Search the Archive

RE: Replacement problem

  • To: mathgroup at
  • Subject: [mg36926] RE: [mg36906] Replacement problem
  • From: "DrBob" <drbob at>
  • Date: Wed, 2 Oct 2002 03:32:14 -0400 (EDT)
  • Reply-to: <drbob at>
  • Sender: owner-wri-mathgroup at

Look at the FullForm of your expressions:

FullForm[Sqrt[X + Y + Z]]
Power[Plus[X, Y, Z], Rational[1, 2]]

Plus[Times[Rational[1, 4], C, Power[F, -2], Power[Plus[X, Y,
     Z], Rational[-1, 2]]], Times[B, Plus[A,
       Power[Plus[X, Y, Z], Rational[1, 2]]]]]

Plus[Times[B, Plus[A, Power[Plus[X, Y, Z], 
      Rational[1, 2]]]], Times[C, Power[Plus[Times[4, Power[F, 2]],
           Power[Plus[X, Y, Z], Rational[1, 2]]], -1]]]

The square root appears in two different forms!  A solution is to
replace both patterns:

f = B*(A + Sqrt[X + Y + Z]) + C/(Sqrt[X + Y + Z]/4*F^2);
f /. {Sqrt[X + Y + Z] -> Q, 1/Sqrt[X + Y + Z] -> 1/Q}

(4*C)/(F^2*Q) + B*(A + Q)

This is very annoying, of course, and it may not take care of every
case.  Looking at the FullForm should help, when it fails.


-----Original Message-----
From: Carlos Felippa [mailto:carlos at] 
To: mathgroup at
Subject: [mg36926] [mg36906] Replacement problem

These expressions are condensation of larger ones
(about 700 lines or so each) but they illustrate random
substitution failures in 4.2.  Question: how can the
substitution Sqrt[...]->Q always be made to work?  
The help file under ReplaceAll, ReplaceRepeated, etc, 
does not address this problem.



B*(A + Q) + (4*C)/(F^2*Sqrt[X + Y + Z])  (* fails *)


B*(A + Q) + C/(4*F^2*Sqrt[X + Y + Z])    (* fails *)


B*(A + Q) + C/(4*F^2 + Q)                (* works *)

  • Prev by Date: simple two step optimization
  • Next by Date: Re: Linux Users?
  • Previous by thread: Re: Replacement problem
  • Next by thread: Re: Replacement problem