MathGroup Archive 2011

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

Search the Archive

Re: Just another Mathematica "Gotcha"

  • To: mathgroup at
  • Subject: [mg120802] Re: Just another Mathematica "Gotcha"
  • From: Bill Rowe <readnews at>
  • Date: Wed, 10 Aug 2011 06:48:51 -0400 (EDT)
  • Delivered-to:

On 8/9/11 at 7:19 AM, siegman at (AES) wrote:

>Seems as if the following two expression should yield the same
>output -- seems that way to me anyway -- but they don't.  I'll hide
>the actual outputs down below so Mathematica gurus (or "ordinary
>users") can make their predictions as to which one does what.

>In[1]:= Series[a+(b1+b2)x,{x,0,1}] //Normal /.{b2->0}

>In[2]:= Series[a+(b1+b2)x,{x,0,1}] /.{b2->0} //Normal

>My conclusions:

>1)  By any normal rules of interpretation or ordinary
>interpretations of these statements, they both should do the same
>same thing.

If and only if the // and /. operators had the same precedence
this would be true. But since /. has higher precedence than //

Series[a+(b1+b2)x,{x,0,1}] //Normal /.{b2->0}

is equivalent to

Series[a+(b1+b2)x,{x,0,1}] //(Normal /.{b2->0})

rather thab

(Series[a+(b1+b2)x,{x,0,1}])//Normal /.{b2->0}

The problem here is exactly analogous to why

a + b * c

doesn't yield (a+b)*c

>2)  This is just another Mathematica "Gotcha" -- and not a
>particularly forgivable one.

No, this is simply a failure on your part to understand operator precedence.

  • Prev by Date: Re: Just another Mathematica "Gotcha"
  • Next by Date: Re: Simple Doppler effect
  • Previous by thread: Re: Just another Mathematica "Gotcha"
  • Next by thread: Re: Just another Mathematica "Gotcha"