Since no one mentioned this, it is equivalent to building the Yoda Level[expr, 1]
, you should use Apply to replace the head of the expression with List
:
In[1]:= expr = a + b - c + d + 4 e - 3 f; In[2]:= List @@ expr Level[expr, 1] == % Out[2]= {a, b, -c, d, 4 e, -3 f} Out[3]= True In[4]:= expr2 = a^2 + 5 bc/ef - Sqrt[g - h] - Cos[i]/Sin[j + k]; In[5]:= List @@ expr2 Level[expr2, 1] == % Out[5]= {a^2, (5 bc)/ef, -Sqrt[g - h], -Cos[i] Csc[j + k]} Out[6]= True
The two methods do basically the same thing and have the same timings (using my version of the middle sync function )
In[1]:= SetOptions[TimeAv, Method -> {"MinNum", 80000}, "BlockSize" -> 20000]; In[7]:= List @@ expr // TimeAv Total wall time is 0.244517, total cpu time is 0.13 and total time spent evaluating the expression is 0.13 The expression was evaluated 80000 times, in blocks of 20000 runs. This yields a mean timing of 1.625*10^-6 with a blocked standard deviation of 2.16506*10^-7. Out[7]= {1.625*10^-6, {a, b, -c, d, 4 e, -3 f}} In[8]:= Level[expr, 1] // TimeAv Total wall time is 0.336927, total cpu time is 0.16 and total time spent evaluating the expression is 0.16 The expression was evaluated 80000 times, in blocks of 20000 runs. This yields a mean timing of 2.*10^-6 with a blocked standard deviation of 3.53553*10^-7. Out[8]= {2.*10^-6, {a, b, -c, d, 4 e, -3 f}}