MapThread with several cells as output

Assume I have defined the following function:

FF[{x_, y_}] := {x^2 + y^3, 3.5*x*y}


I would like to apply FF on a list of input such as:

XX = {xa, xb, xc}
YY = {ya, yb, yc}


In order to do it I input the following syntax:

MapThread[FF, {XX, YY}]


but as output I get just the first element of the function:

{xa^2+ya^3, xb^2+yb^3, xc^2+yc^3}


what am I doing wrong here?

-
Try MapThread[FF[{##}] &, {XX, YY}]; alternatively, redefine FF[]: FF[x_, y_] := {x^2 + y^3, 3.5*x*y}. – J. M. Sep 5 '12 at 7:00
Thanks a lot kguler this works!!! now to better understand, what is ACTUALLY the differrence between FF[x_, y_] := {x^2 + y^3, 3.5*xy} and the original FF[{x_, y_}] := {x^2 + y^3, 3.5*xy} as Mathematica understand it? Doron – Doron Sep 5 '12 at 7:31
Doron, I guess the 'thank you" and the follow up question were meant for @J.M.:) – kglr Sep 5 '12 at 7:42
MapThread[FF, {XX, YY}] gives {FF[xa, ya], FF[xb, yb], FF[xc, yc]}, not {xa^2+ya^3,xb^2+yb^3,xc^2+yc^3}. That is, it returns FF unevaluated, because FF requires a single list as its argument, so it is not defined when it is passed a Sequence of two arguments. – kglr Sep 5 '12 at 7:46

1 Answer

I would not use MapThread in this case. From the point of functional programming I consider this

FF /@ Transpose[{XX, YY}]


as more consistent. This is because the signature of FF, namely taking a tuple and returning a tuple, is exactly what you want to express mathematically. Therefore, I would not use the solution

MapThread[FF[{##}] &, {XX, YY}]


because although it works, it has to recreate the tuple parameter by wrapping FF with a pure function.

Another point: Maybe you know that most basic operations like multiplication, powers, etc work with list arguments. Thats why you could spare the Map (/@) of my first example and simply write

Transpose[FF[{XX, YY}]]

-
I think I get it. nevertheless (and I might again be worng...), I think thak fore a more complicate case such as, for example FFFF[x_, y_] := {x^2 + y^3, 3.5*xy, xy^0.5} the Only thing that will work is MapThread[FFFF, {XX, YY}]. right? – Doron Sep 5 '12 at 14:01
You have almost always several possibilities. For an f[x_, y_] := {x^2 + y^3, 3.5*x*y, x*y^0.5} you could write f @@@ Transpose[{XX, YY}] too. – halirutan Sep 5 '12 at 14:08
@Doron, I did not want to force you in one direction which is the best (because it always depends). I wanted to show you that since we have this huge amount of functional operations in Mathematica, you should try to implement your idea. – halirutan Sep 5 '12 at 14:12