Solution (source code)

= Solution

Substitute the <QR decomposition> into the <normal equations>:
$$
R^TRy=R^TQ^Tb.
$$
The diagonal of $R$ is nonzero, so $R^T$ is invertible. Cancel it algebraically to obtain
$$
\boxed{Ry=Q^Tb.}
$$
Compute the three <inner products> in $Q^Tb$, then use <back substitution> in this <upper triangular matrix>. There is no need to form an inverse or explicitly construct $A^TA$. The <orthogonal projection> of $b$ onto the column space is $QQ^Tb$; its orthogonal residual proves that this solution minimizes $\|Ay-b\|_2$.