The Endless Sum That Stops
Train a model, sharpen an estimate, or work through an unfinished sum, and a computer does the same thing underneath: it repeats one step and gives off a long run of numbers, one per step. The whole question is whether that run settles on an answer. It is trickier than it sounds, because a sum the mathematics calls infinite comes to rest, on a real chip, at 15.4037. Sorting out who is right takes three ideas, sequences, limits, and convergence, and the short C behind each one is here to run.
A sum that should be infinite, and isn’t
Start by adding fractions: \(1 + \tfrac12 + \tfrac13 + \tfrac14 + \tfrac15 + \cdots\), one over each whole number, forever. The pieces keep shrinking, a hundredth, a thousandth, a millionth, so it is natural to expect the running total to slow down and level off somewhere finite, the way many sums do.
It does not. This is the harmonic series, and one of the first surprises in calculus is that its total grows without any bound at all: keep going and it passes 10, then 100, then any number you name. The pieces shrink toward nothing and the sum is still infinite. That deserves a proof, which is coming; for now, take it as a fact. Added in full, this series is infinite.
Now hand the same sum to a computer. You might expect it to agree, climbing higher the longer it runs. Here it is in C, added first in double precision, then in the single-precision float the ESP32 uses. Press Run and watch where the two totals end up.
output appears here
The two totals set off together and end up in different worlds. In double precision the sum has passed 15.4 after three million terms and is still climbing, with no end in sight, exactly as the mathematics promised. The float does something else: it climbs, slows, and stops. After 2,097,152 terms it reaches \(15.4037\), and from there every further term leaves it exactly where it was. A sum the mathematics calls infinite has come to rest, on this machine, at a small finite number.
So we are holding two facts that flatly contradict each other, and both are real. The class is really that contradiction, split into two questions. The first is about the mathematics: does the endless sum truly never settle, or does “the pieces shrink to nothing” secretly mean it does after all? The second is about the machine: if the true sum climbs forever, what exactly made the chip stop, and does its stopping tell us anything at all? Answering the first is what sequences, limits, and convergence are for. Answering the second needs one more idea about what a finite machine can notice.
When does an endless run of numbers truly settle, and how do you tell that from a machine that has merely run out of room to notice it is still moving?
Each piece of that has a name. The run of numbers a process gives off is a sequence. The value it heads toward is its limit. Whether it actually gets there is convergence. This is not a detour into pure math: Class 8 showed a model cannot be found by trying every setting, so training can only start somewhere and improve one step at a time, giving off exactly this kind of run of numbers. Whether that run settles is whether training ever finishes.
float, at 15.4037. Pulling those apart forces two verdicts. The mathematics of settling, a sequence, its limit, and whether it converges, shows the true sum never settles. Then the machine’s own limits show why the chip stopped anyway. The sting is that a frozen number could mean either thing, and training, which is just such a sequence, inherits exactly that ambiguity.Sequences: one number per step
We already built a sequence without naming it. Each time the loop added a term, it produced a fresh running total: one number after the first term, another after the second, another after the third. Stand those totals in a line, in the order they appeared, and that line is a sequence, an ordered list \(a_1, a_2, a_3, \ldots\) with one term \(a_n\) for each step \(n\).
Order is what separates a sequence from a set. The set \(\{2, 5, 9\}\) is the same collection as \(\{9, 5, 2\}\); nothing about it cares which number comes first. In a sequence the position is the whole point: the fifth term comes after the fourth, and that word, after, is what lets us ask where the numbers are heading as the steps go on.
Three sequences will keep returning, and we have already met all three. The plainest is the list of terms \(1/n\) by itself, \(1, \tfrac12, \tfrac13, \tfrac14, \ldots\), the very numbers we were adding. Plotted against the step number, it just steps downward toward zero.
Their running totals make the second sequence, the partial sums: \(1\), then \(1 + \tfrac12\), then \(1 + \tfrac12 + \tfrac13\), and so on. That is the sequence we watched climb and freeze in the opening. The third is a training run: the loss after each update, \(a_1, a_2, a_3, \ldots\), one number per step. That is the loss curve you watch while a model trains, and it is nothing more exotic than a sequence, the optimiser stepping and reporting a loss, stepping and reporting again. Every question you ask about training, is it improving, has it settled, did it blow up, is a question about how this one sequence behaves as the steps pile up. And all three raise the same question: where is the sequence heading?
Limits: where a sequence is heading
The useful question about a sequence is not what any single term equals, but where the terms go as you read further along. If they crowd in around one value and settle there, that value is the sequence’s limit, the number it is trying to reach.
What does it mean for the terms to head toward a value \(L\)? Not that any term equals \(L\); plenty of sequences never land on their limit exactly. It means the terms get arbitrarily close to \(L\) and, just as important, do not wander off again. Closeness alone is not enough, since a sequence could pass near \(L\) once and then drift away. The closeness has to last.
One test captures both halves. Draw a band around \(L\), as narrow as you like. The sequence has limit \(L\) if, however narrow the band, there is some step beyond which every later term lies inside it and stays. A tighter band may make you read further before that holds, but for a genuine limit such a step always exists. This is the working definition; the fully formal one waits for an analysis course.
Make it concrete with a sum that does settle. Add \(\tfrac12 + \tfrac14 + \tfrac18 + \cdots\), each term half the last, and follow the running total: \(0.5, 0.75, 0.875, 0.9375, \ldots\). Watch each step act on the gap to 1. The first term leaves a gap of \(\tfrac12\); the next, \(\tfrac14\), closes half of it, leaving \(\tfrac14\); the next closes half again, leaving \(\tfrac18\). Every term halves the remaining gap, so the total can be brought as close to 1 as you like and never reaches or passes it. Its limit is 1.
output appears here
The limit of the loss sequence is the value training reaches for, the bottom of the valley it is heading into. When people say a model has “converged,” they mean its loss sequence has reached a limit and stopped improving. Knowing what a limit is, and what being at one actually requires, is what separates a model that has finished learning from one that has merely slowed down.
Now put the opening sum to this same test. The geometric total settled on 1, its terms trapped inside any band you draw. The harmonic partial sums never stopped climbing, so no band around any value can ever hold them, because they keep rising past it. That looks like a sequence with no limit. But “looks like” is not proof, and those terms are shrinking to nothing, which feels like it should force a limit. Settling that is the next section, and it is where the mathematics side of the opening finally gives its verdict.
Convergence: does the sequence arrive?
A limit is the value a sequence heads toward, but that quietly assumes there is one. Not every sequence has a limit. A sequence that settles on a finite limit is said to converge; one that never settles is said to diverge. Divergence comes in two shapes: a sequence can grow without bound, like \(1, 2, 3, \ldots\), running off to infinity, or it can stay in a fixed range yet never approach a single value, like \(+1, -1, +1, -1, \ldots\), flipping forever. Convergence is the case we want, because only then does running longer buy a definite answer.
One belief about convergence feels obviously true and is not: that a sum must converge as long as its terms shrink to zero, since eventually you are adding almost nothing. The harmonic series is the counterexample, and it shows exactly where the belief breaks. Its terms, \(1/n\), do shrink to zero. But shrinking to zero is not the same as shrinking fast enough.
Group the terms into blocks. After the first, take the next two, \(\tfrac13 + \tfrac14\): both are at least \(\tfrac14\), so the pair beats \(\tfrac14 + \tfrac14 = \tfrac12\). Take the next four, \(\tfrac15\) through \(\tfrac18\): each is at least \(\tfrac18\), so together they beat \(4 \times \tfrac18 = \tfrac12\). The next eight each beat \(\tfrac{1}{16}\), so they beat \(8 \times \tfrac{1}{16} = \tfrac12\). The pattern never ends: each block is twice as long as the last and each adds more than \(\tfrac12\). Infinitely many blocks, each worth more than \(\tfrac12\), drive the running sum past \(\tfrac12\), then 1, then \(1\tfrac12\), then any number you choose. The terms shrank to zero and the sum grew to infinity anyway. What decides convergence is not whether the terms shrink but whether they shrink quickly enough, and the harmonic terms do not.
That settles the first half of the opening. The harmonic sum genuinely has no limit; run it forever and it passes every number. The mathematics was right, and the paradox now has only one loose end: if the true sum never settles, what was the chip doing when it settled at 15.4037? That is the machine’s side of the paradox, and the next section answers it. First, though, convergence has a second face that matters even more for training.
Every sequence so far has been tidy, each term fixed by a rule. The sequence that matters most in machine learning is not tidy at all: its terms are random, with no formula behind them, so it is fair to ask whether something that jumps around at random can converge to anything. Take the simplest case. You want the chance a coin lands heads, and the only way to find out is to flip it many times and track the running fraction of heads. That fraction is a sequence, one term per flip, and a noisy one: after 3 flips it might read \(0.67\), after 10 it might read \(0.40\), because a few lucky flips still dominate. But as the flips pile up, no single flip can move the fraction much, so the swings shrink and the value settles toward the true \(0.5\). A random sequence can converge after all, as long as the noise averages out. This is a Monte Carlo estimate: approximate a quantity by drawing random samples and averaging them, trusting that average to converge as the sample grows. Drag the slider to add flips, and press flip again for a fresh run.
Both faces are everyday training. A run that converges is one whose loss sequence settles toward the bottom of its valley; a run that diverges is one whose loss climbs without bound or swings back and forth and never settles, which is what a too-large learning rate produces. And Monte Carlo convergence is why more data and more samples help at all: an estimate built from random samples, the average loss over a batch, a sampled reward, an approximate integral, is a running average converging to its true value, and drawing more samples is walking further along that sequence toward its limit.
The machine’s limit: when to stop
Back to the loose end. If the true harmonic sum never settles, why did the float stop dead at 15.4037? The answer has nothing to do with limits and everything to do with the machine being finite. A machine computes only finitely many terms and stores each in finitely many bits, so it must stop somewhere, and there are two rules for when.
The first is to fix a tolerance ahead of time: once a new term changes the total by less than, say, \(0.001\), call it close enough and stop. The second is to keep going until the total stops changing on its own. The second sounds safer, since the machine makes the call for you, but it is the one that misleads. Start with the rule you control, on the geometric sum, stopping once a term drops below a tolerance you set. A loose tolerance quits early, short of the true limit of 1; a tight one runs longer and lands closer.
output appears here
That rule keeps you honest: you decided what counts as close enough, and you can read off exactly how many terms it cost. The second rule, stop when the total stops changing, is where the harmonic series ambushes you, and it is time to open up the freeze from the opening. Run the harmonic partial sums in float and the total does stop changing, but not because the series reached a limit; it has none. It is the machine epsilon from Unit 1. A float can only land on certain spaced-out values, and that spacing grows with the size of the number. By the time the running sum is near 15, the nearest float values are about \(15 \times 10^{-7} \approx 0.0000018\) apart. Once a term \(1/n\) shrinks below half of that spacing, adding it produces a result that rounds straight back to the total you already had. The addition still runs; it just changes nothing, and every later term is smaller still, so the entire infinite tail contributes nothing the machine can record. The sum froze at 15.4037 not because it arrived, but because the chip ran out of the resolution it would need to feel that it is still moving.
So a total that has stopped changing carries two opposite meanings, and nothing on the screen tells them apart. It can mean the sequence genuinely reached its limit. Or it can mean the steps fell below the machine’s resolution and the total froze short of the truth, here resting at a finite 15.4037 when the real answer is infinite. The honest double and the float agree term for term right up until the terms get too small, and only there do they part.
Training stops in exactly these two ways: after a fixed number of steps, or once the loss changes by less than a set tolerance. So the phrase “the model converged” inherits the same ambiguity as the frozen sum. The model may be resting at a genuine minimum, or its updates may have shrunk below what the numbers can hold, the gradients underflowing toward zero just as in Class 7, leaving it stranded well short of a good answer. A flat loss curve is not proof on its own: you check whether the mathematics could converge at all, and whether the precision is fine enough to register the steps that remain.
The optimiser is a sequence
Now the payoff, closing the loop back to Class 8. That class showed a model cannot be found by trying every possible setting; the alternative is to start at one setting and nudge it a little at a time, and each nudge produces a new value, then another, then another. That is a sequence, the same object this whole class has studied, so whether training succeeds is just whether this particular sequence converges.
Shrink the model to the smallest thing that still moves: a single number \(x\), with a loss measuring how bad that number is. Take \(f(x) = x^{2}\). It is 0 at \(x = 0\) and grows as \(x\) moves away either direction, so \(x = 0\) is the target, the bottom of the valley. Training cannot see the whole valley at once; standing at one value \(x\), all it can feel is the local slope, how steeply the loss rises there. The slope points uphill, so to go downhill you step the opposite way, against the slope, by a fixed fraction called the learning rate, \(\text{lr}\). One step is \(x \leftarrow x - \text{lr} \times (\text{slope at } x)\).
For \(f(x) = x^{2}\) the slope at \(x\) is \(2x\). (Pinning down what “slope” means precisely is the work of Unit 4, calculus; for now take \(2x\) as given.) It behaves as a valley should: at the bottom, \(x = 0\), the slope is 0, so there is nothing left to step; far out, the slope is large, so the steps are large. Put that slope into the step rule and something familiar drops out:
\( x_{\text{next}} = x - \text{lr}\times 2x = (1 - 2\,\text{lr})\,x \)
Every step multiplies the current \(x\) by the same fixed number, \((1 - 2\,\text{lr})\). This is not a new kind of sequence; it is exactly the geometric sequence from the limits section, a value multiplied by a fixed factor over and over, the same shape as \(\tfrac12 + \tfrac14 + \cdots\). And there we already found the one thing that decides its fate: the size of the factor. Run it and watch, then change the learning rate.
output appears here
If the factor’s size, \(|1 - 2\,\text{lr}|\), is below 1, multiplying by it over and over shrinks \(x\) toward 0 and the loss settles at its minimum. That is convergence, and it holds for every learning rate between 0 and 1. Inside that range the approach comes in two flavours. With a small \(\text{lr}\) the factor is positive and below 1, so \(x\) slides smoothly toward 0, each step a little nearer. With a larger \(\text{lr}\), above 0.5, the factor turns negative and \(x\) flips sign each step: it overshoots the minimum, lands on the far side, overshoots back, but because the factor’s size is still under 1, each overshoot is smaller than the last, so it spirals in rather than sliding in.
Two learning rates sit on the edges. At \(\text{lr} = 0.5\) the factor is exactly 0, so a single step lands on the minimum. At \(\text{lr} = 1\) the factor is \(-1\), so \(x\) bounces between the same two values forever and never settles, the \(+1, -1, +1, -1\) divergence from the convergence section, made out of a training step. Past \(\text{lr} = 1\) the factor’s size climbs above 1, so every step makes \(x\) larger and the loss runs away to infinity. Sweep the slider and watch each outcome in turn.
This one-number toy is why the learning rate is the first thing anyone tunes. A real model swaps the single \(x\) for billions of numbers and the plain slope for a gradient, but the behaviour is the same: too small a rate and training converges so slowly it never finishes, too large and the loss oscillates or explodes, and a band of rates between settles quickly. And the warning from the machine section still stands: even a converging run can freeze early if its steps shrink below what the numbers can hold, so a flat loss is where the questions start, not where they end.
What to carry out of Class 9
A sequence is the ordered list of numbers a repeated process gives off, one per step. Its limit is the value the terms get close to and stay close to. Convergence is whether that ever happens, and the catch is that terms shrinking to zero is not enough; they must shrink fast enough, which is why \(\tfrac12 + \tfrac14 + \cdots\) settles at 1 while \(1 + \tfrac12 + \tfrac13 + \cdots\) climbs without bound. On a real machine every limit is truncated to finitely many steps, so you stop at a tolerance, and a value that has stopped moving may have reached its true limit or may have only fallen below the machine’s resolution, the false finish that freezes the float harmonic sum at 15.4037. Training is one of these sequences, gradient descent is a geometric one, and the learning rate decides whether it converges, oscillates, or explodes.
That completes the language of Unit 2, functions, sums, counting, and limits. Unit 3 turns next to exponentials and logarithms, beginning with the number that falls out of multiplying without end. And further on, in Unit 4, the very slope each optimiser step follows is defined as the derivative, which turns out to be itself a limit, the idea from this class returning as the engine of calculus.
See if it stuck
Eight questions, all answerable from this post. Tap an answer for an immediate verdict and the reason.
Comments