Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4320 > unrolled thread
| Started by | Glenn Carlson <g.crlsn@gmail.com> |
|---|---|
| First post | 2011-08-11 09:20 +0000 |
| Last post | 2011-08-11 11:56 +0000 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
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
| From | Glenn Carlson <g.crlsn@gmail.com> |
|---|---|
| Date | 2011-08-11 09:20 +0000 |
| Subject | Re: Just another Mathematica "Gotcha" |
| Message-ID | <j206sg$775$1@smc.vnet.net> |
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
[toc] | [next] | [standalone]
| From | David Bailey <dave@removedbailey.co.uk> |
|---|---|
| Date | 2011-08-11 11:56 +0000 |
| Message-ID | <j20g1b$8tf$1@smc.vnet.net> |
| In reply to | #4320 |
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
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web