Matrix Permutations

For the following exercise I would like to get all permutations of a Matrix with integer values in the range $0$ to $9$. There should be $10^4$ permutations. And then generate the permutations of tuples with three matrices. $10^{12}$ permutations and then I would filter the list somehow for the invertible matrices.

2 answers

For the exercise, to loop among the list of all 2x2 matrices with entries in [0..9] the suitable mathematical construction is the cartesian product of four copies of [0..9]. This may be achieved like this:

The product $STU$ is invertible iff each matrix in it is invertible. So the exercise is solved in one more line. It is a good idea to use structure in mathematics, when it is possible. Brute force can then confirm the result.

Note: Permutations are not involved in the exercise. Inn order to get info on this or an other mathematical object, just try the first letters of it in the sage interpreter, which has autocompletion. We can try here perm[TAB] and/or Perm[TAB]. In the second case we get a list of classes / constructors, among them we can put a question mark before or after...

sage: Permutation?

to get more information on this. The sage interpreter is a good tool to learn sage.

As it is written: "The product STU is invertible if and only if each of the matrices S, T and U is invertible." So there is no need to compute all the products (that would be too long to terminate anyway).

It is possible to make an even less computational solution than in @dan_fulea answer. As already mentioned, we simply want to count the solutions of a d - b c != 0 where a, b, c, d are elements of {0, 1, ..., 9}. This is easily obtained from the number of solutions of ad - bc = 0 which itself can be obtained by solving x y = s for all possible values of s. For example

Here 570 is the number of non-invertible matrices with entries in {0, 1, ..., 9}. Now, we can even be more clever. The number of solutions for xy = s is, excepted for s = 0, the number of divisors d of s that belongs to {1, ..., 9} and so that s/d also beongs to {1, ..., 9}. We recover 570 with

Comments

Thanks for the post! I must confess, this was the first solution i wanted to type, then saw that there is a little combinatorial point to explain when we place the a,b,c,d elements with ad == bc on the two diagonals in case a == d and/or b == c. Since the cartesian product was already an issue, i decided to avoid combinatorics. This means then to compute for each possible product the number of the ways to produce it. Of course, we do not have $10^4$ cases, since for each possible product we can count the pairs. At most $10^2$ cases. But then i was generous to get all $10^4$. The argument is not better, but it better illustrates the cartesian product as a construction. I was really glad to see it in action for $S,T,U$ again. (Although the bits needed are too many.)

It is a good homework to try to implement this idea for counting $3\times 3$ invertible matrices with entries among $0,1,2,3,4,5,6,7,8,9$. The $10^9$-steps loop would not be my solution. (Of course, there is no structural meaning for the number obtained after much work, just an exercise. The experience will eventually pay later many times the dividends...)