[Date Index]
[Thread Index]
[Author Index]
Re: Expand[] on the RHS of a rule
 To: mathgroup at yoda.physics.unc.edu
 Subject: Re: Expand[] on the RHS of a rule
 From: roger at isy.liu.se (Roger Germundsson)
 Date: Thu, 28 May 92 15:50:00 +0200
> From: athos at warp.stanford.edu (Athos Kasapi)
> Subject: Expand[] on the RHS of a rule
>
> 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
> define
>
> 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.
>
> Athos Kasapi
>
>
You should use a delayed rule, i.e.
In[11]:= r = Sqrt[ x_ y_ ] :> Sqrt[ Expand[ x y ] ]
Out[11]= Sqrt[(x_) (y_)] :> Sqrt[Expand[x y]]
In[12]:= Sqrt[ (a+b)(c+d) ] /. r
Out[12]= Sqrt[a c + b c + a d + b d]
... if you use > the right hand side gets evaluated
only when the rule is defined. In this case
In[13]:= Expand[ x y ]
Out[13]= x y
Happy computing // Roger
Prev by Date:
re: speed
Next by Date:
nonlinear fitting of data
Previous by thread:
Re: Expand[] on the RHS of a rule
Next by thread:
Re: Expand[] on the RHS of a rule
