Hamiltonian density from Klein-Gordon field In the solution for Peskin & Shroeder 2.2 where the Hamiltonian density obtained from the Klein-Gordon Lagrangian is given by:
$$
 H = \pi^* \pi + \nabla \phi \cdot \nabla \phi^* + m^2 \phi^* \phi \\
 =  \pi^* \pi + \phi ^ * (- \nabla ^ 2 + m^2 ) \phi
$$
Im confused with how the last equality was obtained. The notes said they used integration by parts and canceling out the surface term. Using the product rule
$$ 
 \nabla \phi \cdot \nabla \phi^* = \frac{1}{2} (\nabla ^2(\phi \phi^*) - \phi \nabla^2 \phi^* - \phi^* \nabla^2 \phi) 
$$
Besides the surface term $\nabla^2(\phi \phi^*)$, I have an extra term which does not seem to evaluate to zero here
 A: So, part (a) of problem 2.2 in P&S asks you to find the expression of the Hamiltonian (which you already found):$$H=\int d^3x \,\mathcal{H}=\int d^3x\,(\pi^*\pi+\nabla\phi^*\cdot\nabla\phi+m^2\phi^*\phi).$$To get to the next expression you mentioned, we use the chain rule (Einstein summation convention is assumed)$$\nabla\phi^*\cdot\nabla\phi=(\partial_i\phi^*)(\partial_i\phi)=\partial_i(\phi^*\partial_i\phi)-\phi^*(\nabla^2\phi)$$Now, substituting this expression in the Hamiltonian, we find that$$\begin{align*}H=&\int d^3x\,(\pi^*\pi+(\partial_i(\phi^*\partial_i\phi)-\phi^*(\nabla^2\phi))+m^2\phi^*\phi)\\ =&\int d^3x\,(\pi^*\pi-\phi^*(\nabla^2\phi)+m^2\phi^*\phi)+\int d^3x\;\partial_i(\phi^*\partial_i\phi)\\ =&\int d^3x\,(\pi^*\pi-\phi^*(\nabla^2\phi)+m^2\phi^*\phi)\end{align*}$$Note that the last term in step two is a surface term whose integral goes to zero. The integral of the surface term goes to zero because $\phi,\phi^*\rightarrow0$ as $x\rightarrow\infty$ which is a necessary condition for integrals like $\int_{\text{all space}} d^3x\,\phi^*\phi$ (which are clearly present in the Hamiltonian and the Lagrangian) to make sense.
Therefore you have the desired expression for the Hamiltonian density:$$\mathcal{H}=\pi^*\pi+\phi^*(-\nabla^2+m^2)\phi$$
Hope this clarified.
