Areas, volumes, speeds, energies, errors and the scaling inside attention all have the letter raised to a power or under a root. Undoing a square needs a square root, undoing a root needs a square, and undoing a cube needs a cube root. Each brings its own trap: a square root has two answers, a negative number has no real square root, and the root of a sum doesn't split into two roots. This lesson covers transposing every power you'll meet in the Foundation.
What you'll be able to do
Undo a square with a square root, keeping both answers (±) until you know which one makes sense
Undo a root by raising to the matching power, and a cube or any power n by the matching root
Rearrange A = πr², T = 2π√(l/g), V = (4/3)πr³, E = ½mv² and y = kxⁿ for each letter
Avoid the named traps: a root of a sum doesn't split, a negative has no real square root, and -8 ** (1/3) isn't what it looks like
Undo the squares and roots inside ML numbers: RMSE, standard deviation, attention's √d and scaling laws
Quick check
Have a guess before you start. x² = 25. What is x?
5 or −5
12.5
5 only
625
Show the answer
5 or −5
5 × 5 = 25, and (−5) × (−5) = 25 too. Undoing a square gives two answers, written x = ±5. A length or a time would keep only the 5.
The math: undo a power with the matching root
Purpose. Free a letter that's squared, cubed, raised to any power, or under a root.
Done to the letter
Undone by
square it, x²
square root, ±√ (two answers)
square root, √x
square it (only when √x is 0 or more)
cube it, x³
cube root, ∛ (one answer, sign kept)
power n, xⁿ
power 1/n, the nth root
Two answers. Squaring hides the sign: 5 and −5 both square to 25. So x² = 25 gives x = 5 or x = −5, written x = ±5. Keep both until the question tells you which makes sense: a radius, a length or a time is never negative.
No answer. A square root is never negative, so √x = −6 has no solution, and no real number squares to −4. Each of these is a condition to write down, like the "can't divide by 0" conditions so far.
Quick check
From an earlier lesson: what is 64 to the power 1/3?
192
4
21.3
8
Show the answer
4
Power 1/3 is the cube root: which number cubed is 64? 4 × 4 × 4 = 64.
Watch the area of a circle, A = πr², built from r = 5 and peeled back, with π as 3.14. Then try r = −5: a radius can't be negative, so the flow shows why the answer keeps only the positive root. Each step works backward from the finished area, one operation at a time, the way you would check the answer by hand.
Try it now
Change the input to −5 and press Use these numbers: the way back lands on 5.
Symbols and formula. The same peeling as before. When you reach a power, use the matching root; when you reach a root, raise to the matching power.
T=2πgl⇒2πT=gl⇒(2πT)2=gl⇒l=g(2πT)2
In plain words: a pendulum's period T is 2π times the square root of length over gravity. To get the length, divide by 2π, square both sides, then multiply by g.
More of the same: V = (4/3)πr³ gives r = ∛(3V/(4π)); E = ½mv² gives v = √(2E/m); y = kxⁿ gives x = (y/k)^(1/n).
Named mistake: a root of a sum doesn't split. √(a² + b²) is not a + b. With 3 and 4, √(9 + 16) = 5, not 7. So Pythagoras, c² = a² + b², rearranges to a = √(c² − b²), never to c − b.
Quick check
A pendulum swings with period T = 2π√(l/g). Make l the subject.
l = gT²/(2π)
l = √(gT/2π)
l = g(T/2π)²
l = g(T − 2π)²
Show the answer
l = g(T/2π)²
Divide by 2π, square both sides, multiply by g. A pendulum with a 2-second period is about 1 meter long: 9.8 × (2/6.28)² ≈ 0.99.
Negative and fractional powers follow the same rule. A power undoes with its reciprocal power: xⁿ is undone by power 1/n. Light from a lamp fades as I = k/d², which is k·d^(−2). Undo the −2 with power −1/2: d = (I/k)^(−1/2), which is the same as √(k/I). A power of 1/2 is a square root, so it's undone by squaring, and a power of 3/2 is undone by power 2/3. Whatever the power, multiply it by its undoing power and you get 1: the letter on its own.
In your own words
Why does undoing a square give two answers, but undoing a cube gives one?
Write a sentence or two, then compare it with a good answer in the lesson.
In Python: roots, and the traps around them
Purpose. Python has two ways to take a root, and both have a trap worth seeing once.
It runs right here in your browser, with nothing to install.
** 0.5 and math.sqrt agree. A power of 1/3 comes out as 3.9999999999999996, because a third can't be stored exactly in binary. Round before comparing: round(64 ** (1 / 3), 9) is 4.0.
-8 ** (1 / 3) gives −2.0 only by luck of the order of operations: ** runs before the minus sign, so it means −(8^(1/3)).
With brackets, (-8) ** (1 / 3) gives a complex number (the j part), a kind of number this course doesn't use. For the cube root of a negative, take the root of its size and put the minus back: −(8 ** (1/3)).
Worked example
Worked example: a radius and a leg, with conditions
r from A = πr², and a from c² = a² + b², each refusing inputs with no real answer.
import math
defradius(area):
if area < 0:
returnNonereturn math.sqrt(area / math.pi)
defleg(c, b):
if b > c:
returnNonereturn math.sqrt(c ** 2 - b ** 2)
print(round(radius(78.54), 3), leg(13, 5), leg(5, 13))
print(round(math.pi * radius(50) ** 2, 9))
In the lesson you can change this and run it.
A circle of area 78.54 has radius 5.0. A right triangle with longest side 13 and one leg 5 has the other leg 12.0. A leg longer than the longest side is impossible: c² − b² would be negative, and math.sqrt would stop the program with an error. The function returns None instead. The last line is a round trip: the radius for area 50, put back into πr², gives 50.0.
√(9 + 16) = √25 = 5.0, while 3 + 4 = 7: the root of a sum isn't the sum of the roots. math.sqrt always gives a float.
Quick check
Which line stops the program with an error?
(-4) ** 2
math.sqrt(-4)
math.sqrt(4)
abs(-4) ** 0.5
Show the answer
math.sqrt(-4)
No real number squares to −4, so math.sqrt raises a ValueError ("math domain error"). Check the condition before you take the root.
Drill
Fix the roots
side(area) should give a square's side from its area, and pendulum_length(T, g) should undo T = 2π√(l/g). Fix both.
import math
defside(area):
return area / 2defpendulum_length(T, g):
return g * T / (2 * math.pi)
print(side(49), round(pendulum_length(2, 9.8), 3))
In the lesson, your code is checked as you write it.
In your own words
Why round 64 ** (1 / 3) before checking whether it equals 4?
Write a sentence or two, then compare it with a good answer in the lesson.
In AI and ML: squares and roots inside the numbers
Purpose. Several numbers you'll read in ML reports are roots of something, and planning with them means undoing the root.
RMSE, the root mean squared error, is √MSE. An RMSE of 3 °C means an MSE of 9.
A standard deviation is the square root of a variance, so a variance is a standard deviation squared.
Attention's scale. Attention divides each raw score by √d, where d is the length of each query vector. If a raw score of 24 becomes 3, then √d = 8, so d = 64.
Scaling laws. Researchers fit a model's loss to its size N (the number of parameters, its adjustable numbers) with formulas like L = a·N^(−α). Rearranged: N = (a/L)^(1/α), the size a target loss needs.
31Formulas with fractions: clear them firstFreeClearing denominators, cross-multiplying, a letter in the bottom, and reciprocal formulas like 1/R = 1/R₁ + 1/R₂.35 min
37Inverse functions, lines and scalingFreeUndoing a function by making x the subject, domains that allow it, line forms, and unscaling predictions.40 min
38Sequences and sums: find n, a, d and rFreeEvery letter of the arithmetic and geometric formulas as the subject, and an average's window from its decay.40 min
40Review: rearrange anything (algebra)FreeBroken rearrangements to fix, mixed practice from the whole algebra block, a strategy chart, and its formula sheet.35 min
41Coordinates and distanceFreePoints as (x, y), Pythagoras, distance in any number of coordinates, and nearest neighbors.42 min
42Angles, degrees and radiansFreeMeasuring a turn, converting units, arcs, and the angle between two arrows.36 min
43Sine and cosineFreeAcross and up: right triangles, the unit circle, and directions and rotations.42 min
44Waves: height, speed and shiftFreeAmplitude, period and phase, sampling a wave, and position codes in transformers.37 min
68Vector equations: rearranging with arrowsFreeSolving for a vector or a scale, recovering a gradient from two weight snapshots, and an angle from a dot product.40 min
87Counting: choices, orders and groupsFreeThe counting principle, factorials, ordered picks and groups, and why attention's cost grows with the square of the length.43 min
88Probability: from counts to chancesFreeEqually likely outcomes, the complement, distributions, seeded simulation, and a next-word model.43 min
89Combining events: and, or, independentFreeThe or rule, independence, probability trees, drawing with and without replacement, and chains of steps.42 min
100Maximum likelihoodFreeLikelihoods as products, log-likelihoods as sums, grid search, underflow, and the negative log-likelihood loss.45 min
101Linear regression: the best lineFreeResiduals, least squares by formula, three roads to one line, the matrix form, and train versus test error.45 min
109One neuron, start to finishFreeWeighted sum, activation, loss, slopes and update, by hand and in code, and what one straight line can and can't split.45 min
111Training a small networkFreeThe backward pass in matrix form, gradient checks, a full training loop, and reading loss curves.45 min
112The same network in PyTorchFreenn.Sequential with the NumPy weights loaded, the same loss and slopes, then SGD and mini-batches.45 min
113Attention as matrix mathFreeScaled dot-product scores, the causal mask, a row-by-row softmax, and blending value vectors.45 min
114Residual connections and layer normFreeAdding the input back and why its slope keeps learning alive, layer norm by hand, and add and norm.40 min
115A transformer block, start to finishFreeA sentence through embeddings, attention, add and norm, a small network and next-word scores, every shape named.45 min
117Final test: transpose any formulaFreeSlips to fix from every topic, mixed practice of every kind of rearranging, the strategy chart and the full sheet.45 min
Learn the math behind AI from arithmetic up: numbers, algebra, vectors and matrices, calculus, probability and statistics, each shown as numbers moving and checked in Python, ending with a network you build and train from the formulas.
Learn to make any letter of any formula the subject: layers undone in reverse order, fractions, a letter that appears twice, powers, roots, quadratics, logs, inequalities, trigonometry, vectors, matrices, calculus, probability, statistics and the formulas inside AI models, each checked in Python.
See the course →
Never trained an AI? Teach a small one to write, right in your browser. It takes about 20 seconds and needs no account. Teach it to write