Smith normal form

Let A be a non-zero m cross times n matrix over a principal ideal domain (PID). Then, there exist invertible m cross times m and n cross times n matrices S and T, so that

S times A times T space equals space open parentheses table row cell alpha subscript 1 end cell 0 0 blank midline horizontal ellipsis blank 0 row 0 cell alpha subscript 2 end cell 0 blank blank blank 0 row 0 0 down right diagonal ellipsis blank blank blank 0 row vertical ellipsis blank blank cell alpha subscript r end cell blank blank vertical ellipsis row blank blank blank blank 0 blank blank row blank blank blank blank blank down right diagonal ellipsis blank row 0 blank blank midline horizontal ellipsis blank blank 0 end table close parentheses

where the diagonal elements satisfy alpha subscript i vertical line alpha subscript i plus 1 end subscript. They are called invariant factors.

smith_normal_form(Matrix)

Given a matrix, returns a vector with the invariant factors.