This is the last lesson of the transposition subcourse, and its final test. Every kind of rearranging you've met comes back, mixed: peeling layers, clearing fractions, collecting a letter that appears twice, roots with ±, logs, flipped inequalities, angles, vectors, matrices, slopes, chances, sample sizes and the formulas that size a model. First you fix slips from every block. Then you practice every kind. Last, you collect the master strategy chart and the sheet.
What you'll be able to do
Spot and fix the slips of every block: a lost ±, a missing flip, a principal value taken as the only angle, a vector divided, an inverse on the wrong side, a conditional turned round, a count not rounded up
Choose the right move for any formula from where the letter sits and how many times it appears
Rearrange formulas from algebra, trig, vectors, matrices, calculus, probability, statistics and model planning, with their conditions
Check every rearrangement with numbers put back in, a round trip in code, and units
Use the master strategy chart and the formula sheet for the whole subcourse
Quick check
Have a guess before you start. Make x the subject of y = 3e^(2x) − 4.
x = ln(y + 4)/6
x = ln(y/3 + 4)/2
x = ln((y + 4)/3)/2
x = (ln y + 4)/6
Show the answer
x = ln((y + 4)/3)/2
The layers on x are × 2, e to the power, × 3 and − 4. Undo them in reverse: + 4, ÷ 3, ln, ÷ 2. Check with x = 0: y = 3 − 4 = −1, and ln((−1 + 4)/3)/2 = ln 1/2 = 0. The condition: y > −4, so the log has a positive number.
Find the slip
Purpose. Catch the slips of every block of the subcourse before they reach your answers. Each kind has a quick check:
Put numbers back in. A rearranged formula must give back the numbers you started with.
Count the answers. A positive number has two square roots, and most sines belong to two angles from 0° to 180°.
Check the domain. Probabilities stay from 0 to 1, logs need positive numbers, and divisors can't be 0.
Check the shape. A matrix product has a shape, and you can't divide by a vector.
Try a number. For an inequality, try a value on each side of your answer.
Below are thirteen worked lines from the algebra block and from trig, vectors and matrices. Each comment says what the line should give. Seven have a slip.
Try it now
How the checks catch them. Put numbers in: legs 3 and 4 give a hypotenuse of 5, not 7. Count the answers: 2x² = 18 has x = 3 and x = −3, but a square root gives only 3. Look for the other angle: 150° has the same sine as 30°. Picture the point: (−3, −3) is down and to the left, but atan(1) = 45° points up and to the right. Divide a vector entry by entry and the ratios rarely agree, so no single k exists. Multiply back: X @ A isn't B when the inverse sits on the wrong side. And try a number: x = 0 fits x ≥ −5 but fails −2x ≥ 10. Run the next check in your head.
Quick check
What does this print?
import math
x, y = -3, -3print(round(math.degrees(math.atan(y / x))), round(math.degrees(math.atan2(y, x))))
-135 -135
45 -135
45 45
-45 135
Show the answer
45 -135
y / x is 1, and atan(1) is 45°: atan can't tell (−3, −3) from (3, 3). atan2 sees both signs, so it gives the true direction, −135°.
The later blocks. Slips in calculus, probability, statistics and model planning hide inside longer formulas, and most of them still give a believable number. Thirteen more lines, and eight have a slip. Look for a lost ±, a slope set to 0 wrongly, a conditional the wrong way round, a chance outside 0 to 1, a count not rounded up, the wrong log, a missing bias and a root of the wrong thing.
How these were caught. Put x = −2 into 3x²: it's 12 too. Differentiate C(x) = ax² − bx + c and the 2 in 2ax is there to keep. Read a conditional aloud: P(A and B) ÷ P(B) is "A, given B". A chance of −0.3 is outside 0 to 1, so a sign went wrong. Work out the margin for 1,067: 0.030002, just over 0.03, so round up. 2³ = 8 choices carry 3 bits. And 64 × 64 + 64 = 4,160, so the layer has 64 outputs. The lines left alone are right: Newton's step, the constant C = 4, total probability, the surprise and the compute plan.
Quick check
f(x) = x³ − 12x + 1. At which x is its slope 0?
x = 4
x = 12 and x = −12
x = 2 and x = −2
x = 2 only
Show the answer
x = 2 and x = −2
f′(x) = 3x² − 12. Set it to 0: x² = 4, so x = ±2. Both are turning points: f(2) = −15 and f(−2) = 17.
Drill
The inverse on the wrong side
solve_right(A, B) should return the X with X @ A == B, but its check prints False. Find the one slip and fix it.
import numpy as np
A = np.array([[2.0, 1.0], [1.0, 1.0]])
B = np.array([[7.0, 4.0], [5.0, 3.0]])
defsolve_right(A, B):
return np.linalg.inv(A) @ B
X = solve_right(A, B)
print(X)
print(np.allclose(X @ A, B))
In the lesson, your code is checked as you write it.
In your own words
Which slip in this part are you most likely to make, and which quick check would catch it?
Write a sentence or two, then compare it with a good answer in the lesson.
Mixed practice
Purpose. Practice every kind of rearranging the subcourse teaches, mixed, so you choose the move yourself. There are three ladders. Each problem says "rearrange, then put the numbers in", and the number tests the rearrangement.
Before you start each one, answer the first question of the strategy chart: where is the letter, and how many times does it appear? Once means peeling layers. Twice means collecting and factoring. Squared and plain means a quadratic. If one stops you, the steps show the way.
Quick check
The next ladder starts with letters in powers. You need t from 500 × 0.8ᵗ = 200. Which move frees t?
Take the t-th root of 200
Square both sides first
Divide 200 by 0.8 first
Divide by 500, then take logs
Show the answer
Divide by 500, then take logs
0.8ᵗ = 0.4, so t ln 0.8 = ln 0.4, and t = ln 0.4/ln 0.8 ≈ 4.1. Logs bring a power down to where you can divide.
The later blocks. The last ladder runs from trig to model planning. When an answer is a vector or a matrix, the item asks for one entry of it. Angles are in degrees unless the item says otherwise.
The master strategy chart. Every rearrangement in the subcourse follows the same six steps:
Where is the letter, and how many times does it appear?
Twice or more: collect its terms on one side and factor it out. Squared and plain: make it a quadratic.
Once: list the layers around it, in the order they were put on.
Undo them in reverse, each with its opposite.
Write the conditions: zero divisors, ±, log domains, a flip.
Check: numbers back in, a round trip in code, and units.
Three more rules finish the chart:
A matrix is undone by its inverse, on the same side it multiplied from.
A trig function is undone by its inverse, which gives one principal angle. Look for the others.
An inequality takes the same moves. Flip the sign when you multiply or divide by a negative, take reciprocals of positive sides, or divide by the log of a base below 1.
Watch steps 3 to 6 run on a formula with five layers.
The opposites for step 4.
Done to the letter
Undone by
Watch for
add k, multiply by k
take k away, divide by k
k ≠ 0 to divide
square, any even power
± root
two answers
eˣ, bˣ
ln, log ÷ log b
positive numbers only
sin, cos, tan
arcsin, arccos, arctan; atan2 for a point
one principal angle
sigmoid
logit
0 < p < 1
a matrix A
A⁻¹, same side
det A ≠ 0
In plain words: find the letter, peel off what was done to it from the outside in, and write down what must be true for the answer to exist.
Worked example
Worked example: one plan, three blocks, three round trips
Three planning questions from three blocks. Each answer is checked by putting it back into the formula it came from.
import math
# Statistics: test-set size for a margin of 0.03, z = 1.96, p = 0.5
n = math.ceil((1.96 * 0.5 / 0.03) ** 2)
print(n, round(1.96 * 0.5 / math.sqrt(n), 4))
# Model planning: outputs of a layer with 64 inputs and 4,160 parameters
out = 4160 // (64 + 1)
print(out, 64 * out + out)
# Logs and a flip: steps until lr = 0.05 * 0.95 ** t drops below 0.005
t = math.ceil(math.log(0.005 / 0.05) / math.log(0.95))
print(t, 0.05 * 0.95 ** (t - 1) > 0.005, 0.05 * 0.95 ** t < 0.005)
It runs right here in your browser, with nothing to install.
The test set needs 1,068 examples, rounded up from 1,067.1, and its margin prints as 0.03. The layer has 64 outputs, and 64 × 64 + 64 gives back 4,160, so the bias is counted. For the learning rate, dividing by ln 0.95 < 0 flips the sign: t > 44.9, so t = 45. The last line checks both sides: the step before is still above the target, and step 45 is below it.
Quick check
What does this print?
import math
z = math.log(0.9 / 0.1)
p = 1 / (1 + math.exp(-z))
print(round(z, 3), round(p, 3))
0.9 2.197
2.197 0.1
9.0 0.9
2.197 0.9
Show the answer
2.197 0.9
The logit of 0.9 is ln 9 ≈ 2.197. The sigmoid of that score gives 0.9 back: a round trip through an inverse pair.
Drill
The plan comes up short
n_for_margin(z, sigma, margin) should give the smallest whole n with z·σ/√n ≤ margin, but its answers miss the margin. Find the one slip and fix it.
In the lesson, your code is checked as you write it.
In your own words
Pick a ladder problem that made you stop. Which step of the master strategy chart told you what to do?
Write a sentence or two, then compare it with a good answer in the lesson.
The formula sheet
Purpose. The rearranged formulas of the second half of the subcourse, each with its condition and its line of Python. The algebra half has its own sheet, in lesson 40. Trig and vectors:
lesson
formula
rearranged
condition
in Python
46
sin θ = o/h
θ = arcsin(o/h), h = o/sin θ
−1 ≤ o/h ≤ 1; one angle, −90° to 90°; sin θ ≠ 0 for h
math.asin(o / h)
46
x = r cos θ, y = r sin θ
r = √(x² + y²), θ = atan2(y, x)
atan(y/x) fails when x < 0
math.atan2(y, x)
46
y = A sin(ωt + φ)
t = (arcsin(y/A) − φ)/ω
−A ≤ y ≤ A; A, ω ≠ 0; add the period if t < 0
(math.asin(y / A) - phi) / omega
68
w_new = w − ηg
g = (w − w_new)/η
η ≠ 0; never divide by a vector
(w - w_new) / lr
68
a·b = ‖a‖‖b‖cos θ
θ = arccos(a·b/(‖a‖‖b‖))
no zero vector; θ from 0 to π
np.arccos(np.clip(c, -1, 1))
68
v = βv + g, steady
v = g/(1 − β), g = (1 − β)v
β ≠ 1
g / (1 - beta)
Quick check
From the sheet: cos θ = a·b/(‖a‖‖b‖) comes out as 1.0000000002 in code, for two vectors pointing the same way. What do you do?
Clip it to 1 before arccos
Use arcsin in its place
Report that no angle exists
Divide by ‖a‖ once more
Show the answer
Clip it to 1 before arccos
Rounding pushed the value a hair past 1, where arccos has no answer. The true value is 1, so clip to [−1, 1] and get θ = 0.
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