18
2
There's a type of n×n matrix W called the basic Weyr canonical form. Such a matrix is described by its blocks and has the following properties, using the following reference diagram:
- the main diagonal blocks Wii are ni×ni matrices of the form λIni where Ini is the ni×ni identity matrix.
- n1 ≥ n2 ≥ ... ≥ nr
- the first superdiagonal blocks Wk-1,k for k ∈ 2..r are nk-1×nk matrices that are full column rank in row-reduced echelon form, or more simply put, Ink sitting on top of nk-1 - nk rows of zeros.
- all other blocks are 0 matrices.
For example:
- The main diagonal blocks (yellow) are such that the ni are 4, 2, 2, and 1.
- The first superdiagonal blocks are in green.
- The grey zone consists of all the other blocks, which are all 0.
For this challenge we will assume λ=1.
Input
A square matrix with 0s and 1s in any convenient format.
Output
Output one of two distinct values for whether the input matrix is Weyr or not Weyr.
Rules
This is code-golf. Fewest bytes in each language wins. Standard rules/loopholes apply.
Test cases
Presented as arrays of rows.
Weyr:
[[1]]
[[1,1],[0,1]]
[[1,0,1,0,0],[0,1,0,1,0],[0,0,1,0,1],[0,0,0,1,0],[0,0,0,0,1]]
[[1,0,0,1,0,0,0,0,0],[0,1,0,0,1,0,0,0,0],[0,0,1,0,0,1,0,0,0],[0,0,0,1,0,0,1,0,0],[0,0,0,0,1,0,0,1,0],[0,0,0,0,0,1,0,0,1],[0,0,0,0,0,0,1,0,0],[0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1]]
[[1,0,0,0,1,0,0,0,0],[0,1,0,0,0,1,0,0,0],[0,0,1,0,0,0,0,0,0],[0,0,0,1,0,0,0,0,0],[0,0,0,0,1,0,1,0,0],[0,0,0,0,0,1,0,1,0],[0,0,0,0,0,0,1,0,1],[0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1]]
Non-Weyr:
[[0]]
[[1,0],[1,1]]
[[1,0,0,1,0,0],[0,1,0,0,0,0],[0,0,1,0,0,1],[0,0,0,1,0,0],[0,0,0,0,1,0],[0,0,0,0,0,1]]
[[1,0,1,0,0],[0,1,0,0,0],[0,0,1,0,0],[0,0,0,1,0],[0,0,0,0,1]]
[[1,0,0,1,0,0,0,0,0],[0,1,0,0,1,0,0,0,0],[0,0,1,0,0,1,0,0,0],[0,0,0,1,0,0,0,0,0],[0,0,0,0,1,0,1,0,0],[0,0,0,0,0,1,0,1,0],[0,0,0,0,0,0,1,0,1],[0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1]]
2Your definition of weyr, matrix is very unclear. In order to understand it I needed to first read the definition from wikipedia (which is not very clear either) and even then your definition is rather vague and ambiguous. For one I would make it clearer what n<sub>i</sub> is and what it is mean to do, currently it is not very clear that a matrix is weyr if such ns exist and rather it seems like they are some property of the matrix. – Post Rock Garf Hunter – 2018-05-30T19:07:06.767
Is it correct that the identity matrix is a Weyr-matrix? – Stewie Griffin – 2018-05-30T19:43:22.560
The identity matrix is be a Weyr matrix with r = 1 and n_1 = n, so yes, albeit a degenerate one. – S.Klumpers – 2018-05-30T20:10:04.710
2Suggested test case:
[[1,0,0,1,0,0,0,0,0],[0,1,0,0,1,0,0,0,0],[0,0,1,0,0,1,0,0,0],[0,0,0,1,0,0,0,0,0],[0,0,0,0,1,0,1,0,0],[0,0,0,0,0,1,0,1,0],[0,0,0,0,0,0,1,0,1],[0,0,0,0,0,0,0,1,0],[0,0,0,0,0,0,0,0,1]]
. I think it's falsy (but my answer fails to identify it as such). – Arnauld – 2018-05-30T21:43:45.830The definitions you included suggest you only want to identify basic weyr matrices, and not general weyr matrices. Is this what you intended for this challenge? – S.Klumpers – 2018-05-31T06:58:15.863
@S.Klumpers what do you mean by degenerate? Did you mean trivial? – dylnan – 2018-05-31T13:23:19.220
I meant to say it is a degenerate case, but I forgot that it could be confused with a degenerate matrix, which is of course not what I meant. So yeah trivial would have been a better choice of words. – S.Klumpers – 2018-05-31T13:52:11.833
I can’t exactly see how the ngn/k answer works, but I tried to write a purely iterative implementation, as opposed to the JS answer, in x86 machinecode that didn’t go so well. Should I post the Java code I tried to base it off as a non-competitive reference? – S.Klumpers – 2018-06-03T07:09:01.257