Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
A partial inverse for Thread
ResourceFunction["Unthread"][f[g[a1,…,an],g[b1,…,bn],…]] "unthreads" g to return g[f[a1,b1,…],…,f[an,bn,…]]. |
"PreserveRepeats" | True | whether to preserve all repeating elements or flatten them |
Unthread f from a list:
In[1]:= | ![]() |
Out[1]= | ![]() |
Unthread a head with two arguments:
In[2]:= | ![]() |
Out[2]= | ![]() |
Convert lists of equations to equations for lists:
In[3]:= | ![]() |
Out[3]= | ![]() |
Unthread a Thread:
In[4]:= | ![]() |
Out[4]= | ![]() |
In[5]:= | ![]() |
Out[5]= | ![]() |
In[6]:= | ![]() |
Out[6]= | ![]() |
In[7]:= | ![]() |
Out[7]= | ![]() |
By default, repeating elements in the output of Unthread will all appear:
In[9]:= | ![]() |
Out[9]= | ![]() |
In[10]:= | ![]() |
Out[10]= | ![]() |
In[11]:= | ![]() |
Out[11]= | ![]() |
In this case, Unthread can be coerced into being an inverse by setting "PreserveRepeats"→False:
In[12]:= | ![]() |
Out[12]= | ![]() |
Unthread is just another form of Thread, where the second argument is chosen automatically:
In[13]:= | ![]() |
Out[13]= | ![]() |
In[14]:= | ![]() |
Out[14]= | ![]() |
In[15]:= | ![]() |
Out[15]= | ![]() |
Unthread is a generalization of Transpose:
In[16]:= | ![]() |
Out[16]= | ![]() |
In[17]:= | ![]() |
Out[17]= | ![]() |
In[18]:= | ![]() |
Out[18]= | ![]() |
Unthread is its own inverse:
In[19]:= | ![]() |
Out[19]= | ![]() |
In[20]:= | ![]() |
Out[20]= | ![]() |
In[21]:= | ![]() |
Out[21]= | ![]() |
In[22]:= | ![]() |
Out[22]= | ![]() |
Unthread cannot always invert Thread, even when using "PreserveRepeats"→False:
In[23]:= | ![]() |
Out[23]= | ![]() |
In[24]:= | ![]() |
Out[24]= | ![]() |
In[25]:= | ![]() |
Out[25]= | ![]() |
In[26]:= | ![]() |
Out[26]= | ![]() |
The inner expressions must have the same number of arguments:
In[27]:= | ![]() |
Out[27]= | ![]() |
The inner expressions must have the same Head:
In[28]:= | ![]() |
Out[28]= | ![]() |
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License