Many questions take two formulas at once. You measured the distance around a circle, but the area formula wants the radius. When two formulas share a letter like that, you can remove it: rearrange one formula for the shared letter, then put the result, in brackets, into the other. The new formula goes straight from what you know to what you want. Physics gets v² = u² + 2as this way, and engineers use it to plan training runs and models from a budget.
What you'll be able to do
Remove a letter two formulas share: rearrange one formula for it, then substitute the result, in brackets, into the other
Eliminate t from v = u + at and s = ut + ½at² to reach v² = u² + 2as, showing every step and what the result can't tell you
Tell building a new formula apart from solving two equations for numbers
Combine geometry formulas: a circle's area from its circumference, and a rectangle's area from its perimeter and the ratio of its sides
Check a combined formula against the chained originals in Python, and size a training run, an API budget and a model's width
Quick check
Have a guess before you start. A circle measures 31.4 cm around. Using π = 3.14, what is its area?
493 cm²
774 cm²
78.5 cm²
15.7 cm²
Show the answer
78.5 cm²
The distance around is C = 2πr, so r = 31.4 ÷ 6.28 = 5. Then A = πr² = 3.14 × 25 = 78.5. That's two formulas joined by r, and this lesson joins them into one.
The math: substitute to remove a letter
Purpose. Join two formulas that share a letter into one formula without it.
A circle's circumference (the distance around it) is C = 2πr, and its area is A = πr². Both contain the radius r. If you measured C and want A, r is a go-between: needed on the way, not in the answer. To eliminate it (remove it):
Rearrange one formula to make the go-between the subject: r = C/(2π).
Substitute it: put that whole expression in the letter's place in the other formula, in brackets, everywhere the letter appears. A = π(C/(2π))².
Simplify. The result, A = C²/(4π), has no r.
Quick check
From an earlier lesson: put y = 3x into x + y = 20. What is x?
5
6.67
17
15
Show the answer
5
x + 3x = 20, so 4x = 20 and x = 5, then y = 15. There, substitution ended in numbers. Here, it ends in a formula.
Substituting is the chaining from Chaining and undoing functions: the first formula's output, r, is the second one's input. Watch C = 31.4 go through both, with π as 3.14, then come back.
Try it now
Change C and press Use these numbers: the area always equals C² ÷ (4 × 3.14), so one formula does the work of two.
Symbols and formula. The circle's three steps, written out:
C=2πr⇒r=2πC⇒A=π(2πC)2=4π2πC2=4πC2
In plain words: square the distance around, then divide by 4π. For C = 31.4: 985.96 ÷ 12.56 = 78.5, the same as the route through r = 5.
Named mistakes.
Dropping the brackets. π × C²/2π squares only the top and simplifies to C²/2: 493 for this circle, not 78.5.
Leaving a copy behind. Substitute everywhere the letter appears, or it isn't eliminated.
Removing the wrong letter. Rearrange for the go-between, never for a letter you want in the answer.
Quick check
The tent shop ropes off a rectangle whose length is twice its width: l = 2w, and P = 2(l + w). What is w in terms of P alone?
w = P/3
w = P/4
w = P/6
w = P/2 − l
Show the answer
w = P/6
Substitute l = 2w: P = 2(2w + w) = 6w, so w = P/6. A 36 m rope gives w = 6 m and l = 12 m.
Building a formula, not solving for numbers. In Two equations, two unknowns, the other letters had numbers, so eliminating one unknown left a number. Here the letters stay letters, so eliminating leaves a formula. With a 36 m rope, l = 2w and 2(l + w) = 36 are two equations: w = 6 and l = 12. Leave P as a letter, and the same substitution builds w = P/6 and A = lw = 2w² = 2(P/6)² = P²/18: the area for every rope. For 36 m, 1296 ÷ 18 = 72, which is 12 × 6.
Eliminating time. Two formulas describe anything speeding up steadily, like a cyclist rolling downhill: v = u + at and s = ut + ½at². u is the starting speed, v the speed after t seconds, a the acceleration (the speed gained each second), and s the distance covered. To link speed and distance without t:
Line by line: make t the subject of the first formula (a can't be 0). Substitute it, in brackets, for both copies of t. Multiply every term by 2a to clear the fractions. Expand: the 2uv terms cancel. Add u² to both sides.
Quick check
Substituting t = (v − u)/a into ½at² gives what?
(v − u)/2
(v − u)²/(2a)
(v − u)²/2
a(v − u)²/2
Show the answer
(v − u)²/(2a)
½a × (v − u)²/a² = (v − u)²/(2a): the a on top cancels one of the two below. Check with u = 4, v = 8 and a = 0.5: t = 8, so ½at² = ½ × 0.5 × 64 = 16, and (v − u)²/(2a) = 16 ÷ 1 = 16.
Check it, and see what it can't tell you. A cyclist starts down a hill at u = 4 m/s and gains a = 0.5 m/s each second. After 48 m, v² = 16 + 2 × 0.5 × 48 = 64, so v = 8. Through t: 8 = 4 + 0.5t gives t = 8, and s = 4 × 8 + ½ × 0.5 × 8² = 48. The same.
Removing t also removed information: v = ±√(u² + 2as). A ball thrown up at 20 m/s, with a = −10, is 15 m up twice: v² = 400 − 300 = 100, so v = 10 rising and −10 falling. Only t knew which. And v² can't be negative, so when u² + 2as is below 0 there is no real v: the ball never reaches 25 m, since 400 − 500 = −100.
In your own words
In your own words: how is eliminating t here different from eliminating y in two equations, two unknowns?
Write a sentence or two, then compare it with a good answer in the lesson.
In Python: chain the originals, then compare
Purpose. A combined formula is new algebra, and new algebra can slip. Check it by working out each answer two ways: through the go-between, with formulas you trust, and with the combined formula.
import math
defarea_chained(C):
r = C / (2 * math.pi)
return math.pi * r ** 2defarea_combined(C):
return C ** 2 / (4 * math.pi)
for C in [31.4, 2.5, 100]:
print(C, round(area_chained(C), 6), round(area_combined(C), 6))
It runs right here in your browser, with nothing to install.
The columns agree for every C. With the full π from math, 31.4 gives 78.46 rather than 78.5. The middle row is a tree trunk: a tape measures 2.5 m around, so its cross-section is about 0.497 m². Foresters work it out this way, since a tape goes around a trunk more easily than a ruler goes through it.
Worked example
Worked example: v² = u² + 2as, checked through t
Pick a time, run both original formulas, and compare v² with u² + 2as. The cyclist again: u = 4 and a = 0.5.
u = 4
a = 0.5for t in [0, 2, 8, 3.5]:
v = u + a * t
s = u * t + a * t ** 2 / 2print(t, s, v ** 2, u ** 2 + 2 * a * s)
In the lesson you can change this and run it.
Each row is one moment of the ride. At t = 8 she has gone 48.0 m, and the last two columns both say 64.0, as found by hand. They match at every t, even t = 0. That's the point of eliminating t: the new formula holds whatever t was, so you never need to know it.
Quick check
What does this print?
import math
C = 10
r = C / 2 * math.pi
print(round(r, 2), round(C / (2 * math.pi), 2))
1.59 1.59
1.59 15.71
15.71 1.59
15.71 15.71
Show the answer
15.71 1.59
Python reads C / 2 * math.pi left to right: 10 ÷ 2 = 5, then 5 × π ≈ 15.71. Only the brackets in C / (2 * math.pi) put the whole 2π on the bottom, giving 1.59.
Quick check
You derived A = C²/(4π). Which test would catch a slip in it?
Compare with π(C/(2π))² for several C
Run it once, for C = 0
Check that r no longer appears
Print A for C = 31.4 and look
Show the answer
Compare with π(C/(2π))² for several C
The chained route uses formulas you trust, so it's a fair answer to compare against. Several inputs, including a decimal, leave a slip nowhere to hide.
Drill
Fix the combined formulas
area_combined(C) should match the chained circle formulas, and rect_area(P) should give the area of a rectangle whose length is twice its width. Each has one slip. Fix them so both match their chains.
import math
defarea_chained(C):
r = C / (2 * math.pi)
return math.pi * r ** 2defarea_combined(C):
return C ** 2 / 4 * math.pi
defrect_chained(P):
w = P / 6return2 * w * w
defrect_area(P):
return P ** 2 / 16print(area_chained(31.4), area_combined(31.4), rect_chained(36), rect_area(36))
In the lesson, your code is checked as you write it.
In your own words
Why compare a combined formula with the chain of original formulas, instead of rereading the algebra?
Write a sentence or two, then compare it with a good answer in the lesson.
In AI and ML: budgets for time, money and memory
Purpose. Planning a training run or a product usually takes two formulas joined by a go-between. Combine them, then rearrange for the number the budget controls.
Time. A run takes T = steps × s, with s seconds per step, and steps = epochs × n ÷ batch, from Rearranging formulas. Substitute: T = epochs × n × s ÷ batch. For the data a time budget allows: n = T × batch ÷ (epochs × s).
Money. A language model's bill is cost = tokens × price, where tokens are the small pieces of text it reads and writes, and tokens = requests × tokens per request. So requests = budget ÷ (tokens per request × price). Prices are quoted per million tokens, so the code divides that price by 1e6 (a million) to get the price of one token.
The trail club's photo model gets 7,200 s (2 hours), 3 epochs, batches of 32 and 0.25 s a step: 307,200 photos, and the check gives back 7,200 s. Its help bot uses 1,500 tokens a request. At $3 per million tokens (an invented price for this example: real price lists differ, and charge input and output tokens differently), $90 buys 20,000 requests.
Quick check
A run takes T = epochs × n × s ÷ batch. With 4 epochs, batches of 64 and 0.5 s a step, how many examples fit in 3,600 s?
1,843,200
115,200
7,200
460,800
Show the answer
115,200
n = T × batch ÷ (epochs × s) = 3,600 × 64 ÷ 2 = 115,200. Check: 4 × 115,200 ÷ 64 = 7,200 steps, and 7,200 × 0.5 s = 3,600 s.
Memory. A model's weights take M = params × b bytes, with b bytes per number: 4 for the 32-bit floats from Scientific notation, 2 for 16-bit. In a standard transformer (the design inside language models), params ≈ 12 × layers × d². The width d is how many numbers describe each token inside the model. The 12 counts about 4d² weights in each block's attention part and 8d² in its feed-forward part. Embeddings (the table that turns tokens into numbers) and small extras are left out, so it's an approximation.
Substitute: M = 12 × layers × d² × b. d is squared, so freeing it takes a square root, the positive one, since a width can't be negative: d = √(M ÷ (12 × layers × b)). For 6 GB (6 × 10⁹ bytes), 20 layers and 4 bytes: d = √(6 × 10⁹ ÷ 960) = √6,250,000 = 2,500.
At an invented $2.50 per million tokens, 1,200 tokens cost $0.003 a request, and $60 ÷ 0.003 = 20,000. Twice the tokens per request halves the requests: 10,000.
Drill
Width and layers from a memory budget
With M = 12 × layers × d² × b, write width_for_memory(M, layers, bytes_per), the width d that fills M bytes, and layers_for_memory(M, d, bytes_per), the number of layers that fills it.
defwidth_for_memory(M, layers, bytes_per):
return M / (12 * layers * bytes_per)
deflayers_for_memory(M, d, bytes_per):
return M / (12 * d * bytes_per)
print(width_for_memory(6e9, 20, 4), layers_for_memory(6e9, 2500, 4))
In the lesson, your code is checked as you write it.
In your own words
Why does 4 times the memory buy only twice the width?
Write a sentence or two, then compare it with a good answer in the lesson.
Goes deeper in
lesson 20 chains functions. Substituting one formula into another is the same chaining.
lesson 60 eliminates letters from many equations at once, with matrices.
lesson 116 plans whole models from memory and compute budgets.
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