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

后端 未结 2 1306
说谎
说谎 2021-02-13 03:29

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 t

2条回答
  •  别那么骄傲
    2021-02-13 03:46

    Thread is a bit like a generalization zip from other functional languages.

    For simple cases, where all the elements of args from your example are lists,

    Thread[f[args]]
    

    is equivalent to

    f @@@ Transpose[{args}]
    

    as shown in the first couple examples in the documentation. The major wrinkle is when you have args that are not lists, in which case they're effectively curried out; for example,

    Thread[g[{a, b}, c, {d, e}, f]]
    

    is equivalent to

    g[#1, c, #2, f]& @@@ Transpose[{{a, b}, {d, e}}]
    

    I usually find myself using Thread to construct lists of rules or lists of equations.

提交回复
热议问题