Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4287
| From | Heike Gramberg <heike.gramberg@gmail.com> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Re: Just another Mathematica "Gotcha" |
| Date | 2011-08-10 10:59 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <j1toa1$pu5$1@smc.vnet.net> (permalink) |
| References | <201108091119.HAA15770@smc.vnet.net> |
Not a gotcha IMO, just a case of /. taking precedence over //, so the first example is interpreted as
Series[a + (b1 + b2) x, {x, 0, 1}] // (Normal /. b2 -> 0)
and the second one as
(Series[a + (b1 + b2) x, {x, 0, 1}] /. {b2 -> 0}) // Normal
You can check this by looking at TracePrint:
First case:
TracePrint[Series[a + (b1 + b2) x, {x, 0, 1}] // Normal /. b2 -> 0]
out:
(Normal/. b2->0)[Series[a+(b1+b2) x,{x,0,1}]]
Normal/. b2->0
ReplaceAll
Normal
b2->0
Rule
b2
0
b2->0
=85...
Second case
TracePrint[Series[a + (b1 + b2) x, {x, 0, 1}] /. {b2 -> 0} // Normal]
out:
Normal[Series[a+(b1+b2) x,{x,0,1}]/. {b2->0}]
Normal
Series[a+(b1+b2) x,{x,0,1}]/. {b2->0}
ReplaceAll
Series[a+(b1+b2) x,{x,0,1}]
Series
a+(b1+b2) x
Plus
=85.
In both cases, the ReplaceAll is evaluated first
Heike.
On 9 Aug 2011, at 13:19, 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.
>
> 2) This is just another Mathematica "Gotcha" -- and not a
> particularly forgivable one.
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> Out[1]= a+(b1+b2) x
>
> Out[2]= a+b1 x
>
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Re: Just another Mathematica "Gotcha" Heike Gramberg <heike.gramberg@gmail.com> - 2011-08-10 10:59 +0000
csiph-web