Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 1992

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

Search the Archive

Re: Expand[] on the RHS of a rule

  • To: mathgroup at
  • Subject: Re: Expand[] on the RHS of a rule
  • From: ags at (Dave Seaman)
  • Date: Thu, 28 May 92 09:30:21 EST

athos at (Athos Kasapi) writes:

>Has anybody found a way to work around the problem that Expand does not
>work when it is on the right hand side of a rule?  For example, if I
>p := Sqrt[ (a + b) (c + d) ]
>and then apply the rule
>p /. Sqrt[ x_ y_ ] -> Sqrt[ Expand[ x y ] ]
>Then all I get back is
>Sqrt[ (a + b)(c + d) ]
>What I wanted was
>Sqrt[ ac + ad + bc + bd ]
>I'd appreciate any suggestions for getting around this.

You specified immediate transformation by using "->", which means
"Expand[x y]" is immediately evaluated to "x y", and then the
resulting rule is applied.

You need to use the ":>" operator to specify delayed transformation.
The rule is

	p /. Sqrt[ x_ y_ ] :> Sqrt[ Expand[ x y ] ]

in which the delayed transformation operator ":>" causes the product
to be expanded after the substitution is made, rather than before.


  • Prev by Date: non-linear fitting of data
  • Next by Date: Macs, memory and mma
  • Previous by thread: Re: Expand[] on the RHS of a rule
  • Next by thread: [no subject]