       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:= Map[f, {{1, 2}, {1, 2}}, 2]
>
> Out= {f[{f, f}], f[{f, f}]}
>
> 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:= Function[x, 0 x + 2][{2, 2}]
>
> Out= {2, 2}
>
> In:= Function[x, 2][{2, 2}]
>
> Out= 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:= Map[Function[x, 2], {{1, 2}, {1, 2}}, 2]
>>
>> Out= {2, 2}
>>
>> In:= Map[Function[x, 0 x + 2], {{1, 2}, {1, 2}}, 2]
>>
>> Out= {{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