# list manipulation – Finding the sum of all subsets of a given set

``````Clear("Global`*")

Format(a(n_)) := Subscript(a, n);
Format(b(n_)) := Subscript(b, n);

list(1) = {{1, 1, 0}, {1, 0, 1}, {0, 1, 1}, {-1, 1, 0}, {1, -1, 0}, {-1, -1,
0}, {-1, 0, 1}, {1, 0, -1}, {-1, 0, -1}, {0, -1, 1}, {0,
1, -1}, {0, -1, -1}};

list(2) = {{2, 0, 0}, {0, 2, 0}, {0, 0, 2}, {-2, 0, 0}, {0, -2, 0}, {0,
0, -2}};
``````

Create a replacement `Rule` for each list element

``````(repl(#) =
Array({a, b}((#)), Length(list(#))))) & /@ {1, 2}
``````

The above code which @Bob Hanlon gave, turns `list(1)` in a form that `list(1)={a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12}`; where `a1={1, 1, 0}, a2={1, 0, 1}, a3={0, 1, 1}, a4={-1, 1, 0}, a5={1, -1, 0}, a6={-1, -1, 0},a7= {-1,0,1}, a8= {1,0,-1}, a9= {-1,0,-1}, a10={0,-1,1}, a11={0,1,-1}, a12={0,-1,-1},`
and turns `list(2)` in a form that `list2={b1, b2, b3, b4, b5, b6}` where `b1={2, 0, 0}, b2={0, 2, 0}, b3={0, 0, 2}, b4={-2, 0, 0}, b5={0, -2, 0}, b6={0, 0, -2}.`

Let me explain my problem with an example. Given a set of indexed variables, let say `list(3)={(a(1),a(2),(b4)}`. First ı want to find all subsets of `list(3)`, that is `list(3)={ {}, {a(1)}, {a(2)}, {(b4)}, {(a(1),a(2)},{(a(1),b(4)}, {a(2),b(4)}, {(a(1),a(2),(b4)} }`. Then, ı want to sum up the elements of each subsets and represent each summation in the tuple form, and finally ı want to list all results with corresponding indexed variables.

So the final results may have the form `{},0, {a(1)},{1, 1, 0}, {a(2)},{1, 0, 1}, {b(4)},{-2, 0, 0}, {(a(1),a(2)},{2, 1, 1}, {(a(1),b(4)},{-1,1,0}, {a(2),b(4)},{-1,0,1}, {(a(1),a(2),(b4)}, {0, 1, 1}`. To make it more clear. Here, for example, `{(a(1),a(2)},{2, 1, 1}` should be read as: when we do `(a(1)+(2)`, it gives `{2, 1, 1}` Similarly, `{(a(1),a(2),(b4)}, {0, 1, 1}` should be read as: when we do`(a(1)+a(2)+(b4)`, it gives `{0, 1, 1}`.

I did the following algorithm which gives desired result, but it is not efficient. Because, I need to enter indexed elements into list(3) , and also need to enter corresponding tuples into list(4). The code is given as follows:

``````FFF = list(3) = {a(1), a(2), b(4)};
list(4) = {{1, 1, 0}, {1, 0, 1}, {-2, 0, 0}};
K = Subsets(list(3))
F = Subsets(list(4))   For(i = 1, i <= Length(F), i++,
Print("(case No. " , i, ")", K((i)), Total(F((i)))
));
``````

I would like to ask how can we update this code such as I need only to enter elements of `list(3)` ,and I got desired results. If it is not possible, then entering only elements of `list(4) `and getting desired result will be fine as well. I think Bob Hanlon’s code which I explained in the beginning can be used, but I could not manage it.