MathGroup Archive 2010

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

Search the Archive

Re: beginner question about syntax

For map to work you must be mapping over the elements of an
expression, be it a list like {a,b,c} or a generic expression like
in your first example :
 Map[Function[x, x^2], a]
a is an atomic symbol,  Map normally tries to apply the function to
level one of the expression but "a" has no level 1 this fails, what
you would want to use is:
Function[x, x^2][a]
In your second example what is going on is that a+b+c is really seen
by Mathematica as Plus[a,b,c],
Map[Function[x, x^2], a + b + c]
is really
Map[Function[x, x^2],Plus[a,b,c]]
and the function is applies to each element of the Plus statement
while keeping Plus as the "head" of the expression
an intermediate step might look something like:
Plus[Function[x, x^2][a],Function[x, x^2][b],Function[x, x^2][c]]
which becoms:


On Apr 12, 6:48 am, AK <aaa... at> 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
> advance.

  • Prev by Date: Re: beginner question about syntax
  • Next by Date: Selecting subscripted variables from an expression
  • Previous by thread: Re: beginner question about syntax
  • Next by thread: Re: beginner question about syntax