As both a programmer and a math student, I am trying to come up with a fool-proof way to handle errors from subtractive cancellation caused by trying to evaluate $x-y$, where x,y are extended (long double) precision floating-point numbers. (Obviously, if x is very close to y, this causes problem.) I found two equivalent forms, ${x^2-y^2\over x+y}$ and $(\sqrt{x}-\sqrt{y})(\sqrt{x}+\sqrt{y})$. I was trying to evaluate regions where either form would work better, as well as the regions where either form might produce the same result, and/or a worse result in comparison to a straight subtraction.
I have tried to do the error-analysis as such:
Let the long double c be defined such that $x-y=c$.Then, ${x^2-y^2\over x+y}=x-y=c$, which rewrites as ${x^2-y^2\over x-y}={x^2-y^2\over c}=x+y$, which means that, if ${x^2-y^2\over x+y}$ does better than x-y, then $|x+y|>1$. Now, we take a look at $(\sqrt{x}-\sqrt{y})(\sqrt{x}+\sqrt{y})=x-y=c$. A rewriting of this yields $\sqrt{x}-\sqrt{y}={c\over \sqrt{x}+\sqrt{y}}$, which means that $\sqrt{x}+\sqrt{y}<1$ for this decomposition to work. (This also poses the additional condition that x,y>0.) It would then follow that $x+y=x-y+2y>1$, or, in other terms, $x-y>1-2y$. Also, $\sqrt{x}+\sqrt{y}<1$ can be rewritten as $\sqrt{x}<1-\sqrt{y}$, or after squaring both sides, $x-y<1-2\sqrt{y}$. This means that $1-2y<1-2\sqrt{y}$, which simplifies to $y>\sqrt{y}$ which returns $y>1$ (this is the only place where it is true....)
So, if y > 1, then the decomposition works better, right? Well, not according to my program, which can be found here: http://ideone.com/amwv9H ; // Disclaimer: It is written in C++