Re: Simple edit ...

*To*: mathgroup at smc.vnet.net*Subject*: [mg19363] Re: [mg19319] Simple edit ...*From*: "Wolf, Hartmut" <hwolf at debis.com>*Date*: Fri, 20 Aug 1999 23:09:39 -0400*Organization*: debis Systemhaus*References*: <199908150342.XAA00982@smc.vnet.net.>*Sender*: owner-wri-mathgroup at wolfram.com

Michael L. Stokes schrieb: > > Consider the following examaple; > > z = (a+Sqrt[d+e])/(a Sqrt[d+e]) > > z //. Sqrt[d+e] ->L > > The replacement function only replaces the instance of Sqrt[d+e] in the > numerator and leaves the instance in the denominator alone. Why does > this not work and what is the work around? > Hello Mike, look at the FullForm of z In[1]:= z // FullForm Out[1]//FullForm= Times[Power[a, -1], Power[Plus[d, e], Rational[-1, 2]], Plus[a, Power[Plus[d, e], Rational[1, 2]]]] So for replacement you have to define a pattern that matches both Power[Plus[d, e], Rational[1, 2] and Power[Plus[d, e], Rational[-1, 2]. This simple guess doesn't do In[2]:= (d + e)^(n_Integer/2) // FullForm Out[2]//FullForm= Power[Plus[d, e], Times[Rational[1, 2], Pattern[n, Blank[Integer]]]] but working backwards In[3]:= Power[Plus[d, e], Rational[n, 2]] // InputForm Out[3]//InputForm= (d + e)^(Rational[n, 2]) you'll get it. So... In[4]:= z /. (d + e)^(Rational[n : (1 | -1), 2]) :> L^n Out[4]= (a + L)/(a*L) ...will do, but for the following more complicated examathematica In[5]:= zz = Expand[(a + Sqrt[d + e])^3]/(a Sqrt[d + e]^5); better use In[6]:= zz /. (d + e)^(Rational[n_Integer, 2]) :> L^n Out[6]= (a^3 + 3*a*d + 3*a*e + 3*a^2*L + d*L + e*L)/(a*L^5) Kind regards, hw

**References**:**Simple edit ...***From:*"Michael L. Stokes" <stokes@aris.net>