Round-off Error

Round-off Error#

Round-off errors are possible whenever you have to write down a number. This is especially problematic for irrational numbers, but also true for rationals!

from numpy import pi, e, sqrt, binary_repr
print(pi, e, 1/3, sqrt(2))
3.141592653589793 2.718281828459045 0.3333333333333333 1.4142135623730951

The problem is that we can only write down a finite number of digits before we get tired. So we round the last digit or chop it.

This error is inherant to finite precision numerics, not necessarily computations. The problem is that if computations include millions of calculations, these little mistakes can add up.

The average human is capable of around 1 mistake per second, but computers are capable of millions of mistakes a second!

NB: If we could use infinite digits, or represent numbers symbolically (e.g. 1/3, \(\pi\), \(\sqrt 2\)), this wouldn’t be an issue. This is why tools like Mathematica, Maple, or the sympy module, don’t evaluate anything until they have too.

Q: What are the pros and cons of keeping symbols?

The impact of roundoff error is related to the precision (the number of digits we write down), and the way (base) we write numbers in.