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.

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

2 Answers 2


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

  • 1
    $\begingroup$ Or, one can use PowerExpand[]... $\endgroup$ Aug 9, 2012 at 15:47
  • $\begingroup$ @J.M. Interestingly (but understandably), using PowerExpand without explicit assumptions yields a different answer: the square roots are no longer distributed over the quotient. $\endgroup$
    – whuber
    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].


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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