When computing , we know that catastrophic cancellation may happen when we are computing the minus operation between and when we have close to 1. While this kind of cancellation may not happen when we are computing under the same condition, as close to one does not implies that should also be extremely close to .
I am going to show how can we construct so that catastrophic cancellation will only happen in while not in .
Assume is a small number, let . Then, will be evaluated in the following form: For , we know that the only place that rounding error can happen on should be term . There should be no cancellation happening on the part, as it is going to be impossible for us to represent by otherwise.
In this case, in order to maximize the rounding error during the computation of , we want to be as large as possible while making (i.e. Let term gets rounded off completely). Therefore, Therefore, the maximum value can take should be less than . Catastrophic cancellation should happen when computing when we have right below the theoretical bound we just derived. However, the same kind of cancellation will not happen when we are computing . As the value of is much larger than , there’s no reason for us to suffer from the cancellation problem in this case. Because the value of will be much smaller than that of , we can treat the upper bound of as during experiment. The MATLAB code and its corresponding output for the experiment I have done as provided below. The value of during experiment was set to .
delta = sqrt(1.9 * eps);
x = 1 + delta;
a = (1 - x^2);
b = (1 - x) * (1 + x);
disp((a - b)/b);
>> experiment
5.4052e-10
We can see that the error level here is pretty high comparing to the value of . Thus, the two expressions are indeed different from each other during evalution.