16. The derivative as a limit
Everything in §1 was preparation for this one definition. Here it is:
f'(a) = \lim_{h\to0}\frac{f(a+h) - f(a)}{h}
If that limit exists, f is differentiable at a and f'(a) is its derivative there.
Look at what the expression does at h = 0: numerator zero, denominator zero. Every derivative is a \frac00 limit, always, for every function. That's not a defect — it's why we spent a whole module learning to evaluate exactly this kind of limit.
An equivalent form
Substituting x = a + h (so h = x - a, and h \to 0 becomes x \to a):
f'(a) = \lim_{x\to a}\frac{f(x)-f(a)}{x-a}
The same thing. The h form is better for computing (algebra in one variable that's heading to zero); the x form is better for proofs and for recognising a derivative in disguise. You saw the second form already in §1.1, where \lim_{x\to4}\frac{\sqrt x - 2}{x-4} turned out to be exactly \frac{d}{dx}\sqrt x at 4.
Three readings of the same number
Geometric: the slope of the tangent line. \frac{f(a+h)-f(a)}{h} is the slope of the secant through (a, f(a)) and (a+h, f(a+h)). As h \to 0 the second point slides into the first and the secant pivots into the tangent. The derivative is the tangent's slope.
Physical: the instantaneous rate of change. If f is position, the difference quotient is average velocity over a time interval h, and the derivative is velocity now. The speedometer problem from §0.0, solved.
Analytic: the best linear approximation. Near a,
f(x) \approx f(a) + f'(a)(x-a)
and f'(a) is the unique slope making the error vanish faster than (x-a) itself. This is the reading that generalises — in §10 the derivative of a multivariable function is a linear map, and in §15 that becomes the definition.
All three are the same limit. Which one you reach for depends on what you're doing.
Notation
Four notations, all common, each with a reason to exist:
| Notation | Name | Good for |
|---|---|---|
| f'(x) | Lagrange | compact; stacking primes for higher orders |
| \dfrac{dy}{dx} | Leibniz | shows the variables; makes the chain rule look like cancellation |
| \dfrac{d}{dx}f(x) | Leibniz operator | emphasises "differentiate this" |
| \dot y | Newton | derivative with respect to time, in physics |
Leibniz notation is worth being comfortable with even though it's longer. It names the input variable — essential once there's more than one — and it makes \frac{dy}{dx} = \frac{dy}{du}\cdot\frac{du}{dx} memorable. It is not a fraction, but it was designed to behave like one, and it mostly does.
For a value at a specific point, \left.\frac{dy}{dx}\right|_{x=a} or f'(a).
The derivative as a function
Let a vary and f' becomes a function in its own right:
f'(x) = \lim_{h\to0}\frac{f(x+h)-f(x)}{h}
Its domain is every point where the limit exists — possibly smaller than f's. That's the whole subject of the next lesson.
Computing from the definition
Three you should do by hand once, because the rules in §2.2 will make them instant and you should know what the rules are hiding.
f(x) = x^2.
\frac{(x+h)^2 - x^2}{h} = \frac{x^2 + 2xh + h^2 - x^2}{h} = \frac{2xh + h^2}{h} = 2x + h
Cancelling h is legal because h \neq 0 in the limit. So f'(x) = 2x.
f(x) = \frac1x.
\frac{\frac{1}{x+h} - \frac1x}{h} = \frac{\frac{x - (x+h)}{x(x+h)}}{h} = \frac{-h}{h\,x(x+h)} = \frac{-1}{x(x+h)}
Let h \to 0: f'(x) = -\frac{1}{x^2}. (Compound fraction, §1.1 technique 3.)
f(x) = \sqrt x.
\frac{\sqrt{x+h}-\sqrt x}{h}\cdot\frac{\sqrt{x+h}+\sqrt x}{\sqrt{x+h}+\sqrt x} = \frac{h}{h(\sqrt{x+h}+\sqrt x)} = \frac{1}{\sqrt{x+h}+\sqrt x}
Let h \to 0: f'(x) = \frac{1}{2\sqrt x}. (Conjugate, §1.1 technique 2.)
Notice the pattern: every one of these is a §1 limit technique, applied to a \frac00 form. The derivative isn't a new kind of computation — it's the computation §1 was building toward.
Units, which are free error-checking
If f maps seconds to metres, f' maps seconds to metres per second. In general the derivative's units are (units of output) per (unit of input), and that's true of every derivative you will ever take:
- position (m) → velocity (m/s)
- velocity (m/s) → acceleration (m/s²)
- cost ($) with respect to quantity → marginal cost ($/unit)
- concentration (mol/L) with respect to time → reaction rate (mol/L·s)
Checking units catches a surprising number of setup errors in §3's related-rates and optimization problems, for free.
Doing it in Python
The secant sliding into the tangent:
def f(x):
return x * x
a = 3.0
print(f"{'h':>12} {'secant slope':>16} {'error vs 2a':>14}")
for k in range(1, 9):
h = 10.0 ** -k
slope = (f(a + h) - f(a)) / h
print(f"{h:>12.0e} {slope:>16.10f} {slope - 2*a:>14.2e}")
print(f"\nf'(3) = 2*3 = {2*a}")
print("the algebra said 2x + h, and the error column is exactly h")
All three worked examples, checked at once:
from math import sqrt
cases = [
("x^2", lambda x: x * x, lambda x: 2 * x),
("1/x", lambda x: 1 / x, lambda x: -1 / x**2),
("sqrt(x)", sqrt, lambda x: 1 / (2 * sqrt(x))),
]
h = 1e-7
print(f"{'f':>10} {'a':>5} {'numerical':>14} {'exact':>14} {'diff':>10}")
for name, f, df in cases:
for a in (1.0, 2.0, 4.0):
num = (f(a + h) - f(a)) / h
print(f"{name:>10} {a:>5} {num:>14.8f} {df(a):>14.8f} {num - df(a):>10.1e}")
SymPy does it symbolically, straight from the definition:
import sympy as sp
x, h = sp.symbols('x h')
for expr in (x**2, 1/x, sp.sqrt(x), sp.sin(x), sp.exp(x)):
from_definition = sp.simplify(sp.limit((expr.subs(x, x + h) - expr) / h, h, 0))
print(f"d/dx [{expr}] = {from_definition} (sympy diff: {sp.diff(expr, x)})")
And the reading as a linear approximation:
def f(x):
return x * x
a, fa, fpa = 3.0, 9.0, 6.0
print(f"{'x':>8} {'f(x)':>12} {'tangent':>12} {'error':>12} {'error/(x-a)':>14}")
for dx in (1.0, 0.5, 0.1, 0.01, 0.001):
x = a + dx
tangent = fa + fpa * dx
err = f(x) - tangent
print(f"{x:>8.3f} {f(x):>12.6f} {tangent:>12.6f} {err:>12.6f} {err/dx:>14.6f}")
print("\nthe error is exactly (x-a)^2, so error/(x-a) -> 0.")
print("that vanishing-faster-than-linear property is what 'best' means.")
Worked example
A ball's height is s(t) = 40t - 5t^2 metres, t in seconds. Find its velocity at t = 3, and say when it's momentarily at rest.
Velocity is the derivative. Compute it from the definition once:
s(t+h) = 40(t+h) - 5(t+h)^2 = 40t + 40h - 5t^2 - 10th - 5h^2
s(t+h) - s(t) = 40h - 10th - 5h^2
\frac{s(t+h)-s(t)}{h} = 40 - 10t - 5h
Let h \to 0:
v(t) = s'(t) = 40 - 10t
At t = 3: v(3) = 40 - 30 = 10 m/s, upward.
At rest: v(t) = 0 when 40 - 10t = 0, i.e. t = 4 s. That's the apex — the instant the ball stops rising and starts falling. Its height there is s(4) = 160 - 80 = 80 m.
Two checks. Units: s is metres, t is seconds, so v should be m/s, and 40 - 10t is (m/s) − (m/s²)(s) ✓. And the sign of v flips from positive to negative at t=4, which is what "reaches a peak" means — the observation §3.5 turns into the first derivative test.
Your turn
1. Use the definition to find f'(x) for f(x) = 3x^2 - 5x + 2.
2. Use the definition to find f'(x) for f(x) = \frac{1}{x+1}.
3. Find the equation of the tangent line to y = x^2 at x = 3.
4. If C(q) is the cost of producing q widgets, what does C'(500) = 12 mean in plain language?
Solutions
1. Expand f(x+h):
3(x+h)^2 - 5(x+h) + 2 = 3x^2 + 6xh + 3h^2 - 5x - 5h + 2
Subtract f(x) = 3x^2 - 5x + 2:
f(x+h) - f(x) = 6xh + 3h^2 - 5h
Divide by h and let h \to 0:
\frac{6xh + 3h^2 - 5h}{h} = 6x + 3h - 5 \longrightarrow \boxed{6x - 5}
2. Compound fraction, so combine first:
\frac{1}{x+1+h} - \frac{1}{x+1} = \frac{(x+1) - (x+1+h)}{(x+1+h)(x+1)} = \frac{-h}{(x+1+h)(x+1)}
Divide by h:
\frac{-1}{(x+1+h)(x+1)} \longrightarrow \boxed{-\frac{1}{(x+1)^2}}
3. The point is (3, 9) and the slope is f'(3) = 6 (from the definition computation above). Point-slope form:
y - 9 = 6(x-3) \implies \boxed{y = 6x - 9}
Sanity check: at x=3, y = 18-9 = 9 ✓. And the tangent should sit below the parabola everywhere else — at x=4 it gives 15 while the curve gives 16 ✓, which is the concavity fact from §3.5.
4. "When you're already producing 500 widgets, making one more costs about $12."
More precisely, C'(500) is the instantaneous rate of change of cost per widget at q = 500 — the marginal cost. The one-more-unit reading is the linear approximation C(501) \approx C(500) + 12, which is accurate exactly to the extent that the cost curve is nearly straight over that one-unit step.
Note it is not the average cost per widget. Average cost is C(500)/500; marginal cost is what the next one adds. They're usually very different, and conflating them is the classic economics error.
Check yourself in code
Compute derivatives from the definition and check them against the known answers.
For f(x) = x^2, f(x) = 1/x, and f(x)=\sqrt x, evaluate the difference quotient at a = 2 with h = 10^{-6}, and compare to the exact values 2a, -1/a^2, 1/(2\sqrt a). Print each to 8 decimals plus the absolute error in scientific notation with 1 decimal.
Print exactly this:
x^2 numeric 4.00000100 exact 4.00000000 err 1.0e-06
1/x numeric -0.24999988 exact -0.25000000 err 1.2e-07
sqrt(x) numeric 0.35355335 exact 0.35355339 err 4.4e-08
from math import sqrt
a, h = 2.0, 1e-6
cases = [
("x^2", lambda x: x * x, 2 * a),
("1/x", lambda x: 1 / x, -1 / a**2),
("sqrt(x)", sqrt, 1 / (2 * sqrt(a))),
]
for name, f, exact in cases:
# difference quotient at a, then compare to exact
print(f"{name:<8} ...")
from math import sqrt
a, h = 2.0, 1e-6
cases = [
("x^2", lambda x: x * x, 2 * a),
("1/x", lambda x: 1 / x, -1 / a**2),
("sqrt(x)", sqrt, 1 / (2 * sqrt(a))),
]
for name, f, exact in cases:
num = (f(a + h) - f(a)) / h
print(f"{name:<8} numeric {num:.8f} exact {exact:.8f} err {abs(num - exact):.1e}")
The derivative is one specific limit — the difference quotient as the step goes to zero — and it's a \frac00 form every single time, which is why §1 came first. Read it as a tangent slope, an instantaneous rate, or the best linear approximation; all three are the same number. Computing it from the definition means factoring, conjugating, or combining fractions, exactly as before.
Next: when that limit fails to exist, and why differentiability is strictly stronger than continuity.