I am trying to understand why do we go from line 1 to line 2 in the way its shown? Why can't we directly just take the momentum operator squared outside and jump to line 3?
1 Answer
You cannot move the momentum operator past the wavefunction as it is an operator, which means it acts on the wavefunction to the right of it. The momentum operator is defined as
\begin{equation} \hat{p} = -i\hbar\frac{\partial}{\partial x}, \end{equation}
such that we can rewrite your first line as
\begin{equation} \begin{split} \frac{1}{2m}\int(\hat{p}^2 \psi)^*\psi \,dx &= \frac{(i\hbar)^2}{2m}\int \frac{\partial^2 \psi^*}{\partial x^2} \,\psi\, dx \\ &=\frac{(i\hbar)^2}{2m}\bigg\{\bigg[\frac{\partial \psi^*}{\partial x} \psi\bigg] _{-\infty}^{+\infty} - \int\frac{\partial \psi^*}{\partial x}\frac{\partial \psi}{\partial x}\, dx\bigg\} \\ &= \frac{1}{2m}\int\bigg(i\hbar\frac{\partial \psi^*}{\partial x}\bigg)\bigg(-i\hbar\frac{\partial \psi}{\partial x}\bigg) \, dx \\ &=\frac{1}{2m}\int(\hat{p}\psi)^*(\hat{p}\psi) \,dx, \end{split} \end{equation}
where in going from the first to second line we have integrated by parts, and then in going from the second to third line we have used the fact that the wavefunction must vanish at infinity, $\psi(\infty) = \psi(-\infty) = 0$. If you repeat this working then you should be able to keep going until the final answer.