# Coulomb gauge in magnetostatics should give divergence-free vector potential

Say we're dealing with magnetostatics ($$\vec{\nabla} \cdot \vec{j} = 0$$). If we define $$\vec{A}$$ to satisfy $$\vec{B} = \vec{\nabla} \times \vec{A}$$, and we take the assumption that $$\vec{\nabla} \cdot \vec{A} = 0$$, then each component of $$\vec{A}$$ satisfies Poisson's equation ($$\nabla ^2 \vec{A} = - \mu _0 \vec{j}$$). This gives that the general form of $$\vec{A}(\vec{r})$$ is $$\vec{A}(\vec{r}) = \frac{\mu _0}{4\pi} \int d^3r' \frac{\vec{j}(\vec{r}')}{|\vec{r}-\vec{r}'|}.$$

However, if I take the divergence of the above expression, I should be getting $$0$$ based on the initial divergence-free assumption, but I'm not.

After product-rule expansion, I'm getting $$\vec{\nabla} \cdot \vec{A} = \frac{\mu _0}{4\pi}\int d^3r' \vec{j}(\vec{r}') \cdot \vec{\nabla}\Big(\frac{1}{|\vec{r}-\vec{r}'|}\Big),$$ where the first of the two product-rule terms went to $$0$$ because of $$\vec{\nabla} \cdot \vec{j} = 0$$, but I still have that leftover stuff to integrate, and it's not clear why that needs to be $$0$$. Where did I mess up (or if I didn't, why does that need to be $$0$$?)

There aren't two product rule terms - remember which variable you are differentiating with respect to ($$\vec r$$, in this case, not $$\vec r'$$).
That being said, a good way to handle it is to note that $$\frac{\partial}{\partial \vec r} \frac{1}{|\vec r- \vec r'|} = - \frac{\partial}{\partial \vec r'} \frac{1}{|\vec r-\vec r'|}$$
Which means that if you throw in a spare minus sign, you can switch that $$\nabla \equiv \frac{\partial}{\partial \vec r}$$ to a $$\nabla ' \equiv \frac{\partial}{\partial \vec r'}$$. Once you've done that, integration by parts (along with a reasonable physical assumption) should give you what you're looking for.