Solution (source code)

= Solution

The thin <QR decomposition> gives $AX=QR$. Its columns already belong to the <column space> of $Q$, so the <orthogonal projection> $QQ^T$ leaves them fixed:
$$
\boxed{\widehat AX=QQ^TAX=QQ^TQR=QR=AX}.
$$
This identity uses only $AX=QR$ and $Q^TQ=I_r$; it remains valid if $R$ is singular, provided such a factorization with <orthonormal> $Q$ is used.