Compute both roots with an alternative method to avoid bad computation This question is from exercises in the course Numerical Analysis.
I want to compute both roots for $x^2-10^8x+1$ with an alternative method to avoid bad computation. In the task it also gives the clue that you should try multiply the formula for the roots to see what you get, i.e: $$\frac{-b-\sqrt{b^2-4ac}}{2}\cdot\frac{-b+\sqrt{b^2-4ac}}{2}.$$ And and I would appreciate help in understanding how to proceed to do it this way.
My attempts: From this clue I came to think that for two roots $\alpha$ and $\beta$ for the quadratic polynomial $ax^2+bx+c$ it applies that $\alpha\beta=\frac{c}{a}$ and $\alpha+\beta=-\frac{b}{a}$ and from this I got $$ \alpha\beta=1,$$ $$\alpha+\beta=10^8.$$
But this doesn't give a method with less bad computation since when rewriting it one only go back to what we started with, for example $\alpha+\beta=10^8 \Rightarrow \alpha=10^8-\beta$ that gives us $\beta(10^8-\beta)=\beta 10^8 -\beta^2=1$ which equals to $\beta^2-\beta 10^8+1=0$.
And if one multiply the formula for the roots with the values a,b and c we get
$$\alpha\beta=\frac{(10^8+\sqrt{10^{16}-4})(10^8-\sqrt{10^{16}-4})}{4}$$ but neither does this provide us with a better method. Am I at all onto something here or have I misunderstood anything?
Thanks in advance!
 A: When you apply the quadratic formula as you are used to, you get the quantity $\sqrt{10^{16}-4}$.  $10^{16}$ is a perfect square, so this square root will be just less than $10^8$.  How much less?  Ask you calculator-it may give you $0$.  Back in the day of $32$ bit floats the accuracy was only about $7$ decimal digits.  You couldn't tell the numbers apart.  Now when you subtract it from $10^8$ you get $0$.  You need to find a way to eliminate the subtraction of two nearly equal numbers.  Often this comes from multiplying analytically by the conjugate, but any formulation that avoids the subtraction will do.
A: You are facing the situation where $b^2 \gg 4ac$. So write the roots as
$$r_{1,2}=-\frac b 2\big[1\pm \sqrt{1-\epsilon}\big] \quad \text{with} \quad \epsilon=\frac {4ac}{b^2} $$ and use
$$\sqrt{1-\epsilon}=1-\frac{\epsilon }{2}-\frac{\epsilon ^2}{8}-\frac{\epsilon ^3}{16}+O\left(\epsilon
   ^4\right)$$ or much better to avoid powers of $\epsilon$
$$\sqrt{1-\epsilon}=\frac {4-3\epsilon}{4-\epsilon}+O(\epsilon^3)$$ Notice that
$$1-\frac{\epsilon }{2}-\frac{\epsilon ^2}{8}-\frac{\epsilon ^3}{16}-\frac {4-3\epsilon}{4-\epsilon}=-\frac{\epsilon ^3}{32}+O\left(\epsilon
   ^4\right)$$
A: The point of this exercise is that, while you can compute $\sqrt{10^{16}-4}\approx 10^8$ and hence
$$
\frac{10^8+\sqrt{10^{16}-4}}{2}\approx 10^8
$$
with reasonable accuracy in any finite-precision arithmetics (let's say $4\times 10^{-16}<\epsilon$ the machine epsilon, which is almost true for IEEE754 double $\epsilon=2^{-52}\approx 2.2\times 10^{-16}$.  So if you are using single precision it is definitely no difference, but for double whether $\sqrt{(\text{number}\approx 10^{16}(1-\epsilon))}$ will give you $\approx 10^8$ or $\approx 10^8(1-\epsilon)$ is probably machine-dependent), the same cannot be said about the disastrous cancellation in $10^8-\sqrt{10^{16}-4}\approx 10^8-10^8=0$, a relative error of 100%.  However, if you use
$$
\frac{10^8-\sqrt{10^{16}-4}}{2}
=\frac1{\frac{10^8+\sqrt{10^{16}-4}}{2}}
=\frac{2}{10^8+\sqrt{10^{16}-4}}
$$
you get (more-or-less) the same relative error for both roots.
