MathGroup Archive 2007

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

Search the Archive

Re: Substituting simpler expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78712] Re: Substituting simpler expressions
  • From: David Bailey <dave at Remove_Thisdbailey.co.uk>
  • Date: Sat, 7 Jul 2007 06:08:59 -0400 (EDT)
  • 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
> 
You really should give us a specific  example of the substitution not 
working, but at a guess, you are trying something like:

1/Sqrt[x^2+y^2-xy]/.Sqrt[x^2+y^2-xy]->rootxy

The problem with this is that the reciprocal Sqrt is actually 
represented as an expression to the power -1/2 - so it doesn't match 
your replacement rule! (Look at expressions using FullForm to see this 
in more detail) The answer is to use a slightly more general pattern:

1/Sqrt[x^2+y^2-xy]/.Power[x^2+y^2-xy,n_]:>rootxy^(2 n) /; (!IntegerQ[n])

Here we look for the expression raised to any non-integer power, and 
perform the replacement.

David Bailey
http://www.dbaileyconsultancy.co.uk


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