# How to transform a list (of sums) into list of summands

Suppose you have the list list={a,Sin[b+c],d+c}. What I want is to transform all elements of list with head Plus into a list again, so that the desired output would be {a,Sin[b+c],d,c}. Simply using List@@ or /.Plus->List will for sure not work since it either transforms all heads (including those that should be left unchanged) or e.g. replaces function arguments.

So what is a neat way to accomplish this potentially very easy task?

• Does the order matter, i.e., {a, Sin[b+c],c,d} vs your result. – ciao Aug 11 '15 at 2:07
• @ciao The order does not matter. All elements will be symbolic terms that will be summed up at the very end of a long computation. But thanks for pointing this out - I didn't think about the importance while posting the question :) – Lukas Aug 11 '15 at 2:45
• Then Jens' answer is the way to go... – ciao Aug 11 '15 at 2:50

list = {a, Sin[b + c], d + c};

Replace[list, HoldPattern[Plus[x__]] :> Sequence[x], 1]

(* ==> {a, Sin[b + c], {c, d}} *)


Here, HoldPattern is needed to prevent the Plus from being swallowed. I use Replace because it allows me to specify the level 1 at which the replacement is to occur.

• Not what they're after... c d s/b sequence... – ciao Aug 11 '15 at 2:12
• @Ciao Oh, right... – Jens Aug 11 '15 at 2:13
• And if order matters.... whole 'nother ball-o-wax, +1 though ;-) – ciao Aug 11 '15 at 2:14
• @ciao Thanks - you're right that the order could be tricky because you have to deal with the lexical rules. – Jens Aug 11 '15 at 2:16
• You can also do Replace[list, Plus -> Sequence, {2}, Heads -> True] – mfvonh Aug 11 '15 at 3:01