Re: Replacement Rule with Sqrt in denominator

*To*: mathgroup at smc.vnet.net*Subject*: [mg114379] Re: Replacement Rule with Sqrt in denominator*From*: Roland Franzius <roland.franzius at uos.de>*Date*: Thu, 2 Dec 2010 05:42:23 -0500 (EST)*References*: <ic5igm$44p$1@smc.vnet.net> <ic8ad7$81f$1@smc.vnet.net>

Am 20.11.2010 12:11, schrieb kj: > In<ic5igm$44p$1 at smc.vnet.net> Themis Matsoukas<tmatsoukas at me.com> writes: > >> This replacement rule works, > >> Sqrt[-4 \[Zeta]^2 + (1 + \[Rho]^2)^2] /. >> Sqrt[-4 \[Zeta]^2 + (1 + \[Rho]^2)^2] -> G > >> G > >> but this doesn't: > >> 1/Sqrt[-4 \[Zeta]^2 + (1 + \[Rho]^2)^2] /. >> Sqrt[-4 \[Zeta]^2 + (1 + \[Rho]^2)^2] -> G > >> 1/Sqrt[-4 \[Zeta]^2 + (1 + \[Rho]^2)^2] > >> The only difference is that the quantity to be replaced is in the denominator. If I remove Sqrt from the replacement rule it will work but I don't understand why a square root in the denominator (but not in the numerator) causes the rule to fail. > > > Yes, that's very annoying. > > The reason is that the pattern matching is done on the full forms > of the expressions, which is not always immediately obvious. To > see this compare FullForm[Sqrt[x]], which is > Power[x, Rational[1, 2]], with FullForm[1/Sqrt[x]], which is > Power[x, Rational[-1, 2]]. > > I don't know a way to write the replacement rule so that it works > for both Sqrt[x] and 1/Sqrt[x], but maybe someone else does. Use rules like HoldPattern[x^Rational[a_,2]] :> G^a eg this works for contraction of products of fractional powers ((1 + I x)^(1/2)/(1 - I x)^(1/2)) /. {HoldPattern[a_^Rational[b_, c_] d_^Rational[e_, c_]] :> (a^b d^e)^(1/c)} while this one does not work (1 + I x)^(1/2)/(1 - I x)^( 1/2) /. {a_^(b_/c_) d_^(e_/c_) :> (a^b d^e)^(1/c)} The reason is that fractions of patterns are represented by Times with Power[#,-1]. Explicit integer fractions are represented by Rational. The same problem arises with Complex. It is impossible to transform explicitly complex expressions (expressions with I, Re, Im, Abs) without inspection of FullForm. -- Roland Franzius