Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4329

Re: Just another Mathematica "Gotcha"

From David Bailey <dave@removedbailey.co.uk>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Just another Mathematica "Gotcha"
Date 2011-08-11 11:56 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j20g1b$8tf$1@smc.vnet.net> (permalink)
References <j206sg$775$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Just another Mathematica "Gotcha" Glenn Carlson <g.crlsn@gmail.com> - 2011-08-11 09:20 +0000
  Re: Just another Mathematica "Gotcha" David Bailey <dave@removedbailey.co.uk> - 2011-08-11 11:56 +0000

csiph-web