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
Module material
Take these after the last lesson, in this order. Next on each page leads through them.
- Module quiz10 questions across the whole module. Take it after the last lesson; your first pick on each question is the one that counts.
- NotebooksOpen them in Google Colab. Each answer is checked as you go: correct, wrong with the expected value, or not answered yet.
- Common mistakesWhat you see when it goes wrong, why it happens, and the fix, across the whole module.
- Cheat sheetOne page of the module’s terms, rules and gotchas, with the output each rule produces.
- 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₂for0.755.1 - exponent
- the power of two the significand is multiplied by |
−1for0.755.1 - rounding error
- the difference between a number and the float stored for it |
0.1is stored5.55 × 10⁻¹⁸too high 5.1 - machine epsilon
- the gap between 1 and the next float,
2.22 × 10⁻¹⁶in float64 |np.finfo(float).eps5.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)² − 1ath = 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 asm + log Σ e^(zᵢ − m)withmthe largestzᵢ|1001.3133for[1000, 1001]5.1- numerically stable
- computed so that rounding, overflow and underflow do not change the answer |
log_expit(-1000)→−1000.05.1