17. Differentiability vs. continuity
The derivative is a limit, and §1 spent a whole module on the ways a limit can fail. So a function can be perfectly well-behaved and still have no derivative at a point.
The relationship between the two properties is one-directional, and knowing which direction saves you from a very common error.
Differentiable implies continuous
If f is differentiable at a, then f is continuous at a.
Proof. Continuity at a means \lim_{x\to a}\left[f(x)-f(a)\right] = 0. Write that difference in a way that lets the derivative appear — multiply and divide by (x-a), legal since x \neq a in the limit:
f(x)-f(a) = \frac{f(x)-f(a)}{x-a}\cdot(x-a)
Both factors have limits: the first is f'(a) by hypothesis, the second is 0. By the product law,
\lim_{x\to a}\left[f(x)-f(a)\right] = f'(a)\cdot 0 = 0 \qquad\blacksquare
The intuition: a derivative existing means the function is locally almost linear, and a linear function certainly has no jumps.
Where the hypothesis enters is worth noticing. The product law needs both limits to exist, and it's differentiability that supplies the first one. Without it the argument gives nothing.
The converse is false
Continuity does not imply differentiability. The standard witness:
f(x) = |x| \quad\text{at } x = 0
It's continuous — \lim_{x\to0}|x| = 0 = f(0), no argument. But the difference quotient is
\frac{|0+h| - |0|}{h} = \frac{|h|}{h}
which is +1 for h > 0 and -1 for h < 0. The one-sided limits exist and disagree, so the two-sided limit doesn't exist and f'(0) doesn't exist.
That's the jump discontinuity from §1.2 — but in the difference quotient, not in the function itself. Geometrically: the graph has a corner, and a corner has no single tangent line. Approaching from the left you'd draw a line of slope -1, from the right slope +1, and there is no way to choose.
Continuity is about the function's values; differentiability is about the function's slopes. The second is strictly stronger.
The four ways to fail
1. Corner. The one-sided derivatives exist and differ. |x| at 0. The graph has a sharp bend.
2. Cusp. The one-sided derivatives run to +\infty and -\infty. f(x) = x^{2/3} at 0:
f'(x) = \frac{2}{3}x^{-1/3} = \frac{2}{3\sqrt[3]{x}}
which blows up in opposite directions on the two sides. Sharper than a corner — the graph comes to a point with vertical edges.
3. Vertical tangent. Both sides run to +\infty (or both to -\infty). f(x) = x^{1/3} at 0:
f'(x) = \frac{1}{3}x^{-2/3} = \frac{1}{3x^{2/3}} \to +\infty
The curve is smooth and has an unambiguous tangent line — it's just vertical, so its slope is not a number. The derivative doesn't exist, but for the mildest possible reason.
4. Discontinuity. If f isn't continuous at a it certainly isn't differentiable there — that's the contrapositive of the theorem above. Jumps, blow-ups, and oscillations all qualify.
The one from §1.7, revisited
Recall
h(x) = \begin{cases}x\sin(1/x) & x \neq 0\\ 0 & x=0\end{cases}
which §1.7 showed is continuous at 0 by the squeeze theorem. Is it differentiable there?
\frac{h(0+t) - h(0)}{t} = \frac{t\sin(1/t) - 0}{t} = \sin\!\left(\frac1t\right)
The t cancels perfectly — and leaves exactly the function with no limit at 0. So h'(0) does not exist, and this is failure mode 4's oscillatory variant appearing in the difference quotient.
Bump the power and it changes:
g(x) = \begin{cases}x^2\sin(1/x) & x \neq 0\\ 0 & x=0\end{cases} \implies \frac{g(t)-g(0)}{t} = t\sin\!\left(\frac1t\right) \to 0
by the squeeze. So g'(0) = 0 does exist. One extra factor of x is the whole difference — and the resulting g' is itself discontinuous at 0, which makes g a standard example of a differentiable function whose derivative isn't continuous.
The pathological case
Can a function be continuous everywhere and differentiable nowhere?
Yes. Weierstrass exhibited one in 1872:
W(x) = \sum_{n=0}^{\infty} a^n\cos(b^n\pi x), \qquad 0<a<1,\; b \text{ an odd integer},\; ab > 1 + \tfrac{3\pi}{2}
The odd-integer requirement on b is not decoration — Weierstrass's proof uses it. With a = \tfrac12 the threshold ab > 1 + \tfrac{3\pi}{2} \approx 5.712 forces b > 11.42, so b = 13 is the smallest odd integer that qualifies. (Hardy later proved the far sharper condition ab \ge 1 suffices, which is why you will see gentler parameters elsewhere; the demo below stays inside Weierstrass's own hypothesis.)
Every term is a smooth cosine. The sum converges uniformly (§8.4), so W is continuous. But the frequencies b^n grow faster than the amplitudes a^n shrink, so the wiggle never smooths out at any scale — zoom in anywhere and it looks just as jagged. No tangent line exists anywhere.
This was genuinely shocking in 1872; the prevailing intuition held that a continuous function must be differentiable except at isolated points. It matters beyond curiosity value: Brownian motion paths (§8 of the statistics course) are continuous and nowhere differentiable with probability 1, which is why stochastic calculus needs a different derivative altogether.
Doing it in Python
The corner, one side at a time:
def f(x):
return abs(x)
print(f"{'h':>12} {'(f(h)-f(0))/h':>16}")
for k in (1, 3, 6, 9):
h = 10.0 ** -k
print(f"{h:>12.0e} {(f(h) - f(0)) / h:>16.6f}")
print(f"{-h:>12.0e} {(f(-h) - f(0)) / -h:>16.6f}")
print("\n+1 from the right, -1 from the left: no derivative at 0")
Cusp and vertical tangent, distinguished by their signs:
def cusp(x):
return abs(x) ** (2 / 3)
def vertical(x):
return x ** (1 / 3) if x >= 0 else -((-x) ** (1 / 3))
print(f"{'h':>10} {'x^(2/3) right':>16} {'x^(2/3) left':>16} "
f"{'x^(1/3) right':>16} {'x^(1/3) left':>16}")
for k in (2, 6, 10, 14):
h = 10.0 ** -k
print(f"{h:>10.0e} {cusp(h)/h:>16.1f} {cusp(-h)/-h:>16.1f} "
f"{vertical(h)/h:>16.1f} {vertical(-h)/-h:>16.1f}")
print("\ncusp: +inf and -inf, opposite signs. vertical tangent: +inf both sides.")
The pair that differs by one power of x:
from math import sin
def h_fn(t):
return t * sin(1 / t)
def g_fn(t):
return t * t * sin(1 / t)
print(f"{'t':>10} {'h(t)/t':>14} {'g(t)/t':>14}")
for k in range(2, 9):
t = 10.0 ** -k
print(f"{t:>10.0e} {h_fn(t)/t:>14.6f} {g_fn(t)/t:>14.2e}")
print("\nleft column never settles -> h'(0) does not exist")
print("right column is squeezed to 0 -> g'(0) = 0")
The Weierstrass function, refusing to smooth out:
from math import cos, pi
def W(x, terms=60, a=0.5, b=13):
# a=0.5, b=13: odd integer, ab = 6.5 > 1 + 3*pi/2 = 5.712. hypothesis satisfied.
return sum(a**n * cos(b**n * pi * x) for n in range(terms))
print("secant slopes at x=0.3, over shrinking windows:")
for k in range(1, 9):
h = 10.0 ** -k
print(f" h=1e-{k} slope = {(W(0.3 + h) - W(0.3)) / h:>14.2f}")
print("\nno convergence -- the slopes grow without bound as you zoom in.")
print("continuous everywhere, differentiable nowhere.")
Worked example
For f(x) = \begin{cases}x^2 & x \le 1\\ 2x - 1 & x > 1\end{cases}, is f continuous at 1? Differentiable?
Continuity. Check both sides and the value:
\lim_{x\to1^-}x^2 = 1, \qquad \lim_{x\to1^+}(2x-1) = 1, \qquad f(1) = 1
All three agree, so continuous. ✓
Differentiability. Compute the one-sided derivatives at 1 — not the derivatives of the formulas, but the actual one-sided limits of the difference quotient. (In practice, for pieces this simple, differentiating each formula and evaluating at the join gives the same thing.)
From the left, f is x^2, whose derivative is 2x, giving 2 at x=1.
From the right, f is 2x-1, whose derivative is 2.
Both one-sided derivatives equal 2, so f'(1) = 2 and f is differentiable. ✓
The graph is a parabola that hands off to a straight line at exactly the point where the parabola's tangent is that line — the pieces meet smoothly, no corner.
Contrast. Change the second piece to 3x - 2. Continuity still holds (3-2 = 1 ✓), but the right derivative is now 3 against a left derivative of 2. Continuous, not differentiable — a corner. Matching values gives continuity; matching slopes is the extra condition differentiability demands.
Your turn
1. Is f(x) = |x-3| differentiable at x=3? Why?
2. Find a, b making f(x) = \begin{cases}ax + b & x < 2\\ x^2 & x \ge 2\end{cases} differentiable everywhere.
3. True or false: if f is continuous on [0,1] then f' exists somewhere in (0,1).
Solutions
1. No. The difference quotient at 3 is
\frac{|3+h-3| - 0}{h} = \frac{|h|}{h}
which is +1 for h>0 and -1 for h<0. The one-sided limits disagree, so no derivative exists. It's |x| shifted right by 3 — a corner at x=3, and shifting doesn't smooth anything.
2. Two conditions, one for each property.
Continuity at 2: the left value 2a + b must equal the right value 4:
2a + b = 4
Differentiability at 2: left slope a must equal right slope 2x|_{x=2} = 4:
a = 4
Substituting: 8 + b = 4, so b = -4.
\boxed{a = 4,\; b = -4}
The line y = 4x-4 is exactly the tangent to y = x^2 at x=2 — which is the only line that can join on smoothly, and a good way to check the answer without redoing the algebra.
3. False, and the Weierstrass function is the counterexample: continuous on [0,1], differentiable at no point of it.
The statement feels true, which is exactly why Weierstrass's example mattered so much in 1872. What is true is a weaker, measure-theoretic version — a monotone continuous function is differentiable almost everywhere (Lebesgue's theorem) — but plain continuity buys you nothing about derivatives at all.
Check yourself in code
Classify differentiability at 0 by comparing one-sided difference quotients.
For each function, compute \frac{f(h)-f(0)}{h} at h = \pm10^{-12} and report:
corner if both sides are bounded (magnitude below 10^{3}) but differ by more
than 10^{-3}; differentiable if both are bounded and agree; vertical if both
blow up with the same sign; cusp if they blow up with opposite signs.
The threshold has to be reachable, which is a real constraint rather than a detail. The cusp's quotient is h^{-1/3}, only 100 at h = 10^{-6} — small enough to pass for bounded. At h = 10^{-12} it is 10^4 and the vertical tangent's is 10^8, so the two regimes separate unambiguously.
Print exactly this:
abs(x) corner
x**2 differentiable
x**(2/3) cusp
x**(1/3) vertical
def signed_root(x, p):
return abs(x) ** p if x >= 0 else -(abs(x) ** p)
funcs = [
("abs(x)", abs),
("x**2", lambda x: x * x),
("x**(2/3)", lambda x: abs(x) ** (2 / 3)),
("x**(1/3)", lambda x: signed_root(x, 1 / 3)),
]
h = 1e-12
for name, f in funcs:
right = (f(h) - f(0)) / h
left = (f(-h) - f(0)) / -h
# classify: corner / differentiable / vertical / cusp
print(f"{name:<13} ...")
def signed_root(x, p):
return abs(x) ** p if x >= 0 else -(abs(x) ** p)
funcs = [
("abs(x)", abs),
("x**2", lambda x: x * x),
("x**(2/3)", lambda x: abs(x) ** (2 / 3)),
("x**(1/3)", lambda x: signed_root(x, 1 / 3)),
]
h = 1e-12
for name, f in funcs:
right = (f(h) - f(0)) / h
left = (f(-h) - f(0)) / -h
bounded = abs(right) < 1e3 and abs(left) < 1e3
if bounded:
verdict = "differentiable" if abs(right - left) < 1e-3 else "corner"
else:
verdict = "vertical" if right * left > 0 else "cusp"
print(f"{name:<13} {verdict}")
Differentiability implies continuity, never the reverse. A function fails to be differentiable at a corner (one-sided slopes differ), a cusp (they run to opposite infinities), a vertical tangent (they run to the same infinity), or anywhere it isn't continuous at all. For piecewise definitions, matching values gives continuity and matching slopes gives differentiability — two conditions, two equations. And continuity alone guarantees nothing: Weierstrass's function is continuous everywhere and differentiable nowhere.
Next: the rules that make all of this fast — starting with the power rule, proved rather than asserted.