MathGroup Archive 2011

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

Search the Archive

Re: Just another Mathematica "Gotcha"

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120821] Re: Just another Mathematica "Gotcha"
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Thu, 11 Aug 2011 07:55:22 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j206sg$775$1@smc.vnet.net>

On 11/08/2011 10:20, Glenn Carlson wrote:
> It seems not simply a matter of operator precedence since [7] evaluates to neither [3] nor [6].
>
> In[1]:= Series[a + (b1 + b2) x, {x, 0, 1}];
> % // Normal;
> % /. {b2 ->  0}
>
> Out[3]:= a+b1 x
>
> In[4]:= Series[a + (b1 + b2) x, {x, 0, 1}];
> % /. {b2 ->  0};
> % // Normal
>
> Out[6]:= a+b1 x
>
> In[7]:= Series[a + (b1 + b2) x, {x, 0, 1}] // Normal /. {b2 ->  0}
>
> Out[7]:= a + (b1+b2) x
>
The best way to explore operator precedence is to wrap the whole 
expression in Hold and FullForm:

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



Hold[ReplaceAll[Normal,List[Rule[b2,0]]][Series[Plus[a,Times[Plus[b1,b2],x]],List[x,0,1]]]]

This shows you that because of the precedence rules, the replacement 
rule ends up acting on the function Normal - and so does absolutely nothing.

Incidentally, FullForm, sometimes in combination with Hold, solves a 
great many mysterious Mathematica problems!

David Bailey
http://www.dbaileyconsultancy.co.uk




  • Prev by Date: Re: How does Clear["Global`*"] work?
  • Next by Date: Re: FunctionInterpolation and NIntegrate
  • Previous by thread: Re: Just another Mathematica "Gotcha"
  • Next by thread: Re: Just another Mathematica "Gotcha"