Conjugate gradient method

We can also compute the residual iteratively as $$ \begin{equation*} \hat{r}_{k+1}=\hat{b}-\hat{A}\hat{x}_{k+1}, \end{equation*} $$ which equals $$ \begin{equation*} \hat{b}-\hat{A}(\hat{x}_k+\alpha_k\hat{p}_k), \end{equation*} $$ or $$ \begin{equation*} (\hat{b}-\hat{A}\hat{x}_k)-\alpha_k\hat{A}\hat{p}_k, \end{equation*} $$ which gives $$ \begin{equation*} \hat{r}_{k+1}=\hat{r}_k-\hat{A}\hat{p}_{k}, \end{equation*} $$