Calculus/The chain rule and Clairaut's theorem

Let $$f:\R^m\to\R^n$$ be a function and let $$g:\R^n\to\R^l$$ be another function. Assume that $$g$$ is differentiable at $$x_0$$ and that $$f$$ is differentiable at $$g(x_0)$$.
 * Theorem

Then $$f\circ g$$ is differentiable at $$x_0$$ and
 * $$(f\circ g)'(x_0)=f'\big(g(x_0)\big)\circ g'(x_0)$$

We prove that $$f'(g(x_0))\circ g'(x_0)$$ is a valid differential of $$f\circ g$$, thereby proving differentiability.
 * Proof

We begin by noting from the second triangle inequality, that
 * $$\left|\frac{\big\|g(x_0+\mathbf h)-g(x_0)\big\|}{\|\mathbf h\|}-\frac{\|g'(x_0)\mathbf h\|}{\|\mathbf h\|}\right|\le\frac{\Big\|g(x_0+\mathbf h)-\big[g(x_0)+g'(x_0)\mathbf h\big]\Big\|}{\|\mathbf h\|}\to0,\mathbf h\to0$$

and hence the boundedness of
 * $$\frac{\|g'(x_0)\mathbf h\|}{\|\mathbf h\|}\le\frac{mn\max\limits_{1\le i\le n\atop1\le j\le m}|a_{i,j}|\|\mathbf h\|}{\|\mathbf h\|}$$

implies that of
 * $$\frac{\big\|g(x_0+\mathbf h)-g(x_0)\big\|}{\|\mathbf h\|}$$

where $$A=(a_{i,j})_{1\le i\le n\atop1\le j\le m}$$ is the matrix of $$g'(x_0)$$.

Now we note by the triangle inequality, that
 * $$\begin{align}

&\frac{\Big\|(f\circ g)(x_0+\mathbf h)-\big[(f\circ g)(x_0)+f'\big(g(x_0)\big)g'(x_0)\mathbf h\big]\Big\|}{\|\mathbf h\|}\\ &\le\frac{\bigg\|f\big(g(x_0+h)\big)-\Big[f\big(g(x_0)\big)+f'\big(g(x_0)\big)\big[g(x_0+h)-g(x_0)\big]\Big]\bigg\|}{\|\mathbf h\|}\\ &+\frac{\bigg\|f\big(g(x_0)\big)+f'\big(g(x_0)\big)\big[g(x_0+h)-g(x_0)\big]-\Big[(f\circ g)(x_0)+f'\big(g(x_0)\big)g'(x_0)\mathbf h\Big]\bigg\|}{\|\mathbf h\|} \end{align}$$ We shall first treat the first summand, which is more difficult, but not so difficult still. We rewrite it as
 * $$\frac{\bigg\|f\big(g(x_0+h)\big)-\Big[f\big(g(x_0)\big)+f'\big(g(x_0)\big)\big[g(x_0+h)-g(x_0)\big]\Big]\bigg\|}{\big\|g(x_0+h)-g(x_0)\big\|}\cdot\frac{\big\|g(x_0+h)-g(x_0)\big\|}{\|\mathbf h\|}$$

The latter factor is bounded due to the above considerations, and the first one converges to 0 as $$h\to0$$ (and thus $$g(x_0+h)\to g(x_0)$$ due to the same boundedness (multiply with $$\|h\|$$); in fact, differentiability thus implies continuity).

Now for the second summand, which, by elementary cancellation and linearity of differentials, equals
 * $$\frac{\bigg\|f'\big(g(x_0)\big)\Big[\big[g(x_0+h)-g(x_0)\big]-g'(x_0)\mathbf h\Big]\bigg\|}{\|\mathbf h\|}\le mn\max_{1\le i\le l\atop1\le j\le n}|b_{i,j}|\frac{\Big\|\big[g(x_0+h)-g(x_0)\big]-g'(x_0)\mathbf h\Big\|}{\|\mathbf h\|}$$

where $$B=(b_{i,j})_{1\le i\le l\atop1\le j\le n}$$ is the matrix of the differential of $$f$$. This goes to 0 as $$\mathbf h\to0$$ due to the definition of the differential of $$f$$.

The gradient
The first application of the chain rule that we shall present has something to do with a thing called gradient, which is defined for functions $$f:\R^n\to\R$$, that is, the image is one-dimensional (in the special case $$n=2$$ these functions look like "mountains" of a function on the plane $$\R^2$$).

Let $$f:\R^n\to\R$$ be differentiable. Then the column vector
 * Definition
 * $$\nabla f(x):=\begin{pmatrix}\dfrac{\partial f}{\partial x_1}\\\vdots\\\dfrac{\partial f}{\partial x_n}\end{pmatrix}$$

is called the gradient.

Theorem:

Let $$f,g:\R^n\to\R$$ be two functions totally differentiable at $$x_0$$. Since they both map to $$\R$$, their product is defined, and we have
 * $$\nabla(fg)=f\nabla g+g\nabla f$$

Proof:

Now one could compute this directly from the definition of the gradient and the usual one-dimensional product rule (which actually has the merit of not requiring total differentiability), but there is a clever trick using the chain rule, which I found in Terence Tao's lecture notes, on which I based my repetition of this part of mathematics.

We simply define $$h:\R^n\to\R^2,h(x):=\big(f(x),g(x)\big)$$ and $$i:\R^2\to\R,i(x,y):=x\cdot y$$. Then the function $$f\times g$$ equals $$i\circ h$$. Now the differential of $$i$$ is given by the Jacobian matrix
 * $$J_i(x,y)=(y\ x)$$

and the differential of $$h$$ is given by the Jacobian matrix
 * $$J_h(x)=\begin{pmatrix}

\dfrac{\partial f}{\partial x_1}(x)&\cdots&\dfrac{\partial f}{\partial x_n}(x)\\ \dfrac{\partial g}{\partial x_1}(x)&\cdots&\dfrac{\partial g}{\partial x_n}(x) \end{pmatrix}$$ Hence, the product rule implies that the differential of $$i\circ h$$ at $$x$$ is given by
 * $$\begin{pmatrix}g(x)&f(x)\end{pmatrix}\begin{pmatrix}

\dfrac{\partial f}{\partial x_1}(x)&\cdots&\dfrac{\partial f}{\partial x_n}(x)\\ \dfrac{\partial g}{\partial x_1}(x)&\cdots&\dfrac{\partial g}{\partial x_n}(x) \end{pmatrix}$$ and from the definition of the gradient we see that the differential is nothing but the transpose of the gradient (and vice versa, as taking transpose is idempotent).

Now we shall use the chain rule to generalize a well-known theorem from one dimension, the mean value theorem, to several dimensions.

Theorem:

Let $$f:\R^n\to\R$$ be totally differentiable, and let $$a\ne b\in\R^n$$. Then there exists $$t\in[0,1]$$ such that
 * $$f(b)-f(a)=\bigl\langle b-a,\nabla f\bigl(tb+(1-t)a\bigr)\bigr\rangle$$

where $$\langle\cdot,\cdot\rangle$$ is the standard scalar product on $$\R^n$$.

Proof:

This is actually a straightforward application of the chain rule.

We set
 * $$g(\lambda):=f\bigl((1-\lambda)a+\lambda b\bigr)$$

thus $$g(0)=f(a)$$ and $$g(1)=f(b)$$. By the one-dimensional mean-value theorem,
 * $$g(1)-g(0)=g'(t)$$

for a suitable $$t\in[0,1]$$. Now by the chain rule,
 * $$g'(t)=\bigl\langle b-a,\nabla f\bigl(tb+(1-t)a\bigr)\bigr\rangle$$.

Clairaut's theorem
The next theorem shows that the order of differentiation does not matter, provided that the considered function is sufficiently differentiable. We will not need the general chain rule or any of its consequences during the course of the proof, but we will use the one-dimensional mean-value theorem.

Proof:

We begin with the following lemma:

Lemma:
 * $$\partial_j\partial_if(x)=\lim_{\delta\to0}\frac{f(x)-f(x+\delta e_i)-f(x+\delta e_j)+f\bigl(x+\delta(e_i+e_j)\bigr)}{\delta^2}$$

Proof: We first apply the fundamental theorem of calculus to obtain that the above limit equals
 * $$\lim_{\delta\to0}\frac{1}{\delta^2}\left(\int\limits_0^\delta\partial_if(x+se_i)ds-\int\limits_0^\delta\partial_if(x+\delta e_j+se_i)ds\right)$$

Using integration by substitution and linearity of the integral, we may rewrite this as
 * $$\lim_{\delta\to0}\frac{1}{\delta}\int\limits_0^1\bigl(\partial_if(x+\delta se_i)-\partial_if(x+\delta e_j+\delta se_i)\bigr)ds$$

Now we apply the mean value theorem in one variable to obtain
 * $$\partial_if(x+\delta se_i)-\partial_if(x+\delta e_j+\delta se_i)=\delta\partial_j\partial_if(x+\delta se_i+t_\delta e_j)$$

for a suitable $$t_\delta\in[0,\delta]$$. Hence, the above limit equals
 * $$\lim_{\delta\to0}\int\limits_0^1\partial_j\partial_if(x+\delta se_i+t_\delta e_j)ds$$

This is the average of $$\partial_j\partial_if$$ over a certain subset of $$B_\delta(x)$$ and therefore converges to $$\partial_j\partial_if(x)$$ by the continuity of $$\partial_j\partial_if$$ (you can prove this rigorously by using
 * $$\partial_j\partial_if(x)=\int\limits_0^1\partial_j\partial_if(x)ds$$

and subtracting the integrals and applying the triangle inequality for integrals).

Now the expression of the lemma is totally symmetric in $$i$$ and $$j$$, which is why Clairaut's theorem follows.