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


Groups > comp.soft-sys.math.mathematica > #4314 > unrolled thread

Re: Just another Mathematica "Gotcha"

Started byGlenn Carlson <g.crlsn@gmail.com>
First post2011-08-11 09:10 +0000
Last post2011-08-12 09:08 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

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

#4314 — Re: Just another Mathematica "Gotcha"

FromGlenn Carlson <g.crlsn@gmail.com>
Date2011-08-11 09:10 +0000
SubjectRe: Just another Mathematica "Gotcha"
Message-ID<j2069b$6vn$1@smc.vnet.net>
Yes, I think it's a matter of precedence.  For example,

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

Out[1]= Normal
Out[2]= a + (b1 + b2) x

At my level of proficiency with Mathematica, I shy away from stringing together too many operations. I prefer smaller, more manageable portions. 

It took my brain some time before it allowed me to see [1] as a legitimate operation.  Is [1] just a curiosity? Or is there a situation that would call for such usage?

Thanks and regards,
Glenn

[toc] | [next] | [standalone]


#4336

FromDavid Bailey <dave@removedbailey.co.uk>
Date2011-08-12 09:08 +0000
Message-ID<j22qhv$gqm$1@smc.vnet.net>
In reply to#4314
On 11/08/2011 10:10, Glenn Carlson wrote:
> Yes, I think it's a matter of precedence.  For example,
>
> In[1]:= Normal /. b2 ->  0
> Series[a + (b1 + b2) x, {x, 0, 1}] // %
>
> Out[1]= Normal
> Out[2]= a + (b1 + b2) x
>
> At my level of proficiency with Mathematica, I shy away from stringing together too many operations. I prefer smaller, more manageable portions.
>
> It took my brain some time before it allowed me to see [1] as a legitimate operation.  Is [1] just a curiosity? Or is there a situation that would call for such usage?
>
> Thanks and regards,
> Glenn
>
I would not describe this as a total curiosity.

1)    There are plenty of situations in which you might want to apply a 
substitution whether or not it will actually 'fire'. You certainly would 
not to have to write code to test if an expression contained b2 before 
applying a replacement operation to remove b2!

2)    Creating a head of an expression that is, itself subject to 
evaluation isn't that unusual. A simple use is to create a synonym of a 
function:

In[673]:= sine=Sin

Out[673]= Sin

In[674]:= sine[0.2]

Out[674]= 0.198669

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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web