Field shift in free Klein-Gordon theory I am reading Peskin & Schroeder Ch9 and am stuck on a calculation going from equation 9.36.
The problem is essentially a change of variable of a Klein-Gordon field.
Beginning, we have an integral of the KG Lagrangian and a source term
\begin{align}
\int d^4 x\: [\mathcal{L}_0(\phi) + J\phi] = \int d^4 x \left[\frac{1}{2} \phi (-\partial^2 - m^2 + i \epsilon)\phi + J\phi\right].
\end{align}
Now we want to shift the field so introduce
\begin{align}
\phi' = \phi - i\int d^4 y\: D_F(x-y)J(y).
\end{align}
Substitution is then supposed to give
\begin{align}
\int d^4 x\: [\mathcal{L}_0(\phi) + J\phi] = \int d^4 x \left[\frac{1}{2} \phi' (-\partial^2 - m^2 + i \epsilon)\phi' \right] - \int d^4x d^4y\; \frac{1}{2}J(x)[-iD_F(x-y)]J(y).
\end{align}
To do this, they use that $D_F$ is a Green's function of the KG operator, which I have been using as
\begin{align}
(-\partial^2 - m^2 + i \epsilon)i\int d^4 y\: D_F(x-y)J(y) = -J(x).
\end{align}
So I find
\begin{align}
\int d^4 x\: [\mathcal{L}_0(\phi) + J\phi] = &\int d^4 x \left[\frac{1}{2} \left(\phi' + i\int d^4 y\: D_F(x-y)J(y)\right) (-\partial^2 - m^2 + i \epsilon)\left(\phi' + i\int d^4 y\: D_F(x-y)J(y)\right) + J(x)\left(\phi' + i\int d^4 y\: D_F(x-y)J(y)\right)\right] \\ =&
\int d^4 x \left[\frac{1}{2} \phi'(-\partial^2 - m^2 + i \epsilon)\phi' - \frac{1}{2} \phi' J(x) + \frac{1}{2}  i\int d^4 y\: D_F(x-y)J(y) (-\partial^2 - m^2 + i \epsilon)\phi' \\ - \frac{1}{2} i\int d^4 y\: D_F(x-y)J(y) J(x) + J(x)\phi' + J(x)i\int d^4 y\: D_F(x-y)J(y)\right] \\= &\int d^4 x \left[\frac{1}{2} \phi' (-\partial^2 - m^2 + i \epsilon)\phi' \right] - \int d^4x d^4y\; J(x)[-iD_F(x-y)]J(y) \\ &+ \frac{1}{2}\int d^4x \: J(x)\phi' +\frac{1}{2}  i\int d^4x d^4 y\: D_F(x-y)J(y) (-\partial^2 - m^2 + i \epsilon)\phi' \\= &\int d^4 x \left[\frac{1}{2} \phi' (-\partial^2 - m^2 + i \epsilon)\phi' \right] - \int d^4x d^4y\; J(x)[-iD_F(x-y)]J(y) \\ &+ \frac{1}{2}\int d^4x \: J(x)\phi' -\frac{1}{2}  i\int d^4x d^4 y\: (-\partial^2 - m^2 + i \epsilon)D_F(x-y)J(y) \phi' + \text{boundary terms} \\= &\int d^4 x \left[\frac{1}{2} \phi' (-\partial^2 - m^2 + i \epsilon)\phi' \right] - \int d^4x d^4y\; J(x)[-iD_F(x-y)]J(y) \\ &+ \int d^4x \: J(x)\phi' ,
\end{align}
where the boundary terms come from integration by parts. I'm off by a factor of $\frac{1}{2}$ in the second term, and I also have an additional term, but I can't see where it's going wrong.
 A: $\newcommand{\ip}[1]{\left<#1\right>}\newcommand{\d}{\mathrm{d}}\newcommand{\inv}[1]{{#1}^{-1}}$What happens here is a simple completion of a square. To see it in its cleanest form, without potentially error-inducing calculations, remember that, in the space where $\phi$ lives,
$$\ip{\bullet,\tilde\bullet}:= \int \mathrm{d}^4 x\  \bullet(x)\,\tilde{\bullet}(x),$$
is an inner product. Moreover, let
$\Omega := -\partial^2-m^2+\mathrm{i}\epsilon$
be the Klein-Gordon operator that you are interested in.
The scenario you have, then, is that
\begin{align}
\frac12\ip{\phi,\Omega\phi}+\ip{J,\phi}&=\frac12\ip{(\phi'-\inv{\Omega}J),\Omega\,(\phi'-\inv{\Omega}J)}+\ip{J,(\phi'-\inv{\Omega}J)} = \\
&= \frac12\Big(\ip{\phi',\Omega\phi'}-\ip{J,\phi'}-\ip{\phi',J}+\ip{J,\inv{\Omega}J}\Big)+\ip{J,\phi'}-\ip{J,\inv{\Omega}J} = \\
&= \frac12\ip{\phi',\Omega\phi'} - \frac12\ip{J,\inv{\Omega}J},
\end{align}
where I used that the invertible operator $\Omega$ is self-adjoint, i.e. $\ip{\bullet,\Omega\tilde\bullet}=\ip{\Omega\bullet,\tilde\bullet}$, and hence so is its inverse and further that the inner product defined above is symmetric, so $\ip{\phi,J}=\ip{J,\phi}$.
The missing factor of $\frac12$ comes in your second-leading-to-third line where you have
$$-\frac12\mathrm{i}\int\d^4 x J(x) D(x-y) J(y) + \mathrm{i}\int\d^4 x J(x) D(x-y) J(y) = \color{red}{\frac12} \mathrm{i}\int\d^4 x J(x) D(x-y) J(y) $$
but you've missed the red $\frac12$. As for the $J\phi'$, there are two terms that give this contribution from the kinetic part of the action, while you've only written one of them. If you write both, they exactly cancel the term that comes from the $J\phi$ part (cf. my equations above).
