Math for AILoading progress…

Basic rules

Calculate slopes, use the chain rule and distinguish derivatives from partial derivatives.

Three rules cover every polynomial

Computing a limit for every function would be exhausting. Instead we compute a few once and combine them.

  • Constant: a constant never changes, so its slope is 0. d/dx 7 = 0.
  • Power rule: d/dx xn = n·xn−1. Bring the exponent down, then lower it by one. So x² gives 2x, x³ gives 3x² and x (which is x¹) gives 1.
  • Constant multiple and sum: d/dx (c·f) = c·f′ and d/dx (f + g) = f′ + g′. Differentiate term by term.

Together: d/dx (3x² + 2x + 5) = 3·2x + 2·1 + 0 = 6x + 2, the answer to the quiz question.

See a function and its derivative together

The blue curve is f. The orange curve is f′: its height at x is the slope of the blue curve at x. Change the coefficients and probe different x. Notice three habits: where blue is flat, orange crosses zero. Where blue rises, orange is above zero. Where blue falls, orange is below. And adding a constant lifts blue without changing orange at all.

-3-2-10123-12-8-404812
x³0x²1x010
f(x) = x²
f′(x) = 2x
f(1) = 1
slope of the green tangent (numerical) = 2.0000
f′(1) from the rule = 2.0000

The orange dot rides at height f′(x) above or below the blue dot. Where the blue curve is flat the orange dot sits on the axis.

Set x² (c₂ = 1, others 0) and watch the orange line 2x. Then raise c₀ and see that only the blue curve moves.

Predict first. What is the derivative of f(x) = x³ + 4x − 9?

Match the slope to the graph

Reading a derivative graph is a skill of its own. For each blue curve choose the orange graph that shows its slope. Think about where the blue curve rises, falls and flattens before you click.

f(x) = x² (blue). Which orange graph is f′?

-2-1012-6-3036912

f(x) = x³ (blue). Which orange graph is f′?

-2-1012-6-3036912

f(x) = 3x + 1 (blue). Which orange graph is f′?

-2-1012-6-3036912

f(x) = x² − 2x (blue). Which orange graph is f′?

-2-1012-6-3036912

0 of 0 answered correctly.

Four functions, four candidates each. You can answer each only once.

Common mistake: confusing f with f′

A derivative is a new function. Its value is a slope, not a height. The check below compares the power rule with a numerical slope:

f = lambda x: x ** 3
h = 1e-5
print((f(2 + h) - f(2 - h)) / (2 * h))
print(3 * 2 ** 2, 2 ** 2)
# output:
12.00000000021184
12 4
Chapter context

A derivative measures a local rate of change. It describes what a function does under a very small input change, rather than its average behavior over an arbitrary interval. This local sensitivity is what training algorithms use.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

f′(x)=lim⁡h→0f(x+h)−f(x)h.f'(x)=\lim_{h\to0}\frac{f(x+h)-f(x)}h. ddxf(g(x))=f′(g(x))g′(x),∂∂x(x2+3xy)=2x+3y.\frac{d}{dx}f(g(x))=f'(g(x))g'(x),\quad \frac{\partial}{\partial x}(x^2+3xy)=2x+3y.

For numerical checking, use (f(x+h)−f(x−h))/(2h)(f(x+h)-f(x-h))/(2h) and report a tolerance.

Worked example

Let f(x)=(3x+1)^2. At x=2, the inner value is 7, its derivative is 3, and the outer derivative is 14. Multiplying gives 42. A central difference with h=0.00001 gives approximately the same answer, within numerical error.

Reference code

The following example uses the Python standard library and does not call a remote service.

from math import isclose
f = lambda x: (3*x + 1)**2
x, h = 2, 1e-5
analytic = 6*(3*x + 1)
numeric = (f(x+h)-f(x-h))/(2*h)
assert analytic == 42
assert isclose(numeric, analytic, rel_tol=1e-7)

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

A function value is not its derivative. The chain rule multiplies sensitivities, not intermediate values. At a corner such as abs(x) at zero, a two-sided derivative does not exist.