• To: mathgroup at smc.vnet.net
• Subject: [mg109104] Re: beginner question about syntax
• From: Murray Eisenberg <murray at math.umass.edu>
• Date: Mon, 12 Apr 2010 23:02:40 -0400 (EDT)

```There are two keys here.  First, the official definition of Map, said
briefly (in response to evaluating ?Map) is, "Map[f, expr] ... applies f
to each element on the first level in expr."

Second, the FullForm of expressions, which can show you what the
"elements" are at various "levels".  Look, first at a + b + c:

FullForm[a + b + c]
Plus[a, b, c]

{Part[a + b + c, 1], Part[a + b + c, 2], Part[a + b + c, 3]}
{a, b, c}

So when you Map Function[x,x^2] onto a + b + c, what it's doing is to
evaluate that expression at each of the three parts a, b, c,
respectively and stick the results back in place of a, b, c,
respectively, in the whole expression:

Plus[a^2, b^2, c2]
a^2 + b^2 + c^2

Which is what you obtained.

Now look at the object a:

FullForm[a]
a
Part[a, 1]
(* you get an error message along with the input you gave returned
unevaluated -- but in the abbreviated form: *)
a[[1]]

Thus the object a does not have any parts at level 1, so Map does
nothing to it, and the result is just the original object a.

Map[Function[x,x^2], a]
a

On the other hand:

FullForm[{a}]
List[a]

Part[{a}, 1]
a

Map[Function[x,x^2], {a}]
{a^2}

Hope this helps.

On 4/12/2010 6:53 AM, AK wrote:
> Hi,
>
> I'm a fairly seasoned user of another system who's just started using
> Mathematica. Although at the moment I'm just playing around with
> Mathematica (without any specific task at hand), trying to figure out
> the Mathematica way of doing things from the documentation
> (particularly the examples) there are some things I can't seem to wrap
> my head around. For example, can anyone explain the outputs for the
> inputs below:
> In[1]:= Map[Function[x, x^2], a]
> Out[1]:= a
> In[2]:=Map[Function[x, x^2], a + b + c]
> Out[2]:= a^2 + b^2 + c^2
>
> If I enclose the second argument of Map[] inside a list, I get the
> expected output, but I don't understand what the operations given in
> the example above represent and why the outputs are what they are.
> Would appreciate an explanation for what's going here... thank you in
>

--
Murray Eisenberg                     murray at math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

```

• Prev by Date: Re: beginner question about syntax
• Next by Date: Washington DC Area Mathematica Special Interest Group