0
$\begingroup$

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

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – CA Trevillian Oct 20 '19 at 12:37
  • 1
    $\begingroup$ (2)every row must contain at least a "4", then just ignore the last list. $\endgroup$ – OkkesDulgerci Oct 20 '19 at 13:03
  • $\begingroup$ Do you think there is a typo at 7th entry? May you meant {-4,-4,-4,4} $\endgroup$ – OkkesDulgerci Oct 20 '19 at 14:30
  • $\begingroup$ yes it is a typo, needs to be {-4,-4,-4,4} $\endgroup$ – gunes Oct 20 '19 at 14:35
0
$\begingroup$

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}

$\endgroup$
  • $\begingroup$ Comments are not for extended discussion; this conversation has been moved to chat. $\endgroup$ – Kuba Oct 23 '19 at 5:26
0
$\begingroup$
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}

$\endgroup$
0
$\begingroup$

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
$\endgroup$
  • $\begingroup$ I run the code, but the length appears as 3 and also the outputs are not working. $\endgroup$ – gunes Oct 20 '19 at 18:06
  • $\begingroup$ I think you need version 12 and a cloud account (free). $\endgroup$ – SHuisman Oct 20 '19 at 18:57
  • $\begingroup$ 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. $\endgroup$ – gunes Oct 21 '19 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.