Mathematical Foundations

I.1 · Mathematical Language

Why does squaring forget something?

A scalar is one number, a quantity is a number that remembers its unit, and squaring and rooting are two questions about the same square. We follow the units through every calculation, learn why powers obey their rules, and find out exactly what a root is and is not.

A square and its side: q↦q2↦q2q\mapsto q^{2}\mapsto\sqrt{q^{2}}

I choose
Unit

Try a side

A square standing on the x-axis whose side runs from 0 to 3 metres, on the right of the origin, with area 9 square metres. A marker on the positive side of the axis shows the square root of that area, 3.

side (signed)
3 m
area of the square
9 m²
its square root
3 m

= exact · ≈ rounded to 6 decimals · ⚠ undefined

Squaring and then taking the root brings q = 3 back, because q is not negative. Try the negative twin of q: the same square, but the root returns a different number.

q2=32=9\begin{aligned}q^{2}&=3^{2}=9\end{aligned}
q2=9=3=∣q∣\begin{aligned}\sqrt{q^{2}}&=\sqrt{9}=3\\&=\abs{q}\end{aligned}

from −6 to 6, up to 2 decimal places

A square with side q has area q². Drag the corner on the left, use the arrow keys on it, or type a side. Switch to the area and the stage asks the reverse question: which side has this area?

Try it before reading on. Put the side at 33, then at −3-3, and compare the areas. Then switch to the area, ask for area 99, and look at how many sides the stage reports. Then ask for area 22 and for area −4-4. By the end of the chapter you will know why squaring throws information away, why the question “which side has area 99?” has two answers while the symbol 9\sqrt{9} has only one, why 2\sqrt 2 is written exactly and not as a decimal, and what a unit does to every one of these calculations.

Intuition: a number and what it measures

A scalar is a single real number: 33, −1.5-1.5, 74\tfrac{7}{4}, 2\sqrt 2. The word is used to separate one number from the lists of numbers (vectors) that this Part builds up to in the Vectors chapter. In the real world a number is almost never alone. It counts something, or measures it: 33 metres, 1212 seconds, 55 kilograms. A number together with what it measures is a quantity.

The unit is not decoration. Three metres and two seconds cannot be added: there is no common thing to count in, so the sum has no meaning, however easy the arithmetic looks. But they can be multiplied or divided, and the result has a unit of its own: three metres by two metres is an area, six square metres; twelve metres in four seconds is a speed, three metres per second. Following the unit through the arithmetic is the oldest sanity check in engineering, and it is also the reason this chapter puts units, powers and roots in the same place. A square’s side is a length. Its area is a length squared. Asking for the side from the area is a root, and a root of an area is a length again.

Definition: quantity, power and root

Quantity. A quantity is a real number (its value) together with a unit. We write a unit as a product of three base units, metre (m), second (s) and kilogram (kg), each raised to a whole-number exponent:

unit=ma⋅sb⋅kgc,(a,b,c)∈Z3.\text{unit}=\mathrm{m}^{a}\cdot\mathrm{s}^{b}\cdot\mathrm{kg}^{c},\qquad (a,b,c)\in\mathbb Z^{3}.

The triple (a,b,c)(a,b,c) is the exponent vector of the unit, and it is the whole of the unit as far as arithmetic is concerned: two units are the same exactly when their exponent vectors are equal. A plain number has the vector (0,0,0)(0,0,0) and is called dimensionless. A speed in metres per second has (1,−1,0)(1,-1,0) and an area in square metres has (2,0,0)(2,0,0).

Power. For a real number bb and a positive whole number kk, the power bkb^{k} is bb multiplied by itself kk times. The exponent 00 and the negative exponents are defined for b≠0b\neq 0 by

b0=1,b−k=1bk.b^{0}=1,\qquad b^{-k}=\frac{1}{b^{k}}.

This book leaves 000^{0} and every negative power of 00 undefined: 0−10^{-1} would be 1/01/0. (Some programs define 00=10^0=1 as a convenience for polynomials. That is a convention for a particular notation, not a fact about numbers, and we do not use it for powers of numbers. One place later in this Part does adopt it, openly and only there: in a geometric sum ∑ri\sum r^{i} the first term r0r^{0} is read as 11 for every rr, even r=0r=0, as the empty product, so that the formula and the loop agree. Chapter I.8 says so where it happens.)

Root. Let n≥2n\ge 2 be a whole number and AA a real number. A real number xx is an nnth root of AA when xn=Ax^{n}=A. How many there are depends on the parity of nn and the sign of AA:

  • nn odd. There is exactly one real root, for every AA, and it has the sign of AA. We write it An\sqrt[n]{A}. For example −83=−2\sqrt[3]{-8}=-2.
  • nn even and A>0A>0. There are exactly two real roots, rr and −r-r. The symbol An\sqrt[n]{A} means the non-negative one, rr. For example 9=3\sqrt{9}=3, while the equation x2=9x^{2}=9 has the two solutions 33 and −3-3.
  • A=0A=0. The only root is 00.
  • nn even and A<0A<0. There is no real root, because an even power is never negative. −4\sqrt{-4} and −164\sqrt[4]{-16} are undefined among the real numbers.

The reasons are short. For odd nn the map x↦xnx\mapsto x^{n} is strictly increasing on all of R\mathbb R and takes every real value, so each AA is reached exactly once. For even nn it is strictly increasing on [0,∞)[0,\infty), takes every non-negative value there, and satisfies (−x)n=xn(-x)^{n}=x^{n}, which creates the second root and keeps every value non-negative.

The decision that the symbol   \sqrt{\ \ } means only the non-negative root is what makes it a function: one input, one output. It has a consequence that surprises most people at first:

q2=∣q∣for every real q,(A)2=Afor A≥0 only.\sqrt{q^{2}}=\lvert q\rvert\quad\text{for every real }q,\qquad \bigl(\sqrt{A}\bigr)^{2}=A\quad\text{for }A\ge 0\text{ only.}

Squaring and then rooting returns the size of the number but not its sign, because squaring maps qq and −q-q to the same area. That is the first thing the stage above shows.

Squares, roots and the sign you lose

Look again at the hero stage with side −3-3. The square has area 99, drawn exactly as for side 33; the picture and the number 99 do not remember which sign you started with. Now ask the inverse question from the area, and the stage reports two sides, +3+3 and −3-3 (the equation x2=9x^{2}=9), and one root, 9=3\sqrt 9=3 (the function). A length cannot be negative, so for a physical square only the root matters. For an equation, both solutions matter. The stage keeps the two ideas apart in its verdict line.

Two further facts the stage makes visible:

  • Exact versus approximate. The area 99 has the side 9=3\sqrt 9=3 exactly. The area 22 has the side 2\sqrt 2, which is irrational: its decimal expansion never ends and never repeats, so any decimal such as 1.4142141.414214 is a rounding. The book writes == for the exact statement and ≈\approx for a rounded decimal, and never swaps them. The area 1212 gives 12=23≈3.464102\sqrt{12}=2\sqrt3\approx 3.464102: the exact form takes the square factor out of the root.
  • Units. If the side is 3 m3\ \mathrm m then the area is 9 m29\ \mathrm m^{2}, and the root of 9 m29\ \mathrm m^{2} is 3 m3\ \mathrm m. Squaring doubles the exponent of the unit; rooting halves it.

Why is 2\sqrt2 irrational? Suppose 2=p/q\sqrt2=p/q with whole numbers p,qp,q that have no common factor. Then p2=2q2p^{2}=2q^{2}, so p2p^{2} is even, so pp is even, say p=2rp=2r. Then 4r2=2q24r^{2}=2q^{2}, so q2=2r2q^{2}=2r^{2} and qq is even too. Both are even, which contradicts “no common factor”. So no such fraction exists. The same idea shows that n\sqrt n is irrational unless nn is a perfect square; for a fraction a/ba/b in lowest terms the square root is rational exactly when both aa and bb are perfect squares.

Taking a square factor out of a root rests on one line. For a≥0a\ge0 and b≥0b\ge0, the number aba\sqrt b is non-negative and its square is a2ba^{2}b, so a2b=ab\sqrt{a^{2}b}=a\sqrt b. Repeating this with the largest square factor gives the simplest radical form: 72=36⋅2=62\sqrt{72}=\sqrt{36\cdot 2}=6\sqrt 2. Two more habits keep radicals in one standard form. A root in a denominator is moved to the top (1/2=2/2\sqrt{1/2}=\sqrt2/2), and the fraction is reduced to lowest terms (8/9=22/3\sqrt{8/9}=2\sqrt2/3).

Units are exponents

A quantity is a number and an exponent vector, and arithmetic acts on both at once. This stage lets you choose the operation, the two numbers and their units, and shows the exponent vectors of both inputs and of the result.

Units are exponents

Operation

Or try one

Quantitylength L (m)time T (s)mass M (kg)unit
a100m
b100m
result100m
Each quantity is a number and three whole-number exponents, one for each base unit.
first quantity
3 m
second quantity
2 m
result
5 m

= exact · ≈ rounded to 6 decimals · ⚠ undefined

The units are identical (m), so they carry over unchanged: only the numbers are added.

3 m + 2 m=5 m\begin{aligned}3\,\mathrm{m}\ +\ 2\,\mathrm{m}&=5\,\mathrm{m}\end{aligned}
exponents of (m,s,kg):(1, 0, 0)=(1, 0, 0) ⇒ same unit, kept: (1, 0, 0)\text{exponents of }(\mathrm{m},\mathrm{s},\mathrm{kg}):\quad (1,\,0,\,0)=(1,\,0,\,0)\ \Rightarrow\ \text{same unit, kept: }(1,\,0,\,0)

from −20 to 20, up to 2 decimal places

from −20 to 20, up to 2 decimal places

Choose an operation, two numbers and their units. The table shows the exponent of each base unit; the verdict says which rule applied, or why there is no result.

The rules are the whole of dimensional analysis:

OperationValueExponent vectorDefined when
a×ba\times ba⋅ba\cdot bthe vectors addalways
a÷ba\div ba/ba/bthe vectors subtractb≠0b\neq0
a+ba+b, a−ba-ba±ba\pm bunchangedthe vectors are equal
a2a^{2}a⋅aa\cdot adoubledalways
a\sqrt aa\sqrt{a}halveda≥0a\ge0 and every exponent even

The reason for each is small. Addition is the distributive law: 3 m+2 m=(3+2) m3\ \mathrm m+2\ \mathrm m=(3+2)\ \mathrm m, which only works because the unit is a common factor. For different units there is no common factor to pull out, so there is nothing to compute. Multiplication simply multiplies the numbers and the units separately, and the units multiply as powers: ma⋅mb=ma+b\mathrm m^{a}\cdot\mathrm m^{b}=\mathrm m^{a+b} (the product rule for powers, which the next section explains). A square root needs the exponents halved, and a whole-number exponent vector has no way to represent a half: 9 m2=3 m\sqrt{9\ \mathrm m^{2}}=3\ \mathrm m, but 9 m\sqrt{9\ \mathrm m} would need m1/2\mathrm m^{1/2}, which this model does not have, so it is refused.

Dividing two quantities of the same kind subtracts equal vectors and gives the zero vector: 6 m÷3 m=26\ \mathrm m\div3\ \mathrm m=2, a plain number. That is why “how many times longer” has no unit.

Powers and their rules

The previous section used the fact that exponents add when quantities multiply. Here is why powers behave that way, and what the exponents 00 and −1-1 must mean.

For positive whole numbers, bm⋅bnb^{m}\cdot b^{n} is mm factors of bb followed by nn more, which is m+nm+n factors. So bm⋅bn=bm+nb^{m}\cdot b^{n}=b^{m+n}. Likewise (bm)n(b^{m})^{n} is nn groups of mm factors, so (bm)n=bmn(b^{m})^{n}=b^{mn}.

Extending the exponents to 00 and below is not a free choice: we ask that the product rule keep working. Step down the ladder from b3b^{3}, dividing by bb at each step: b3,b2,b1b^{3},b^{2},b^{1}, and the next rung must be b1/b=1b^{1}/b=1, so b0=1b^{0}=1. One further step gives b−1=1/bb^{-1}=1/b. The only definitions that keep bm⋅bn=bm+nb^{m}\cdot b^{n}=b^{m+n} true are

b0=1andb−k=1bk(b≠0).b^{0}=1\qquad\text{and}\qquad b^{-k}=\frac{1}{b^{k}}\qquad(b\neq0).

Explore the ladder and the four rules on the stage. Every row is computed in exact arithmetic, and each rule shows its two sides.

Powers and their rules: bm⋅bn=bm+nb^{m}\cdot b^{n}=b^{m+n}

Try

powervaluestep
2 to the power 6=64=64
2 to the power 5=32=32
2 to the power 4=16=16n
2 to the power 3=8=8m
2 to the power 2=4=4
2 to the power 1=2=2
2 to the power 0=1=1
2 to the power minus 1=0.5=0.5
2 to the power minus 2=0.25=0.25
2 to the power minus 3=0.125=0.125
One step up the ladder multiplies by b; one step down divides by b. Continuing the pattern past 1 is what forces b⁰ = 1 and b⁻ᵏ = 1/bᵏ.
base
2
b to the power 3
8
b to the power 4
16

= exact · ≈ rounded to 6 decimals · ⚠ undefined

All four rules hold for these numbers: each pair of sides is exactly equal.

  • Product of powersholds
    23⋅24=8⋅16=12823+4=27=128\begin{aligned}2^{3}\cdot 2^{4}&=8\cdot 16=128\\2^{3+4}&=2^{7}=128\end{aligned}

    Both sides are equal: 128.

  • Power of a powerholds
    (23)4=(8)4=409623⋅4=212=4096\begin{aligned}\left(2^{3}\right)^{4}&=\left(8\right)^{4}=4096\\2^{3\cdot 4}&=2^{12}=4096\end{aligned}

    Both sides are equal: 4096.

  • Zero exponentholds
    20=1the rule says 1\begin{aligned}2^{0}&=1\\&\text{the rule says }1\end{aligned}

    Both sides are equal: 1.

  • Negative exponentholds
    2−4=0.0625124=116=0.0625\begin{aligned}2^{-4}&=0.0625\\\dfrac{1}{2^{4}}&=\dfrac{1}{16}=0.0625\end{aligned}

    Both sides are equal: 0.0625.

from −5 to 5, up to 1 decimal place

from −3 to 6, whole numbers only

from −3 to 6, whole numbers only

The powers of 2 from exponent -3 to 6, with the rows for exponents 3 and 4 marked.

Choose a base b and two exponents m and n. The ladder lists powers of b; the four rule cards check each rule in exact arithmetic and report holds, makes no claim, or fails.

Notice three things.

  1. The rules never fail. For every base and every pair of exponents where both sides exist, both sides are equal. You will not see a “fails” card for any input the stage accepts.
  2. A rule can be silent. For base 00 with m=−1m=-1, the left side of 0−1⋅01=000^{-1}\cdot0^{1}=0^{0} contains 0−10^{-1}, which does not exist. The rule is not false there, because there are not two numbers to compare. It makes no claim, and the stage says so. Saying “the rule is false for 00” and saying “the rule does not apply to 00” are different statements, and only the second is correct.
  3. Signs follow parity. An odd power keeps the sign of the base ((−2)3=−8(-2)^{3}=-8), an even power erases it ((−2)2=4(-2)^{2}=4). A negative exponent never makes a number negative; it makes it a reciprocal.

Two more consequences. The quotient rule follows from the two above: bm/bn=bm⋅b−n=bm−nb^{m}/b^{n}=b^{m}\cdot b^{-n}=b^{m-n}. And roots are powers in disguise: xn=Ax^{n}=A asks for the base whose nnth power is AA, and the power-of-power rule says that taking the exponent 1/n1/n undoes the exponent nn, since (A1/n)n=A1(A^{1/n})^{n}=A^{1}. This book defines the exponent 1/n1/n only for A≥0A\ge0, where A1/n=AnA^{1/n}=\sqrt[n]{A} (the non-negative root). That restriction matters in code, as the reference section below shows.

Roots as the reverse question

The equation xn=Ax^{n}=A has a picture. Draw the curve y=xny=x^{n} and the horizontal line y=Ay=A. A real solution is a point where they meet, and its xx-coordinate is the root.

Roots as intersections: xn=Ax^{n}=A

Try

The graph of y equals x to the power 2 and the horizontal line y equals 2. The line meets the curve at two points, plus and minus the root. Drag the handle on the y-axis up or down to move the line.

the value
2
square root
√21.414214…
the root, raised to the power again
2
real solutions x
±√2

= exact · ≈ rounded to 6 decimals · ⚠ undefined

Two real numbers satisfy x² = 2: √2 and −√2. The root symbol means only the positive one; the line meets the curve in two places because even powers are symmetric.

A=2=2≈1.414214…\begin{aligned}\sqrt{A}&=\sqrt{2}\\&=\sqrt{2}\\&\approx 1.414214\ldots\end{aligned}
x2=2⇒x=±2(2)2=2\begin{aligned}x^{2}&=2\\&\Rightarrow x=\pm \sqrt{2}\\\left(\sqrt{2}\right)^{2}&=2\end{aligned}

from −8 to 8, up to 2 decimal places

Root index n

Drag the point on the y-axis to move the level A; choose the index n. The curve y = xⁿ depends only on n and does not move when you drag A. The markers show where the line meets it.

The graph explains every case in the definition at once. For n=3n=3 the curve climbs through the whole plane, so every level meets it exactly once. For n=2n=2 and n=4n=4 the curve is a bowl that never goes below the xx-axis: a level above the axis meets it twice, at rr and −r-r; the level 00 touches it once; a level below the axis misses it entirely, which is the picture of “no real root”. Moving the level AA never changes the curve; changing the index nn does. If you see the curve move while you drag the level, something is wrong, and the page has a test for exactly that.

The round trip is the last check the stage makes. For every AA that has a root, (An)n=A\bigl(\sqrt[n]{A}\bigr)^{n}=A. In the other direction, xnn=x\sqrt[n]{x^{n}}=x only for odd nn; for even nn it is ∣x∣\lvert x\rvert, the sign loss again.

Worked examples

Exact roots follow one method, and it is worth seeing as a method, not as a trick. For a non-negative rational number p/qp/q in lowest terms and index nn:

  1. Rationalise. Multiply top and bottom by q n−1q^{\,n-1}, so that the whole number N=p q n−1N=p\,q^{\,n-1} is under the root and qq is outside it.
  2. Factor NN into primes.
  3. Take out groups of nn equal prime factors: each group leaves the root as one factor.
  4. Cancel any factor shared with the denominator.
  5. Check by raising the answer to the power nn.

For a negative number with an odd index, set the sign aside, root the positive number, and put the sign back. Step through four cases below. The last asks for the side of a square of area 2.25 m22.25\ \mathrm{m}^{2}, so the unit is part of the work.

Worked examples: exact roots

Choose a root

72\sqrt{72}

We want the non-negative number whose square is 72.

Choose a root and step through the work. Going back selects an earlier step; nothing is undone.

Executable reference code

Run the Python examples below to follow the calculations step by step. First the exact arithmetic of roots with whole numbers and fractions, using the same method as the worked examples.

code/python/quantity_exact_roots.pyexact square roots, no decimals
from fractions import Fraction
from math import gcd, isqrt


def simplify_sqrt(n):
    """Write sqrt(n) as a*sqrt(b) with b square-free, for a whole number n >= 0. Returns (a, b)."""
    a, b, d = 1, n, 2
    while d * d <= b:
        while b % (d * d) == 0:  # a square factor d*d can leave the root as d
            b //= d * d
            a *= d
        d += 1
    return a, b


def exact_sqrt(q):
    """sqrt of a non-negative rational, as (a, b, c) meaning a*sqrt(b)/c, or None for a negative number."""
    q = Fraction(q)
    if q < 0:
        return None  # no real square root
    # sqrt(p/q) = sqrt(p*q) / q : after this step the number under the root is a whole number
    a, b = simplify_sqrt(q.numerator * q.denominator)
    g = gcd(a, q.denominator)  # 6*sqrt(2)/9 is the same number as 2*sqrt(2)/3: cancel the common factor
    return a // g, b, q.denominator // g


# Perfect squares come out whole; everything else keeps its root symbol.
side_of_area_9 = exact_sqrt(9)  # (3, 1, 1): 3 exactly
side_of_area_12 = exact_sqrt(12)  # (2, 3, 1): 2*sqrt(3), exactly
side_of_area_8_9 = exact_sqrt(Fraction(8, 9))  # (2, 2, 3): 2*sqrt(2)/3
side_of_area_2_25 = exact_sqrt(Fraction("2.25"))  # (3, 1, 2): 3/2, since 2.25 = 9/4
side_of_area_negative = exact_sqrt(-4)  # None

# The check that matters: square the answer and compare with what you started from.
a, b, c = side_of_area_8_9
round_trip = Fraction(a * a * b, c * c)  # (a*sqrt(b)/c)**2 = a*a*b / (c*c), all whole numbers

# isqrt is exact for whole numbers of any size, unlike int(math.sqrt(n)).
exact_floor = isqrt(10**30 + 1)  # 10**15

print(side_of_area_12, side_of_area_8_9, round_trip, exact_floor)

Then units as exponent tuples, with the refusals written out as errors.

code/python/quantity_units.pyquantities with units
# A quantity is a number and a unit. Keep the unit as a tuple of exponents (metres, seconds, kilograms).
LENGTH = (1, 0, 0)
TIME = (0, 1, 0)


def times(a, b):
    """Multiplying quantities ADDS the exponents."""
    return (a[0] * b[0], tuple(x + y for x, y in zip(a[1], b[1])))


def over(a, b):
    """Dividing quantities SUBTRACTS the exponents."""
    return (a[0] / b[0], tuple(x - y for x, y in zip(a[1], b[1])))


def plus(a, b):
    """Adding needs identical units, and keeps them."""
    if a[1] != b[1]:
        raise ValueError(f"cannot add units {a[1]} and {b[1]}")
    return (a[0] + b[0], a[1])


def sqrt_unit(a):
    """A square root halves the exponents, so they must all be even."""
    if any(e % 2 for e in a[1]):
        raise ValueError(f"the square root of units {a[1]} needs a fractional exponent")
    return (a[0] ** 0.5, tuple(e // 2 for e in a[1]))


side = (3.0, LENGTH)  # 3 m
area = times(side, side)  # (9.0, (2, 0, 0)): 9 m^2
speed = over((12.0, LENGTH), (4.0, TIME))  # (3.0, (1, -1, 0)): 3 m/s
back_to_side = sqrt_unit(area)  # (3.0, (1, 0, 0)): 3 m again
ratio = over(side, side)  # (1.0, (0, 0, 0)): no unit left

try:
    plus(side, (2.0, TIME))  # 3 m + 2 s
except ValueError as error:
    refused_sum = str(error)

try:
    sqrt_unit(side)  # sqrt(3 m) would be m^(1/2)
except ValueError as error:
    refused_root = str(error)

print(area, speed, back_to_side, ratio, refused_sum, refused_root)

Finally, what Python does with floats, negative bases and zero. This is where the “exact” of the mathematics and the “rounded” of the machine meet.

code/python/quantity_float_pitfalls.pyfloats, complex surprises, zero
import cmath
import math

# Floating point stores binary fractions, so most decimals are stored with a tiny error.
square_of_point_one = 0.1**2  # 0.010000000000000002, not 0.01
exactly_equal = math.sqrt(2) ** 2 == 2  # False: sqrt(2) was rounded, squaring does not undo the rounding
squared_root_of_two = math.sqrt(2) ** 2  # 2.0000000000000004
close_enough = math.isclose(math.sqrt(2) ** 2, 2)  # True: compare with a tolerance, never with ==

# math.sqrt only knows real numbers.
try:
    math.sqrt(-1)
except ValueError as error:
    real_sqrt_of_negative = str(error)  # math domain error
complex_sqrt = cmath.sqrt(-1)  # 1j: the complex number whose square is -1 (a different number system)

# Python's ** with a fractional exponent silently switches to complex numbers for a negative base.
cube_root_attempt = (-8) ** (1 / 3)  # (1.0000000000000002+1.7320508075688772j), NOT -2
real_cube_root = -(8 ** (1 / 3))  # -2.0: take the root of the size, then restore the sign (odd roots only)

# Integer powers are exact in Python for whole numbers of any size.
big_power = 3**100  # 515377520732011331036461129765621272702107522001

# Negative exponents mean reciprocals, and 0 has no reciprocal.
try:
    0.0**-1
except ZeroDivisionError:
    zero_negative_power = "ZeroDivisionError"

print(square_of_point_one, squared_root_of_two, cube_root_attempt, real_cube_root)

Explore: change the parameters

Use the stages as a laboratory. These questions have definite answers; check them against the stage.

  • On the square stage, switch to the area and step the area slider from 11 to 3636. For which areas is the side a whole number? (There are six.) For which of the presets is the side irrational?
  • On the square stage, type the side 0.10.1. The area is exactly 0.010.01. What does that tell you about the number of decimal places in a square?
  • On the units stage, find an operation on two different units that is accepted, and one that is refused. What distinguishes them?
  • On the units stage, which unit pairs make a\sqrt{a} accepted? Try m2\mathrm m^{2}, m/s\mathrm{m/s} and m2/s2\mathrm{m^{2}/s^{2}}.
  • On the powers stage, set the base to 0.50.5, m=2m=2, n=−3n=-3. Which power is bigger than 11, and why does a negative exponent do that for a base less than 11?
  • On the roots stage, set n=4n=4 and drag the level from −8-8 up through 00. At which level does the number of solutions change, and how does it change? Repeat for n=3n=3.

Common mistakes

Numerical considerations

Everything above is exact. A program, however, stores a real number in a fixed number of bits, and most numbers have to be rounded to fit. A double (Python’s float) stores a binary fraction, so 0.10.1 is not stored exactly, and operations on rounded numbers can break identities that hold exactly. The table puts the exact value from the model next to what a double holds.

expressionPythonexact valuedouble (what the program holds)agree?
0.1²0.1**20.010.010000000000000002⚠ no
(√2)²math.sqrt(2)**222.0000000000000004⚠ no
(√3)²math.sqrt(3)**232.9999999999999996⚠ no
(√4)²math.sqrt(4)**244yes
3¹⁰⁰3.0**1005153775207320113310364611297656212727021075220015.153775207320113e+47⚠ no

Three more cautions. Squaring a large double can overflow: 1020010^{200} times itself is inf, even though its square root, 1020010^{200}, is perfectly representable (the length of a vector gets the same warning in the vectors chapter). math.sqrt accepts real numbers only and raises ValueError for a negative argument, but the operator ** with a fractional exponent on a negative base quietly returns a complex number: (-8) ** (1/3) is about 1+1.732 i1+1.732\,i, not −2-2. To get a real cube root, root the size and restore the sign, or use math.cbrt. And in floating point, a very small positive number raised to a high power underflows to exactly 0.0: 0.5 ** 1100 is 0.0, so a loop that multiplies many probabilities should add logarithms instead.

Connections to engineering and machine learning

  • Unit errors are real failures. In 1999 the Mars Climate Orbiter was lost after one team’s software produced impulse data in pound-force seconds where another expected newton seconds. A unit tracked as part of the value turns this class of error into a refusal like the ones on the units stage; libraries such as pint do exactly this in Python.
  • Features with different units. A data point with a height in metres and a duration in seconds is a vector whose two numbers cannot be compared. Distances between such points depend on the choice of units unless the features are first made dimensionless: subtracting the mean and dividing by the standard deviation (which has the same unit as the feature) is the standard way.
  • Errors and spread. Mean squared error is measured in the square of the target’s unit; the root-mean-square error, its square root, is in the target’s own unit, which is why RMSE is the one people read. A standard deviation is the square root of a variance for the same reason.
  • Exponents in practice. Geometric decay, such as a learning rate halved at each step (0.5k0.5^{k}), is a power with a negative-exponent mirror image in growth. Floating-point underflow at large kk is the numerical caution above.
  • Looking ahead. Squares and square roots return at once in Coordinates and points, where the distance between two points is the root of a sum of two squares, and again in vectors, where the length of a vector is the same thing and Pythagoras’ areas are literal.

Exercises

Answer each question and press Check. A wrong answer tells you which mistake it looks like. After one attempt you may open a worked solution.

prediction

Square, then root

What is √((−5)²)? Predict the answer first, then check it on the stage above by choosing side −5.

Choose one answer

calculation

Simplify √72

Write √72 as a·√b, where b has no square factor left (no 4, 9, 16, … divides it). Enter the whole numbers a and b.

construction

Build a square

A square must have area 0.0049 square metres. Enter a side length, in metres, whose square is exactly 0.0049.

explanation

Which has a meaning?

Exactly one of these expressions is a meaningful quantity in the model of the stage above. Which one?

Choose one answer

calculation

A speed, with its unit

A cart covers 150 m in 12.5 s. Enter its speed as a number of metres per second, and the exponent of seconds in its unit (the unit is m·s^e).

calculation

A negative exponent

Compute 2⁻³ exactly. Enter a whole number, a decimal or a fraction such as 3/4.

calculation

A power of a power

(2³)² can be written as 2^k. Enter k, and then the value of (2³)².

explanation

Where a rule goes silent

On the powers stage, choose base 0 with m = −1 and n = 1. The product rule bᵐ·bⁿ = bᵐ⁺ⁿ would say 0⁻¹ · 0¹ = 0⁰. Which statement is correct?

Choose one answer

calculation

A cube root of a negative number

Compute ∛(−27), the real number whose cube is −27. Enter a number (or the word undefined if you think there is none).

prediction

How many real solutions?

How many real numbers x satisfy x⁴ = −16? Predict, then check on the roots stage with n = 4 and A = −8.

Choose one answer

prediction

What does Python say?

In Python 3, what does (-8) ** (1/3) evaluate to? Predict, then see the reference code below.

Choose one answer

Summary and checkpoints

  • A scalar is a number. A quantity is a number with a unit, and the unit is an exponent vector of base units that multiplication adds, division subtracts, a square root halves, and addition requires to be equal.
  • A power bkb^{k} counts factors; b0=1b^{0}=1 and b−k=1/bkb^{-k}=1/b^{k} are forced if bmbn=bm+nb^{m}b^{n}=b^{m+n} is to keep holding. 000^{0} and negative powers of 00 are undefined, and a rule is silent, not false, where a side is undefined.
  • An nnth root solves xn=Ax^{n}=A. Odd nn: always exactly one real root. Even nn: two roots ±r\pm r for A>0A>0, one for A=0A=0, none for A<0A<0. The symbol An\sqrt[n]{A} is the non-negative root, so q2=∣q∣\sqrt{q^{2}}=\lvert q\rvert.
  • Exact values (such as 72=62\sqrt{72}=6\sqrt2) are written with ==. A decimal is a rounding and is written with ≈\approx.
  • In code: keep exact values exact, compare floats with a tolerance, remember that ** on a negative base can return a complex number.

Checkpoints. You are ready to move on when you can, without looking:

  1. Say why (−5)2\sqrt{(-5)^{2}} is 55 and not −5-5, and how many real solutions x2=25x^{2}=25 has.
  2. Simplify 72\sqrt{72} and say whether the answer is exact.
  3. Explain why 3 m+2 s3\ \mathrm m+2\ \mathrm s is undefined, but 3 m×2 s3\ \mathrm m\times2\ \mathrm s is not.
  4. Compute 2−32^{-3} and (23)2(2^{3})^{2} and name the rule each uses.
  5. Say, with one picture, why x4=−16x^{4}=-16 has no real solution and x3=−8x^{3}=-8 has exactly one.

The map of the book

97 of 97 chapters written · eight Parts

demo Foundation demo Try the live vector example Open as a page

Part I

Mathematical Language

The notation and mental objects everything else uses.

9 of 9 chapters written

  1. I.1 Scalars, quantities, units, powers and roots available
  2. I.2 Coordinates and points available
  3. I.3 Vectors: components, magnitude, and direction reference chapter available
  4. I.4 Algebraic expressions, equations and inequalities available
  5. I.5 Functions as input → transformation → output available
  6. I.6 Essential function families available
  7. I.7 Sets, intervals, and relations available
  8. I.8 Indexed quantities and summation available
  9. I.9 The notation map for ML available

Part II

Linear Algebra

Matrices as transformations: the strongest foundation in the book.

19 of 19 chapters written

  1. II.1 Vector addition and subtraction available
  2. II.2 Scalar multiplication and vector scaling available
  3. II.3 Norms, magnitude, and normalization available
  4. II.4 Dot product, angle, and orthogonality available
  5. II.5 Projection and distance to a direction available
  6. II.6 Linear combinations and span available
  7. II.7 Linear independence, basis, and coordinates available
  8. II.8 Matrices as linear transformations available
  9. II.9 Matrix × vector available
  10. II.10 Matrix × matrix as composition available
  11. II.11 Transpose and orthogonality available
  12. II.12 Determinant: orientation and area/volume scaling available
  13. II.13 Linear systems as intersecting constraints available
  14. II.14 Gaussian elimination and row operations available
  15. II.15 Rank and invertibility available
  16. II.16 Inverse matrices available
  17. II.17 Eigenvalues and eigenvectors available
  18. II.18 Orthogonal bases and least-squares geometry available
  19. II.19 Singular Value Decomposition available

Part III

Calculus

Change, local approximation, and sensitivity made visible.

15 of 15 chapters written

  1. III.1 Limits through approach available
  2. III.2 Continuity and local behavior available
  3. III.3 Derivative as secant → tangent available
  4. III.4 Derivative as rate of change and local linear model available
  5. III.5 Derivative rules available
  6. III.6 Chain rule available
  7. III.7 Multivariable functions and partial derivatives available
  8. III.8 Gradient and directional derivatives available
  9. III.9 Jacobian available
  10. III.10 Computational graphs and automatic differentiation available
  11. III.11 Hessian and curvature available
  12. III.12 Integrals as accumulation available
  13. III.13 Fundamental derivative/integral connection available
  14. III.14 Numerical differentiation available
  15. III.15 Numerical integration available

Part IV

Probability

Uncertainty through sample spaces, evidence, and repetition.

16 of 16 chapters written

  1. IV.1 Random experiments, outcomes, and sample spaces available
  2. IV.2 Events and probability mass available
  3. IV.3 Counting and finite probability where needed available
  4. IV.4 Conditional probability as restricted sample space available
  5. IV.5 Independence available
  6. IV.6 Bayes' theorem as probability-mass update available
  7. IV.7 Random variables available
  8. IV.8 PMF, PDF, and CDF available
  9. IV.9 Bernoulli and Binomial distributions available
  10. IV.10 Uniform and Gaussian distributions available
  11. IV.11 Expectation available
  12. IV.12 Variance and standard deviation available
  13. IV.13 Joint, marginal, and conditional distributions available
  14. IV.14 Covariance and correlation available
  15. IV.15 Law of Large Numbers available
  16. IV.16 Central Limit Theorem available

Part V

Statistics

From observed data to estimates, intervals, and likelihood.

10 of 10 chapters written

  1. V.1 Data summaries: mean, median, mode available
  2. V.2 Spread: variance, standard deviation, robust interpretation available
  3. V.3 Population, sample, and sampling variability available
  4. V.4 Estimators and estimation available
  5. V.5 Confidence intervals through repeated sampling available
  6. V.6 Covariance matrices and multivariate spread available
  7. V.7 Regression fundamentals available
  8. V.8 Likelihood available
  9. V.9 Maximum Likelihood Estimation available
  10. V.10 Maximum A Posteriori estimation available

Part VI

Optimization

Learning as repeated parameter updates governed by an objective.

10 of 10 chapters written

  1. VI.1 Objective functions and optimization landscapes available
  2. VI.2 Local vs global optima and stationary points available
  3. VI.3 Convexity available
  4. VI.4 Gradient descent flagship chapter available
  5. VI.5 Learning rate and convergence behavior available
  6. VI.6 Momentum available
  7. VI.7 Stochastic and mini-batch gradient descent available
  8. VI.8 Adam intuition available
  9. VI.9 Constraints and projected/penalized intuition available
  10. VI.10 Numerical stopping and optimization diagnostics available

Part VII

Information Theory

Logarithms, entropy, and the loss behind token prediction.

8 of 8 chapters written

  1. VII.1 Logarithms and log probabilities in computation available
  2. VII.2 Self-information available
  3. VII.3 Entropy available
  4. VII.4 Cross entropy and negative log-likelihood available
  5. VII.5 KL divergence available
  6. VII.6 Logits and softmax available
  7. VII.7 Numerical stability: log-sum-exp and stable softmax available
  8. VII.8 From token logits to language-model loss available

Part VIII

Numerical Computing

Why equivalent expressions behave differently on real machines.

10 of 10 chapters written

  1. VIII.1 Floating-point representation available
  2. VIII.2 Rounding and representation error available
  3. VIII.3 Error propagation and conditioning available
  4. VIII.4 Catastrophic cancellation available
  5. VIII.5 Overflow and underflow available
  6. VIII.6 Stable algorithms available
  7. VIII.7 Numerical linear algebra realities available
  8. VIII.8 Sparse matrices and sparse structure available
  9. VIII.9 Vectorized computation available
  10. VIII.10 Reproducibility, random seeds, and nondeterminism available