# Second partial derivatives

A brief overview of second partial derivative, the symmetry of mixed partial derivatives, and higher order partial derivatives.

## Generalizing the second derivative

Consider a function with a two-dimensional input, such as
f, left parenthesis, x, comma, y, right parenthesis, equals, x, start superscript, 2, end superscript, y, start superscript, 3, end superscript.
Its partial derivatives $\dfrac{\partial f}{\partial x}$ and $\dfrac{\partial f}{\partial y}$ take in that same two-dimensional input left parenthesis, x, comma, y, right parenthesis:
\begin{aligned} \dfrac{\partial f}{\partial \blueE{x}} = \dfrac{\partial}{\partial \blueE{x}}(\blueE{x}^2 y^3) = 2\blueE{x} y^3 \end{aligned}
\begin{aligned} \dfrac{\partial f}{\partial \redE{y}} = \dfrac{\partial}{\partial \redE{y}}(x^2 \redE{y}^3) = 3x^2 \redE{y}^2 \end{aligned}
Therefore, we could also take the partial derivatives of the partial derivatives.
These are called second partial derivatives, and the notation is analogous to the start fraction, d, start superscript, 2, end superscript, f, divided by, d, x, start superscript, 2, end superscript, end fraction notation for the ordinary second derivative in single-variable calculus:
\begin{aligned} \dfrac{\partial}{\partial \blueE{x}} \left(\dfrac{\partial f}{\partial \blueE{x}} \right) &= \dfrac{\partial^2 f}{\partial \blueE{x}^2} \\ \dfrac{\partial}{\partial \blueE{x}} \left(\dfrac{\partial f}{\partial \redE{y}} \right) &= \dfrac{\partial^2 f}{\partial \blueE{x} \partial \redE{y}} \\ \dfrac{\partial}{\partial \redE{y}} \left(\dfrac{\partial f}{\partial \blueE{x}} \right) &= \dfrac{\partial^2 f}{\partial \redE{y} \partial \blueE{x}} \\ \dfrac{\partial}{\partial \redE{y}} \left(\dfrac{\partial f}{\partial \redE{y}} \right) &= \dfrac{\partial^2 f}{\partial \redE{y}^2} \\ \end{aligned}
Using the f, start subscript, x, end subscript notation for the partial derivative (in this case with respect to x), you might also see these second partial derivatives written like this:
\begin{aligned} (f_\blueE{x})_\blueE{x} &= f_{\blueE{x}\blueE{x}} \\ (f_\redE{y})_\blueE{x} &= f_{\redE{y}\blueE{x}} \\ (f_\blueE{x})_\redE{y} &= f_{\blueE{x}\redE{y}} \\ (f_\redE{y})_\redE{y} &= f_{\redE{y}\redE{y}} \\ \end{aligned}
The second partial derivatives which involve multiple distinct input variables, such as f, start subscript, start color redE, y, end color redE, start color blueE, x, end color blueE, end subscript and f, start subscript, start color blueE, x, end color blueE, start color redE, y, end color redE, end subscript, are called "mixed partial derivatives"

## Example 1: The full tree

Problem: Find all the second partial derivatives of f, left parenthesis, x, comma, y, right parenthesis, equals, sine, left parenthesis, x, right parenthesis, y, start superscript, 2, end superscript
Solution: First, find both partial derivatives:
\begin{aligned} \dfrac{\partial}{\partial \blueE{x}} (\sin(\blueE{x})y^2) &= \cos(\blueE{x})y^2 \\ \\ \dfrac{\partial}{\partial \redE{y}} (\sin(x)\redE{y}^2) &= 2\sin(x)\redE{y} \end{aligned}
Then for each one, write both partial derivatives:
\begin{aligned} \dfrac{\partial}{\partial \blueE{x}}\left( \dfrac{\partial}{\partial x}(\sin(x)y^2) \right) &= \dfrac{\partial}{\partial \blueE{x}}(\cos(\blueE{x})y^2) = -\sin(\blueE{x})y^2 \\ \\ \dfrac{\partial}{\partial x}\left( \dfrac{\partial}{\partial y}(\sin(x)y^2) \right) &= \dfrac{\partial}{\partial \blueE{x}}(2\sin(\blueE{x})y) = 2\cos(\blueE{x})y \\ \\ \dfrac{\partial}{\partial \redE{y}}\left( \dfrac{\partial}{\partial x}(\sin(x)y^2) \right) &= \dfrac{\partial}{\partial \redE{y}}(\cos(x)\redE{y}^2) = 2\cos(x)\redE{y} \\ \\ \dfrac{\partial}{\partial \redE{y}}\left( \dfrac{\partial}{\partial y}(\sin(x)y^2) \right) &= \dfrac{\partial}{\partial \redE{y}}(2\sin(x)\redE{y}) = 2\sin(x) \\ \end{aligned}
Second partial derivative tree

## Symmetry of second derivatives

Notice, in the example above, the two mixed partial derivatives $\dfrac{\partial^2 f}{\partial x \partial y}$ and $\dfrac{\partial^2 f}{\partial y \partial x}$ are the same. This is not a coincidence; it happens for almost every function you encounter in practice. For example, look at what happens to a general polynomial term x, start superscript, n, end superscript, y, start superscript, k, end superscript:
\begin{aligned} \frac{\partial}{\partial \blueE{x}}\left( \frac{\partial}{\partial \redD{y}}(\blueE{x}^n \redD{y}^k) \right) &= \frac{\partial}{\partial \blueE{x}}(k \blueE{x}^n \redD{y}^{k-1}) = nk \blueE{x}^{n-1} \redD{y}^{k-1} \\ \frac{\partial}{\partial \redD{y}}\left( \frac{\partial}{\partial \blueE{x}}(\blueE{x}^n \redD{y}^k) \right) &= \frac{\partial}{\partial \redD{y}}(n \blueE{x}^{n-1} \redD{y}^k) = nk \blueE{x}^{n-1} \redD{y}^{k-1} \\ \end{aligned}
Technically, the symmetry of second derivatives is not always true. There is a theorem, referred to variously as Schwarz's theorem or Clairaut's theorem, which states that symmetry of second derivatives will always hold at a point if the second partial derivatives are continuous around that point. To really get into the meat of this, we'd need some real analysis.
You should keep in the back of your mind that exceptions exist, but the symmetry of second derivatives work for just about every "normal" looking function that you will come across.
These mixed derivatives $\dfrac{\partial^2 f}{\partial x \partial y}$ and $\dfrac{\partial^2 f}{\partial y \partial x}$ evaluated at the origin left parenthesis, 0, comma, 0, right parenthesis turn out to be 1 and minus, 1 respectively. Computing this is actually pretty tricky, and requires looking directly at the limit-based definition of the derivative. Wikipedia provides a nice explanation, should you find yourself feeling ambitious.

## Example 2: Higher order derivatives

Why stop at second partial derivatives? We could also take, say, five partial derivatives with respect to various input variables.
Problem: If f, left parenthesis, x, comma, y, comma, z, right parenthesis, equals, sine, left parenthesis, x, y, right parenthesis, e, start superscript, x, plus, z, end superscript, what is f, start subscript, z, y, z, y, x, end subscript?
Solution: The notation f, start subscript, z, y, z, y, x, end subscript is shorthand for left parenthesis, left parenthesis, left parenthesis, left parenthesis, f, start subscript, z, end subscript, right parenthesis, start subscript, y, end subscript, right parenthesis, start subscript, z, end subscript, right parenthesis, start subscript, y, end subscript, right parenthesis, start subscript, x, end subscript, so we differentiate with respect to z, then with respect to y, then z, then y, then x. That is, we read left to right.
It's worth pointing out that the order is different in the other notation:
So the order of differentiation is indicated by the order of the terms in the denominator from right to left.
Anyway, back to the problem at hand. This is one of those tasks where you just have to roll up your sleeves and slog through it, but to help things let's color the variables start color blueD, x, end color blueD, comma, start color redD, y, end color redD, comma, start color greenE, z, end color greenE to keep track of where they all are:
This last step uses the extended product rule,
\begin{aligned} \quad \frac{d}{dx} f(x)g(x)h(x) = f'(x)g(x)h(x) + f(x)g'(x)h(x) + f(x)g(x)h'(x) \end{aligned}
Man! That was a tedious example. But if you could follow all the way through, computing multiple partial derivatives should not be an issue for you. It's one of those things that just requires more bookkeeping than anything else.