SchoolWhool
Quizzes and saved progress, freeSign in freeSign in
Maths · Module 5

Numbers on a Computer

Take each lesson, answer its quiz, then do its practice. After the last lesson come the module quiz, the project and the interview questions.

Lessons

  1. 5.1Floating Point and Numerical StabilityKnow why a correct formula can give a wrong answer on a computer, and the standard fixes.

Module material

Take these after the last lesson, in this order. Next on each page leads through them.

  1. Module quiz10 questions across the whole module. Take it after the last lesson; your first pick on each question is the one that counts.
  2. NotebooksOpen them in Google Colab. Each answer is checked as you go: correct, wrong with the expected value, or not answered yet.
  3. Common mistakesWhat you see when it goes wrong, why it happens, and the fix, across the whole module.
  4. Cheat sheetOne page of the module’s terms, rules and gotchas, with the output each rule produces.
  5. Interview questions10 questions interviewers ask on this module’s topics, from first principles to the follow-ups. Each comes with a model answer.

Glossary

Every term the module introduces, with the lesson that introduces it.

floating-point number
a sign, a significand and an exponent, ±1.f × 2ᵉ | 0.75 = 1.1₂ × 2⁻¹ 5.1
significand
the binary digits of the number, 53 of them in float64 | 1.1₂ for 0.75 5.1
exponent
the power of two the significand is multiplied by | −1 for 0.75 5.1
rounding error
the difference between a number and the float stored for it | 0.1 is stored 5.55 × 10⁻¹⁸ too high 5.1
machine epsilon
the gap between 1 and the next float, 2.22 × 10⁻¹⁶ in float64 | np.finfo(float).eps 5.1
relative error
the error divided by the size of the number | at most 1.11 × 10⁻¹⁶ after rounding 5.1
cancellation
the loss of correct digits when two nearly equal numbers are subtracted | (1 + h)² − 1 at h = 10⁻¹² 5.1
overflow
a result larger than the largest float, stored as inf | np.exp(710) 5.1
inf
the float for infinity | np.exp(1000) 5.1
underflow
a result closer to zero than the smallest float, stored as 0.0 | np.exp(-746) 5.1
nan
"not a number", the result of an undefined operation such as inf / inf | np.exp(1000) / np.exp(1000) 5.1
log-sum-exp
log Σ e^(zᵢ), computed as m + log Σ e^(zᵢ − m) with m the largest zᵢ | 1001.3133 for [1000, 1001] 5.1
numerically stable
computed so that rounding, overflow and underflow do not change the answer | log_expit(-1000) → −1000.0 5.1