listing matrices with some special constraint

Let we have

list = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4,4, 4, -4}, {-4, -4, 4, 4}, {-4, -4, -4, 4}, {-4, -4, -4, -4}}

I would like to first obtain the list of all possible 4 x 4 matrices which are created considering every 4 tuples in the above list as columns of the matrix.

From this list, I would like to have the list of matrices satisfying the following properties at the same time.

1. Determinant is non-zero
2. Every row must contain at least a "4"
3. The row which is obtained by the sum of any two rows must contain at least an "8".
4. If a higher index row is substracted from a lower index row, then there must be an "8"

thanks

• Tuples is your friend here! You should post your code, too, for us to help you with, after you take a look at the link I posted. Oct 20, 2019 at 12:37
• (2)every row must contain at least a "4", then just ignore the last list. Oct 20, 2019 at 13:03
• Do you think there is a typo at 7th entry? May you meant {-4,-4,-4,4} Oct 20, 2019 at 14:30
• yes it is a typo, needs to be {-4,-4,-4,4} Oct 20, 2019 at 14:35

Edit2 We can use @SHuisman condition checker

  list = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4,
4, 4, -4}, {-4, -4, 4, 4}, {-4, -4, -4, 4}, {-4, -4, -4, -4}};
mat = Transpose /@ Permutations[list, {4}];
result = Select[mat,
Det@# != 0 && AllTrue[#, MemberQ[4]] &&
AllTrue[Plus @@@ Subsets[#, {2}], MemberQ[8]] &&
AllTrue[Subtract @@@ Subsets[#, {2}], MemberQ[8]] &];
Length@result


96

Edit:

list = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4,
4, 4, -4}, {-4, -4, 4, 4}, {-4, -4, -4,
4}, {-4, -4, -4, -4}} /. {4 -> 1, -4 -> -1};
det = Select[mat, Det@# != 0 &];
cond2 = Map[MemberQ[#, 1] &, det, {2}];
det = Extract[det, Position[cond2, Table[True, 4]]];
cond3 = Map[MemberQ[#, 2] &,
Apply[#1 + #2 &, Subsets[#, {2}] & /@ det, {2}], {2}];
det = Extract[det, Position[cond3, Table[True, 6]]];
cond4 = Map[MemberQ[#, 2] &,
Apply[#1 - #2 &, Subsets[#, {2}] & /@ det, {2}], {2}];
result2 = Extract[det, Position[cond4, Table[True, 6]]];
Length@result


96

You have repeated element 5th and 7th: delete 7th and the last one we will have

list = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4,
4, 4, -4}, {-4, -4, 4, 4}};


Since Det will be zero whenever there are two identical rows, better to use Permutations

list = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4,
4, 4, -4}, {-4, -4, 4, 4}};
mat = Permutations[list, {4}];
mat2 = Select[mat, Det@# != 0 &];
Length@mat2


312

Condition 3 automatically apply:

condition3 = Thread[Total /@ Total /@ Permutations[list, {2}] >= 8]


{True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True, True}

• Comments are not for extended discussion; this conversation has been moved to chat.
– Kuba
Oct 23, 2019 at 5:26
rows = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4, 4, 4, -4}, {-4, -4, 4, 4}, {4, 4, 4, -4}};

det = Select[Tuples[rows, 4], Det@# =!= 0 &];

result = Select[det,
MemberQ[MemberQ[#, 8] & /@ (Total /@ Tuples[#, 2]), True] &];

Length /@ {det, result}


{528, 528}

Another way is using the WFR function SelectPermutations:

list = {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}, {4,
4, 4, -4}, {-4, -4, 4, 4}, {-4, -4, -4, 4}, {-4, -4, -4, -4}};
out = ResourceFunction["SelectPermutations"][list, {4},
Det[#] =!= 0 && AllTrue[#, MemberQ[4]] &&
AllTrue[Plus @@@ Subsets[#, {2}], MemberQ[8]] &&
AllTrue[Subtract @@@ Subsets[#, {2}], MemberQ[8]] &];
Length[out]


returns:

122

• I run the code, but the length appears as 3 and also the outputs are not working. Oct 20, 2019 at 18:06
• I think you need version 12 and a cloud account (free). Oct 20, 2019 at 18:57
• I run the code with version 12. There is something wrong, for example first ouput matrix is : {{4, 4, 4, 4}, {-4, 4, 4, 4}, {4, -4, 4, 4}, {4, 4, -4, 4}} which does not satisfy the 4th condition. for instance, 2nd row minus 1st row does not give an 8, but It gives a -8. Oct 21, 2019 at 19:49