TITLE: How does rewriting $x^2 -y^2$ as $(x+y)(x-y)$ avoid catastrophic cancellation?
QUESTION [11 upvotes]: Why is rewriting $x^2 -y^2$ as $(x+y)(x-y)$ a way to avoid catastrophic cancellation?
We are still doing $(x-y)$. Is it because the last operation in the second form is a multiplication?

REPLY [2 votes]: The answer by penartur is correct. His argument works for x and y of order 10^4, which is much less than the 10^16 order at which an overflow error would occur in a double IEEE format. The cancellation really is catastrophic, as the relative error is quite large (in some of my computations it becomes large enough to crash my models).
That being said, if you are dealing with numbers on the order of 10^8, then overflow considerations would start coming into play when trying to compute the squared quantities.