       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:= 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: 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