Skip to content
Math Foundations

Derivatives

How a function's output responds to a change in its input: instantaneous rate of change, differentiation rules, and partial derivatives.

Vectors and matrices describe objects and transformations. But many problems come down to a more basic question: if an input changes by a tiny amount, how does the output respond? The tool for measuring that response is the derivative.

The Derivative

The derivative of a function ff at a point xx is the instantaneous rate of change. Increase xx by a small amount ε\varepsilon; the derivative captures how much f(x)f(x) changes in response, as ε\varepsilon shrinks to zero:

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

Geometrically, f′(x)f'(x) is the slope of the tangent line to the curve at xx. A large positive value means the function is rising steeply. Zero means a flat region, typically a minimum or maximum. Negative means the function is falling.

Take f(x)=x2f(x) = x^2, whose derivative is f′(x)=2xf'(x) = 2x:

  • At x=1x = 1: slope =2= 2, the function is rising.
  • At x=0x = 0: slope =0= 0, the bottom of the parabola.
  • At x=−1x = -1: slope =−2= -2, the function is falling as xx increases.

Two notations appear interchangeably. Lagrange notation writes f′(x)f'(x). Leibniz notation writes dfdx\dfrac{df}{dx}, which reads as "the rate of change of ff with respect to xx." Both mean the same thing; you will encounter both in papers and code.

Differentiation Rules

Computing derivatives from the limit definition every time would be impractical. A handful of rules covers the vast majority of cases:

  • Power: ddx[xn]=nxn−1\dfrac{d}{dx}[x^n] = nx^{n-1}
  • Constant: ddx[c]=0\dfrac{d}{dx}[c] = 0
  • Constant multiple: ddx[c⋅f]=c⋅f′\dfrac{d}{dx}[c \cdot f] = c \cdot f'
  • Sum: ddx[f+g]=f′+g′\dfrac{d}{dx}[f + g] = f' + g'
  • Product: ddx[f⋅g]=f′g+fg′\dfrac{d}{dx}[f \cdot g] = f'g + fg'
  • Chain: ddx[f(g(x))]=f′(g(x))⋅g′(x)\dfrac{d}{dx}[f(g(x))] = f'(g(x)) \cdot g'(x)

The chain rule handles composed functions: apply gg, then apply ff to the result. Its derivative is the product of the two individual derivatives, evaluated at the right point. It is fundamental enough to have its own article.

A few examples using these rules:

ddx[3x4]=12x3ddx[x2+5x]=2x+5ddx[sin⁡(x2)]=cos⁡(x2)⋅2x\frac{d}{dx}[3x^4] = 12x^3 \qquad \frac{d}{dx}[x^2 + 5x] = 2x + 5 \qquad \frac{d}{dx}[\sin(x^2)] = \cos(x^2) \cdot 2x

The last one uses the chain rule: f=sin⁡f = \sin, g=x2g = x^2.

Functions of Multiple Variables

Some functions take more than one input. Consider f(x,y)=x2+3xyf(x, y) = x^2 + 3xy. How does ff respond when xx changes? When yy changes?

Each question has its own answer: a partial derivative. To compute ∂f∂x\dfrac{\partial f}{\partial x}, treat yy as a fixed constant and differentiate with respect to xx alone:

∂f∂x=2x+3y\frac{\partial f}{\partial x} = 2x + 3y

To compute ∂f∂y\dfrac{\partial f}{\partial y}, treat xx as a fixed constant:

∂f∂y=3x\frac{\partial f}{\partial y} = 3x

The symbol ∂\partial signals that other variables are held fixed. Each partial derivative is a standard one-variable derivative in disguise — the slope along one axis of a multi-dimensional surface, with every other axis frozen.

At the point (x,y)=(2,1)(x, y) = (2, 1):

∂f∂x∣(2,1)=2(2)+3(1)=7∂f∂y∣(2,1)=3(2)=6\frac{\partial f}{\partial x}\bigg|_{(2,1)} = 2(2) + 3(1) = 7 \qquad \frac{\partial f}{\partial y}\bigg|_{(2,1)} = 3(2) = 6

Nudging xx by a small amount has a larger effect than nudging yy by the same amount, at that specific point.

In Code

The limit definition translates directly into a numerical approximation. Using two nearby points (centered difference) instead of a one-sided limit gives better accuracy for the same ε\varepsilon:

def deriv(f, x, eps=1e-5):
    return (f(x + eps) - f(x - eps)) / (2 * eps)

f = lambda x: x ** 2
print(deriv(f, 1.0))   # 2.0  —  f'(x) = 2x, so f'(1) = 2
print(deriv(f, 3.0))   # 6.0

# Partial derivatives of g(x, y) = x² + 3xy, evaluated at (2, 1)
g = lambda x, y: x**2 + 3*x*y
print(deriv(lambda x: g(x, 1.0), 2.0))   # 7.0  —  ∂g/∂x = 2x + 3y
print(deriv(lambda y: g(2.0, y), 1.0))   # 6.0  —  ∂g/∂y = 3x

For a function of nn inputs, there are nn partial derivatives: one for each axis of the space. Listing them all in order turns them into a vector, and that vector has a precise geometric meaning of its own. That is the subject of the next article.