1 | initial version |
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:
sage: R = [0..9]
sage: C = cartesian_product( (R,R,R,R) )
sage: len(C)
10000
sage: C.random_element()
(6, 5, 4, 7)
One can build the matrix with the las entries (last value is _
in the sage interpreter) like this:
sage: _
(6, 5, 4, 7)
sage: matrix( ZZ, 2, 2, list(_) )
[6 5]
[4 7]
So the number of invertible matrices $S$ of the given shape is:
sage: R = [0..9]
sage: C = cartesian_product( (R,R,R,R) )
sage: len( [ c for c in C if matrix( ZZ, 2, 2, list(c) ).det() ] )
9430
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
.