Problem with Klein-Gordon equation derivation In Notes for a course on Classical Fields by R. ALdrovandi, one the the exercises in page 94 is to derive the klein Gordon equation $(\Box + m²)\phi = 0$ from the following lagrangian density
\begin{equation}
\mathcal{L} = \frac{1}{2} (\partial _\mu \phi \partial ^{\mu}\phi - m² \phi ²).\tag{1}
\end{equation} which I've solved. Here the sign convention is $(+,-,-,-)$. But after he states: 

"Show that it (KG Equation) comes also from"
  \begin{align}
\mathcal{L} &= \frac{1}{2} (\phi \partial _\mu \partial ^\mu \phi + m² \phi ²). \tag{2}\\ 
\end{align}

My problem is when I make the variation in the lagrangian I get the following problem
\begin{align}
\delta S &= \int d⁴ x \left( \frac{\partial \mathcal{L}}{\partial \phi} \delta\phi + \frac{\partial \mathcal{L}}{\partial(\partial_\lambda \phi))}\delta\partial_\lambda \phi\right) \\ &= \int d⁴ x \left( \frac{1}{2} \partial _\mu   \partial ^\mu \phi \ + m² \phi\right) \delta \phi \\ &= 0
\tag{3}\end{align}
the problem is this equation will give me the KG equation with a wrong factor $1/2$.
Can someone say where my mistake is?
 A: Your issue comes when you expand the variation of the action. Since your action now contains second derivatives of your fields, you should, in fact, have something like
\begin{equation}
\delta S=\int\mathrm{d}^dx\left(\frac{\partial\mathcal{L}}{\partial\phi}\delta\phi+\frac{\partial\mathcal{L}}{\partial(\partial_{\mu}\phi)}\partial_{\mu}\delta\phi+\frac{\partial\mathcal{L}}{\partial(\partial_{\mu}\partial_{\nu}\phi)}\partial_{\mu}\partial_{\nu}\delta\phi+\cdots\right),
\end{equation}
where the $\cdots$ terms appear if you have higher derivatives involved (there also may be an annoying factor of $2$ somewhere in that last line since partial derivatives commute, and we don't want to overcount). We can also simply overcome the difficulty of using the above equation by just directly finding $\delta\mathcal{L}$ by finding the first order variation of $\mathcal{L}$ with respect to $\phi\to\phi+\delta\phi$. This gives
\begin{equation}
\begin{gathered}
\mathcal{L}+\delta\mathcal{L}=\frac{1}{2}(\phi+\delta\phi)\partial^2\left(\phi+\delta\phi\right)+\frac{1}{2}m^2\left(\phi+\delta\phi\right)^2\\
\Longrightarrow\delta\mathcal{L}=\frac{1}{2}\delta\phi\,\partial^2\phi+\frac{1}{2}\phi\,\partial^2\delta\phi+m^2\delta\phi.
\end{gathered}
\end{equation}
Throwing this into the action gives
\begin{equation}
\delta S=\int\mathrm{d}^dx\left(\frac{1}{2}\partial^2\phi\,\delta\phi+m^2\phi+\frac{1}{2}\phi\,\partial^2\delta\phi\right),
\end{equation}
and finally integrating by parts twice and setting $\delta S=0$ gives the correct equations of motion.
A: Let the Klein-Gordon Lagrangian be given by: 
$$\mathcal{L} = \frac{1}{2} \phi(x) \partial_\mu \partial^\mu \phi(x) + \frac{1}{2}m^2 \phi(x)^2,$$
where $\partial_\mu = \frac{\partial}{\partial x^\mu}$. 
The idea is that for the Euler-Lagrange equation we require that: 
$$\forall y: \frac{\delta S}{\delta \phi(y)} = 0.$$ 
Let's calculate this:
$$\frac{\delta S}{\delta \phi(y)} = \frac{\delta}{\delta \phi(y)}\int d^4 x \Big(\frac{1}{2} \phi(x) \partial_\mu \partial^\mu \phi(x) + \frac{1}{2}m^2 \phi(x)^2\Big)$$
$$=\int d^4 x \Big(\frac{1}{2}\delta(x-y)\partial_\mu \partial^\mu \phi(x) + \frac{1}{2} \phi(x) \partial_\mu \partial^\mu \delta(x-y) + m^2 \phi(x)\delta(x-y)\Big),$$ 
where I used various properties of the functional derivatives. Using integration by parts twice and throwing away the boundary terms this yields
$$\frac{\delta S}{\delta \phi(y)} = \int d^4 x \Big(\frac{1}{2} \partial_\mu \partial^\mu \phi(x) + \frac{1}{2}\delta(x-y) \partial_\mu \partial^\mu \phi(x)+m^2 \phi(x)\delta(x-y)\Big) = \frac{1}{2}\partial_{\mu,y}\partial^{\mu,y}\phi(y) + \frac{1}{2} \partial^{\mu,y}\partial_{\mu,y} + m^2 \phi(y),$$ 
where $\partial_{\mu,y} = \frac{\partial}{\partial y^\mu}$. So indeed we find that (changing $y$ to $x$ for simplicity):
$$\frac{\delta S}{\delta \phi(x)} = (\partial_\mu \partial^\mu + m^2)\phi(x) = 0.$$
A: There is an easier way to solve this problem.
You can flip the sign of a Lagrangian and add a four-divergence without changing the equations of motion. Thus,
$$\mathcal{L}'=\partial_{\mu}\left(\frac{\phi\partial^{\mu}\phi}{2}\right)-\mathcal{L}=\frac{1}{2}(\phi\partial_{\mu}\partial^{\mu}\phi+m^2\phi^2)$$
gives the same Euler Lagrange equations as $\mathcal{L}$, as desired.
A: Hints: 


*

*OP has forgot to vary wrt. second-order derivatives in eq. (3). 

*Note that when the Lagrangian density ${\cal L}(\phi,\partial\phi,\partial^2\phi, \ldots)$ depends on higher-order spacetime derivatives of the fields, then
the Euler-Lagrange (EL) equations become 
$$ 0~\approx~\frac{\delta S}{\delta \phi}
~=~\frac{\partial {\cal L}}{\partial \phi} 
-\sum_{\mu} \frac{d}{dx^{\mu}} \frac{\partial {\cal L}}{\partial (\partial_{\mu}\phi)} + \sum_{\mu\leq \nu} \frac{d}{dx^{\mu}} \frac{d}{dx^{\nu}} \frac{\partial {\cal L}}{\partial (\partial_{\mu}\partial_{\nu}\phi)} - \ldots,  $$
where the $\approx$ symbol means equality modulo eoms, and the ellipsis $\ldots$ denotes possible higher-derivative terms.

*Alternatively, note that the two Lagrangian densities (1) & (2) only differ modulo total derivative terms and over-all normalization, and hence lead to the same EL-equations, cf. e.g. this Phys.SE post.
