# Transform a Sum into a List

I want to turn a sum like this

sum =a-b+c+d


Into a List like this:

sumToList[sum]={a,-b,c,d}


How can I achieve this?

• I am a professor of "vectorial analysis" in Mexico. I try to teach the subjects with the use of "Mathematica". I solved a problem seeing this page and also this: mathematica.stackexchange.com/questions/100758/… ... in which I was not allowed to comment. This was what I did to find the "scalar potential function". i.stack.imgur.com/ugIlP.png Feb 6, 2017 at 17:43
• @David I converted your answer to a comment, as it seems more appropriate as such. I know that new users do not have the "privilege" to comment everywhere (a "spam" control measure I believe) but if you continue to participate you will find that you soon do. Feb 6, 2017 at 19:12

List @@ sum


{a, -b, c, d}

From the docs on Apply (@@):

f@@expr replaces the head of expr by f.

So List@@sum replaces Head[sum] (that is, Plus) with List.

You can also get the same result by changing 0th Part of sum (which is its Head) to List:

sum[[0]] = List; sum


{a, -b, c, d}

• There is a slight hiccup that you can encounter using this. If you're not explicitly doing a sum, you will list over whatever the head of the function is. e.g. List @@ 2*3 will result in {2,3} Feb 10, 2017 at 17:10
• @AlexDB, you are right; List@@expr does change the head of expr, whatever it is, to List.
– kglr
Feb 10, 2017 at 17:16
• So what's the most general way to make a list, so that we include both distinct cases where there is one and multiple terms?
– hal
Aug 7, 2020 at 18:30

Try :

a - b + c + d /. Plus -> List


You can have a look at a - b + c + d //FullForm to see why this works.

• Good one. And maybe sum[[0]] = List; sum Oct 22, 2012 at 19:32
• @TomD that is the one I like to use :) Oct 22, 2012 at 22:24

Still another route:

Last[CoefficientArrays[#]] Variables[#] &[a - b + c + d]
{a, -b, c, d}