Solution (source code)

= Solution

The <Euler-Lagrange equation> for the <real scalar field> gives
$$
\partial_\mu\frac{\partial\mathcal L}{\partial(\partial_\mu\phi)}-\frac{\partial\mathcal L}{\partial\phi}=0
\quad\Longrightarrow\quad
\boxed{(\Box+m^2)\phi=0.}
$$
Thus the <conjugate momentum> and <Hamiltonian density> are
$$
\boxed{\pi=\frac{\partial\mathcal L}{\partial\dot\phi}=\dot\phi,\qquad
\mathcal H=\pi\dot\phi-\mathcal L=\frac12\bigl[\pi^2+(\nabla\phi)^2+m^2\phi^2\bigr],\qquad H=\int d^3x\,\mathcal H.}
$$
The spatial <Fourier transform> reduces the <Klein-Gordon equation> to $\ddot\phi_{\mathbf p}+\omega_{\mathbf p}^2\phi_{\mathbf p}=0$, with positive <frequency> $\omega_{\mathbf p}=\sqrt{\mathbf p^2+m^2}$. Hence a general real solution is the <mode expansion of a free field>
$$
\boxed{\phi(t,\mathbf x)=\int\frac{d^3p}{(2\pi)^3\sqrt{2\omega_{\mathbf p}}}
\left[a_{\mathbf p}e^{-i\omega_{\mathbf p}t+i\mathbf p\cdot\mathbf x}
+a_{\mathbf p}^*e^{i\omega_{\mathbf p}t-i\mathbf p\cdot\mathbf x}\right].}
$$
The two coefficients are complex conjugates because the <field> is real. Each pair of initial data $\phi(0,\mathbf x),\pi(0,\mathbf x)$ fixes these coefficients. The normalization anticipates <canonical quantization> and the relativistic normalization of one-particle states.