Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

2026-09-11 Polynomials

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 Polynomials

Fundamental Theorem of Algebra

Every non-zero, single-variable, degree nn polynomial with complex coefficients has, counted with multiplicity, exactly nn complex roots.

Wilkinson’s polynomial

Let’s make a polynomial with roots at positive integers up to 20.

w(x)=∏k=120(x−k)=(x−1)(x−2)⋯(x−20)=∑k=020akxkw(x) = \prod_{k=1}^{20} (x - k) = (x - 1) (x - 2) \dotsb (x - 20) = \sum_{k=0}^{20} a_k x^k
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)
Loading...
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)
Loading...

Which is better to model inputs to a rootfinder?

  • A: coefficients rkr_k in

    p(x)=∏k(x−rk)p(x) = \prod_k (x - r_k)
  • B: coefficients aka_k in

    p(x)=∑kakxkp(x) = \sum_k a_k x^k

Figure from Trefethen and Bau (1999)

Ill conditioning of roots of Wilkinson's polynomial

Stability

“nearly the right answer to nearly the right question”

∣f~(x)−f(x~)∣∣f(x~)∣∈O(ϵmachine)\frac{\lvert \tilde f(x) - f(\tilde x) \rvert}{| f(\tilde x) |} \in O(\epsilon_{\text{machine}})

for some x~\tilde x that is close to xx

Backward Stability

“exactly the right answer to nearly the right question”

f~(x)=f(x~)\tilde f(x) = f(\tilde x)

for some x~\tilde x that is close to xx

  • 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)
Loading...
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))
Loading...

Are we observing A=stability, B=backward stability, or C=neither?

  • The numbers (cos⁡~θ,sin⁡~θ=(fl⁡(cos⁡θ),fl⁡(sin⁡θ))(\widetilde\cos \theta, \widetilde\sin \theta = (\operatorname{fl}(\cos \theta), \operatorname{fl}(\sin\theta)) do not lie exactly on the unit circles.

    • There does not exist a θ~\tilde\theta such that (cos⁡~θ,sin⁡~θ)=(cos⁡θ~,sin⁡θ~)(\widetilde\cos \theta, \widetilde \sin\theta) = (\cos\tilde\theta, \sin\tilde\theta)

Accuracy of backward stable algorithms (Theorem)

A backward stable algorithm for computing f(x)f(x) has relative accuracy

∣f~(x)−f(x)f(x)∣≲κ(f)ϵmachine.\left\lvert \frac{\tilde f(x) - f(x)}{f(x)} \right\rvert \lesssim \kappa(f) \epsilon_{\text{machine}} .

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 ϵmachine≈10−16\epsilon_{\text{machine}} \approx 10^{-16}.

  • IEEE-754 single precision (float in 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).

Typeϵmachine\epsilon_{\text{machine}}exponent bitsmantissa bitsdiagram
double1.11e-161152
single5.96e-8823
half4.88e-4510
bfloat163.91e-387

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.