Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question

3 Answers 3

up vote 10 down vote accepted
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.

share|improve this answer

Try :

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

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

share|improve this answer
1  
Good one. And maybe sum[[0]] = List; sum –  TomD Oct 22 '12 at 19:32
1  
@TomD that is the one I like to use :) –  Mike Honeychurch Oct 22 '12 at 22:24

Still another route:

Last[CoefficientArrays[#]] Variables[#] &[a - b + c + d]
   {a, -b, c, d}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.