Last time¶
Breaking Newton’s method
Exploration
Multiple roots
Conditioning of the rootfinding problem
Today¶
Polynomials and their roots
Forward and backward stability
Beyond IEEE double precision
using Plots
default(linewidth=4, legendfontsize=12)
using PolynomialsFundamental Theorem of Algebra¶
Every non-zero, single-variable, degree polynomial with complex coefficients has, counted with multiplicity, exactly complex roots.
n = 20
r = collect(1.:n)
w = fromroots(r)
w[10] *= 1 + 1e-10
plot(x -> abs(w(x)), xlims=(0, n+1), yscale=:log10)w = fromroots(r)
scatter(r, zero(r), color=:red)
for i in 1:100
noise = randn(length(w))
q = copy(w); # noise[1:8] .= 0; noise[10:end] .= 0
q[:] .*= 1 .+ 1e-10 * noise
xs = roots(q)
scatter!(real(xs), imag(xs), markersize=1)
end
plot!(legend=:none)Which is better to model inputs to a rootfinder?¶
A: coefficients in
B: coefficients in
Figure from Trefethen and Bau (1999)¶

Stability¶
“nearly the right answer to nearly the right question”
for some that is close to
Backward Stability¶
“exactly the right answer to nearly the right question”
for some that is close to
Every backward stable algorithm is stable.
Not every stable algorithm is backward stable.
Map angle to the unit circle¶
theta = 1 .+ LinRange(0, 3e-15, 100)
scatter(cos.(theta), sin.(theta), legend=:none, aspect_ratio=:equal)theta = 0 .+ LinRange(1., 1+2e-5, 100)
mysin(t) = cos(t - (1 + 1e10)*pi/2)
plot(cos.(theta), sin.(theta), aspect_ratio=:equal)
scatter!(cos.(theta), mysin.(theta))Are we observing A=stability, B=backward stability, or C=neither?¶
The numbers do not lie exactly on the unit circles.
There does not exist a such that
Accuracy of backward stable algorithms (Theorem)¶
A backward stable algorithm for computing has relative accuracy
Backward stability is generally the best we can hope for.
In practice, it is rarely possible for a function to be backward stable when the output space is higher dimensional than the input space.
Beyond IEEE-754 double precision¶
Lower precision IEEE-754 and relatives¶
The default floating point type in Julia (and Python, etc.) is double precision, which requires 8 bytes (64 bits) to store and offers .
IEEE-754 single precision (
floatin C and related languages) is half the size (4 bytes = 32 bits) and has long been popular when adequate.IEEE-754 half precision reduces both range (exponent bits) and precision (mantissa) bits.
bfloat16 is a relatively new non-IEEE type that is popular in machine learning because it’s easy to convert to/from single precision (just truncate/round the mantissa).
Posits¶

Mixed-precision algorithms¶
Sometimes reducing the precision (from double to single, or from single to half) compromises the quality of results (due to ill-conditioning or poor stability), but one can recover accurate results by using higher precision in a small fraction of the computation. These are mixed-precision algorithms, and can be a useful optimization technique.
Such techniques can give up to 2x improvement if memory bandwidth (for floating point data) or pure vectorizable flops are the bottleneck. In case of single to half precision, the benefit can be greater than 2x when using special hardware, such as GPUs with “tensor cores”.
Warning: Premature use of mixed-precision techniques can often obscure better algorithms that can provide greater speedups and/or reliability improvements.