MathGroup Archive 2007

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

Search the Archive

Re: Substituting simpler expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78685] Re: Substituting simpler expressions
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 7 Jul 2007 05:54:54 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f6krve$l9o$1@smc.vnet.net>

Steve Gray wrote:
> Suppose I  have a long complex expression in which the term
> exx=Sqrt[x^2+y^2-xy] (for example) appears many times. I would like to
> substitute say "rootxy" (for example) for it everywhere it appears. I
> know about doing exx/.Sqrt[x^2+y^2-xy]-> rootxy but that doesn't do
> it. Any tips? Thank you.
> 
> Steve Gray

Steve,

I suspect that you have your sqrt expression appears both on numerator 
and denominator. In the example below, I have named your sqrt expression 
'expr'. Looking at the fullform of expr and 1/expr, you can see that 
they are /almost/ identical except in their last term: power a 1/2 in 
the first case, power -1/2 in the second case. This is why the 
replacement operator does not transform expr in rootxy when expr is in 
the denominator. You must look for both form of exponent as in In[5]. I 
hope this helps.

In[1]:=
expr = Sqrt[x^2 + y^2 - x*y];

In[2]:=
expr + 1/expr /. expr -> rootxy

Out[2]=
rootxy + 1/Sqrt[x^2 - x*y + y^2]

In[3]:=
FullForm[expr]

Out[3]//FullForm=
Power[Plus[Power[x, 2], Times[-1, x, y], Power[y, 2]],

   Rational[1, 2]]

In[4]:=
FullForm[1/expr]

Out[4]//FullForm=
Power[Plus[Power[x, 2], Times[-1, x, y], Power[y, 2]],

   Rational[-1, 2]]

In[5]:=
expr + 1/expr /. expr -> rootxy /. 1/expr -> 1/rootxy

Out[5]=
1/rootxy + rootxy

Regards,
Jean-Marc


  • Prev by Date: Re: Why does this happen?
  • Next by Date: Re: Substituting simpler expressions
  • Previous by thread: Substituting simpler expressions
  • Next by thread: Re: Substituting simpler expressions