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: [mg44020] Re: [mg44018] Bug in ReplaceAll and ReplaceRepeated?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sat, 18 Oct 2003 03:12:13 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

On Friday, October 17, 2003, at 06:14 PM, Artūras Acus wrote:

> 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.
>
>
>

There is an old and wise saying: if all else fails read the manual. A 
less polite version is frequently found on various mailing lists.

"ReplaceAll looks at each part of expr, tries all the rules on it, and 
then goes on to the next part of expr. The first rule that applies to a 
particular part is used; no further rules are tried on that part, or on 
any of its subparts"

The rule (a_ + b_)^c_ :> Expand[(a + b)^c] matches first because it 
matches the whole expression (due tot he flat attribute of plus), so 
the other rule is disregarded.

Andrzej Kozlowski
Yokohama, Japan
http://www.mimuw.edu.pl/~akoz/
http://platon.c.u-tokyo.ac.jp/andrzej/


  • Prev by Date: Re: Solve bug in Mathematica 5
  • Next by Date: Re: Problem with Sum
  • Previous by thread: Re: Bug in ReplaceAll and ReplaceRepeated?
  • Next by thread: RE: Bug in ReplaceAll and ReplaceRepeated?