Root finding with interval arithmetic
Abstract
We consider the solution of nonlinear equations in one real variable, the problem usually called by root finding. Although this is an old problem, we believe that some aspects of its solution using interval arithmetic are not well understood, and we present our views on this subject. We argue that problems with just one variable are much simpler than problems with more variables, and we should use specific methods for them. We provide an implementation of our ideas in C++, and make this code available under the Mozilla Public License 2.0.
1 Introduction
Many books and articles explain how to solve the nonlinear equation for , and some of them consider the verified solution of such equation, that is, finding solutions with rigorous bounds on them. Here we discuss the computation of verified solutions using interval arithmetic. This is an old subject, but the interval arithmetic literature is mostly concerned with the solution of the general equation for using variations of Newton’s method, since its very beginning [2, 10, 11]. For instance, the third chapter of [13] gives a nice description of interval Newton’s method and [2, 3] present interesting ways to improve it. Here we focus on the simplest case , because it is very important in practice and there are techniques which are applicable only for . As far as we know, the most detailed discussion of this particular case is presented in chapter 9 of [4], but we believe that there is more to be said about this subject than what is presented there.
In this article, is a function from to . We denote ’s th derivative by and when we mention such derivatives we assume that they exist. We consider the class
of all closed intervals, including the empty and unbounded ones. For , we write
We assume that we have extensions of and its derivatives, in the sense that:
Definition 1
We say that a function is an extension of a function in an interval if for every we have that .
We usually identify the point with the interval , and for functions we write . The set of roots is denoted by , and is a generic root.
When is differentiable, the main tool for root finding is Newton’s method
(1) |
This method has a natural extension to interval arithmetic:
(2) |
where is a point in and and are extensions of and . Traditionally, we compute by rounding the midpoint of . The first question an alert numerical analyst would ask about Equation is:
(3) |
However, we see few people asking the following question:
(4) |
Both questions are quite relevant, but before we answer them we must say that the interval version of Newton’s method may be implemented without Equation . Instead, we could write in the centered form
(5) |
and replace the extended derivative by an extension of the slope of at . This leads to an improved version of Newton’s method given by
(6) |
The slope is defined as
(7) |
and centered forms are already mentioned in Moore’s book [10]. They have been discussed in detail in the interval arithmetic literature [7, 12] and have generalizations called Taylor forms or Taylor models [9]. Our algorithm uses only the plain centered form , and in situations in which practical implementations of such generalizations are available we would use them only as a tool to obtain more accurate centered forms.
The Mean Value Theorem shows that
and this implies that any extension of is an extension of , but there may be better ones, specially when the interval is not small. For instance, if then
and any extension of yields intervals twice as large than necessary for an slope.
In practice the gain by replacing derivatives by slopes may not be great, because usually at the roots and in this case, for close to , the difference between and for in a short interval is not large. Moreover, extensions of derivatives have an important feature that extensions of slopes do not have: derivative extensions can detect monotonicity. In other words, if then is increasing in , but we cannot reach the same conclusion from the fact that . The ease with which we can use information about monotonicity when we have only one variable is what makes the case so special, and this is the reason why this article was written to start with.
We can ask questions similar to and about the modified Newton’s step :
(8) |
(9) |
and there are at least two more questions we must ask:
(10) |
(11) |
After much thought about the questions above, we devised a root finding algorithm which combines the interval versions of Newton’s method in Equations and , and modifies them in order to exploit montonicity. Our algorithm tries to strike a balance between theory and practice, and takes into account the following practical issues:
-
1.
Usually, the evaluation of interval extensions over intervals is much less accurate than the evaluation of interval extensions at points, that is, the width of the interval is much smaller than the width of the interval . The same applies to the derivative .
-
2.
Usually, the floating point evaluation of yields a reasonable estimate this derivative, at a much lower cost than the evaluation of the extensions or . The only defect of is that it does not come with a guarantee of its accuracy. As a result we can, and should, use floating point computations in order to obtain reasonable estimates (which may turn out to be inaccurate sometimes) and resort to interval computation only when we absolutely need guarantees about our results. In particular, the computed may be very wide even when the floating point would lead to a good Newton step , where is the mid point of .
-
3.
In interval arithmetic, our goal is to find short intervals which may contain roots and to discard intervals guaranteed not to contain roots.
-
4.
The simplest way to ensure that an interval contains a root is to prove that and have opposite signs. We can do that by evaluating at the points and , and as we noted above this evaluation tends do yield sharp results.
-
5.
The simplest way to ensure that an interval does not contain a root is to prove that and are different from zero and have the same sign and does not contain . In practice, this is not as easy as in the previous item because the computed tends to be inflated by the usual weaknesses of interval arithmetic. However, when we know that is monotonic we can dispense with and check only the values of at the end points. This simplifies things immensely for monotonic functions. Actually, it makes little practical sense to compute once we already know that it does not contain 0, and we have this information for all nodes below a first node in the branch and bound tree which is such that does not contain 0.
-
6.
Multiple roots, i.e., roots such that , are a major problem and should be handled differently from single roots. Usually, it is hopeless to try to get them with the same accuracy as single roots, and the cases in which we have some hope are too specific to deserve attention in a generic software.
Combining the items above, we propose an algorithm which can be outlined as follows. For each candidate interval we keep seven additional bits of information:
-
•
The sign of at its infimum,
-
•
The sign of at its supremum
-
•
The sign of in
-
•
A point in its interior, indicating where it should be split in the Newton step
-
•
A point , which lies near .
-
•
The value .
-
•
The expected sign of .
Regarding the signs above, means definitely negative, means definitely positive and means that we do not know the corresponding sign.
We then procedure in the usual branch and bound way:
-
1.
If the stack is empty then we are done. Otherwise we pop a tuple
from the stack.
-
2.
If the width of is below a given tolerance then we insert in a list of possible solutions and go to item 1.
-
3.
We compute . If it does not contain , then drop and go to item 1. (Tolerances are discussed in Section 3.)
-
4.
We compute the slope . If it does not contain then we compute the derivative . If does not contain then we change to the specific algorithm to handle strictly monotonic functions described in Section 5, and once we are done we go to item 1. Otherwise, we replace by and continue.
-
5.
We compute and check whether it contains zero or is too close to zero. If it does then use the algorithm described in Section 3 to handle and go to item 1.
-
6.
If is not too close to zero then and apply the version of the interval Newton step described in Section 2, obtaining at most two intervals and . If there are no then we drop and go to item 1.
-
7.
If there is just one then we check whether the sign matches the sign of . If it does not then we set to zero, take as the mid point of , obtain the extra information for and push it on the stack and go to item 1. Otherwise, we compute using floating point arithmetic and use and to check whether the corrected Newton step described in Section 4 lies in . If it does then we use this , otherwise we take as the midpoint of . We then obtain the additional information for , push it on the stack and go to item 1.
-
8.
If there are two s, then we check whether the width of lies below the cluster threshold . If it does then we deem to contain a cluster of zeros, and proceed as in item 2. Otherwise we apply the same procedure as in item 7 to and and go to item 1.
We implemented the algorithm outlined above in C++, using our Moore interval arithmetic library [8]. This code is available with the arxiv version of this article. It is distributed under the Mozilla Public License 2.0. Unfortunately, the code is much more involved than the summary above, because it must deal with many technical details which were not mentioned in this article in order not to make it longer and more complex than it already is.
In the rest of the article we discuss in more detail several aspects of the algorithm outline above. We start with Section 2, in which we present a version of Newton’s method for interval arithmetic. This version is similar to the ones found in the literature, but it is slightly different because it ensures that is different from zero at some of the extreme points of the new intervals, and computes the signs of at these extremes at a low extra cost. As a result, our algorithm yields not only intervals containing the roots but also the sign of at the extreme of such intervals, and these signs certify the existence of a root in the interval when they are different from each other. In Section 3 we make some comments about interval arithmetic in general and discuss the thorny subject of tolerances, which are unavoidable for defining stopping criterion for interval root solvers. Section 4 presents yet another version of the classic Newton’s method for exact, “point arithmetic.” This “point version” is the motivation for the interval version of Newton’s method for monotone functions presented in Section 5. Finally, in Section 6 we discuss the important subject of testing.
2 The Interval version of Newton’s step
This section is about the interval version of Newton’s step
(12) |
where can be either the derivative or the slope . Here we make the simplifying assumption that the interval
does not contain , answering to the questions , , and in the introduction in this case. By replacing by if necessary, we can assume that , and we make this simplifying assumption from now on.
The answer to questions and , in which case contains , is illustrated in Figure 2. In this Figure, the inclined lines have equations
(13) |
and by intersecting these lines with the axis we obtain a better bound on (recall that is the set of roots.) There are three possibilities for our bounds on after we take in to account the intersections above. We may find that:
There is nothing new in our approach up to this point. We just explained with a picture what most people do algebraically. Our slight improvement comes in the way we compute the intersections in Equations . These intersections are
and, as usual in the Moore Library [8], we propose that and be computed with the rounding mode upwards, using the following expressions:
(14) | |||||
(15) |
This order of evaluation ensure that and are rounded in the correct direction, so that we do not risk loosing roots. The expressions in Equation and are so simple that we find whether and where computed exactly by checking whether
(16) |
and
(17) |
If we find that was computed exactly then we increase it to the next floating point number. If was computed exactly then we decrease it to the previous floating point number. By doing so, we ensure that and , without computing or . We should also mention that it is possible to prove that, even after the rounding, incrementing and decrementing steps above, and there is no risk of crossing .
Regarding the cost of all this, note that in the Moore library the rounding mode is always upwards. Therefore, there is no cost associated with changing rounding modes. Moreover, the expensive operations in Equations and are the divisions, and the extra couple of sums and multiplications do not increase the overall cost of computing the intersections by much. In fact, if we take into account branch prediction and speculative execution and the fact that computations are usually inexact, the extra cost due to the verification in Equations and and the decrement of and the increment of is likely to be minimal. We would not be surprised if by performing the verification in Equations and above the code would be faster than blindly incrementing and decrementing (we did not have the time to check this.)
Finally, by using symmetry, we can reduce the analysis of questions and in the case in which does not contain to the cases described in Figure 2. In this Figure, the inclined lines have equations
and we may either have no intersection or one intersection. We can use the same technique described above for find intersections which are correctly rounded and such that is different from zero in the new extreme points , without evaluating (the old extreme points stay as they were.)
3 What we can expect from Interval Arithmetic
In order to appreciate the content of this article, one must realize that interval arithmetic is quite different from floating point arithmetic, and it is used for different purposes. Floating point methods are usually faster than interval methods, but do not provide rigorous bounds on their results. We use interval arithmetic when we want global solutions to our problems, with rigorous bounds on them, and we are willing to pay more for that.
Interval arithmetic is fundamentally limited. When we evaluate the extension at a point obtain an interval containing . The width of depends on the quality of the implementation of and the underlying arithmetic. When is not too complex and is , we expect that the width of to be , where is the machine precision. It is also reasonable to expect that the functions will be as in Figure 3 when is a root of .
When the evaluation of using interval arithmetic leads to wide intervals, we can (and do) use centered forms and Taylor models to reduce the width of , but this will not free us from facing the reality that the evaluation of interval extensions is usually imperfect. This is a fact, and we need to be prepared to handle not only the monotone situation described in Figure 3, but also the noisy situation described in Figure 4, which often occurs near a double root, and gets worse near roots of higher multiplicities.
Another fundamental fact about interval arithmetic is that it is a pessimistic theory: it always considers the worst scenario, and it would be inconsistent if it were otherwise. As consequence, of this fundamental fact, the functions and are indistinguishable by their common extension , that is, if is all the information that we have, then all our conclusions about must also apply to . This forces us to be very conservative, and include all possible roots for as candidates for roots for too, and vice versa. We emphasize this point because we found that it is not always clear in the minds of people trying to implement roots finders like the one we propose here, and this makes them under estimate the effort required for this task in real life.
Taking into account all that was said since the beginning of this section, we reached the conclusion that we should use three tolerances to try to handle the problems caused by the very nature of interval arithmetic. First, we should have a tolerance to handle “normal” roots like the one in Figure 3, at which , so that we consider intervals around such roots with width below to be good enough. Clusters of zeros of , as in Figure 4, are a different kind of beast, as the experience with other problems in interval arithmetic has show [5, 6]. By using the same tolerance for them we can end up with literally thousands of small intervals as candidates for containing roots, in the favorable case in which the program actually ends and returns something. We say this from our experience with our own interval root finders as well as with interval root finders developed by other people.
Our algorithm asks the user to also provide a “cluster tolerance” , which could be something of the order of , and a tolerance so that function values with magnitude below are deemed to be negligible. We take the liberty of increasing if we find it to be smaller than times the maximum width of the intervals which compute along the execution of algorithm. Contrary to what is proposed in [4], we believe that all tolerances should be absolute, and not relative (and users are free to choose which approach suits their needs best.) Using these tolerances, we can implement Algorithm 1 which “expands” a zero . By applying this algorithms to the point and the interval in Figure 4 we would identify the cluster and submit the intervals and to further examination. Finally, we must say that the actual algorithms for zero expansion in the C++ code are more involved than Algorithm 1, but the details are too cumbersome to be presented here.
4 The modified Newton’s method
As mentioned in the introduction, the main tool for root finding is Newton’s method
(18) |
This method was devised to find a “point approximation” to the root , that is, we for such that is small. It is our opinion that the goal of interval arithmetic is a bit different: we look for a short interval such that . Of course, in the end both goals amount to the same, but they suggest slightly different perspectives. We can rephrase the interval arithmetic goal as finding a short interval such that and have opposite signs (modulo degenerate cases in which or .) From this perspective, we believe that we should modify the classic Newton step so that it produces iterates such that the signs of alternate, in order to ensure that the interval
always contain a root.
A simple modification with this purpose is described in Figure 5. This Figure illustrates only the case in which and , but cases in which or are similar and can be reduced to the case and by replacing by or by . A simple way to obtain a reasonable approximation for the second derivative mentioned in Figure 5 is to use the quotient
with data and from previous iterations.
Motivated by Figure 5, we propose Algorithm 2 below for finding a short interval containing the single root of in the interval using exact arithmetic, in the case in which and for . It is not difficult to prove that Algorithm 2 has the same properties as the many other versions of Newton’s method that we find in the literature:
-
•
When the model
(19) is inaccurate for , we fallback into a bisection step. This guarantees that eventually the interval will become very short, and the analysis in the next item will apply
-
•
When the quadratic model is accurate in , and the interval is very short, will be a good approximation of and our modification in the Newton step will ensure that bisection will stop being necessary, the signs of the will alternate and the iterates will converge at the same quadratic rate as the classic method.
5 The Monotonic Method
This Section presents an interval Newton’s method for functions with for (in order to used for functions with we can simply replace by . The method is a simple adaptation of the “point method” presented in Section 4, taking into account the fundamental differences between exact (point) arithmetic and interval arithmetic. Among such differences we have the following ones:
-
•
In interval arithmetic, for a strictly increasing function, we may have that for many ’s. In exact arithmetic this can only happen for one value of .
-
•
In interval arithmetic we have a natural measure for the error in the the values of , given by the maximum width of the intervals . This allows us to correct a poor choice of the tolerance by the user and dispense with the cluster tolerance mentioned in Section 3.
As we mentioned in the introduction, the increasing case is much simpler than the general one. In this case, we do not need to compute neither nor . We only need the interval and the floating point number , and this entails a considerable reduction in the cost of the steps. The analysis of degenerate cases is also much simpler in the increasing case. These ideas are explored in Algorithm 3, which is presented after the bibliography. For brevity, we omit the expand_zero label in this code, but it is similar to the zero expansion algorithms presented in Section 3.
6 Testing
In practice, it is quite difficult to implement the algorithm presented here due to the need of much attention to detail. It is quite likely that the first attempts at such an implementation will fail, as ours did. Even worse, it is also likely that the failure will be undetected, specially if the details involved in the actual coding of the algorithm are considered to be of little relevance. As a result, in order to have some assurance of the reliability of our code in practice it is necessary to have a good suit of tests. Readers should not underestimate this point (and should not underestimate our remark that they should not underestimate this point, and, recursively…)
It is also important to realize that a good test suit may reveal problems not only in the code but also in the theory upon which it is based. A good example of this point is the choice of the stopping criterion presented in chapter 9 of [4]. When using that stopping criterion for the simple polynomial
(20) |
in the interval , we would obtain that the solution set is the whole interval , regardless of the tolerances provided by the user, and a good set of tests could detect this problem. The authors of [4] do mention that their stopping criterion may be problematic in some rare cases, and that users would detect this kind of problem afterwards. Readers may think that the polynomial in Equation is one of such cases, but we beg to differ: we believe that a proper algorithm should get the roots of a function as simple as the one in Equation with high accuracy without user intervention, and if it does not then it must be fixed. Asking users to analyze the result may not be an option for instance when our algorithm is being used thousands of times as part of a larger routine. In this scenario, users will not have the chance to look at the result of each call of the algorithm, and they will need either to rely on the algorithm to provide good answers, or to write their own code to do what the algorithm should have done for them.
The example in Equation can be though as a mild version of Wilkinson’s polynomial, and we believe that we can obtain a good test suit by adding multiple roots to polynomials similar to it. In our opinion, a robust root finder must not choke when trying to find the roots of polynomials of the form
(21) |
where and the exponents are integers and
If and are not large then the coefficients of can be computed exactly in floating point arithmetic. For instance, when and the coefficients of can be computed exactly with the usual IEEEE 754 double precision arithmetic. There are
(22) |
elements in the family of polynomials in Equation . For we have that
and for tolerances and with our code we can test all these million cases in a couple of days on our desktop machine, which has an AMD® Ryzen 7 2700x eight-core processor with 64MB of RAM (see the discussion about tolerances in Section 3.)
The family of functions in Equation has the following features, which make it a good test suit:
-
1.
By taking or we can check how our code handles roots on the border of the interval . This situation is a common source of bugs in root finders.
-
2.
Usually some will be greater than one, and the polynomials tend to have multiple roots. In fact, they may have roots with multiplicity as high as , or a couple of roots with multiplicity . These problems are quite challenging and some root finders may return thousands of candidates intervals for containing such multiple roots.
-
3.
It is easy to write an algorithm to generate these polynomials by writing them in the factored form
(23) where the are polynomials of the form
with degree at most . For and there are
polynomials and we can keep them in a table in memory, and let several threads build the polynomials from them using Equation .
-
4.
When the coefficients of the expanded version of
(24) can be computed exactly, we know the exact roots of the polynomial in Equation and we can use this knowledge to evaluate the robustness of our code with respect to the inaccuracies in the evaluation of and its derivatives using the expanded form. In other words, we should test our code using Horner’s method or a Taylor model version of it to evaluate using its expanded form , because the evaluation of the expanded form is usually much less accurate than the evaluation of the product form in Equation , and the purpose of testing is to stress our code.
Once we have chosen the family of functions and the intervals on which will search for roots, we must decide which tolerances to use for testing. Our advice is to use both large and small tolerances. Using large tolerances, like , and , we can detect gross mistakes, like mistyping. We may miss some of these gross mistakes if we only use tiny tolerances, because with tiny tolerances the part of the code affected by mistyping may never be executed during the tests, or may only cause bugs which are not severe enough to be detected (we say this based on our personal experience with our own blunders.) Tests with small tolerances are necessary to access the algorithm’s accuracy and to check how much time it takes to find accurate roots.
References
- [1] Alefeld, G., On the convergence of some interval arithmetic modifications of Newton’s method, SIAM J. Numer. Anal. 21, 363–372 (1984)
- [2] Hansen, E., On Solving Systems of Equations Using Interval Arithmetic. Math. Comp. 22, 374–384 (1968)
- [3] Hansen, E., Interval Forms of Newtons Method, Computing 20, 153–163 (1978)
- [4] Hansen, E., Walster, G., Global Optimization and Interval Analysis, Second Edition, Revised and Expanded, Marcel Dekker (2004)
- [5] Kearfott, R. B., and Du, K., The cluster problem in global optimization, the univariate case. Computing Supplement 9, 117–127 (1992)
- [6] Kearfott, R. B., and Du, K., The cluster problem in multivariate global optimization. Journal of Global Optimization, 5:253–265 (1994)
- [7] Krawczyk, R. and Neumaier, A., Interval Slopes for Rational Functions and Associated Centered Forms, SIAM J. Numer. Anal. 22, 604–616 (1985)
- [8] Mascarenhas, W. F., Moore: Interval Arithmetic in C++20, In: Barreto G., Coelho R. (eds) Fuzzy Information Processing. NAFIPS 2018. Communications in Computer and Information Science, vol 831, pp 519–529 (2018)
- [9] Neumaier, A., Taylor Forms–Use and Limits. Reliable Computing 9, 43–79 (2003)
- [10] Moore, R. E., Interval Analysis. Prentice-Hall, Englewood Cliffs, NJ. (1966)
- [11] Nickel, K., On the Newton Method in Interval Analysis. Mathematics Research Center Report 1136, University of Wisconsin (1971)
- [12] Ratschek, H., Centered forms, SIAM J. Numer. Anal. vol 15, no. 5, 656-662 (1980)
- [13] Ratschek, H. and Rokne, J., Geometric Computations with Interval and New Robust Methods, Applications in Computer Graphics, GIS and Computational Geometry. Horwood Publishing Chichester (2003)