Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
Please post your Mma code for the sums – Dr. belisarius Aug 9 '12 at 12:28
@J.M. That was just in case you were a chemist :D – Dr. belisarius Aug 9 '12 at 12:42
@Verde, I am a chemist, you insensitive clod! ;P – J. M. Aug 9 '12 at 12:44
@Verde I have a file on you too. – Sjoerd C. de Vries Aug 9 '12 at 18:59
@verde There are lots of sausages in there. – Sjoerd C. de Vries Aug 9 '12 at 19:12
up vote 8 down vote accepted

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:

MMA screen shot

share|improve this answer
Or, one can use PowerExpand[]... – J. M. Aug 9 '12 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. – whuber Aug 9 '12 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].

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.