Wolfram Research

Function Repository Resource:

FoldThread

Source Notebook

Perform a folding operation parsing multiple arguments

Contributed by: Sander Huisman

ResourceFunction["FoldThread"][f,x ,{{a1,a2,},{b1,b2,},}]

gives the last element of ResourceFunction["FoldThreadList"] [f,x,{{a1,a2,},{b1,b2,},}].

ResourceFunction["FoldThread"][f,{{a1,a2,},{b1,b2,},}]

gives ResourceFunction["FoldThread"][f,{a1,b1,},{{a2,},{b2,},}].

ResourceFunction["FoldThread"][f]

represents an operator form of ResourceFunction["FoldThread"] that can be applied to expressions.

Details and Options

ResourceFunction["FoldThread"][f][list] is equivalent to ResourceFunction["FoldThread"][f,list].
ResourceFunction["FoldThread"][f][x,list] is equivalent to ResourceFunction["FoldThread"][f,x,list].

Examples

Basic Examples

Basic example:

In[1]:=
ResourceFunction[
 "FoldThread"][f, x, {{a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}}]
Out[1]=

Scope

Without an initializer, the first element of each list is the initializer:

In[2]:=
ResourceFunction[
 "FoldThread"][f, {{a1, a2, a3}, {b1, b2, b3}, {c1, c2, c3}}]
Out[2]=

Make an operator:

In[3]:=
op = ResourceFunction["FoldThread"][g];

Feed a list of lists:

In[4]:=
op[start, {{a, b}, {c, d}}]
Out[4]=

Applications

Use Integrate to integrate x from 0 to 2, y from 0 to 2 and z from 0 to 2:

In[5]:=
ResourceFunction["FoldThread"][Integrate[#1, {#2, #3, #4}] &, x + y + z, {{x, y, z}, {0, 0, 0}, {2, 2, 2}}]
Out[5]=

Create a continued fraction with different numerators:

In[6]:=
ResourceFunction[
 "FoldThread"][#3/(#1 + #2) &, 5, {{a, b, c, d}, {4, 3, 2, 1}}]
Out[6]=

Properties and Relations

Fold and FoldThread give equivalent results for the case in which a single argument is folded:

In[7]:=
ResourceFunction["FoldThread"][f, x, {{x, y, z}}] == Fold[f, x, {x, y, z}]
Out[7]=

Resource History

Related Resources

License Information