Square Roots
The square root of a number is the value that, multiplied by itself, gives that number: because . Square roots undo squaring, and they appear whenever you turn an area back into a length, compute a distance, or measure spread in statistics.
Definition and vocabulary
The symbol is the radical sign, and the number under it is the radicand. Every positive number has two numbers that square to it ( and ), but always means the principal, non-negative one. When both are needed we write .
Perfect squares
Numbers like 1, 4, 9, 16, 25 are perfect squares: their roots are whole numbers.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 15 | 20 | 25 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 4 | 9 | 16 | 25 | 36 | 49 | 64 | 81 | 100 | 121 | 144 | 225 | 400 | 625 |
The square root of any other whole number is irrational: its decimals go on forever without repeating. is the most famous example.
Estimating
You can bracket a root between two perfect squares. For : , so , and since 50 is very close to 49, is just over 7 (it is about 7.071).
A quick refinement: , where is the nearest perfect square. For : . That is one step of Newton's method, which repeats the idea until the answer stops changing:
def newton_sqrt(x, steps=5):
guess = x / 2
for i in range(steps):
guess = (guess + x / guess) / 2
print(f"step {i + 1}: {guess:.10f}")
return guess
newton_sqrt(50)step 1: 13.5000000000
step 2: 8.6018518519
step 3: 7.2072768409
step 4: 7.0723549068
step 5: 7.0710679290
Each step averages the guess with : if the guess is too big, is too small, so their average is closer. The number of correct digits roughly doubles each step. Square-root routines in libraries and hardware use refinements like this.
Square roots in Python
import math
print(math.sqrt(49))
print(math.sqrt(50))
print(50 ** 0.5)
print(math.isqrt(50), "(integer square root, rounded down)")
print(math.sqrt(2) ** 2, "(not exactly 2: floating point)")
try:
math.sqrt(-4)
except ValueError as e:
print("math.sqrt(-4) ->", e)
import cmath
print("cmath.sqrt(-4) =", cmath.sqrt(-4))7.0
7.0710678118654755
7.0710678118654755
7 (integer square root, rounded down)
2.0000000000000004 (not exactly 2: floating point)
math.sqrt(-4) -> math domain error
cmath.sqrt(-4) = 2j
Note: There is no real number whose square is negative, so
math.sqrt(-4)fails. Thecmathmodule (and the**operator) instead return a complex number, 2j, where j stands for in Python. Complex numbers are covered later in the calculus course; for now, keep radicands non-negative.
Use math.isqrt for exact integer work, such as checking whether a big number is a perfect square: math.isqrt(n) ** 2 == n.
Rules for square roots
For non-negative and :
But : , not . The product rule is the basis of the next lesson, Simplifying Radicals.
In software
- Distances: the length of a vector and the distance between two points both end with a square root (Pythagorean theorem). Game engines avoid it when they can by comparing squared distances.
- Normalising vectors: dividing by the length gives a direction of length 1 (see length and normalize). The famous "fast inverse square root" hack from the game Quake III computed this way, with a bit trick plus one Newton step.
- Statistics: the standard deviation is the square root of the variance, bringing squared units back to the original ones.
- Algorithms: to test if is prime you only try divisors up to , because any larger factor pairs with a smaller one.
Exercises
Exercise 1: Exact roots
Find , , and .
Answer
12, 0.5, , 1000.
Solution
Exercise 2: Bracket
Between which two whole numbers is ? Which one is it closer to?
Answer
Between 9 and 10, closer to 9 ().
Solution
, so . 90 is 9 above 81 and 10 below 100, so it is a little closer to 9; the estimate is close to the true 9.487.
Exercise 3: Perfect square test
Write is_square(n) using math.isqrt and list the perfect squares among 120 … 200.
Answer
121, 144, 169, 196.
Solution
import math
def is_square(n):
r = math.isqrt(n)
return r * r == n
print([n for n in range(120, 201) if is_square(n)])[121, 144, 169, 196]
Exercise 4: Room size
A square room has an area of . How long is each wall, to the nearest centimetre?
Answer
About 5.48 m.
Solution
. Since and , the side is between 5 and 6 m. , which rounds to 5.48 m.
import math
print(round(math.sqrt(30), 2))5.48
Test yourself
What is ?
- 9
- 40.5
- −9
Which is true?
- for every
lies between which two whole numbers?
- 6 and 7
- 7 and 8
- 8 and 9
- 34 and 35