MathGroup Archive 2003

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

Search the Archive

RE: Bug in ReplaceAll and ReplaceRepeated?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg44019] RE: [mg44018] Bug in ReplaceAll and ReplaceRepeated?
  • From: "Simons, F.H." <F.H.Simons at tue.nl>
  • Date: Sat, 18 Oct 2003 03:12:12 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Arturas,

Though it looks like a bug, it is a feature.

The first time the rules are applied, the expression at the left hand side is written as Sqrt[(X+(Y+Z))^2] and therefore the argument of the square root is expanded. We then arrive at an expression (x^2 + (...))^(1/2). This expression matches the structure of the left hand side of your second rule, so this rule is applied and the result does not change any more.

Observe that when you require c to be an integer, the substitution works as expected.

Sqrt[(X + Y + Z)^2] //. {Z -> 2, (a_ + b_)^c_Integer :> Expand[(a + b)^c]}

Regards,

Fred Simons
Eindhoven University of Technology


> -----Original Message-----
> From: Arturas Acus [mailto:acus at itpa.lt]
To: mathgroup at smc.vnet.net
> Sent: vrijdag 17 oktober 2003 11:15
> To: mathgroup at smc.vnet.net
> Subject: [mg44019] [mg44018] Bug in ReplaceAll and ReplaceRepeated?
> 
> 
> Hi, 
> 
> 
> Sqrt[(X + Y + Z)^2] //. {Z -> 2, (a_ + b_)^c_ :> Expand[(a + b)^c]}
> 
> don't replace Z with 2. If I remove c in right hand side of 
> second rule,
> works as expected. 
> 
> 
> is the following behaviour bug or the feature?
> In applies both to 4.1, and 5.0.
> 
> 


  • Prev by Date: Re: Problem with Sum
  • Next by Date: ask for help on list operation
  • Previous by thread: Re: Bug in ReplaceAll and ReplaceRepeated?
  • Next by thread: RE: Bug in ReplaceAll and ReplaceRepeated?