I'm trying to self study quantum mechanics and am having a little trouble manipulating commutators. I get two different answers below, depending on the method I'm using. The second method gives me the correct answer for the more complicated textbook problem, but I'm just trying to understand why the first method is wrong.
So here $D$ is just the partial derivative with respect to $x$. $A$ is the $x$-component of the electromagnetic vector potential. I'm trying to calculate $[D^2, A]$.
Method 1: Use a test function. $$\begin{array}{rcl} [D^2, A]f & = & D^2(Af) - A(D^2f) \\ & = & D(A'f + Af') - Af''\\ & = & A''f + A'f' + A'f' +Af'' - Af'' \\ & = & A''f+2A'f'.\end{array}$$ So from this version, we end up with $[D^2, A] = A'' + 2A'D$.
Method 2: Use the formula $[AB, C] = A[B,C] + [A,C]B$.
Using this formula, $$\begin{array}{rcl} [D^2, A] & = & D[D, A] + [D, A]D \\ & = & D(A') + A'D = A'' +A'D. \end{array}$$ So in this method, $[D^2, A] = A'' + A'D$, which is different from the first method! (It doesn't have that factor of 2.) Can you please help me see what I'm doing wrong!