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:
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.
from −6 to 6, up to 2 decimal places
Try it before reading on. Put the side at , then at , and compare the areas. Then switch to the area, ask for area , and look at how many sides the stage reports. Then ask for area and for area . By the end of the chapter you will know why squaring throws information away, why the question “which side has area ?” has two answers while the symbol has only one, why 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: , , , . 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: metres, seconds, 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:
The triple 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 and is called dimensionless. A speed in metres per second has and an area in square metres has .
Power. For a real number and a positive whole number , the power is multiplied by itself times. The exponent and the negative exponents are defined for by
This book leaves and every negative power of undefined: would be . (Some programs define 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 the first term is read as for every , even , as the empty product, so that the formula and the loop agree. Chapter I.8 says so where it happens.)
Root. Let be a whole number and a real number. A real number is an th root of when . How many there are depends on the parity of and the sign of :
- odd. There is exactly one real root, for every , and it has the sign of . We write it . For example .
- even and . There are exactly two real roots, and . The symbol means the non-negative one, . For example , while the equation has the two solutions and .
- . The only root is .
- even and . There is no real root, because an even power is never negative. and are undefined among the real numbers.
The reasons are short. For odd the map is strictly increasing on all of and takes every real value, so each is reached exactly once. For even it is strictly increasing on , takes every non-negative value there, and satisfies , which creates the second root and keeps every value non-negative.
The decision that the symbol 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:
Squaring and then rooting returns the size of the number but not its sign, because squaring maps and 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 . The square has area , drawn exactly as for side ; the picture and the number do not remember which sign you started with. Now ask the inverse question from the area, and the stage reports two sides, and (the equation ), and one root, (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 has the side exactly. The area has the side , which is irrational: its decimal expansion never ends and never repeats, so any decimal such as is a rounding. The book writes for the exact statement and for a rounded decimal, and never swaps them. The area gives : the exact form takes the square factor out of the root.
- Units. If the side is then the area is , and the root of is . Squaring doubles the exponent of the unit; rooting halves it.
Why is irrational? Suppose with whole numbers that have no common factor. Then , so is even, so is even, say . Then , so and is even too. Both are even, which contradicts “no common factor”. So no such fraction exists. The same idea shows that is irrational unless is a perfect square; for a fraction in lowest terms the square root is rational exactly when both and are perfect squares.
Taking a square factor out of a root rests on one line. For and , the number is non-negative and its square is , so . Repeating this with the largest square factor gives the simplest radical form: . Two more habits keep radicals in one standard form. A root in a denominator is moved to the top (), and the fraction is reduced to lowest terms ().
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
| Quantity | length L (m) | time T (s) | mass M (kg) | unit |
|---|---|---|---|---|
| a | 1 | 0 | 0 | m |
| b | 1 | 0 | 0 | m |
| result | 1 | 0 | 0 | m |
- 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.
from −20 to 20, up to 2 decimal places
from −20 to 20, up to 2 decimal places
The rules are the whole of dimensional analysis:
| Operation | Value | Exponent vector | Defined when |
|---|---|---|---|
| the vectors add | always | ||
| the vectors subtract | |||
| , | unchanged | the vectors are equal | |
| doubled | always | ||
| halved | and every exponent even |
The reason for each is small. Addition is the distributive law: , 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: (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: , but would need , 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: , 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 and must mean.
For positive whole numbers, is factors of followed by more, which is factors. So . Likewise is groups of factors, so .
Extending the exponents to and below is not a free choice: we ask that the product rule keep working. Step down the ladder from , dividing by at each step: , and the next rung must be , so . One further step gives . The only definitions that keep true are
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:
Try
| power | value | step |
|---|---|---|
| 2 to the power 6 | ||
| 2 to the power 5 | ||
| 2 to the power 4 | n | |
| 2 to the power 3 | m | |
| 2 to the power 2 | ||
| 2 to the power 1 | ||
| 2 to the power 0 | ||
| 2 to the power minus 1 | ||
| 2 to the power minus 2 | ||
| 2 to the power minus 3 |
- 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
Both sides are equal: 128.
- Power of a powerholds
Both sides are equal: 4096.
- Zero exponentholds
Both sides are equal: 1.
- Negative exponentholds
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.
Notice three things.
- 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.
- A rule can be silent. For base with , the left side of contains , 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 ” and saying “the rule does not apply to ” are different statements, and only the second is correct.
- Signs follow parity. An odd power keeps the sign of the base (), an even power erases it (). A negative exponent never makes a number negative; it makes it a reciprocal.
Two more consequences. The quotient rule follows from the two above: . And roots are powers in disguise: asks for the base whose th power is , and the power-of-power rule says that taking the exponent undoes the exponent , since . This book defines the exponent only for , where (the non-negative root). That restriction matters in code, as the reference section below shows.
Roots as the reverse question
The equation has a picture. Draw the curve and the horizontal line . A real solution is a point where they meet, and its -coordinate is the root.
Roots as intersections:
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.
from −8 to 8, up to 2 decimal places
The graph explains every case in the definition at once. For the curve climbs through the whole plane, so every level meets it exactly once. For and the curve is a bowl that never goes below the -axis: a level above the axis meets it twice, at and ; the level touches it once; a level below the axis misses it entirely, which is the picture of “no real root”. Moving the level never changes the curve; changing the index 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 that has a root, . In the other direction, only for odd ; for even it is , 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 in lowest terms and index :
- Rationalise. Multiply top and bottom by , so that the whole number is under the root and is outside it.
- Factor into primes.
- Take out groups of equal prime factors: each group leaves the root as one factor.
- Cancel any factor shared with the denominator.
- Check by raising the answer to the power .
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 , so the unit is part of the work.
Worked examples: exact roots
Choose a root
We want the non-negative number whose square is 72.
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.
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.
# 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.
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 to . 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 . The area is exactly . 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 accepted? Try , and .
- On the powers stage, set the base to , , . Which power is bigger than , and why does a negative exponent do that for a base less than ?
- On the roots stage, set and drag the level from up through . At which level does the number of solutions change, and how does it change? Repeat for .
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 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.
| expression | Python | exact value | double (what the program holds) | agree? |
|---|---|---|---|---|
| 0.1² | 0.1**2 | 0.01 | 0.010000000000000002 | ⚠ no |
| (√2)² | math.sqrt(2)**2 | 2 | 2.0000000000000004 | ⚠ no |
| (√3)² | math.sqrt(3)**2 | 3 | 2.9999999999999996 | ⚠ no |
| (√4)² | math.sqrt(4)**2 | 4 | 4 | yes |
| 3¹⁰⁰ | 3.0**100 | 515377520732011331036461129765621272702107522001 | 5.153775207320113e+47 | ⚠ no |
Three more cautions. Squaring a large double can overflow: times itself is inf, even though its square root, , 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 , not . 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
pintdo 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 (), is a power with a negative-exponent mirror image in growth. Floating-point underflow at large 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.
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 counts factors; and are forced if is to keep holding. and negative powers of are undefined, and a rule is silent, not false, where a side is undefined.
- An th root solves . Odd : always exactly one real root. Even : two roots for , one for , none for . The symbol is the non-negative root, so .
- Exact values (such as ) are written with . A decimal is a rounding and is written with .
- 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:
- Say why is and not , and how many real solutions has.
- Simplify and say whether the answer is exact.
- Explain why is undefined, but is not.
- Compute and and name the rule each uses.
- Say, with one picture, why has no real solution and has exactly one.