A slope is a local statement
After thiswhat you will be able to doEstimate a slope at one point with shrinking intervals and finite differences, and state why neither estimate guarantees behaviour far from that point.
Questionwhat this lesson answersWhen one quantity depends on another, how sharply does it respond to a small nudge, and what does an answer measured at one point promise about anywhere else?
Not coveredwhat this lesson leaves outWe keep one input quantity only. We do not treat quantities depending on several inputs, prove any limit result, give general rules for differentiating expressions beyond the worked case and the chain rule as stated, cover integration, or develop what happens when a quantity has no slope at a point beyond noting that such points exist.
A lift’s height depends on how much time has passed. Its height tells you where the cabin is, but not whether it is crawling toward a floor or passing it quickly. That needs a second quantity: how sharply the height responds when time advances.
Suppose the lift rises from at to at . Divide the height gained by the time taken:
The stretch from one time to the other is an interval. The quotient is the average rate over that interval. It answers exactly how much height was gained per second across the whole stretch.
The interval is the problem
That average does not say what happened at any one instant. One lift could move steadily. Another could wait, then move twice as fast:
Both average across . For the first , one is moving and the other is not. An answer about the interval cannot choose between them.
Shrink the interval
Take a simple rule that assigns one output to each input, called a function: . Ask how sharply its output responds at . Compare the output there with the output a positive width to the right. The average rate is
Now shrink the width while keeping the starting point fixed:
The rates settle toward . Letting a changing number settle toward one value as shrinks is the process called taking a limit. This lesson uses that process without building its proof. The settled value is the slope at the point. The result of finding such a slope is called the derivative, so here . Some rules have a corner or a break where the shrinking rates do not settle. They have no slope at that point; their treatment stops outside this lesson.
What one point promises
At the function value is and the slope is . Draw a straight line through that point with that slope:
This line matches the function’s first response to a small nudge. A line chosen this way is called the tangent. It is the straight-line stand-in for the curved quantity near the chosen point.
Near the point, the agreement is close. Farther away, it is not:
No distance is guaranteed. How far the line can be trusted depends on the function and on how much error the question allows, so it has to be checked. The slope at one point says nothing whatever about behaviour far away: the function could be changed outside a small neighbourhood without changing either its value or slope at the measured point. The farther you carry the tangent, the less its local promise is worth. Treating one slope as a rule for the whole function is the common mistake.
A slope of zero is equally local. It says a small nudge from either direction has no straight-line response there. The rule has zero slope at its lowest point. The rule has zero slope at its highest point. The rule also has zero slope at , but it rises from negative values to positive values through that point, so the point is neither highest nor lowest. Zero slope alone cannot tell these cases apart.
Responses multiply
One output can feed the next rule. At , the rule turns a small input change into about twice that change. Its output, also , then enters the rule that cubes it, where a small change becomes about three times as large. The response from the first input to the last output is
The factor relating one small change to the next is its sensitivity. When quantities feed one another in a chain, their sensitivities multiply along the route. This multiplication rule is called the chain rule. It is stated here and not proved here.
When only evaluation is available
If you have a formula for a function, its slope can often be worked out exactly. Sometimes all you have is a procedure you can run: supply an input and receive an output. Then evaluate it at and again at , subtract, and divide by the nudge:
This uses a nonzero interval, so it is called a finite difference. Shrinking usually removes more of the interval error. On a real computer that improvement has a limit.
Use the same bowl shifted upward by one trillion, . The shift changes no exact slope, so at the slope is still . But the computer must subtract two stored numbers near . The distance from an estimate to , without regard to which side it falls on, is called its absolute error. These are the results from the solver used below:
Among the tested sizes, the best nudge is , with error . It is positive, not the smallest available, and not extremely tiny. Below it, subtracting nearly equal stored numbers loses useful digits faster than the shorter interval removes error. That limit on stored detail is called precision. By both outputs are stored as the same number, so the estimated slope is zero. The error curve has turned around.
This search can name its best nudge because the exact slope of the toy rule is known. If a procedure can only be evaluated, the true error column is hidden too. You try several nudge sizes and look for the range where the estimate stops stabilising. The useful size depends on the scale of the outputs and the arithmetic doing the subtraction.
One point, shrinking intervals
Closer helps, until the arithmetic turns
The drawn curve has the shape x squared. Its stored output also includes one trillion, hidden here because moving a whole curve vertically does not change its slope. Move the point or shrink the nudge. The left plot compares the two lines. The right plot keeps the whole error curve visible, including its turn.
Two points close onto one
The solid interval line uses the two values the computer stored. The dashed line is the exact line that touches at the movable point.
The error has a bottom
Nudge size shrinks from left to right. Lower is better. The marked bottom is found by testing every shown size, not by assuming the smallest wins.
- Nudge
- 1 × 10-2
- Estimated slope
- 6.0058594
- Exact slope
- 6
- Absolute error
- 5.859375 × 10-3
This is the lowest tested error. The nudge is positive and visibly not the smallest available.
Doorswhat to read next, and why
- Limits and dominanceThe shrinking process here assumes that interval rates settle toward one value. That lesson develops what settling toward a limit means, although it does not supply the full proof machinery for limits.
- What training actually meansThis lesson defines the slope for one input, but it does not show how training uses the chain rule and backpropagation to find gradients for many adjustable parameters.
- Pretrainingnot written yetThis lesson defines local slopes, but it does not explain the data, objective, scale, or compute tradeoffs involved in pretraining a language model.
- Linear mapsThe straight-line stand-in near a point is a map of that kind after its fixed offset is separated, which is the precise sense in which a slope gives a local approximation.
- Directional derivatives and gradientsA quantity depending on several inputs at once can have a different slope in every direction, while this lesson permits one input and therefore one input direction only.
Symbolswhat each one means, and whether we defined it, measured it, or just started there
- xStatus: defined
- The symbol x is defined as the single input quantity whose change is being followed.
- f(x)Status: defined
- The expression f(x) is defined as the output quantity assigned to input x by the rule under study.
- R[a,b]Status: defined
- The average rate R[a,b] over the interval from a to b is defined as the output change f(b) minus f(a), divided by the input change b minus a.
- h -> 0Status: door
- Letting the nonzero interval width h shrink toward zero uses a limit, and the general meaning and proof machinery of that process are not built here.
- f'(x_0)Status: defined
- The derivative f'(x_0) is defined as the single value approached by the average rates over shrinking intervals at the point x_0, when they settle.
- L_{x_0}(x)Status: defined
- The line L at x_0 is defined to pass through f(x_0) with slope f'(x_0), so it is the straight-line stand-in that agrees with the quantity near that point.
- the useful range of LStatus: empirical
- How far the straight-line stand-in remains accurate depends on the particular quantity and required accuracy, so its useful range is found by checking rather than guaranteed by the slope.
- f'(x_0) = 0Status: defined
- A zero slope is defined to mean that the straight-line response to a small input nudge is zero at x_0, without classifying that point as high, low, or neither.
- S[z<-x] = S[z<-y] S[y<-x]Status: defined
- The chain rule is defined here as the rule that sensitivities multiply when a change in x passes through y before reaching z; this lesson states the rule and does not prove it.
- D_h f(x)Status: defined
- The finite difference D_h f(x) is defined as f(x+h) minus f(x), divided by the positive nudge h, and estimates the point slope from two evaluations.
- h_bestStatus: empirical
- The best nudge size is the tested positive h with the least error, and its value depends on the scale of the calculation and the arithmetic the machine actually performs.
What these classifications mean
- defined
- circular by construction, true because we chose it
- empirical
- a measured claim about the world that could have come out otherwise
- bottoms out
- a primitive of the model, with nothing under it here
- door
- used here, explained elsewhere