|
Initialization: Load the package and set the display of special functions in output to typeset mathematical notation (textbook notation):
|
>
|
|
| (1) |
Set the value of Digits to 15 and create an Array with 40,000 random complex numbers, organized into four Arrays, with 1/4 of these numbers in each of the four quadrants of the complex plane, and with all the numbers having absolute value in between 1/10000 and 1/2 - see QuadrantNumbers
>
|
|
Concatenate the four Arrays into one containing the 40,000 numbers
>
|
|
Add now these numbers, using both the standard Maple add command and the PairwiseSummation command: compare the precision (higher with PairwiseSummation) and also the time consumed to perform the summations
>
|
|
| |
>
|
|
| |
Note that, depending on the random sample of numbers, the difference in time consumed for adding 40,000 complex numbers is either advantageous for PairwiseSummation or negligible, due to performing the pairwise summation under evalhf. Now, we know from the theory [1] that the pairwise summation result has less round-off error but how could we verify that? By performing the same addition with a higher value of Digits in order to diminish the accumulation of round-off error. For instance, perform the addition with Digits = 20, then round the result to Digits = 15 and compare with the results (5) and (6):
| (5) |
>
|
|
| (6) |
We see that the result (8) by PairwiseSummation only changed the last couple of digits of (6) while the result (7) by add changed various trailing digits of (5) and actually came closer to (6) by PairwiseSummation. Since these last two results (7) and (8) are assured to have less round-off error that (5) and (6), we see that (6) using PairwiseSummation has less less round-off error (2 to 4 more correct digits) than (5).
In conclusion from this experiment, depending on the random sample of complex numbers, for example for Digits = 15 we can expect say from two to four more correct digits when adding using pairwise summation than when adding the same numbers one at a time. In practice, even adding a small amount of numbers with Digits = 10, we can expect one to two more correct digits when performing the addition using the pairwise technique.