Vocabulary
math.matrices

Inputs
 matrix a matrix

Outputs
 seq a sequence

Word description
Find the main diagonal of a matrix.

This diagonal begins in the upper left of the matrix at index { 0 0 }, continuing downward and rightward for all indices { n n } in the square-matrix subset of the input (see <square-rows> ).

Notes
 • If the number of rows in the square subset of the input is even, then this diagonal will not contain elements found in the anti-diagonal. However, if the size of the square subset is odd, then this diagonal will share at most one element with anti-diagonal. • This diagonal is sometimes called the first diagonal. • This word is the opposite variant of anti-diagonal.

Examples
The operation is simple on a square-matrix:
USING: math.matrices prettyprint ; { { 7 2 11 } { 9 7 7 } { 1 8 0 } } main-diagonal .
{ 7 7 0 }

The square subset of the following input matrix consists of all rows but the last. The main diagonal does not include the last row because it has no fourth element.
USING: math.matrices prettyprint ; { { 6 5 0 } { 7 2 6 } { 4 3 9 } { 3 3 3 } } main-diagonal .
{ 6 2 9 }

Definition