Re: beginner question about syntax
- To: mathgroup at smc.vnet.net
- Subject: [mg109116] Re: beginner question about syntax
- From: Albert Retey <awnl at gmx-topmail.de>
- Date: Mon, 12 Apr 2010 23:04:54 -0400 (EDT)
- References: <hputp3$lh7$1@smc.vnet.net>
Am 12.04.2010 12:48, schrieb AK: > 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. I think this is probably one of the remarkable differences between mathematica and most other systems: "Everything is an expression" and there is no difference between a List and a sum of terms, one is an expression with head List and a variable number of arguments, the other an expression with head Plus and also a variable number of arguments. Map will work on both. On the other hand the symbols a is an "Atom", its Head is symbol and it cannot have arguments, so Map will not work for it. This is also working for user defined symbols: Map[f,a[1,2,3]] If you have experience with other systems, but are new to mathematica and are primarily interested in the difference to other comparable systems I think reading the tutorials at the bottom of the page guide/ExpressionStructure in the documentation center will be a good starting point. For the next step I would suggest everything in howto/WorkWithVariablesAndFunctions especially tutorial/PatternsAndTransformationRules which will reveal the next important difference IMO: the whole evaluation process is just rewritting an expression by applying rules that have been defined with = (Set) or := (SetDelayed). hth, albert