Trying to solve the following linear nonhomogeneous ODE $$ (D + 2)^2y = \cosh 2x $$ We can easily find the complementary function $$ y_c = c_1 e^{-2x} + c_2 {x} e^{-2x} $$ Using the inverse differential operator $$y_p = \frac{1}{(D+2)^2}\cosh 2x$$
I tried two methods to solve it but one of them gives an incomplete particular solution, I first used the fact that $\cosh 2x = ({e^{2x} + e^{-2x}})/{2}$, and then applied the shift theorem
$$y_p = \frac{1}{(D+2)^2} \frac{e^{2x} + e^{-2x}}{2} = \frac{1}{2}\left(\frac{1}{16}e^{2x} + \frac{1}{(D+2)^2}e^{-2x}\right) = \frac{1}{2}\left(\frac{1}{16}e^{2x} + e^{-2x}\frac{1}{D^2}(1)\right) = \frac{1}{2}\left(\frac{1}{16}e^{2x} + \frac{x^2}{2}e^{-2x}\right)$$
$$y_p = \frac{1}{32}e^{2x} + \frac{x^2}{4}e^{-2x}$$
which gives a complete particular solution, so the general solution is $$y = c_1 e^{-2x} + c_2 {x} e^{-2x} + \frac{1}{32}e^{2x} + \frac{x^2}{4}e^{-2x}$$
But when I tried to expand $(D+2)^2$ then substitute $2^2$ in place of $D^2$, and lastly apply the shift theorem, I got
$$y_p = \frac{1}{D^2+4D+4}\cosh 2x = \frac{1}{4}\left(\frac{1}{D+2}\cosh 2x\right) = \frac{1}{4}\left(\frac{1}{D+2} \frac{e^{2x} + e^{-2x}}{2}\right) = \frac{1}{32}e^{2x} + \frac{1}{8}\left(\frac{1}{D+2}e^{-2x}\right)$$ $$y_p = \frac{1}{32}e^{2x} + \frac{1}{8}xe^{-2x}$$
but the term $\dfrac{x^2}{4}e^{-2x}$ is missing in this particular solution while the other $\dfrac{1}{8}xe^{-2x}$ is already there in the complementary function. So my question is, what exactly did I do wrong?, and when can I be sure that the method I am using will actually give the right complete answer?
The second method is erroneous. Just observe from the homogeneous solution that the linear combination of $e^{-x}$ and $xe^{-x}$ spans the nullspace of linear operator $(D+2)^2$, so any term in $y^p$ which is constant multiple of either of these two; eventually belongs to their span and hence the nullspace. However, this can be avoided using general method to find $y^p$ that involves factorization of $f(D)$ into product of linear factors $(D-a)(D-b)....$; where
$\frac{1}{D-a}f(x)=e^{ax}\int e^{-ax}f(x)dx$, etc.