# How to work out sums symbolically?

Intro

Consider these two equal expressions of the variance

$$\frac{\sum _{i=1}^n x(i)^2}{n}-\frac{\left(\sum _{i=1}^n x(i)\right){}^2}{n^2}$$

and

$$\frac{\sum _{i=1}^n \left(x(i)-\frac{\sum _{i=1}^n x(i)}{n}\right){}^2}{n}$$

I tried to run Simplify on them but they did not boil down to the same expression. I also tried to test if they are equal with:

Reduce[Sum[x[i]^2/n, {i, 1, n}] - Sum[x[i]/n, {i, 1, n}]^2 ==
Sum[(x[i] - Sum[x[i], {i, 1, n}]/n)^2/n, {i, 1, n}]]


but it fails to return either True or False. I think the issue is that it cannot treat expressions like x[i] symbolically but needs an actual array.

General Question

How to work out sums (and other iterative operations on array such as products) symbolically?

Specific question

My personal goal is to see if there is a way to simplify this expression further than what I managed to do by hand

$$\frac{\frac{d-1}{d} s^2}{\bar X - \bar X^2 + \frac{s^2}{r} \left(1-\frac{r-1}{d-1}\right)}$$

, where $\bar X = \frac{\sum_{i=1}^r X_i}{r}$ and $s^2 = \frac{\sum_{i=1}^r X_i - \bar X}{r-1}$

In Mathematica terms it gives

(((d - 1)/(d*(r - 1)))*
Sum[(x[i] - Sum[x[i], {i, 1, r}]/r)^2, {i, 1,
r}])/(Sum[(x[i]/r)*(1 - Sum[x[i]/r, {i, 1, r}]), {i, 1, r}] +
Sum[((x[i] - Sum[x[i], {i, 1, r}]/r)^2/(d*(d - 1)))*(1 - (r -
1)/(d - 1)), {i, 1, r}])

• To share complex expressions, take a look at: How to copy code from Mathematica so it looks good on this site. Commented Aug 16, 2017 at 3:20
• This might be and this of interest. Commented Aug 16, 2017 at 4:27
• I think the problem here is that providing a general solution (that you seek) will not yield a nice answer to your specific question. Zugzwang. Commented Aug 16, 2017 at 17:20