$a$ and $b$ are the floating point representation of two real numbers with no constraints (they can be both negative or both positive or one positive and the other negative and so on).

I read in the Armadillo codebase, a linear algebra library, that the "robust" mean of the two $a$ and $b$ is computed as $a+\frac{b-a}{2}$ and not as the (naïve) $\frac{a+b}{2}$.

I imagine that it is more robust for what regard the overflow that it can happen when $a$ and $b$ are similar to half the largest representable value; moreover I feel that if $a\approx b$ then the cancellation error incurring in their subtraction will not be a problem.

But, how one can rigorously prove these intuitions?

  • 1
    $\begingroup$ Are the numbers positive? Do we know that $a\leq b$? $\endgroup$ – Arthur Aug 5 '20 at 11:58
  • 1
    $\begingroup$ It should be just to avoid exceeding INT_MAX = 2147483647 (or any maximum integer allowed) when calculating a+b. $\endgroup$ – VIVID Aug 5 '20 at 12:35
  • 3
    $\begingroup$ dl.acm.org/doi/10.1145/2493882 $\endgroup$ – Dhanvi Sreenivasan Aug 5 '20 at 12:35
  • 3
    $\begingroup$ @VIVID: But it is counter-productive in that regard if $a$ and $b$ have opposite signs. $\endgroup$ – TonyK Aug 5 '20 at 12:36
  • 2
    $\begingroup$ Yes, it was relative to my first comment. For the original question, a more general case was extensively discussed in math.stackexchange.com/questions/907327/… $\endgroup$ – Lutz Lehmann Aug 5 '20 at 18:32

Your Answer

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

Browse other questions tagged or ask your own question.