MathGroup Archive 2007

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

Search the Archive

Re: Substituting simpler expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg78716] Re: [mg78666] Substituting simpler expressions
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Sat, 7 Jul 2007 06:11:03 -0400 (EDT)
  • Reply-to: hanlonr at cox.net

exx = Sqrt[x^2 + y^2 - xy];

The replacement must match the FullForm of the expression

exx /. \!\(\*
TagBox[
StyleBox[
TagBox[
StyleBox[
RowBox[{"Power", "[", 
RowBox[{
RowBox[{"Plus", "[", 
RowBox[{
RowBox[{"Power", "[", 
RowBox[{"x", ",", "2"}], "]"}], ",", 
RowBox[{"Times", "[", 
RowBox[{
RowBox[{"-", "1"}], ",", "xy"}], "]"}], ",", 
RowBox[{"Power", "[", 
RowBox[{"y", ",", "2"}], "]"}]}], "]"}], ",", 
RowBox[{"Rational", "[", 
RowBox[{"1", ",", "2"}], "]"}]}], "]"}],
ShowSpecialCharacters->False,
ShowStringCharacters->True,
NumberMarks->True],
FullForm],
ShowSpecialCharacters->False,
ShowStringCharacters->True,
NumberMarks->True],
FullForm]\) :> rootxy

rootxy

Alternatively, 

sub = Sqrt[x^2 + y^2 - xy] :> rootxy;

exx /. sub

rootxy


Bob Hanlon

---- Steve Gray <stevebg at roadrunner.com> 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
> 



  • Prev by Date: Re: How to plot a graph in a non-Cartesian coordinate?
  • Next by Date: DensityPlot colours misbehaving
  • Previous by thread: Re: Substituting simpler expressions
  • Next by thread: Background Color in Tooltip