Solution (source code)

= Solution

Put $r_0=|\mathbf x_0|$ and $\mathbf x_0^*=a^2\mathbf x_0/r_0^2$ for $0<r_0<a$. The <Dirichlet Green function inside a sphere> is
$$
\boxed{G_B(\mathbf x;\mathbf x_0)=-\frac1{4\pi}\left(\frac1{|\mathbf x-\mathbf x_0|}-\frac{a/r_0}{|\mathbf x-\mathbf x_0^*|}\right).}
$$
On $|\mathbf x|=a$, the distance identity $|\mathbf x-\mathbf x_0^*|=(a/r_0)|\mathbf x-\mathbf x_0|$ cancels the two terms. The inverse point lies outside the <sphere>, so it introduces no interior source. This weighted inversion is the <Kelvin transform>. For a central source, take the limit to get $G_B(\mathbf x;0)=-(4\pi)^{-1}(1/|\mathbf x|-1/a)$.