Mathematics Book 1 Companion: Arithmetic and NumbersMaths Book 1 · Companion
0 / 0

Workbench / Mathematics Book 1 Companion: Arithmetic and Numbers

B1·11

Estimation, Rounding, Error and Units

Around chapter 11: how estimation, rounding, error and units connect every earlier chapter to measured, real-world numbers; three other ways to see them; what the chapter simplifies (worst-case errors, fixed-size units like "a month", ceilings of big numbers); how Python's timedelta carries mixed units with floored division; four debugging drills; and interview questions.

6 topics · ~13 min read
Updated Suggest a correction

Understanding it better

Concept map

  • Every measured number is a range → precision, significant figures, decimal places.
  • Estimation (one or two significant figures, compatible numbers, Fermi factors, orders of magnitude from chapter 10) → catches errors of size → sanity checks in code.
  • Rounding chooses a value for a range → rules for halves (half up, half even, floor, ceiling; chapter 4's grouping questions) → bias → round once, at the end (chapter 7's invoices).
  • Error: absolute and relative → sums add absolute errors, products add relative errors → cancellation in close differences (chapter 10's variance drill).
  • Units are factors (chapter 8's rates) → convert by multiplying by one → squared and cubed factors for areas and volumes (chapter 10) → mixed units carry at 60, 12, 1000 (chapter 3's carries, chapter 4's division algorithm) → durations vs instants (chapter 9's positions and differences).
  • Next: the real number line (chapter 12), where measurement's "ranges" become the definition of a number.

Explain it differently

A measurement is a blurry dot. On the number line (chapter 9), a measurement isn't a point but a small smudge: 81 cm is the smudge from 80.5 to 81.5. Rounding picks one point inside the smudge to write down; error is the smudge's width; combining measurements combines smudges, and subtracting two nearby smudges leaves a smudge as wide as both, around a value near zero.

Units are the denominators of the real world. Chapter 6 said you can't add thirds and quarters without a common denominator. You can't add metres and centimetres either, until both are in one unit, and the conversion factor plays the part of "multiply top and bottom by the same number".

Estimation is a sketch before the painting. A sketch fixes the proportions; if the painting comes out with a head twice the size of the body, you notice at once. Nobody calls the sketch inaccurate; it's accurate about what matters first.

Gaps and misconceptions

What the chapter oversimplifies

1. "Absolute errors add", which is the worst case, rarely reached. When independent errors each go either way, they mostly cancel:

Python
import random, statistics
random.seed(14)
# 100 lengths, each measured to the nearest cm, so each error is anywhere in -0.5 .. +0.5 cm
totals = [sum(random.uniform(-0.5, 0.5) for _ in range(100)) for _ in range(20_000)]
print(f"worst case ±{100 * 0.5:.0f} cm | typical (standard deviation) ±{statistics.pstdev(totals):.2f} cm | largest seen {max(map(abs, totals)):.1f} cm")
print(f"rule for independent errors: 0.5/√3 × √100 = {0.5 / 3 ** 0.5 * 10:.2f} cm")
Text
worst case ±50 cm | typical (standard deviation) ±2.88 cm | largest seen 11.3 cm
rule for independent errors: 0.5/√3 × √100 = 2.89 cm

A total of 100 lengths, each measured to the nearest centimetre, could in the worst case be 50 cm off. In 20,000 simulated totals the typical error (standard deviation) is about 2.9 cm, and the largest seen is 11.3 cm. Independent errors combine like the square root of the number of terms: 0.53×100. Worst-case bounds are right for guarantees (a part must fit); typical errors are right for estimates (how far off will the total usually be?).

2. "A unit is a fixed amount", which fails for calendar units. A metre is a metre; a month isn't a fixed number of days:

Python
import calendar
from datetime import date, timedelta
start = date(2026, 1, 31)
print("30 days later:", start + timedelta(days=30))
def add_months(d, k):
    y, m = divmod(d.month - 1 + k, 12)
    y, m = d.year + y, m + 1
    return date(y, m, min(d.day, calendar.monthrange(y, m)[1]))     # clamp to the month's last day
print("one month later:", add_months(start, 1), "| two:", add_months(start, 2), "| one then one:", add_months(add_months(start, 1), 1))
print("days in each month of 2026:", [calendar.monthrange(2026, m)[1] for m in range(1, 13)])
Text
30 days later: 2026-03-02
one month later: 2026-02-28 | two: 2026-03-31 | one then one: 2026-03-28
days in each month of 2026: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]

"30 days after 31 January" is 2 March, while "one month after 31 January" must be clamped to 28 February, and adding a month twice (28 March) differs from adding two months at once (31 March). Months, years (with leap years) and even days (with daylight-saving changes, 23 or 25 hours) are calendar units, not fixed durations. Billing cycles, subscriptions and interest periods must say which they mean.

3. "Ceiling answers how many boxes", but not through a float. ⌈n/12⌉ is right in exact arithmetic; for large n, dividing in floating point first loses the remainder:

Python
import math
eggs = 10 ** 17 + 1
print("math.ceil(eggs / 12):", math.ceil(eggs / 12), "| exact -(-eggs // 12):", -(-eggs // 12))
print("difference:", -(-eggs // 12) - math.ceil(eggs / 12))
Text
math.ceil(eggs / 12): 8333333333333333 | exact -(-eggs // 12): 8333333333333334
difference: 1

(1017+1)/12 as a float has no room for the leftover egg, so math.ceil returns one box too few. The integer form −(−n//12) (chapter 4's companion) is exact at any size. The same applies to pages, batches, shards and anything counted in whole groups.

Common misconceptions

Misconception What's actually true Where it's shown
"The total of 100 measurements is uncertain by 100 times each one's error." That's the worst case; independent errors typically grow like the square root of the count. What the chapter oversimplifies, point 1
"A month is 30 days." Months have 28 to 31 days; adding months needs a rule for the last day. What the chapter oversimplifies, point 2
"math.ceil(n / k) counts the groups needed." Only while n fits a float exactly; use integer division. What the chapter oversimplifies, point 3
"Negative durations print with a minus sign on every part." timedelta(minutes=-90) is "−1 day, 22:30:00": floored carries. Code walkthrough
"A tiny error per step doesn't matter." It accumulates: 0.1 s stored with 10−7 error drifts 0.34 s in 100 hours. Drill D1
"Multiply by 3.6 to get m/s." Divide; write the factors and check that the units cancel. Drill D2
"Python's round rounds money like a cash register." It rounds halves to even: 2.5 becomes 2. Drill D3
"7 % can be stored as 7." A rate must say whether it's a percent or a fraction, or interest is off by 100 times. Drill D4

Theoretical gaps: the ideas behind the chapter

  • Error propagation in general. For a function f(x,y), small errors combine according to how sensitive f is to each input (its partial derivatives): calculus turns the chapter's two rules into one. Independent random errors add in quadrature: σf2≈(∂xf)2σx2+(∂yf)2σy2.
  • Conditioning. Some problems amplify input errors whatever the method: subtracting close numbers, solving nearly singular equations. The condition number measures this amplification; numerical analysis separates it from errors the method adds.
  • Dimensions as algebra. Units form a system with multiplication and powers (m, s, kg as independent "letters"); the Buckingham π theorem (1914) uses this to show which combinations of quantities can appear in a physical law, the basis of scale models and wind tunnels.

Applying it

Code walkthrough

Python's datetime.timedelta stores a duration in three mixed units, days, seconds and microseconds, and normalises any input into them with carries, exactly like the chapter's "2 h 75 min = 3 h 15 min". Excerpts from Lib/_pydatetime.py in Python 3.13, the pure-Python version of the module (on your computer: python3 -c "import _pydatetime; print(_pydatetime.__file__)"):

Python
        # Doing this efficiently and accurately in C is going to be difficult
        # and error-prone, due to ubiquitous overflow possibilities, and that
        # C double doesn't have enough bits of precision to represent
        # microseconds over 10K years faithfully.
        ...
        # Normalize everything to days, seconds, microseconds.
        days += weeks*7
        seconds += minutes*60 + hours*3600
        microseconds += milliseconds*1000
        ...
        # Just a little bit of carrying possible for microseconds and seconds.
        seconds, us = divmod(microseconds, 1000000)
        s += seconds
        days, s = divmod(s, 24*3600)
        d += days

        assert isinstance(d, int)
        assert isinstance(s, int) and 0 <= s < 24*3600
        assert isinstance(us, int) and 0 <= us < 1000000

The opening comment is this chapter's error analysis in one sentence: a double has 53 bits, about 16 significant digits, and microseconds over 10,000 years need about 18, so durations can't be stored as one float of seconds; hence three integers. The input units are first converted by their factors (weeks × 7, minutes × 60, hours × 3600: multiplying by one). Then the carries: divmod(microseconds, 1000000) turns surplus microseconds into seconds, and divmod(s, 24*3600) turns surplus seconds into days, the division algorithm at each place (chapter 4). The assertions state the invariant: seconds from 0 to 86,399 and microseconds from 0 to 999,999. Because Python's divmod is floored (chapter 9), the invariant holds for negative durations too: only the days can be negative. Measured:

Python
from datetime import timedelta as td
print(td(hours=2, minutes=45) + td(hours=1, minutes=30))
print(td(minutes=75), "|", td(seconds=100_000), "|", td(minutes=-90), "|", repr(td(minutes=-90)))
print(td(days=1.1), "|", td(seconds=0.1) * 3 == td(seconds=0.3), "|", td(milliseconds=1.5))
Text
4:15:00
1:15:00 | 1 day, 3:46:40 | -1 day, 22:30:00 | datetime.timedelta(days=-1, seconds=81000)
1 day, 2:24:00 | True | 0:00:00.001500

2 h 45 min + 1 h 30 min is 4:15:00; 75 minutes is 1:15:00; 100,000 seconds is 1 day, 3:46:40. Minus 90 minutes is shown as "−1 day, 22:30:00": days −1, seconds 81,000, which is −86,400+81,000 =−5,400 seconds, as the floored carry requires. 1.1 days is 1 day 2:24. And because seconds and microseconds are integers, timedelta(seconds=0.1) * 3 equals timedelta(seconds=0.3) exactly, which 0.1 * 3 == 0.3 with floats doesn't (chapter 7).

Read it yourself

Using the code above, work out the stored (days, seconds, microseconds) for timedelta(seconds=-1) and for timedelta(microseconds=-1), and explain why the designers chose floored carries rather than truncated ones, which would print "−0:00:01".

Debugging drills

D1. A clock that drifts

A long-running system keeps time by adding 0.1 s on every tick. Its clock drifts, and a loop waiting for t == 1.0 never ends:

Python
# A clock that adds 0.1 s every tick, in 24-bit fixed point (like a 1991 missile-defence computer),
# and the same in a double.
FRAC_BITS = 23                                   # 0.1 chopped to 23 bits after the point
tick = int(0.1 * 2**FRAC_BITS) / 2**FRAC_BITS    # truncated, as that system did
ticks = 100 * 3600 * 10                          # 100 hours of tenths of a second
print(f"0.1 stored as {tick!r}, error per tick {0.1 - tick:.3e} s")
print(f"after 100 hours: drift {(0.1 - tick) * ticks:.4f} s")
t = 0.0
for _ in range(10):
    t += 0.1
count = 10                                       # or count ticks as an integer and divide once, at the end
print("ten double-precision ticks:", t, "| t == 1.0:", t == 1.0, "| count / 10 == 1.0:", count / 10 == 1.0)
Text
0.1 stored as 0.09999990463256836, error per tick 9.537e-08 s
after 100 hours: drift 0.3433 s
ten double-precision ticks: 0.9999999999999999 | t == 1.0: False | count / 10 == 1.0: True

Explain both, and fix.

D2. A speed check that never fires

A speed-camera service converts the limit from km/h to m/s and compares measured speeds. Nobody is ever over the limit:

Python
def to_ms(kmh):                       # convert km/h to m/s for a speed-limit check
    return kmh * 3.6

limit = to_ms(50)                     # a 50 km/h zone
for speed_ms in (12.0, 15.0, 20.0):   # measured speeds in m/s
    print(f"{speed_ms} m/s ({speed_ms * 3.6:.0f} km/h): over the limit? {speed_ms > limit}  (limit computed as {limit} m/s)")
Text
12.0 m/s (43 km/h): over the limit? False  (limit computed as 180.0 m/s)
15.0 m/s (54 km/h): over the limit? False  (limit computed as 180.0 m/s)
20.0 m/s (72 km/h): over the limit? False  (limit computed as 180.0 m/s)

Explain, and fix.

D3. Receipts that round 2.5 down

A billing script rounds rupee amounts to whole rupees with Python's round. Customers' receipts disagree with the shop's printed rule, "50 paise and above rounded up":

Python
from decimal import Decimal, ROUND_HALF_UP
amounts = [2.5, 3.5, 4.5, 10.5, 11.5, 0.5]          # rupee amounts to be rounded to whole rupees on a receipt
print("round():   ", [round(a) for a in amounts], "sum", sum(round(a) for a in amounts))
print("half up:   ", [int(Decimal(str(a)).quantize(Decimal(1), ROUND_HALF_UP)) for a in amounts],
      "sum", sum(int(Decimal(str(a)).quantize(Decimal(1), ROUND_HALF_UP)) for a in amounts))
Text
round():    [2, 4, 4, 10, 12, 0] sum 32
half up:    [3, 4, 5, 11, 12, 1] sum 36

Explain, and fix.

D4. A savings account paying 350 %

Interest rates are entered by different teams: some as percentages, some as fractions. One year's interest on ₹1 lakh:

Python
rates = {"savings": 3.5, "fd": 7.25, "loan": 0.0925}       # entered by different people: percent, percent, fraction
principal = 1_00_000
for name, r in rates.items():
    print(f"{name:<8} rate {r!r:>7} -> one year's interest ₹{principal * r:,.2f}")
Text
savings  rate     3.5 -> one year's interest ₹350,000.00
fd       rate    7.25 -> one year's interest ₹725,000.00
loan     rate  0.0925 -> one year's interest ₹9,250.00

Explain, and design the fix.

Career-oriented

Interview prep

Mid level

Q1. Estimate how many requests per second a service needs to handle if 2 crore users each open the app 5 times a day, with each open making 8 requests, and traffic at the peak hour is three times the average.

How to get there. A Fermi estimate with stated factors.

Q2. Write a function that adds durations given as "h:mm" strings and returns "h:mm". What could go wrong?

How to get there. Convert to the smallest unit, add, convert back.

Senior level

Q1. A finance report shows totals that differ from the sum of the displayed line items by a few rupees. Explain why, and what the report should do.

How to get there. Rounding each line versus rounding the total.

Q2. A sensor platform receives temperatures from devices made by three vendors, some reporting °C, some °F, some tenths of a degree as integers. Design the ingestion.

How to get there. Units at the boundary, validation, and storage.

Staff level

Q1. Define the engineering standard for time and durations across your services.

How to get there. Instants, durations, calendar units, clocks and precision.

Q2. An analytics team reports "average order value up 0.3 %" week on week. How would you decide whether that's a real change?

How to get there. Measurement error, sampling variation and precision of reported figures.