4
$\begingroup$

I am trying to make a list of 2x2 matrices whose entries are all possible permutations of 0,1,2 and det=1 mod 2 arithmetic.

First I tried to create a Table like this

T1 = Table[{{i, j}, {m, n}}, {i, 0, 2}, {j, 0, 2}, {n, 0, 2},{m,0,2}]

But how to extract it as a list of matrices in MatrixForm and including the condition of determinant one?

$\endgroup$
  • $\begingroup$ I saw that you changed the requirement for the determinant. I added that option to my answer. $\endgroup$ – MarcoB Dec 10 '19 at 16:19
6
$\begingroup$

Using your Table expression, you will want to Flatten the results to obtain a list of matrices, rather than nested lists:

t1 = Table[{{i, j}, {m, n}}, {i, 0, 2}, {j, 0, 2}, {n, 0, 2}, {m, 0, 2}]~Flatten~3;

The same thing can be obtained more directly using Tuples:

t1 = Tuples[Range[0, 2], {2, 2}]

You will then Select those matrices that have a unity determinant and apply MatrixForm to them individually using Map:

MatrixForm /@ Select[t1, Det[#] == 1 &]

pretty-printed matrices


The question was recently changed to specify that the determinant should be 1 when considered modulo 2. This can be included as well:

MatrixForm /@ Select[t1, Mod[Det[#], 2] == 1 &]

printed matrices with modulo 2 restriction


It is worth it to add the usual caveat: MatrixForm is a formatting wrapper that pretty-prints your matrices, but it will hinder further evaluation; see Why does MatrixForm affect calculations?.

$\endgroup$
  • $\begingroup$ Cool, didn't know about the Tuples[...,{2,2}] form to directly obtain the matrices, nice! $\endgroup$ – Thies Heidecke Dec 10 '19 at 15:25
  • $\begingroup$ @Thies Yeah, it's pretty handy! $\endgroup$ – MarcoB Dec 10 '19 at 15:27
7
$\begingroup$
n = 2;
sol = Solve[{Mod[a d - b c, 2] == 1, 
    And @@ Thread[0 <= {a, b, c, d} <= n]}, {a, b, c, d}, Integers];

solutions = {{a, b}, {c, d}} /. sol;

Length @ solutions

16

TeXForm @ Grid[Partition[MatrixForm /@ solutions, 4]]

$\begin{array}{cccc} \left( \begin{array}{cc} 0 & 1 \\ 1 & 0 \\ \end{array} \right) & \left( \begin{array}{cc} 0 & 1 \\ 1 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 0 & 1 \\ 1 & 2 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 0 \\ 0 & 1 \\ \end{array} \right) \\ \left( \begin{array}{cc} 1 & 0 \\ 1 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 0 \\ 2 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 1 \\ 0 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 1 \\ 1 & 0 \\ \end{array} \right) \\ \left( \begin{array}{cc} 1 & 1 \\ 1 & 2 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 1 \\ 2 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 2 \\ 0 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 1 & 2 \\ 1 & 1 \\ \end{array} \right) \\ \left( \begin{array}{cc} 1 & 2 \\ 2 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 2 & 1 \\ 1 & 0 \\ \end{array} \right) & \left( \begin{array}{cc} 2 & 1 \\ 1 & 1 \\ \end{array} \right) & \left( \begin{array}{cc} 2 & 1 \\ 1 & 2 \\ \end{array} \right) \\ \end{array}$

For n = 3 we get

Length @ solutions

96

Grid[Partition[MatrixForm /@ solutions, 12]]

enter image description here

$\endgroup$
  • $\begingroup$ Can you please include the mod 2 condition also? I mean to say the det one condition is in modular arithmetic 2. Thanks $\endgroup$ – ricci1729 Dec 10 '19 at 16:05
  • $\begingroup$ @ricci1729, please see the updated version. $\endgroup$ – kglr Dec 10 '19 at 16:18
  • $\begingroup$ Thanks a lot for your help. One last question .. How to find the number of the total matrics? I used Length but it did not give the result. Please let me know. $\endgroup$ – ricci1729 Dec 10 '19 at 16:21
  • 1
    $\begingroup$ Length @ sol or Length @ solutions $\endgroup$ – kglr Dec 10 '19 at 16:26
4
$\begingroup$

As long as you don't deal with big matrices or big ranges of possible integer entries, i.e. you don't have to fear combinatorial explosion, you can just brute force generate all of them, and then select the proper ones via Select:

matrices = With[{n = 2, legalmatrixentries = Range[0, 2]}, 
  Select[
    Tuples[legalmatrixentries, {n,n}], 
    OddQ @* Det (* (Mod[Det[#], k] == 1 &) for general modular arithmetic mod k *)
  ]
]
MatrixForm /@ matrices

$$ \left\{\left( \begin{array}{cc} 0 & 1 \\ 1 & 0 \\ \end{array} \right),\left( \begin{array}{cc} 0 & 1 \\ 1 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 0 & 1 \\ 1 & 2 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 0 \\ 0 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 0 \\ 1 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 0 \\ 2 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 1 \\ 0 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 1 \\ 1 & 0 \\ \end{array} \right),\\\left( \begin{array}{cc} 1 & 1 \\ 1 & 2 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 1 \\ 2 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 2 \\ 0 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 2 \\ 1 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 1 & 2 \\ 2 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 2 & 1 \\ 1 & 0 \\ \end{array} \right),\left( \begin{array}{cc} 2 & 1 \\ 1 & 1 \\ \end{array} \right),\left( \begin{array}{cc} 2 & 1 \\ 1 & 2 \\ \end{array} \right)\right\} $$

Related integer sequences:

  • Nr. of solutions for the mod2 case: A210370
  • Nr. of solutions for the non mod2 case: A171503

Updated

  • Updated answer to give solutions for modular arithmetic (mod 2)
$\endgroup$
  • 1
    $\begingroup$ You could give multiple dimensions to Tuples to get arrays directly, e.g. Tuples[legalmatrixentries, {n, n}], so you can avoid the Partition. $\endgroup$ – MarcoB Dec 10 '19 at 15:25
  • $\begingroup$ wrong range btw $\endgroup$ – Alucard Dec 10 '19 at 15:26
  • $\begingroup$ @MarcoB thanks for pointing that out, didn't know about it, i like! thanks! $\endgroup$ – Thies Heidecke Dec 10 '19 at 15:28
  • $\begingroup$ @Alucard The title and the code example in the OP are not matching, so i just picked the example from the title. $\endgroup$ – Thies Heidecke Dec 10 '19 at 15:28
  • $\begingroup$ Thanks a lot. Actually I did a little mistake while making the question... I wish to make the list of matrices with modular arithmetic 2 along with det one condition. I tried Modulus==2 & but it didn't work. Please let me how to incorporate the additional condition. Thanks a lot. $\endgroup$ – ricci1729 Dec 10 '19 at 15: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.