(inspired by this question over on Math)
The Definitions
Given an n x n
square matrix A, we can call it invertible
if there exists some n x n
square matrix B such that AB = BA = In, with In being the identity matrix of size n x n
(the matrix with the main diagonal 1
s and anything else 0
), and AB and BA representing usual matrix multiplication (I won't go into that here - go take a linear algebra class).
From that, we can call an m x n
matrix C totally invertible
if every k x k
submatrix (defined below) of C is invertible for all k > 1
, k <= (smaller of m,n)
.
A submatrix is defined as the resulting matrix after deletion of any number of rows and/or columns from the original matrix. For example, the below 3x3
matrix C can be transformed into a 2x2
submatrix C' by removing the first row 1 2 3
and the middle column 2 5 8
as follows:
C = [[1 2 3]
[4 5 6] --> C' = [[4 6]
[7 8 9]] [7 9]]
Note that there are many different submatrix possibilities, the above is just an example. This challenge is only concerned with those where the resulting submatrix is a k x k
square matrix.
The Challenge
Given an input matrix, determine if it is totally invertible or not.
The Input
- A single matrix of size
m x n
, in any suitable format. - Without loss of generality, you can assume
m <= n
orm >= n
, whichever is golfier for your code, and take the input that way (i.e., you get a transpose operation for free if you want it). - The input matrix size will be no smaller than
3 x 3
, and no larger than your language can handle. - The input matrix will consist of only numeric values from Z+ (the positive integers).
The Output
- A truthy/falsey value for whether the input matrix is totally invertible.
The Rules
- Either a full program or a function are acceptable.
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.
The Examples
Truthy
[[1 2 3]
[2 3 1]
[3 1 2]]
[[2 6 3]
[1 12 2]
[5 3 1]]
[[1 2 3 4]
[2 3 4 1]
[3 4 1 2]]
[[2 3 5 7 11]
[13 17 19 23 29]
[31 37 41 43 47]]
Falsey
[[1 2 3]
[4 5 6]
[7 8 9]]
[[1 6 2 55 3]
[4 5 5 5 6]
[9 3 7 10 4]
[7 1 8 23 9]]
[[2 3 6]
[1 2 12]
[1 1 6]]
[[8 2 12 13 2]
[12 7 13 12 13]
[8 1 12 13 5]]
2 6 3; 1 12 2; 5 3 1
? \$\endgroup\$6
in the corner, not a7
. Clumsy typos. \$\endgroup\$