Okay, got it. I'd suggest that when using Mathematica don't use looping constructs as your first strategy. There are usually built-in functions that already exist to do all of the "standard" things that are done with loops in other languages. I'll walk you through my strategy. Caveat: I don't know what a "norm-4 vector in E8" is, so I'm just guessing based on what I can infer from your comments so far. So, the result here is probably wrong, but hopefully it's close enough for you to modify it to give you what you want.
I'd start with the basic constraint for "norm-4 vector", which I'm guessing means something like "the sum of the squares of the terms is 4". So, I can just list out examples (excluding zero terms):
init = {{2}, {1, 1, 1, 1}, {1, 1, 1, -1}, {1, 1, -1, -1}, {1, -1, -1, -1}, {-1, -1, -1, -1}}
I could have just included the zero terms, but I know there is a PadRight
function, which I'll use next:
vectors = PadRight[init, {Automatic, 8}]
(* {{2, 0, 0, 0, 0, 0, 0, 0},
{1, 1, 1, 1, 0, 0, 0, 0},
{1, 1, 1, -1, 0, 0, 0, 0},
{1, 1, -1, -1, 0, 0, 0, 0},
{1, -1, -1, -1, 0, 0, 0, 0},
{-1, -1, -1, -1, 0, 0, 0, 0}} *)
Now we need all permutations for each of those, and we can do that with Permutations
:
Permutations /@ vectors
This will give a set for each original vector, but we want just the list of vectors without that extra layer of structure, and Catenate
will "join" together the sets, so I'd apply Catenate
:
result = Catenate[Permutations /@ PadRight[init, {Automatic, 8}]]
This seems to be the form you're looking for--here's a sample of every 100th vector in the result:
result[[1 ;; ;; 100]]
(* {{2, 0, 0, 0, 0, 0, 0, 0}, {1, 1, 0, 0, -1, 0, 1, 0},
{-1, 0, 1, 1, 0, 0, 1, 0}, {0, 0, 1, 1, 1, 0, 0, -1},
{1, -1, 0, 0, 0, -1, 0, 1}, {-1, -1, 0, 1, 0, 0, 1, 0},
{0, 1, 0, 1, -1, 0, 0, -1}, {0, 0, 1, -1, 0, 1, -1, 0},
{1, 0, -1, 0, 0, -1, -1, 0}, {-1, 0, 0, -1, 0, 1, -1, 0},
{0, 0, 1, -1, -1, 0, 0, -1}, {0, -1, -1, 0, 0, -1, -1, 0}} *)
At this point, I know I've misunderstood the semantics, because
Length[result]
(* 1128 *)
instead of 1080. So either this gets you close enough to fix on your own, or else you can explain the actual semantics to me more specifically. Or maybe someone else here that has the mathematical knowledge can give you the correct derivation.