III.3 · Calculus
What does a slope at a single point mean?
Two points make a secant. Slide the second point toward the first and watch the secant slopes settle — or refuse to settle at a corner, a jump or a vertical tangent.
Shrink a secant toward a tangent
Secant and tangent of f(x) = (1/6)x³ − x
Graph of f(x) = (1/6)x³ − x. P = (1, −5/6), Q at x + h = 2. The secant through P and Q has slope 1/6. The dashed tangent has slope −0.5.
- Point
- 1
- Step (must be nonzero for a secant)
- 1
- Value at x
- −5/6−0.833333…
- Value at x + h
- −2/3−0.666667…
- Secant slope
- 1/60.166667…
- Tangent slope (derived separately)
- −0.5
- Left slope limit
- −0.5
- Right slope limit
- −0.5
- Secant − tangent gap
- 2/30.666667…
Exact values use =; binary64 approximations use ≈. Undefined values state their reason.
The secant slope 1/6 approaches the tangent slope f′(1) = −0.5 as h → 0 from either side.
| k | h | m(h) | m(−h) |
|---|---|---|---|
| 0 | 1 | 1/6 | −5/6 |
| 1 | 0.5 | −5/24 | −17/24 |
| 2 | 0.25 | −35/96 | −59/96 |
| 3 | 0.125 | −167/384 | −215/384 |
| 4 | 0.0625 | −719/1536 | −815/1536 |
| 5 | 0.03125 | −2975/6144 | −3167/6144 |
| 6 | 0.015625 | −12095/24576 | −12479/24576 |
Secant 1: h = 1
Two distinct points, x and x + h, give the slope 1/6. No division by zero occurs.
from −2.5 to 2.5, up to 2 decimal places
from −2 to 2, up to 2 decimal places
Start with the smooth cubic and drag toward . The orange secant pivots and its slope settles near the dashed tangent. Then choose Corner |x|: the secant slope is from the right and from the left, however small becomes. Finally type : the stage refuses to draw a secant, because two equal points determine no line.
Intuition: zooming in on a curve
A secant is the straight line through two points of a graph, and . Its slope is an ordinary average rate of change: rise over run. When is small, is close to and the secant hugs the graph near . For a smooth function the secant slopes approach one number. That number is the slope of the graph at .
The important word is approach. The secant formula is never evaluated with ; the tangent slope is what the secant slopes tend to as shrinks through nonzero values.
Definition
The difference quotient of at with step is
The function is differentiable at when exists and the two-sided limit
exists as a finite real number. The tangent line at is then . The one-sided limits and are the left and right slopes; the derivative exists exactly when both exist, are finite and agree.
Mechanics: what the explorer computes
Each secant slope is an actual quotient of two function values with a nonzero step. For the cubic and decimal inputs, the values are exact rationals, so the inspector shows . For they are binary64 approximations, marked . The tangent slope row is not read from the table: it comes from the function’s analytic description (for a polynomial, the exact derivative; for a corner, the two exact one-sided slopes). The table is evidence that agrees with it, not a proof.
Moving changes and keeps ; moving changes . Arrow keys move the focused point by , and the numeric fields accept two decimal places.
Derivation: why the secant slope approaches the derivative
For a polynomial the quotient simplifies before any limit is taken. With ,
The cancellation of is legitimate only because . The simplified expression is continuous in , so its limit as is . In general, for a polynomial , Taylor expansion gives
a polynomial in (the omitted terms carry , , …) whose constant term is . The explorer prints this exact polynomial for the cubic: its constant term is the tangent slope and the remaining terms measure how far a finite secant is from the tangent.
Worked example
Take at . Then , and for every the exact difference quotient is
With the secant slope is ; with it is ; with it is . These approach . The replay below steps through the halving sequence and ends with the separately derived limit.
Replay the worked derivation
Secant 1: h = 1
Two distinct points, x and x + h, give the slope 1/6. No division by zero occurs.
When no derivative exists
- Corner. For at , equals for and for . Both one-sided slopes exist, but they differ, so does not exist.
- Vertical tangent. For at , . The graph is smooth to the eye, but the slope is not a real number.
- Endpoint. is defined only for . At only is possible, and the right quotient is unbounded.
- Jump. A function that is not continuous at cannot be differentiable there: from the broken side, does not shrink while does.
Every one of these is reported by the stage as an undefined derivative with its reason; none is replaced by a nearby number.
Executable reference code
The pedagogical reference uses exact Fraction arithmetic for the difference quotient of a polynomial and shows the one-sided slopes of . The practical version tabulates secant slopes with NumPy and compares them with the analytic derivative.
"""Secant slopes as exact difference quotients (III.3). h must be nonzero; the derivative is a limit, never m(0)."""
from fractions import Fraction as F
def poly_value(coefficients, x):
"""coefficients[k] multiplies x**k (constant term first)."""
return sum(c * x**k for k, c in enumerate(coefficients))
def secant_slope(f, x, h):
if h == 0:
raise ZeroDivisionError("h = 0: two equal points determine no secant")
return (f(x + h) - f(x)) / h
cubic = [F(0), F(-1), F(0), F(1, 6)] # x**3/6 - x
f = lambda x: poly_value(cubic, x)
# Exact slopes for h = 1, 1/2, 1/4, ...: they approach f'(1) = 1/2 - 1 = -1/2.
slopes = [secant_slope(f, F(1), F(1, 2**k)) for k in range(6)]
assert slopes[:3] == [F(1, 6), F(-5, 24), F(-35, 96)]
assert all(abs(b + F(1, 2)) < abs(a + F(1, 2)) for a, b in zip(slopes, slopes[1:]))
# |x| at 0: the one-sided slopes are exactly -1 and 1, so no derivative exists.
absolute = lambda x: abs(x)
right = {secant_slope(absolute, F(0), F(1, 2**k)) for k in range(8)}
left = {secant_slope(absolute, F(0), -F(1, 2**k)) for k in range(8)}
assert right == {1} and left == {-1}
try:
secant_slope(f, F(1), F(0))
except ZeroDivisionError:
pass
else:
raise AssertionError("h = 0 must not produce a slope")"""Tabulate secant slopes with NumPy and compare with the analytic derivative (III.3)."""
import numpy as np
f = lambda x: x**3 / 6 - x
fprime = lambda x: x**2 / 2 - 1 # derived analytically, not from the table
x = 1.0
h = 2.0 ** -np.arange(0, 12) # nonzero steps only
slopes = (f(x + h) - f(x)) / h
gaps = np.abs(slopes - fprime(x))
# For this cubic m(h) = f'(x) + h/2 + h**2/6, so the gap shrinks roughly in proportion to h.
assert np.all(np.diff(gaps) < 0)
assert gaps[-1] < 1e-3
# Both sides agree for a smooth function.
left = (f(x - h) - f(x)) / (-h)
assert np.allclose(left[-4:], fprime(x), atol=3e-3) # gap ≈ h/2 ≤ 2⁻⁹Explore
Make negative and compare with positive of the same size. Move to a point where the cubic’s tangent is horizontal ( is not on the input grid; try and and watch the sign of the tangent slope). On Jump, compare the left and right columns of the table. On sin x, notice that every value is marked .
Common mistakes
Substituting into the quotient produces , which has no value. Cancelling is valid only while . A derivative needs agreement from both sides; averaging two different one-sided slopes does not create one. A graph without a visible break can still fail to be differentiable (a vertical tangent), and a numerical table that looks like it settles is not a proof that a limit exists.
Numerical considerations
In exact rational arithmetic, smaller always brings the secant closer to the tangent of a polynomial. In binary64 it does not: subtracts two nearly equal numbers, and the rounding error is divided by a tiny . Chapter III.14 measures this trade-off between truncation and rounding error. Here the halving table stops at , far above that regime.
Engineering and ML connections
Every gradient used to train a model is a collection of derivatives. Automatic differentiation computes them from the operations of a program (III.10) rather than from secants. Finite-difference quotients remain the standard independent check of a gradient implementation, provided the step size and its error are understood.
Exercises
Summary and checkpoints
A secant slope is a quotient with . The derivative is the limit of these slopes as from both sides, when that limit exists and is finite. Corners, vertical tangents, endpoints and jumps are places where it does not. Next, III.4 reads the derivative as a rate of change and uses the tangent line as a local linear model.