Smith normal form supplies a kernel basis (source code)

= Smith normal form supplies a kernel basis
{c}
{title2=$PMQ=D\Longrightarrow\ker M=\langle Qe_{r+1},\ldots,Qe_n\rangle$}

Let $M$ be an $m$-by-$n$ <matrix> over a <principal ideal domain> $R$. Choose <Smith normal form> $PMQ=D$ with exactly $r$ nonzero diagonal entries. Since $P$ and $Q$ are <invertible matrices>, $Mx=0$ is equivalent to $D(Q^{-1}x)=0$. The <integral domain> property forces the first $r$ coordinates of $Q^{-1}x$ to vanish, so $Qe_{r+1},\ldots,Qe_n$ are a <basis of a module> for the <kernel>. These vectors form part of a <basis of a module> of $R^n$, which is stronger than merely finding a nonzero vector in the <kernel> over the <fraction field>.