# Symbolic manipulation with unevaluated sums

If I have two expressions with sums in them, like this:

\begin{align*} b&=\frac{\sum_{i} (x_i - \bar{x})(y_i -\bar{y})}{\sum_{i}(x_i -\bar{x})^2}\\ r&=\frac{\sum_{i} (x_i - \bar{x})(y_i -\bar{y})}{\sqrt{\sum_{i}(x_i -\bar{x})^2\sum_{i}(y_i -\bar{y})^2}} \end{align*}

and I wanted to produce a simplified expression of $\frac{b}{r}$, how would I do it? The problem is the sums. It seems Mathematica doesn't like the unspecified, unevaluated sums.

Edit: I was expecting to end up with something like this:

$$\sqrt{\frac{\sum_{i}(y_i -\bar{y})^2}{\sum_{i}(x_i -\bar{x})^2}}$$

I've been playing around with Expand, Simplify, FullSimplify. There may just be a way to apply it that I'm missing.

• Please post your Mma code for the sums Aug 9, 2012 at 12:28
• @J.M. That was just in case you were a chemist :D Aug 9, 2012 at 12:42
• @Verde, I am a chemist, you insensitive clod! ;P Aug 9, 2012 at 12:44
• @Verde I have a file on you too. Aug 9, 2012 at 18:59
• @verde There are lots of sausages in there. Aug 9, 2012 at 19:12

The absence of a terminal $n$ in the sums suggests you are looking for a combination of symbolic reduction and typography. Let's separate the two, then, by using symbols for the sums, performing the reduction, and then replacing the symbols by whatever we like: • Or, one can use PowerExpand[]... Aug 9, 2012 at 15:47
• @J.M. Interestingly (but understandably), using PowerExpand without explicit assumptions yields a different answer: the square roots are no longer distributed over the quotient. Aug 9, 2012 at 15:56

Here is a completely symbolic manipulation:

ClearAll[x, y, xMean, yMean, n];

varianceX = Sum[(x[i] - xMean)^2, {i, n}]


$\sum _i^n (x(i)-\text{xMean})^2$

varianceY = Sum[(y[i] - yMean)^2, {i, n}]


$\sum _i^n (y(i)-\text{yMean})^2$

coVariance = Sum[(x[i] - xMean) (y[i] - yMean), {i, n}]


$\sum _i^n (x(i)-\text{xMean}) (y(i)-\text{yMean})$

b = coVariance/varianceX;

r = coVariance/Sqrt[varianceX varianceY];

b/r /. {Sqrt[a_ b_] :> Sqrt[a] Sqrt[b]}


$\frac{\sqrt{\sum _i^n (y(i)-\text{yMean})^2}}{\sqrt{\sum _i^n(x(i)-\text{xMean})^2}}$

All I had to do in order to help Mathematica get to the simplified result is to state the rule Sqrt[a_ b_] :> Sqrt[a] Sqrt[b].