Subsections


32.6 Unit Tests

There is currently a unit test for each kind of polynomial. They are all based on setting up the polynomial coefficients for known roots and checking the obtained root accuracies from the respective root solvers. The unit tests try to stress test the root solvers by setting up polynomials which are hard to solve. Two measures are used for judging accuracy of the roots obtained. The relative accuracy of a root is defined as

Relative root accuracy $\displaystyle =$ $\displaystyle \vert(x_e-x_c)/x_e\vert,$ (32.4)

where $ x_e$ is the exact analytical root and $ x_c$ the computational root. The absolute accuracy of a computational root $ x_c$ is
Absolute root accuracy $\displaystyle =$ $\displaystyle \vert x_c\vert.$ (32.5)

For the unit tests we will use the relative root accuracy if $ x_e\neq 0$ and the absolute root accuracy otherwise.


32.6.1 Quadratic Polynomials Root Test

This test solves quadratic polynomials with extreme coefficients involving the largest positive number $ L$ and the smallest postive number $ S$ representable on the machine under the working precision (for double precision we would have $ L\approx 1.797...\times 10^{308}$ and $ S\approx 2.225...\times 10^{-308}$). All possible combinations are tested. We examine only the $ LL$ combination in detail. The four quadratic $ LL$ polynomials are:

$\displaystyle x^2\pm Lx\pm L$ $\displaystyle =$ 0 (32.6)

with the two roots:
$\displaystyle x_1$ $\displaystyle =$ $\displaystyle \mp L/2 + \sqrt{(L/2)^2\mp L}$ (32.7)
$\displaystyle x_2$ $\displaystyle =$ $\displaystyle \mp L/2 - \sqrt{(L/2)^2\mp L}.$ (32.8)

Since $ (L/2)^2$ is much larger than $ L$, we can expand the square root in a Taylor series
$\displaystyle \sqrt{(L/2)^2\mp L}$ $\displaystyle \approx$ $\displaystyle L/2\mp 1 + O[L^{-1}].$ (32.9)

The roots are approximated as
$\displaystyle x_1$ $\displaystyle =$ $\displaystyle \mp L/2 + L/2 \mp 1 + O[L^{-1}]$ (32.10)
$\displaystyle x_2$ $\displaystyle =$ $\displaystyle \mp L/2 - L/2 \mp 1 + O[L^{-1}].$ (32.11)

However, a quantity like $ L+1$ cannot be accurately represented on a machine due to limited mantissa space and will get converted to $ L$. The following table shows the computational roots to be expected for the quadratic $ LL$ polynomials
$ a_1$ $ a_0$ $ x_1$ $ x_2$
$ +L$ $ +L$ $ -1$ $ -L$
$ +L$ $ -L$ $ +1$ $ -L$
$ -L$ $ +L$ $ +L$ $ +1$
$ -L$ $ -L$ $ +L$ $ -1$
Likewise, after going throught the same kind of analysis for the remaining $ LS$, $ SL$ and $ SS$ polynomials, we can establish their computational roots. For the four $ SS$ polynomials we get (since $ \sqrt{S}\gg S$):
$ a_1$ $ a_0$ $ x_1$ $ x_2$
$ +S$ $ +S$ $ +i\sqrt{S}$ $ -i\sqrt{S}$
$ +S$ $ -S$ $ +\sqrt{S}$ $ -\sqrt{S}$
$ -S$ $ +S$ $ +i\sqrt{S}$ $ -i\sqrt{S}$
$ -S$ $ -S$ $ +\sqrt{S}$ $ -\sqrt{S}$
The four $ LS$ polynomials give (since $ S/L$ is not representable and hence equal to zero)
$ a_1$ $ a_0$ $ x_1$ $ x_2$
$ +L$ $ +S$ 0 $ -L$
$ +L$ $ -S$ 0 $ -L$
$ -L$ $ +S$ $ +L$ 0
$ -L$ $ -S$ $ +L$ 0
and the four $ SL$ polynomials have computational roots
$ a_1$ $ a_0$ $ x_1$ $ x_2$
$ +S$ $ +L$ $ +i\sqrt{L}$ $ -i\sqrt{L}$
$ +S$ $ -L$ $ +\sqrt{L}$ $ -\sqrt{L}$
$ -S$ $ +L$ $ +i\sqrt{L}$ $ -i\sqrt{L}$
$ -S$ $ -L$ $ +\sqrt{L}$ $ -\sqrt{L}$
The quadratic solver implemented in FLASH4 obtains all the above roots to within machine epsilon accuracy.


32.6.2 Cubic Polynomials Root Test

The following set of cubic polynomials I-IX is used for the test. It corresponds to the set used in xxx and represents difficult to solve cases that stress test the cubic solver. In Tables 32.1 and 32.2 we list all the coefficients, analytical roots and FLASH4 cubic solver accuracy performance of these polynomials. The polynomials were designed to be tested with double precision machine working precision.

Table 32.1: Coefficients of the cubics I-IX used for the cubic polynomial root test.
Cubic $ a_2$ $ a_1$ $ a_0$
I $ -1.00000010000001e\!+\!14$ $ +1.00000010000001e\!+\!21$ $ -1.e\!+\!21$
II $ -3.000003$ $ +3.000006000002$ $ -1.000003000002$
III $ +8.999e\!+\!80$ $ -1.0009e\!+\!161$ $ +1.e\!+\!238$
IV $ +1.e\!+\!24$ $ -1.0$ $ -1.e\!+\!24$
V $ -1.99999999999999e\!+\!14$ $ +0.99999999999998e\!+\!28$ $ +1.e\!+\!28$
VI $ -3.e\!+\!5$ $ +3.0000000001e\!+\!10$ $ -1.0000000001e\!+\!15$
VII $ -3.0$ $ +1.00000000000003e\!+\!14$ $ -1.00000000000001e\!+\!14$
VIII $ -2.0000001e\!+\!7$ $ +1.00000020000001e\!+\!14$ $ -1.00000000000001e\!+\!14$
IX $ +0.99999999999998e\!+\!14$ $ -1.99999999999998e\!+\!14$ $ +2.e\!+\!14$


Table 32.2: Analytical roots and FLASH4 cubic solver accuracy performance of the cubics I-IX used for the cubic polynomial root test.
Cubic Roots Comments on Roots Accuracy
I $ +10^{+14}$, $ +10^{+7}$, $ +1$ 3 widely spaced real $ <1.e\!-\!15$
II $ +1.000002$, $ +1.000001$, $ +1$ 3 closely spaced real $ <1.e\!-\!9$
III $ -10^{+81}$, $ +10^{+80}$, $ +10^{+77}$ 3 large real $ <1.e\!-\!15$
IV $ -10^{+24}$, $ +1$, $ -1$ 1 large, 2 small real $ <1.e\!-\!15$
V $ +10^{+14}$, $ +10^{+14}$, $ -1$ 2 degenerate large, 1 small real $ <1.e\!-\!15$
VI $ +10^{+5}$, $ +10^{+5}\pm i$ 3 closely spaced, small imag parts $ <1.e\!-\!15$
VII $ +1$, $ +1\pm 10^{+7}i$ 1 small real, 2 large complex, large imag parts $ <1.e\!-\!15$
VIII $ +1$, $ +10^{+7}\pm i$ 1 small real, 2 large complex, small imag parts $ <1.e\!-\!15$
IX $ -10^{+14}$, $ +1\pm i$ 1 large real, 2 small complex $ <1.e\!-\!15$


32.6.3 Quartic Polynomials Root Test

Again the set of quartic polynomials I-XIII have been taken from xxx. Tables 32.3 and 32.4 list all the coefficients, analytical roots and FLASH4 quartic solver accuracy performance of these polynomials. The polynomials were designed to be tested with double precision machine working precision.

Table 32.3: Coefficients of the quartics I-XIII used for the quartic polynomial root test.
Quartic $ a_3$ $ a_2$ $ a_1$ $ a_0$
I $ -1.001001001e\!+\!9$ $ +1.001002001001e\!+\!15$ $ -1.001001001e\!+\!18$ $ +1.e\!+\!18$
II $ -4.006$ $ +6.018011$ $ -4.018022006$ $ +1.006011006$
III $ -9.98899e\!+\!79$ $ -1.1008989e\!+\!157$ $ -1.010999e\!+\!233$ $ -1.e\!+\!307$
IV $ -1.00000000000002e\!+\!14$ $ +1.99999999999999e\!+\!14$ $ +1.00000000000002e\!+\!14$ $ -2.e\!+\!14$
V $ +1.e\!+\!7$ $ -2.00000000000001e\!+\!14$ $ -1.e\!+\!7$ $ +2.e\!+\!14$
VI $ -9.000002e\!+\!6$ $ -0.9999981999998e\!+\!13$ $ +1.9999982e\!+\!13$ $ -2.e\!+\!13$
VII $ +2.000011e\!+\!6$ $ +1.010022000028e\!+\!12$ $ +1.1110056e\!+\!13$ $ +2.828e\!+\!13$
VIII $ -1.00002011e\!+\!8$ $ +2.01101022001e\!+\!11$ $ -1.02200111000011e\!+\!14$ $ +1.1000011e\!+\!15$
IX $ -2.0000002e\!+\!7$ $ +1.01000040000005e\!+\!14$ $ -2.020001e\!+\!14$ $ +5.05e\!+\!14$
X $ -1.9986e\!+\!4$ $ +1.00720058e\!+\!8$ $ -1.8600979874e\!+\!10$ $ +1.00004909000441e\!+\!14$
XI $ -4.006$ $ +5.6008018e\!+\!1$ $ -1.04148036024e\!+\!2$ $ +6.75896068064016e\!+\!2$
XII $ -4.0e\!+\!3$ $ +6.00001e\!+\!6$ $ -4.00002e\!+\!9$ $ +1.000010000009e\!+\!12$
XIII $ -6.0$ $ +1.01000013e\!+\!8$ $ -2.04000012e\!+\!8$ $ +1.00000104000004e\!+\!14$


Table 32.4: Analytical roots and FLASH4 quartic solver accuracy performance of the quartics I-XIII used for the quartic polynomial root test.
Quartic Roots Comments on Roots Accuracy
I $ +10^{+9}$, $ +10^{+6}$, $ +10^{+3}$, $ +1$ 4 widely spaced real $ <1.e\!-\!15$
II $ +1.003$, $ +1.002$, $ +1.001$, $ +1$ 4 closely spaced real $ <1.e\!-\!7$
III $ +10^{+80}$, $ -10^{+77}$, $ -10^{+76}$, $ -10^{+74}$ 4 large real $ <1.e\!-\!15$
IV $ +10^{+14}$, $ +2$, $ +1$, $ -1$ 1 large, 3 small real $ <1.e\!-\!15$
V $ -2\times 10^{+7}$, $ +10^{+7}$, $ +1$, $ -1$ 2 large, 2 small real $ <1.e\!-\!15$
VI $ +10^{+7}$, $ -10^{+6}$, $ +1\pm i$ 2 large real, 2 small complex $ <1.e\!-\!15$
VII $ -7$, $ -4$, $ -10^{+6}\pm 10^{+5}i$ 2 small real, 2 large complex $ <1.e\!-\!15$
VIII $ +10^{+8}$, $ +11$, $ +10^{+3}\pm i$ 1 large and small real, 2 medium complex $ <1.e\!-\!15$
IX $ +10^{+7}\pm 10^{+6}i$, $ +1\pm 2i$ 2 large, 2 small complex $ <1.e\!-\!15$
X $ +10^{+4}\pm 3i$, $ -7\pm 10^{+3}i$ 4 complex, mixed size real and imag parts $ <1.e\!-\!14$
XI $ +1.002\pm 4.998\;i$, $ +1.001\pm 5.001\;i$ 4 closely spaced complex $ <1.e\!-\!12$
XII $ +10^{+3}\pm 3i$, $ +10^{+3}\pm i$ 4 complex, equal real, small imag parts $ <1.e\!-\!15$
XIII $ +2\pm 10^{+4}i$, $ +1\pm 10^{+3}i$ 4 complex, small real, large imag parts $ <1.e\!-\!15$