# Table of Contents

# Classic Definition

Given the quadratic equation

*a x*^{2} + *b x* + *c* = 0
we may find the roots by calculating

Figure 1. Classic form of the quadratic formula.

For example, the roots of *x*^{2} + 8*x* + 15 are
given by

or -3 and -5.

# Alternate Form

Considering simply the positive case, let us rationalize the numerator (see below):

This gives us the formula:

If we consider also the negative case, we get an alternate formula for the two roots,
namely:

Figure 2. Alternate form of the quadratic formula.

Thus, the roots of the above quadratic polynomial are:

which gives us the two roots -5 and -3.

# Subtractive Cancelation

Consider the quadratic equation *x*^{2} + 23500 *x* + 0.0000823, we
may use Matlab and the classic form (Figure 1) to calculate the two roots:

>> format long
>> a = 1; b = 23500; c = 0.0000823;
>> (-b-sqrt(b^2 - 4*a*c))/2/a
ans = -23499.9999999965
>> (-b+sqrt(b^2 - 4*a*c))/2/a
ans = -3.50337359122932e-09

If, however, we use the alternate form (Figure 2) to calculate the roots, we get:

>> -2*c/(b - sqrt(b^2 - 4*a*c))
ans = -23491.6425145288
>> -2*c/(b + sqrt(b^2 - 4*a*c))
ans = -3.50212765957499e-09

These results are tabulated in Table 1 together with the correct answers
to the given number of decimal places:

Table 1. Comparison of results with correct values.

| Larger Root | Smaller Root |

Classic Formula | -23499.9999999965 | -3.50337359122932e-09 |

Alternate Formula | -23491.6425145288 | -3.50212765957499e-09 |

Correct Answer | -23499.9999999965 | -3.50212765957499e-09 |

Notice that the classic form gives an excellent approximation of the larger root, while
the alternate form gives an excellent approximation of the the smaller root.

This occurs because 4*ac* is very small, so *b*^{2} - 4*ac* ≈ *b*^{2}
and therefore we are calculating *b* - |*b*| and *b* + |*b*|.
This leads to subtractive cancelation, a loss of precision due to the subtraction
of similar numbers. For this example, we calculated:

>> b - sqrt(b^2 - 4*a*c)
ans = 0 01111100011 1110000110000000000000000000000000000000000000000000
>> b + sqrt(b^2 - 4*a*c)
ans = 0 10000001110 0110111100101111111111111111111111111111110000111101

If we had been able to maintain full precision, the two floating
point numbers would have been given by the second number in each
case, and thus the red highlights those bits in the mantissa which
match:

0 01111100011 1110000110000000000000000000000000000000000000000000
0 01111100011 1110000101010100001010011010010100110100011101001100
0 10000001110 0110111100101111111111111111111111111111110000111101
0 10000001110 0110111100101111111111111111111111111111110000111101

The first answer is correct to only 8 bits, whereas the second is correct to all 52 bits.

Therefore we see that subtractive cancelation has occurred, giving us a
poor approximation when we used `b - sqrt(b^2 - 4*a*c)`.

Thus we should use a different formula when finding either the
larger or smaller roots:

## Larger Root

We should use the classic formula (Figure 1) if we are searching for the
larger root (choosing the appropriate sign to ensure that `-b` and
`sqrt(b^2 - 4*a*c)` are either both positive or both negative.

## Smaller Root

We should use the alternate formula (Figure 2) if we are searching for the
smaller root (choosing the appropriate sign to ensure that `b` and
`sqrt(b^2 - 4*a*c)` are either both positive or both negative.

# Rationalizing an expression

Recall that:

so that we lose the radical (square root) of the expression.