I can't believe the alternative method I just saw to calculate the average of two numbers:

I use the following:
(a+b)/2 = avrg(a,b)
(b+a)/2 = avrg(a,b)

Found someone using this:
a+((b-a)/2) = avrg(a,b)
b+((a-b)/2) = avrg(a,b)

How to calculate avrg(a,b,c) using the second method? (e.g for the first one is (a+b+c)/3)

How can I transform the first one into the second one, or otherwise find some proof they both are equally equal?

  • 2
    $\begingroup$ I don't think, from a computational point of view, that the second method is a good method, though. $\endgroup$ – Raskolnikov Jun 5 '14 at 23:53
  • 10
    $\begingroup$ @Raskolnikov: not in general, but it's quite good for mental computation of (for example) the average of 83 and 85. And more widely whenever b - a looks a good bit easier than a + b. To average 83 and 183 I'd rather add 50 to 83 than add 183 to it. Naturally my PC doesn't care one way or the other, unless it overflows on one of the two formulae but not the other. $\endgroup$ – Steve Jessop Jun 6 '14 at 0:38
  • 27
    $\begingroup$ The reason people use the latter versions, by the way, is to prevent integer overflow. $\endgroup$ – wchargin Jun 6 '14 at 2:29
  • 1
    $\begingroup$ @SteveJessop Spot on. I'll bet a lot of people do this all the time without even realizing it. The overflow case is valid, but if you are going to overflow by a single bit one also should note that you want to check b > a, or you'll need to use a sign bit anyway. $\endgroup$ – Keith Jun 6 '14 at 3:09
  • 2
    $\begingroup$ As Steve said, the second method is handy for mental averaging of closely spaced numbers, especially for more than two of them: for example if you want to average 82, 91, 94, and 96, it's a lot easier to do 90+(-8+1+4+6)/4 than to try to compute the average directly. And as WChargin said, in computational contexts the second method is preferred to avoid integer overflow. (Most applications will not encounter this issue, but it has drastic effects when it does come up.) $\endgroup$ – David Z Jun 6 '14 at 14:03

Observe that $$ a+\frac{b-a}{2} = \frac{2a}{2} + \frac{b-a}{2} = \frac{2a+b-a}{2} = \frac{a+b}{2}. $$ You can do the analogous thing for $$ b+\frac{a-b}{2} = \frac{a+b}{2}. $$ And for the average of three numbers $a,b,c$, $$ \operatorname{avg}(a,b,c) = a + \frac{b-a}{3}+\frac{c-a}{3} = \frac{a+b+c}{3}. $$ You can "switch around" the $a,b,c$ above to get three different, but similar, expressions. They are proved to be "equally equal" (as you say!) by the approach we took above for proving equality in the two numbers case.

And you could do this for some $n$ numbers $a_1,\dots,a_n$ as follows: $$ \operatorname{avg}(a_1,\dots,a_n) = a_i+\sum_{k\neq i} \frac{a_k-a_i}{n} = \frac{1}{n}\sum_{k=1}^n a_k $$ for each $i\in\{1,2,\dots,n\}$. Can you show they are equal?? :-)

  • $\begingroup$ took me few seconds to see what was done on (a - a/2) to (2a/2 - a/2) to (a/2), I am getting rusty. edit: I just noted if we transform a -> 2a/2, we can from the beginning visualize (2a + b - a)/2 $\endgroup$ – ajax333221 Jun 6 '14 at 5:00
  • $\begingroup$ @ajax333221: I probably didn't take the most explicit route! I switched it. I never think of it as $a\mapsto 2a/2$, but rather I view $a-a/2$ as taking a half from a whole (which is a half!)... so we get $a/2$. $\endgroup$ – user59083 Jun 6 '14 at 15:53
  • $\begingroup$ With two numbers, it's intuitive. WLOG $a < b$, then you're adding half of the distance between the two numbers, to the lower number. It's much less intuitive for more than 2 numbers, so this is really nice to see the math! $\endgroup$ – Cruncher Jun 6 '14 at 19:25

$$ {\rm avrg}(a,b,c) = a + \dfrac{b-a}{3} + \dfrac{c - a}{3} $$

  • 5
    $\begingroup$ Great for programmatically calculating average value of big numbers. You avoid some overflows because you don't have to sum them all in advance. Simple things mean are the most meaningful ones! :) $\endgroup$ – Mateusz Charytoniuk Jun 6 '14 at 11:09

This is one step in an iterative way of computing the average of $N$ numbers:

Suppose that you have a sequence of $N$ numbers $x_i$. Let

$$ \bar{x}_n = \frac{1}{n} \sum_{i=1}^{n} x_i $$

i.e. the average of the first $n \le N$ of them.

Then $$ \bar{x}_{n+1} = \bar{x}_{n} + \frac{ x_{n+1} - \bar{x}_n}{n+1} $$

I'll leave the proof of this general case to the reader.

This iterative (running) approach for taking the average has advantages when doing numerical computations on a computer.

For $n=2$ $x_i = [a,b]$ you get the form indicated in your question:

$$ \bar{x}_1 = a \\ \bar{x}_2 = \bar{x}_1 + (b-\bar{x}_1)/2 = a+(b-a)/2 $$

For $n=3$, $x_i=[a,b,c]$ you could write this out as

$$ \bar{x}_{2} = a+(b-a)/2 \\ \bar{x}_3 = \bar{x}_2 + (c-\bar{x}_2)/3 $$ I'll leave it to the reader to exand out $\bar{x}_2$ in the final expression.


The method runs as follows:

Pick one number.

Make it the new (false) origin (zero) by subtracting it from all the others.

Now average those residuals.

You can usually average the residuals more easily (especially in your head) by doing the division first, that is, divide each of the residuals by the number of values you have (including the false origin), and then add those results together.

Now add the average of the residuals back to the the number you first chose.

This removal of a false origin can also be useful in real engineering calculations as it makes the values and process more easy to comprehend and check.

There are many maths formulas that pre-weight the offset values to avoid confusion about the apparent number of variables. It's a worthwhile 'trick' to learn ;-)


It is obvious that $a+\frac{b-a}{2}=a+\frac b2-\frac a2=\frac a2+\frac b2=\frac{a+b}{2}$.

To use a similar expression for the mean of three numbers, consider the fact that $a+\frac{b-a}{3}+\frac{c-a}{3}=\frac{a+b+c}{3}$.

Similarly, $a+\frac{b-a}{4}+\frac{c-a}{4}+\frac{d-a}{4}=\frac{a+b+c+d}{4}$ for four numbers, and the pattern continues.


In affine geometry, it is a general property of barycentres that they can be computed using any base point $P$. So if $A_1,\ldots,A_n$ are points and $\lambda_1,\ldots,\lambda_n$ associated weights with nonzero total mass $\mu=\lambda_1+\cdots+\lambda_n$, then the barycentre is $$ P+\frac1\mu \left(\lambda_1\overrightarrow{PA_1}+\cdots+\lambda_n\overrightarrow{PA_n} \right) \tag1 $$ and this does not depend on the choice of $P$ (easy proof). Note that the expression $$ \frac{\lambda_1A_1+\cdots+\lambda_nA_n}\mu,\tag2 $$ although it gives the right answer in coordinates, does not make any sense geometrically, since one cannot add points or multiply them by scalars; what one can do is form linear combinations of vectors and add them to points, which is what $(1)$ does. That in coordinates $(2$) gives the right answer, is because this secretly chooses some arbitrary origin $O$, and then confounds any point $A$ with the vector $\overrightarrow{OA}$ (both having the same coordinates), which turns $(2)$ into $(1)$ for $P=O$.

Observe that in $(1)$ one can make one of the vectors zero by choosing $P=A_i$ for some$~i$.

Now taking averages can be seen as a special case of computing barycentres, in a $1$-dimensional space, and with $\lambda_1=\cdots=\lambda_n=1$. Choosing $P$ to be one of the values to be averaged, one gets a formula for the average starting from that value and adding $\frac1n$ times the differences with the other values. Or one could take $P$ to be any initial estimate of the average, which can be practical if the values to be averaged lie close together.


$a+\frac{b-a}{2}=\frac{2a+b-a}{2}=\frac{a+b}{2}$ or in reverse:


  • $\begingroup$ thanks, I can only see myself using the weird one when the difference between them are small, like avrg(18,20), but even then I could confuse to who I should add the difference... $\endgroup$ – ajax333221 Jun 5 '14 at 23:45
  • $\begingroup$ $a$ is $18$ and $b$ is $20$ so you get $18+\frac{20-18}{2}=19$ $\endgroup$ – Jorge Fernández Hidalgo Jun 5 '14 at 23:46

For your example, $a + \frac{b-a}{2} = \frac{2a}{2} + \frac{b-a}{2} = \frac{2a + b - a}{2} = \frac{a+b}{2}$, but I'm not quite sure what you mean by averaging three numbers using this method.

  • $\begingroup$ I didn't mention 'three numbers', rather it's the number of values you have. So (a+b+c)/3 -> a + (a'+b'+c')/3 -> a + (0/3 + b'/3 + c'/3), with a'=a-a=0; c'=c-a; b'=b-a. $\endgroup$ – Philip Oakley Jun 10 '14 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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