Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The semantics of Mathematica's Thread function, someone needs to finally put this to rest

Wolfram Research has had the same documentation for this function for the last 8 years at least:

Thread[f[args]]

"threads" f over any lists that appear in args.

A lovely circular definition if I've ever seen one.

Does anyone know what the actual semantics are and can provide a proper explanation that is non-circular?

like image 517
cons Avatar asked Aug 08 '09 23:08

cons


1 Answers

It works similarly to Python's zip() function, but in a slightly more general fashion. For example:

In[1] := Thread[{{1, 2, 3}, {4, 5, 6}}]  (* f == List *)
Out[1] = {{1, 4}, {2, 5}, {3, 6}}

In[2] := Thread[f[{1, 2, 3}, {4, 5, 6}]]
Out[2] = {f[1, 4], f[2, 5], f[3, 6]}

In[3] := Thread[f[a+b+c, d+e+f], Plus]
Out[3] = f[a, d] + f[b, e] + f[c, f]
like image 86
Adam Rosenfield Avatar answered Nov 12 '22 22:11

Adam Rosenfield