MathGroup Archive 2011

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

Search the Archive

Re: strange behavior with Map

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116398] Re: strange behavior with Map
  • From: Leonid Shifrin <lshifr at gmail.com>
  • Date: Sun, 13 Feb 2011 03:07:07 -0500 (EST)
  • References: <201102121020.FAA20181@smc.vnet.net>

Hi Robert,

It's a bit subtle indeed. The key observation is this:

In[23]:= Map[f, {{1, 2}, {1, 2}}, 2]

Out[23]= {f[{f[1], f[2]}], f[{f[1], f[2]}]}

Since things evaluate from the bottom, the interesting part happens after we
have this:

{f[{2, 2}], f[{2, 2}]}

(schematically - in reality, the first f completely evaluates, and only then
the second). Now,
consider:

In[27]:= Function[x, 0 x + 2][{2, 2}]

Out[27]= {2, 2}

In[28]:= Function[x, 2][{2, 2}]

Out[28]= 2

which is, the functions *are* different, because multiplication by a scalar
(zero included) preserves the
dimensionality of the second factor, for the first function, while the
second function simply replaces the
argument by 2, whatever it is.

Regards,
Leonid


On Sat, Feb 12, 2011 at 1:20 PM, Robert Rosenbaum <robertr at math.uh.edu>wrote:

> This doesn't seem right:
>
>
> In[181]:= Map[Function[x, 2], {{1, 2}, {1, 2}}, 2]
>
> Out[181]= {2, 2}
>
> In[180]:= Map[Function[x, 0 x + 2], {{1, 2}, {1, 2}}, 2]
>
> Out[180]= {{2, 2}, {2, 2}}
>
>
> Best,
> Robert
>
>


  • Prev by Date: Re: solution of equation
  • Next by Date: Re: solution of equation
  • Previous by thread: strange behavior with Map
  • Next by thread: Re: strange behavior with Map