# Splitting list of sums into a sum of lists

I want to split a list of sums into a sum of lists For example, I'd like to turn

{{x + y + z}, {x}, {y}, {z}}


into

x{{1}, {1}, {0}, {0}} +y{{1}, {0}, {1}, {0}} + z{{1}, {0}, {0}, {1}}


as you would when turning a vector with a sum inside it into a sum of vectors.

I've looked all over for documentation for this kind of thing, but I couldn't find anything :(. It would be even further helpful if someone could tell me how to put these three vectors into a single list, I know I can append them, I'm just not sure how to do it when they're being multiplied by something.

You can do this using CoefficientArrays:

expr   = {{x + y + z}, {x}, {y}, {z}};
coeffs = Last@CoefficientArrays[expr, {x, y, z}] ~Flatten~ 1 // Transpose // Normal
(* {{1, 1, 0, 0}, {1, 0, 1, 0}, {1, 0, 0, 1}} *)


You can just Dot this with the variable list to get back the original list:

{x, y, z} . Map[List, coeffs, {2}]
(* {{x + y + z}, {x}, {y}, {z}} *)

• You are a saint, thank you so much! Apr 26, 2013 at 5:32