TExcelTAD
Home › Calculus in Depth › The Derivative as a Function

The Derivative as a Function

Letting the point aa vary turns the derivative into a new function f′f', whose value at each xx is the slope of ff there. This lesson covers the notations, how the graph of f′f' is read off the graph of ff, where derivatives fail to exist, the theorem that differentiability implies continuity, and higher derivatives.

For a first look see The Derivative and Differentiability in the survey course. Here we prove the key theorem and look closely at the failure cases.

f′f' as a function

f′(x)=lim⁡h→0f(x+h)−f(x)hf'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}

The domain of f′f' is the set of xx where this limit exists; it can be smaller than the domain of ff. Example: f(x)=xf(x) = \sqrt{x} (domain x≥0x \ge 0).

x+h−xh=1x+h+x→12x\frac{\sqrt{x + h} - \sqrt{x}}{h} = \frac{1}{\sqrt{x + h} + \sqrt{x}} \to \frac{1}{2\sqrt{x}}

So f′(x)=12xf'(x) = \frac{1}{2\sqrt{x}}, defined only for x>0x > 0. At x=0x = 0 the quotient h/h=1/h→∞\sqrt{h}/h = 1/\sqrt{h} \to \infty: a vertical tangent.

Notations

Notation Read as Notes
f′(x)f'(x) "f prime of x" Lagrange
dydx\frac{dy}{dx}, dfdx\frac{df}{dx} "dee y dee x" Leibniz; reminds you of Δy/Δx\Delta y/\Delta x
Df(x)Df(x), DxfD_x f "D of f" DD is the differentiation operator
y˙\dot{y} "y dot" Newton; time derivatives in physics

The value at a point is written f′(a)f'(a) or dydx∣x=a\left.\frac{dy}{dx}\right\rvert_{x=a}.

python · try it yourself
import sympy as sp

x, h = sp.symbols('x h', positive=True)
for f in [sp.sqrt(x), x**3 - 4*x, 1/(x + 1)]:
    from_def = sp.limit((f.subs(x, x + h) - f)/h, h, 0)
    print(f"f = {str(f):12}  from definition: {str(sp.factor(from_def)):18}  sp.diff: {sp.diff(f, x)}")
f = sqrt(x)       from definition: 1/(2*sqrt(x))       sp.diff: 1/(2*sqrt(x))
f = x**3 - 4*x    from definition: 3*x**2 - 4          sp.diff: 3*x**2 - 4
f = 1/(x + 1)     from definition: -1/(x + 1)**2       sp.diff: -1/(x + 1)**2

(The symbols are declared positive so that SymPy can simplify  \sqrt{\ } freely; the formulas hold wherever they are defined.)

Reading f′f' from the graph of ff

  • Where ff rises, f′>0f' > 0; where ff falls, f′<0f' < 0.
  • At a smooth peak or valley, the tangent is horizontal: f′=0f' = 0.
  • Where ff is steepest, ∣f′∣\lvert f' \rvert is largest.
python · try it yourself
import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(-2.5, 2.5, 501)
f = x**3 - 3*x
df = np.gradient(f, x)                  # numerical derivative (central differences)
fig, (a1, a2) = plt.subplots(2, 1, figsize=(6, 5), sharex=True)
a1.plot(x, f); a1.set_ylabel("f(x) = x³ − 3x"); a1.grid(alpha=0.3)
a2.plot(x, df, "C1"); a2.axhline(0, color="k", lw=0.6); a2.set_ylabel("f′(x)"); a2.grid(alpha=0.3)
zeros = x[np.where(np.diff(np.sign(df)) != 0)[0]]
print("f′ changes sign near x =", [round(float(z), 2) for z in zeros])
print("max error vs 3x² − 3 (interior):", round(float(np.max(np.abs(df[1:-1] - (3*x[1:-1]**2 - 3)))), 10))
f′ changes sign near x = [-1.0, 0.99]
max error vs 3x² − 3 (interior): 0.0001

The sign changes of f′f' sit at x=±1x = \pm 1, the peak and valley of ff. NumPy's np.gradient uses central differences with step 0.010.01, so its error on a cubic is exactly h2=10−4h^2 = 10^{-4}.

Differentiable implies continuous

ff is differentiable at aa if f′(a)f'(a) exists, and differentiable on an open interval if it is differentiable at every point of it.

Theorem. If ff is differentiable at aa, then ff is continuous at aa.

Proof. For x≠ax \ne a,

f(x)−f(a)=f(x)−f(a)x−a⋅(x−a)f(x) - f(a) = \frac{f(x) - f(a)}{x - a} \cdot (x - a)

By the product law,

lim⁡x→a[f(x)−f(a)]=lim⁡x→af(x)−f(a)x−a⋅lim⁡x→a(x−a)=f′(a)⋅0=0\lim_{x \to a} [f(x) - f(a)] = \lim_{x \to a} \frac{f(x) - f(a)}{x - a} \cdot \lim_{x \to a} (x - a) = f'(a) \cdot 0 = 0

so lim⁡f(x)=f(a)\lim f(x) = f(a), which is continuity at aa. ∎

The converse is false: ∣x∣\lvert x \rvert is continuous at 00 but not differentiable there. Continuity is necessary for differentiability, not sufficient. (There are even continuous functions differentiable nowhere, such as the Weierstrass function.)

Three ways to fail

Failure Example at 0 What the difference quotient does
Corner or kink ∣x∣\lvert x \rvert, ReLU max⁡(0,x)\max(0, x) one-sided limits differ (−1-1 vs 11, or 00 vs 11)
Discontinuity step function blows up on one side (theorem above)
Vertical tangent x3\sqrt[3]{x} →∞\to \infty

For corners we still speak of one-sided derivatives: the right derivative of ReLU at 00 is 11, the left derivative is 00.

Higher derivatives

The derivative of f′f' is the second derivative f′′=(f′)′f'' = (f')', written d2ydx2\frac{d^2y}{dx^2}. Then f′′′f''', and f(n)f^{(n)} in general. For position s(t)s(t): s′s' is velocity, s′′s'' acceleration, s′′′s''' jerk. Geometrically, f′′>0f'' > 0 means the slope is increasing (the graph bends upward), a theme of How Derivatives Affect the Shape of a Graph. Example: f(x)=x4−2x2f(x) = x^4 - 2x^2 has f′=4x3−4xf' = 4x^3 - 4x, f′′=12x2−4f'' = 12x^2 - 4, f′′′=24xf''' = 24x, f(4)=24f^{(4)} = 24 and f(n)=0f^{(n)} = 0 for n≥5n \ge 5.

In software

  • ReLU and subgradients. ReLU is not differentiable at 00; frameworks such as PyTorch simply use the left or right derivative there (usually 00). The corner lies on a set of measure zero, so training rarely notices (Machine Learning).
  • Smooth motion. Animation curves are judged by their derivatives: continuous position but discontinuous velocity looks like a jolt, so splines are built to keep f′f' (and often f′′f'') continuous at the joints (Game Math).
  • Jerk-limited motion in robotics, elevators and CNC machines keeps s′′′s''' bounded for comfort and mechanical safety.

Exercises

Exercise 1: Derivative from the definition

Find f′(x)f'(x) from the definition for f(x)=2x2−x+7f(x) = 2x^2 - x + 7.

Answer

f′(x)=4x−1f'(x) = 4x - 1

Solution
f(x+h)−f(x)=2(2xh+h2)−h=4xh+2h2−hdivide by h: 4x+2h−1→4x−1\begin{aligned} &f(x + h) - f(x) = 2(2xh + h^2) - h = 4xh + 2h^2 - h \\ &\text{divide by } h{:}\ 4x + 2h - 1 \to 4x - 1 \end{aligned}

Exercise 2: Domain of f′f'

Find f′(x)f'(x) for f(x)=x−3f(x) = \sqrt{x - 3} and state the domains of ff and f′f'.

Answer

f′(x)=12x−3f'(x) = \frac{1}{2\sqrt{x - 3}}; domain of ff is [3,∞)[3, \infty), of f′f' is (3,∞)(3, \infty).

Solution
x+h−3−x−3h=1x+h−3+x−3→12x−3at x=3 the quotient is h/h=1/h→∞ (vertical tangent), so 3 is excluded\begin{aligned} &\frac{\sqrt{x + h - 3} - \sqrt{x - 3}}{h} = \frac{1}{\sqrt{x + h - 3} + \sqrt{x - 3}} \to \frac{1}{2\sqrt{x - 3}} \\ &\text{at } x = 3 \text{ the quotient is } \sqrt{h}/h = 1/\sqrt{h} \to \infty \text{ (vertical tangent), so 3 is excluded} \end{aligned}

Exercise 3: One-sided derivatives

g(x)=x2g(x) = x^2 for x≤1x \le 1 and g(x)=2x−1g(x) = 2x - 1 for x>1x > 1. Is gg continuous at 11? Differentiable?

Answer

Continuous (both sides give 1) and differentiable, with g′(1)=2g'(1) = 2.

Solution
continuity: left value 12=1, right limit 2−1=1, g(1)=1left derivative: (1+h)2−1h=2+h→2(h<0)right derivative: 2(1+h)−1−1h=2(h>0)both equal 2, so g′(1)=2\begin{aligned} &\text{continuity: left value } 1^2 = 1, \text{ right limit } 2 - 1 = 1,\ g(1) = 1 \\ &\text{left derivative: } \frac{(1 + h)^2 - 1}{h} = 2 + h \to 2 && (h < 0) \\ &\text{right derivative: } \frac{2(1 + h) - 1 - 1}{h} = 2 && (h > 0) \\ &\text{both equal 2, so } g'(1) = 2 \end{aligned}

Exercise 4: Higher derivatives in SymPy

For s(t)=t3−6t2+9ts(t) = t^3 - 6t^2 + 9t (metres, seconds), find the times when the velocity is zero and the acceleration at those times.

Answer

v=0v = 0 at t=1t = 1 and t=3t = 3; acceleration −6 m/s2-6\ \text{m/s}^2 and 6 m/s26\ \text{m/s}^2.

Solution
v=s′=3t2−12t+9=3(t−1)(t−3),a=s′′=6t−12a(1)=−6,a(3)=6\begin{aligned} &v = s' = 3t^2 - 12t + 9 = 3(t - 1)(t - 3), \qquad a = s'' = 6t - 12 \\ &a(1) = -6, \quad a(3) = 6 \end{aligned}
python · try it yourself
import sympy as sp
t = sp.symbols('t')
s = t**3 - 6*t**2 + 9*t
v, a = sp.diff(s, t), sp.diff(s, t, 2)
for r in sp.solve(v, t):
    print(f"t = {r}: acceleration {a.subs(t, r)}")
t = 1: acceleration -6
t = 3: acceleration 6

Test yourself

Which statement is true?

  1. Every continuous function is differentiable
  2. Every differentiable function is continuous
  3. A function with a vertical tangent is differentiable there
  4. ∣x∣\lvert x \rvert is not continuous at 0

The key step in proving that differentiability implies continuity is writing f(x)−f(a)f(x) - f(a) as what?

  1. f′(a)⋅xf'(a) \cdot x
  2. f(x)−f(a)x−a⋅(x−a)\frac{f(x) - f(a)}{x - a} \cdot (x - a)
  3. f(x)⋅f(a)f(x) \cdot f(a)
  4. (x−a)2(x - a)^2

What are the left and right derivatives of ReLU⁡(x)=max⁡(0,x)\operatorname{ReLU}(x) = \max(0, x) at 0?

  1. Both 0
  2. Both 1
  3. Left 0, right 1
  4. Left 1, right 0