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

Workbench / Mathematics Book 1 Companion: Arithmetic and Numbers

B1·10

Powers, Roots, Scientific Notation and Logarithms

Around chapter 10: how powers and logarithms connect place value, growth, scaling, floating point and algorithm cost; three other ways to see them; what the chapter simplifies (exponent laws in floating point, compounding tiny rates, scientific notation's limited digits); how Python's Fraction raises to negative and fractional powers; four debugging drills; and interview questions.

6 topics · ~13 min read
Updated Suggest a correction

Understanding it better

Concept map

  • Powers an = repeated multiplication → exponent laws (count factors) → forced extensions: a0=1, a−n=1/an, a1/n=an (as chapter 9 forced the sign rules).
  • Order of operations: −22=−4 (power before opposite); even/odd powers of negatives (chapter 9).
  • Place value is powers of 10 (chapter 2); floats are scientific notation in base 2 (chapter 7).
  • Scaling: lengths k → areas k2 → volumes k3 (chapter 8's maps, the square–cube law).
  • Roots undo powers → ab=ab → Heron's averaging, quadratic convergence → 2 isn't a fraction (chapter 12).
  • Compound growth P(1+r)n (chapter 7's multiplying changes, in closed form).
  • Logarithms = exponents → products become sums → solve for exponents (doubling time, rule of 72) → count digits ⌊logbn⌋+1 (chapter 2) → halvings log2n → logarithmic scales.
  • Next: estimation and orders of magnitude (chapter 11), irrational numbers and the real line (chapter 12).

Explain it differently

Powers are folding; logarithms are counting folds. Each fold of paper doubles the layers (a power of 2); asking how many folds give a stack as thick as a book is asking for a logarithm. Exponent laws are fold-counting: fold 3 times, then 4 more, is 7 folds.

A logarithm is the length of a number. log10n is, give or take a fraction, the number of digits of n minus 1: a 7-digit salary has log10 between 6 and 7. Multiplying two numbers roughly adds their lengths (a 3-digit number times a 4-digit number has 6 or 7 digits, chapter 4), which is the logarithm law in everyday form.

Scientific notation is a postal address. The exponent is the city (the order of magnitude), the mantissa the street and house number (the digits). To compare two addresses, compare cities first; only within a city do the house numbers matter. A float has a fixed number of digits for the house number, which is why tiny differences between huge numbers get lost.

Gaps and misconceptions

What the chapter oversimplifies

1. "The exponent laws always hold", which floating point bends. The laws are exact for numbers; floats round after every operation, and their range is limited:

Python
print((1.1 ** 3) ** 2 == 1.1 ** 6, (1.1 ** 3) ** 2, 1.1 ** 6)
print(10 ** 309 > 0, len(str(10 ** 309)))
try:
    print(10.0 ** 309)
except OverflowError as e:
    print("10.0 ** 309: OverflowError:", e)
print(float("1e309"), 2.0 ** -1100)
Text
False 1.771561000000001 1.7715610000000008
True 310
10.0 ** 309: OverflowError: (34, 'Numerical result out of range')
inf 0.0

(1.13)2 and 1.16 differ in the last digit, because each was rounded differently. Python's integers make 10309 exactly (310 digits), but the float 10.0309 overflows: the largest double is about 1.8×10308. Writing 1e309 gives infinity, and 2−1100 underflows to 0. Exponent laws are reliable for exact types; for floats, expect last-digit differences and check the range.

2. "Compound growth is P(1+r)n", which loses a tiny r entirely in floats. For small rates over many periods, 1+r can round to exactly 1:

Python
import math
r, n = 1e-16, 10 ** 16
print("(1 + r) ** n =", (1 + r) ** n, "| 1 + r == 1:", 1 + r == 1)
print("exp(n * log1p(r)) =", math.exp(n * math.log1p(r)), "| e =", math.e)
print("small rate, 1 day of 7%/365:", (1 + 0.07 / 365) - 1, "vs", 0.07 / 365, "| expm1(log1p) route:", math.expm1(math.log1p(0.07 / 365)))
Text
(1 + r) ** n = 1.0 | 1 + r == 1: True
exp(n * log1p(r)) = 2.718281828459045 | e = 2.718281828459045
small rate, 1 day of 7%/365: 0.00019178082191784185 vs 0.00019178082191780824 | expm1(log1p) route: 0.00019178082191780824

(1+10−16)1016 should be very close to e, but 1+10−16 is exactly 1.0 in floating point, so the result is 1. Computing it as enln(1+r) with log1p (which computes ln(1+r) accurately for tiny r) gives e. Even an ordinary daily rate, 7%365, loses digits when 1 is added and then subtracted; expm1(log1p(r)) keeps them. Financial and scientific libraries use these functions for exactly this reason.

3. "Scientific notation handles any size", but only a fixed number of digits at each size. A double has about 16 significant decimal digits, wherever the decimal point sits:

Python
total = 1e16
for _ in range(4):
    total += 1.0                       # each 1 is lost: 1e16 + 1 rounds back to 1e16
print(1e16 + 1 == 1e16, total, 1e16 + 4.0)
print(f"{6.02214076e23:.3e} has {len('602214076')} significant digits; a float keeps about 16")
Text
True 1e+16 1.0000000000000004e+16
6.022e+23 has 9 significant digits; a float keeps about 16

At 1016, the gap between neighbouring doubles is 2, so 1016+1 rounds back to 1016: adding 1 four times changes nothing, while adding 4 at once does. Large and small numbers can't be mixed freely; sum small values first, or use exact types.

Common misconceptions

Misconception What's actually true Where it's shown
"Floats obey the exponent laws exactly." They round after each step; (1.13)2≠1.16 in the last digit, and 10.0309 overflows. What the chapter oversimplifies, point 1
"(1+r)n is always safe to compute." For tiny r, 1+r rounds to 1; use log1p and exp. What the chapter oversimplifies, point 2
"Adding 1 to a number always changes it." Not above 253 in a double. What the chapter oversimplifies, point 3
"Fractional powers of fractions stay exact." Fraction(4, 9) ** Fraction(1, 2) is a float; roots are usually irrational. Code walkthrough
"Variance is the mean of squares minus the square of the mean, so compute it that way." In floats that subtracts two huge, nearly equal numbers and can even go negative. Drill D1
"^ means power." In Python, JavaScript, C and Java it's bitwise XOR: 2 ^ 10 is 8. Drill D2
"3 ** 40 in JavaScript is exact." Numbers above 253 are rounded; use BigInt. Drill D3
"Taking logs of data is always safe." log0=−∞ poisons averages; decide how to handle zeros. Drill D4

Theoretical gaps: the ideas behind the chapter

  • Exponentials and logarithms as functions. x↦bx turns addition into multiplication (bx+y=bxby) and logb does the reverse; they're isomorphisms between adding and multiplying. That's the structural reason slide rules work, and why logarithmic scales make multiplicative change look additive.
  • Growth rates compared. For large n, every power of logn is eventually smaller than every power of n, and every power of n eventually smaller than 2n: logn≪nk≪2n≪n!. This ordering is the backbone of algorithm analysis and is proved with limits (beyond this book).
  • Why quadratic convergence. Heron's method is Newton's method for x2−a=0; its error squares each step because the method uses the slope of the curve, matching it to first order, so only the second-order term remains. Calculus explains it fully.

Applying it

Code walkthrough

Python's Fraction raises a fraction to a power. Its method shows the chapter's forced rules (zero and negative exponents) and why fractional powers leave exact arithmetic. Excerpt from Lib/fractions.py in Python 3.13 (on your computer: python3 -c "import fractions; print(fractions.__file__)"):

Python
    def __pow__(a, b):
        """a ** b

        If b is not an integer, the result will be a float or complex
        since roots are generally irrational. If b is an integer, the
        result will be rational.

        """
        if isinstance(b, numbers.Rational):
            if b.denominator == 1:
                power = b.numerator
                if power >= 0:
                    return Fraction._from_coprime_ints(a._numerator ** power,
                                                       a._denominator ** power)
                elif a._numerator > 0:
                    return Fraction._from_coprime_ints(a._denominator ** -power,
                                                       a._numerator ** -power)
                elif a._numerator == 0:
                    raise ZeroDivisionError('Fraction(%s, 0)' %
                                            a._denominator ** -power)
                else:
                    return Fraction._from_coprime_ints((-a._denominator) ** -power,
                                                       (-a._numerator) ** -power)
            else:
                # A fractional power will generally produce an
                # irrational number.
                return float(a) ** float(b)

For a whole exponent n≥0, (pq)n =pnqn (the law (ab)n=anbn applied to p×1q). Since p and q share no prime factor, neither do pn and qn (unique factorisation, chapter 5), so the result is already in lowest terms: _from_coprime_ints skips the gcd. For a negative exponent, (pq)−n =(qp)n: flip, then power, which is a−n=1an. The last branch keeps the sign on top when p is negative (chapter 6's invariant). Zero to a negative power is division by zero. And any non-whole exponent gives up on exactness: "a fractional power will generally produce an irrational number" (chapter 12). Measured:

Python
from fractions import Fraction as F
print(F(2, 3) ** 3, F(2, 3) ** -2, F(-2, 3) ** -3, F(2, 3) ** 0)
print(F(4, 9) ** F(1, 2), F(-8) ** F(1, 3))
try:
    F(0) ** -1
except ZeroDivisionError as e:
    print("ZeroDivisionError:", e)
Text
8/27 9/4 -27/8 1
0.6666666666666666 (1.0000000000000002+1.7320508075688772j)
ZeroDivisionError: Fraction(1, 0)

(23)3 =827, (23)−2 =94, (−23)−3 =−278 (odd power, sign kept, on top), and (23)0=1. (49)1/2 is exactly 23, but the code doesn't check for perfect squares, so it returns the float 0.666…; and (−8)1/3 becomes a complex number, as in the chapter's lab.

Read it yourself

Using the code above, explain why _from_coprime_ints is safe in the negative-exponent branches too, and what Fraction(-2, 3) ** -2 returns and through which branch.

Debugging drills

D1. A standard deviation that crashed

A monitoring job computes the standard deviation of sensor readings with the one-pass formula "mean of squares minus square of mean". For readings around 108 it reports 1.41 instead of 0.08; around 5×108 it crashes:

Python
import math
for base in (1e8, 5e8):                                   # sensor readings around a large value
    readings = [base + 0.1, base + 0.2, base + 0.3] * 3
    n = len(readings)
    mean = sum(readings) / n
    quick = sum(x * x for x in readings) / n - mean * mean      # E[x^2] - E[x]^2, one pass
    two_pass = sum((x - mean) ** 2 for x in readings) / n
    try:
        sd = math.sqrt(quick)
    except ValueError as e:
        sd = f"ValueError: {e}"
    print(f"around {base:.0e}: quick variance {quick}, sqrt -> {sd} | two-pass variance {two_pass:.6f}")
Text
around 1e+08: quick variance 2.0, sqrt -> 1.4142135623730951 | two-pass variance 0.006667
around 5e+08: quick variance -32.0, sqrt -> ValueError: math domain error | two-pass variance 0.006667

Explain, and fix.

D2. Two to the power ten is eight

A capacity calculator computes 2 ^ bits to find how many values a field can hold. For 10 bits it says 8:

Python
print("2 ^ 10 =", 2 ^ 10, "| 2 ** 10 =", 2 ** 10, "| 10 ^ 2 =", 10 ^ 2, "| 3 ^ 3 =", 3 ^ 3)
Text
2 ^ 10 = 8 | 2 ** 10 = 1024 | 10 ^ 2 = 8 | 3 ^ 3 = 0

Explain, and fix.

D3. A power that's almost right

A JavaScript utility computes 340 for a combinatorics feature and compares it with a value from the server, computed exactly. They differ in the last few digits:

JavaScript
console.log(3 ** 40, String(3n ** 40n), 3 ** 40 === Number(3n ** 40n));
console.log(2 ** 53 + 1 === 2 ** 53, Number.MAX_SAFE_INTEGER, Math.pow(10, 21).toString());
Text
12157665459056929000 12157665459056928801 true
true 9007199254740991 1e+21

Explain, and fix.

D4. An average of −∞

An analytics notebook shows the "typical" article's page views as the geometric mean, computed as the mean of log10 of the views. The answer is −∞:

Python
import numpy as np, warnings
warnings.simplefilter("ignore")
views = np.array([1200, 15, 0, 89000, 340, 0, 7])          # page views per article
print("mean of log10(views):", np.log10(views).mean())
print("log10(views + 1):     ", round(np.log10(views + 1).mean(), 3), "| log1p (natural):", round(np.log1p(views).mean(), 3))
print("geometric mean of the non-zero:", round(10 ** np.log10(views[views > 0]).mean(), 1), "from", (views > 0).sum(), "of", len(views))
Text
mean of log10(views): -inf
log10(views + 1):      1.81 | log1p (natural): 4.167
geometric mean of the non-zero: 328.3 from 5 of 7

Explain, and fix.

Career-oriented

Interview prep

Mid level

Q1. Implement fast exponentiation (an in about log2n multiplications) and explain why it's fast.

How to get there. Square-and-multiply, from the binary digits of n.

Q2. How many bits do you need to store numbers up to N? To give every one of 10 million users a unique ID? To store a value from −1000 to 1000?

How to get there. Logarithms count binary digits; signed ranges from chapter 9.

Senior level

Q1. A team plots their service's daily active users on a linear axis and says growth has "exploded" this quarter. The growth rate has been steady at 4 % a month for two years. What do you show them?

How to get there. Exponential growth on linear and logarithmic axes.

Q2. An API's response time grows with input size. You measure 40 ms at n=1,000 and 160 ms at n=2,000. Estimate the complexity and predict n=10,000.

How to get there. Ratios of times as powers of ratios of sizes.

Staff level

Q1. Your organisation's capacity plan assumes traffic grows 8 % a month indefinitely. Review the plan.

How to get there. Compounding, doubling times, and limits to growth.

Q2. Choose a numeric representation for a scientific data platform that stores measurements from nanometres to light-years and from micrograms to tonnes, and must compute sums and products reliably.

How to get there. Range, precision, units and the chapter's failure modes.