RE: simple problem with Map?!?

• To: mathgroup at smc.vnet.net
• Subject: [mg49505] RE: [mg49480] simple problem with Map?!?
• From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
• Date: Thu, 22 Jul 2004 02:45:34 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```>-----Original Message-----
>From: Relishguy [mailto:relishguy at pluggedin.org]
To: mathgroup at smc.vnet.net
>Sent: Wednesday, July 21, 2004 12:41 PM
>To: mathgroup at smc.vnet.net
>Subject: [mg49505] [mg49480] simple problem with Map?!?
>
>
>I do not understand why the last evaluation ends up screwed:
>
>In[1]:= d0 = {30,60,180,60,30};
>
>In[2]:= tt = Plus @@ d0
>Out[2]= 360
>
>In[3]:= pp = N[d0 / tt]
>Out[3]= {0.0833333,0.166667,0.5,0.166667,0.0833333}
>
>In[4]:= ppp = N[d0 / (Plus @@ d0)]
>Out[4]= {0.0833333,0.166667,0.5,0.166667,0.0833333}
>
>In[5]:= pppp = N[# / (Plus @@ #)]& /@ d0
>Out[5]= {1.,1.,1.,1.,1.}
>
>Can anyone explain this simply? Do I need Hold[] or Evaluate[]
>somewhere?
>
>TIA.
>
>Regards..
>
>

Well, what does you last expression evaluate to?

A pure function is mapped over your list, resulting in a list of applications. That is, it's equal to

In[13]:= Table[N[#/(Plus @@ #)] &[d0[[i]]], {i, 1, Length[d0]}]
Out[13]= {1., 1., 1., 1., 1.}

Let's try it e.g. for the first element

In[14]:= N[30/(Plus @@ 30)]
Out[14]= 1.

And this is because

In[15]:= Plus @@ 30
Out[15]= 30

Now "Apply[f, expr] or f @@ expr replaces the head of expr by f"

But if the expression is an atom, nothing is there to be replaced, and the atom is returned (forgetting about the f).

--
Hartmut Wolf

```

• Prev by Date: RE: is List link-based or array-based
• Next by Date: RE: If-statement problems
• Previous by thread: Re: simple problem with Map?!?
• Next by thread: Applying my function to elements of a vector