# Comparing stability of two methods.

In my textbook, there's an example in which we try to determine if $x^2-y^2$ or $(x+y)(x-y)$ is a more stable method.

We do this by computing $\Delta_sr = \bar{F}(g) - F(g)$ and $\delta_sr = \frac{\bar{F}(g) - F(g)}{F(g)}$ in which $F(g)$ is the exact outcome of the method and $\bar{F}(g)$ the actual (shifted) outcome.

For the first method, We compute $fl(x^2-y^2) = [x^2(1 + \epsilon_1) - y^2(1+\epsilon_2)](1+\epsilon_3)$ with $|\epsilon_i| \leq \epsilon_{mach}$.

Therefore, the textbook says:

$|\Delta_sr| \leq (x^2+y^2+|x^2-y^2|)\epsilon_{mach}$ and $|\delta_sr| \leq (\frac{x^2+y^2}{|x^2-y^2|} + 1)\epsilon_{mach}$

They then go on analogous for the second method.

How did the textbook obtain the above inequalities?

First inequality

If you expand,

$$fl(x^2-y^2) = (x^2-y^2) + x^2 \epsilon_1 -y^2\epsilon_2 +x^2\epsilon_3 -y^2\epsilon_3 + O(\epsilon_{\text{mach}}^2)$$

removing the true result, and ignoring the higher order term:

$$\Delta_s r = x^2\epsilon_1 -y^2\epsilon_2 + (x^2-y^2)\epsilon_3$$

now $\epsilon_i$ can be negative so that you can bound $|\Delta_s r|$ by replacing the first term with $|x^2|\epsilon_\text{mach}=x^2\epsilon_\text{mach}$ the second term with $|-y^2|\epsilon_\text{mach}=y^2\epsilon_\text{mach}$ and the third term with $|x^2-y^2|\epsilon_\text{mach}$,

$$|\Delta_s r| \le (x^2 +y^2 +|x^2-y^2|)\epsilon_\text{mach}$$

The second inequality is then trivial,

$$|\delta_s r| \le {|\Delta_s r|\over |F(g)|} \le ({x^2+y^2\over |x^2-y^2|}+1)\epsilon_\text{mach}$$