Totally Invertible Submatrices
Jelly, 26 24 23 20 19 17 16 bytes
-1 byte thanks to @miles (unnecessary for each, €
, when taking determinants)
-2 bytes, @miles again! (unnecessary chain separation, and use of Ѐ
quick)
ZœcLÆḊ
œcЀJÇ€€Ȧ
TryItOnline! or all 8 tests
How?
œcЀJÇ€€Ȧ - Main link: matrix as an array, M
J - range of length -> [1,2,...,len(a)] (n)
Ѐ - for each of right argument
œc - combinations of M numbering n
Ç€€ - call the last link (1) as a monad for €ach for €ach
Ȧ - all truthy (any determinant of zero results in 0, otherwise 1)
(this includes an implicit flattening of the list)
ZœcLÆḊ - Link 1, determinants of sub-matrices: row selection, s
Z - transpose s
L - length of s
œc - combinations of transposed s numbering length of s
ÆḊ - determinant
Mathematica 10.0, 34 bytes
#~Minors~n~Table~{n,Tr@#}~FreeQ~0&
A 6-tilde chain... new personal record!
MATL, 57 bytes
tZyt:Y@!"@w2)t:Y@!"@w:"3$t@:)w@:)w3$)0&|H*XHx]J)]xxtZy]H&
Of course, you can Try it online!
Input should be in 'portrait' orientation (nRows>=nColumns). I feel that this may not be the most efficient solution... But at least I'm leaving some room for others to outgolf me. I would love to hear specific hints that could have made this particular approach shorter, but I think this massive bytecount should inspire others to make a MATL entry with a completely different approach. Displays 0 if falsy, or a massive value if truthy (will quickly become Inf if matrix too large; for 1 extra byte, one could replace H*
with H&Y
(logical and)). Saved a few bytes thanks to @LuisMendo.
tZy % Duplicate, get size. Note that n=<m.
% STACK: [m n], [C]
t: % Range 1:m
% STACK: [1...m], [m n], [C]
Y@ % Get all permutations of that range.
% STACK: [K],[m n],[C] with K all perms in m direction.
!" % Do a for loop over each permutation.
% STACK: [m n],[C], current permutation in @.
@b % Push current permutation. Bubble size to top.
% STACK: [m n],[pM],[C] with p current permutation in m direction.
2)t:Y@!" % Loop over all permutations again, now in n direction
% STACK: [n],[pM],[C] with current permutation in @.
@w:" % Push current permutation. Loop over 1:n (to get size @ x @ matrices)
% STACK: [pN],[pM],[C] with loop index in @.
3$t % Duplicate the entire stack.
% STACK: [pN],[pM],[C],[pN],[pM],[C]
@:) % Get first @ items from pN
% STACK: [pNsub],[pM],[C],[pN],[pM],[C]
w@:) % Get first @ items from pM
% STACK: [pMsub],[pNsub],[C],[pN],[pM],[C]
w3$) % Get submatrix. Needs a `w` to ensure correct order.
% STACK: [Csub],[pN],[pM],[C]
0&| % Determinant.
% STACK: [det],[pN],[pM],[C]
H*XHx% Multiply with clipboard H.
% STACK: [pN],[pM],[C]
] % Quit size loop
% STACK: [pN],[pM],[C]. Expected: [n],[pM],[C]
J) % Get last element from pN, which is n.
% STACK: [n],[pM],[C]
] % Quit first loop
xxtZy% Reset stack to
% STACK: [m n],[C]
] % Quit final loop.
H& % Output H only.