Re: Help to clarify 'Map', 'Apply', and 'Thread'.

• To: mathgroup at smc.vnet.net
• Subject: [mg15716] Re: Help to clarify 'Map', 'Apply', and 'Thread'.
• From: phbrf at t-online.de (Peter Breitfeld)
• Date: Fri, 5 Feb 1999 03:42:15 -0500 (EST)
• Organization: das ist ein breites Feld ...
• References: <78uj8q\$8gu@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Wen-Feng Shaw <wfshaw at ms23.hinet.net> schrieb:
> Hi experts,
>
> useful. However, I am often confused by their functionalities. I often
> should stop to try if a certain expression is correct before coding it
> into my program. Could you help me to clarify them? Thanks a lot!
>
> Best Regards,
>
> Wen-Feng Shaw
>
>

Suppose you have
X={x,y,z}; A={a,b,c};
eq=2x+3y==z

Apply changes the head of the expression: Apply[Subtract,eq]----->
2x+3y-z
or

Map works on the elements in the first level of the expression:
Map[#+3&,eq] ---> 3+2x+3y==3+3   (added 3 on both sides)

MapAt works on the elements at a specified position:
MapAt[k#&,eq,{1,2}]-----> 2x+3ky==z (second element on left side times
k)

Thread is hard to explain, but is changes eg "{a,b,c} operator {x,y,z}"
to "{a operator x, b operator y, c operator z}", so

eq /. Thread[X->A] -----> 2a+3b=c,   (eq/.X->A does nothing)

MapThread I have never used, but AFAIK it works on a list of lists.