MathGroup Archive 2011

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

Search the Archive

Re: strange behavior with Map

  • To: mathgroup at smc.vnet.net
  • Subject: [mg116421] Re: strange behavior with Map
  • From: Robert Rosenbaum <robertr at math.uh.edu>
  • Date: Mon, 14 Feb 2011 04:28:01 -0500 (EST)

Oh, I see.  I didn't realize that Map[f,x,n] applied f to levels 1 through n.  I had intended to do:

Map[Function[x, 2], {{1, 2}, {1, 2}}, {2}]

which indeed gives the same result as

Map[Function[x, 0 x + 2], {{1, 2}, {1, 2}}, {2}]

Thanks for the help.


Best,
Robert



On Feb 13, 2011, at 2:07 AM, Leonid Shifrin wrote:

> 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: Import and Process QuickTime
  • Next by Date: Re: Filtering data from numerical minimization
  • Previous by thread: Re: strange behavior with Map
  • Next by thread: solution of equation