# listing of vectors satisfying some special constraint

We have

list = {{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}}

list2 ={{2, 0, 0}, {0, 2, 0}, {0, 0, 2}, {-2, 0, 0}, {0,-2, 0}, {0, 0, -2}}

1st Problem: I would like to obtain the list of all possible distinct three vectors from the list where the sum of these vectors gives the zero vector.

For example: {1, 1, 0}+{-1, 0, 1}+{0, -1, -1}=={0,0,0}. Hence, {1, 1, 0},{-1, 0, 1},{0, -1, -1} are one of three vectors which we want in our list.

2nd Problem: I would like to obtain the list of all possible distinct four vectors (no duplication is allowed) such that three vectors will be selected from the list, and one vector will be selected from list2 and the sum of these 4 vectors gives the zero vector.

For example: {{2,0,0},{1,1,0},{-1,-1,0},{-1,0,1},{-1,0,-1}} is in our list, where {2,0,0} is selected from list2, and the other 3 vectors are selected from the list.

• For large lists where brute-force enumeration might be impractical, this might be best cast as an Integer Linear Programming problem. Commented May 9, 2021 at 14:28

If you don't want duplicates (i.e., pick each 3-list at most once) and don't want permutations (i.e., only ordered solutions),

Select[Subsets[list, {3}], Total[#] == {0, 0, 0} &]
(*    {{{1, 1, 0}, {-1, 0, 1}, {0, -1, -1}},
{{1, 1, 0}, {-1, 0, -1}, {0, -1, 1}},
{{1, 0, 1}, {-1, 1, 0}, {0, -1, -1}},
{{1, 0, 1}, {-1, -1, 0}, {0, 1, -1}},
{{0, 1, 1}, {1, -1, 0}, {-1, 0, -1}},
{{0, 1, 1}, {-1, -1, 0}, {1, 0, -1}},
{{-1, 1, 0}, {1, 0, -1}, {0, -1, 1}},
{{1, -1, 0}, {-1, 0, 1}, {0, 1, -1}}}    *)


There are only 8 such solutions. Permuting these will give @UlrichNeumann's 48 solutions.

For the second problem, we check if the sum of three vectors is in -list2:

Select[Subsets[list, {3}], MemberQ[-list2, Total[#]] &]
(*    {{{1, 1, 0}, {1, 0, 1}, {0, -1, -1}},
{{1, 1, 0}, {0, 1, 1}, {-1, 0, -1}},
{{1, 1, 0}, {-1, 0, 1}, {0, -1, 1}},
{{1, 1, 0}, {-1, 0, 1}, {0, 1, -1}},
{{1, 1, 0}, {1, 0, -1}, {0, -1, 1}},
{{1, 1, 0}, {-1, 0, -1}, {0, -1, -1}},
{{1, 0, 1}, {0, 1, 1}, {-1, -1, 0}},
{{1, 0, 1}, {-1, 1, 0}, {0, -1, 1}},
{{1, 0, 1}, {-1, 1, 0}, {0, 1, -1}},
{{1, 0, 1}, {1, -1, 0}, {0, 1, -1}},
{{1, 0, 1}, {-1, -1, 0}, {0, -1, -1}},
{{0, 1, 1}, {-1, 1, 0}, {1, 0, -1}},
{{0, 1, 1}, {1, -1, 0}, {-1, 0, 1}},
{{0, 1, 1}, {1, -1, 0}, {1, 0, -1}},
{{0, 1, 1}, {-1, -1, 0}, {-1, 0, -1}},
{{-1, 1, 0}, {-1, 0, 1}, {0, -1, -1}},
{{-1, 1, 0}, {1, 0, -1}, {0, -1, -1}},
{{-1, 1, 0}, {-1, 0, -1}, {0, -1, 1}},
{{1, -1, 0}, {-1, 0, 1}, {0, -1, -1}},
{{1, -1, 0}, {-1, 0, -1}, {0, -1, 1}},
{{1, -1, 0}, {-1, 0, -1}, {0, 1, -1}},
{{-1, -1, 0}, {-1, 0, 1}, {0, 1, -1}},
{{-1, -1, 0}, {1, 0, -1}, {0, -1, 1}},
{{-1, -1, 0}, {1, 0, -1}, {0, 1, -1}}}    *)

• Thanks @Roman, I extended the problem with two lists. How can we adapt your code for the 2nd problem? Commented May 8, 2021 at 20:43

Try

list = {{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}};


All triple combinations:

triple = Tuples[list, 3]
Select[triple, Total[#] == {0, 0, 0} &]
(*{{{1, 1, 0}, {-1, 0, 1}, {0, -1, -1}},
{{1, 1, 0}, {-1,0, -1}, {0, -1, 1}},
{{1, 1, 0}, {0, -1, 1}, {-1, 0, -1}},...}*)


Mathematica finds 48 possibilities!

slist = Subsets[list, {3}];

• Perhaps listb=Subsets[list2,{b}] and Table[{li, Select[slist,Total[ #] == -Total[li] &]}, {li, listb}]? Commented May 9, 2021 at 9:36
• In this case you probably have to use Tuples instead of Subsets I think. Commented Jul 8, 2021 at 6:39
• @gunes Perhaps Association is what you're looking for. Please ask a new question, if you need further assistance. Commented Jul 9, 2021 at 6:08