Stability of arithmetic expressions in Julia

I was thinking about numerical stability (with respect to floating point) of polynomial evaluation, and I had the following question: if I naively write a polynomial (or other) expression in Julia, is it evaluated in a way so as to be backwards stable (a la Horner’s rule)?

Not automatically. It is evaluated using the expressions you wrote in the order you wrote them. There is, however, an evalpoly function that uses Horner’s rule for real values (and an even more efficient, stable rule for complex values). One of the general principles of the language is that it doesn’t play any clever games and just evaluates what you asked it to; however it also makes it easy to ask for something clever to be done.

11 Likes

Naive evaluation is also backwards stable IIRC. The advantage of Horner’s rule is not improved accuracy, it is improved efficiency.

4 Likes