Orthogonal null-space completion of a square matrix (source code)

= Orthogonal null-space completion of a square matrix
{title2=$M=A+LR^\top$}

Let $A$ be a real $n\times n$ <matrix> of <matrix rank> $n-m$, and let the columns of $L,R$ be <bases> of $\ker A^\top$ and $\ker A$, respectively. Then $B=LR^\top$ has <matrix rank> $m$, $A^\top B=AB^\top=0$, and $M=A+B$ is an <invertible matrix>.

\b[Proof.] Since $R$ has independent columns, its <Gram matrix> $R^\top R$ is invertible, and $R^\top$ maps onto $\mathbb R^m$. Thus $\operatorname{im}B=\operatorname{im}L=\ker A^\top$ and $\operatorname{rank}B=m$. The basis conditions give the two zero products. In particular,
$$
MM^\top=AA^\top+BB^\top,
\qquad AA^\top BB^\top=0.
$$
If $MM^\top x=0$, taking its <dot product> with $x$ gives $\|A^\top x\|^2+\|B^\top x\|^2=0$. Hence $x\in\ker A^\top=\operatorname{im}B$ and simultaneously $x\in\ker B^\top=(\operatorname{im}B)^\perp$. Therefore $x=0$, and $M$ is invertible. The case $m=0$ is immediate.

For a common <eigenvector> of $AA^\top$ and $BB^\top$, the two <eigenvalues> have zero product and positive sum: exactly one is zero. Thus the added term fills the missing orthogonal output directions without interfering with the original ones.