Energy of a Continuous Charge Distribution I had a question regarding the derivation for the following expression of the energy of a continuous charge distribution
$$W=\frac{\epsilon_0}{2}\int_\text{all space} E^2d\tau$$
To get this result, we start from the fact that when considering point charges, the work is given by the sum
$$W=\frac{1}{2}\sum_{i=1}^nq_1V(\vec{r}_i)=\frac{1}{2}\sum_{n=1}^{n}\sum_{\begin{align*}j=1\\j\ne i\end{align*}}^n\frac
{q_iq_j}{4\pi\epsilon_0}\frac{1}{r_{ij}}$$
Then, we extend this to continuous distributions by making it a volume integral, and taking into account the charge distributions in two regions of space
$$W=\frac{1}{2}\int_\text{all space}\frac{\rho_1\rho_2}{4\pi\epsilon_0}\frac{1}{r_{12}}d\tau_1d\tau_2$$
We can see that $\int\frac{\rho_2}{4\pi\epsilon_0}\frac{1}{r_{ij}}d\tau_2$ is just the potential at region 1, due to the charge distribution in region 2. Hence we can rewite this as
$$W=\frac{1}{2}\int_\text{all space}\rho Vd\tau$$
I understand that $\rho=\rho_1+\rho_2$, and that $V=V_1+V_2$, then
$$\frac{1}{2}\int\rho Vd\tau=\frac{1}{2}(\int\rho_1 V_1d\tau+\int\rho_1V_2d\tau+\int\rho_2V_1d\tau+\int\rho_2V_2d\tau)$$
Where the two integrals in the middle are equal, so by dividing their sum by two we get the total work. However, the terms which include the product between a potential and its own charge distribution should vanish, yet I haven't been able to see how this happens, since when I try to solve those integrals, like $\int\rho_1V_1d\tau$, the result diverges. I wanted to know whether $\rho$ and $V$ are what I understand them to be, and if so how does the integral vanish, or If this is wrong, then what charge distribution and potential do $\rho$ and $V$ stand for. \
 A: You will soon see that the splitting of charge density and potential into 2 distinct elements, is the same as splitting E into 2 elements.
$$\vec{E}_{total} = \vec{E}_{1} + \vec{E}_{2}$$
$$W = \frac{1}{2} \epsilon_{0} \iiint |\vec{E}_{total}|^2 d^3 r$$
$$W = \frac{1}{2} \epsilon_{0} \iiint |\vec{E}_{1} + \vec{E}_{2}|^2 d^3 r$$
Computing this expression gives us 3 distinct terms.
$$W = \frac{1}{2} \epsilon_{0} \iiint |\vec{E}_{1} |^2 d^3 r $$
$$+\frac{1}{2} \epsilon_{0} \iiint |\vec{E}_{2} |^2 d^3 r $$
$$+\epsilon_{0} \iiint \vec{E}_{1}\cdot \vec{E}_{2} d^3 r $$
What do they represent?
The first term represents the energy of $\vec{E}_{1}$
The second term represents the energy of $\vec{E}_{2}$
The third term represents the potential energy between the charge distributions (building up field 1 in the presence of field 2), I'll leave it to you to prove this!
Splitting up charge density:
This decomposition of E into 2 elements.is the same as splitting up the charge distribution into 2 elements
$$\rho = \rho_{1} + \rho_{2}$$
$$V = V_{1} + V_{2}$$
$V_{1}$ is caused by $\rho_{1}$, and $V_{2}$ is caused by $\rho_{2}$
$$ W= \frac{1}{2}\iiint [\rho_{1} + \rho_{2}][V_{1} + V_{2}] d^3r$$
There are 3 distinct terms of this expression
$$W= \frac{1}{2}\iiint \rho_{1}V_{1} d^3r$$
$$+\frac{1}{2}\iiint \rho_{2}V_{2} d^3r$$
$$+\frac{1}{2}\iiint [\rho_{1}V_{2} + \rho_{2} V_{1}] d^3r$$
The first 2 terms take the form that we are familiar with, they do not vanish. They are the individual energies of $\vec{E}_{1}$ and $\vec{E}_{2}$.
The last term is slightly more complicated.
This term represents the potential energy between the 2 charge distributions!
To show this:
$$\iiint \rho_{1}V_{2} d^3r = \iiint \rho_{2}V_{1} d^3r$$
As building up distribution 1 in the presence of potential 2, is the same as building up distribution 2 in the presence of potential 1 [which is intuitive, you can also prove this mathematically]
Substituting this identity into our third term, reveals that this term. . Is infact
$$\iiint \rho_{1} V_{2} d^3r$$
This is obviously the potential energy between our charge distributions since we are building up a charge $\rho_{1} d^3r$ in the presence of $V_{2}$
Note:
You say the first 2 terms diverge, if your using this expression for a point charge then yes, the field energy is infinite, if you use these formulas. This formula is not valid for point charges since the derivation assumes $\rho$ is finite[discussed further in griffiths]. Instead we model energy of point charges using the discrete formula you mentioned, or using renormalisation]
