\section{The Chain Rule}
In this section, we focus on applying the Chain Rule, with proofs postponed until later. All formulas below are valid, so long as we assume all functions involved are $C^1$ according to the definition we now make.

\begin{definition}
A function $f(x_1,...,x_n)$ is \underline{$C^k$ on an open set $S$} if $f$ and all its partial derivatives of order less than or equal to $k$ are continuous functions on $S$. In particular, $f$ is $C^1$ on $S$ if $f$ and its first-order derivatives $f_1,...,f_n$ are continuous on $S$.
\end{definition}

\medskip
We also say that $f$ is \underline{$C^{\infty}$ on $S$} if $f$ and all of its partial derivatives of any order are continuous on $S$.


\medskip

For example,  polynomials, rational functions, trigonometric functions,  exponentials and all compositions of said functions are $C^{\infty}$ on their domains of definition. 

\subsection{The Chain Rule for Functions of Two Variables} We start by recalling the Chain Rule for single variable functions---this is what we want to generalize.

\begin{theorem} Suppose that $h(x) = f(g(x))$ is the composition of two functions $f$ and $g$ of one real variable.  Further suppose, for some $x$ in $\mathbb{R}$, both $g'(x)$ and $f'(g(x))$ exist. Then $h'(x)$ exists and satisfies
$$
\frac{d}{dx} f (g(x)) = f'(g(x)) \cdot g'(x).
$$ 

\medskip
Written another way, if we let $g(x) = y$ and $f(g(x)) = z$, then
$$
\frac{d z}{d x} = \frac{d z}{d y} \frac{d y}{d x}.
$$
\end{theorem}


\medskip
The situation changes when we have a function of many variables.  For example, if $f(x,y)$ is a function of two variables where $x = x(t)$ and $y = y(t)$ are single variable functions depending on a third variable $t$.  

\begin{example}
Let $(x,y)$ denote the longitude and latitude of a point on a map and let $f(x,y)$ denote the altitude at the point $(x,y)$. Suppose that a hiker is walking along a path so that their coordinates (longitude and latitude) at time $t$ are $(x(t), y(t))$. Then the function $f(x,y) = f(x(t), y(t))$ represents the hiker's altitude at time $t$.
\end{example}

The Chain Rule for functions $f(x(t), y(t))$ is as follows. 

\begin{theorem}
Assume that $x(t)$, $y(t)$, and $f(x(t), y(t))$ are all $C^1$.  Then
$$
\frac{d}{dt} f(x(t), y(t)) = \frac{\partial f}{\partial x} \frac{dx}{dt} + \frac{\partial f}{\partial y	} \frac{dy}{dt}.
$$

\medskip
We use the notation $\frac{d}{dt}$ instead of partial notation $\frac{\partial}{\partial t}$ because $f(x(t), y(t))$ is a function of \underline{one} variable.
\end{theorem}


\medskip

We will see some examples of the Chain Rule applied to functions $f(x(t), y(t))$ in the Worked Examples section.  

\subsection{The Chain Rule for Multiple Variables}
If we have more variables, the Chain Rule tracks the dependence of all ``intermediate'' variables on all ``final'' variables.  For example (again, assuming all functions are $C^1$):
\begin{itemize}
\item If $f(x,y)$ is a function of two variables and $x = x(s,t)$ and $y = y(s,t)$ are also functions of two variables, then
$$
\frac{\partial f}{\partial s} = \frac{\partial f}{\partial x} \frac{\partial x}{\partial s} + \frac{\partial f}{\partial y} \frac{\partial y}{\partial s} \quad \textrm{and} \quad \frac{\partial f}{\partial t} = \frac{\partial f}{\partial x} \frac{\partial x}{\partial t} + \frac{\partial f}{\partial y} \frac{\partial y}{\partial t}.
$$
(This is a situation we will encounter later when we consider change of variables for multivariate functions.)
\smallskip

\item If $f(x,y,z)$ is a function of three variables, and $x,y,z$ are all functions of two variables $(s,t)$, then 
$$
\frac{\partial f}{\partial s} = \frac{\partial f}{\partial x} \frac{\partial x}{\partial s} + \frac{\partial f}{\partial y} \frac{\partial y}{\partial s} + \frac{\partial f}{\partial z} \frac{\partial z}{\partial s},
$$
and the partial derivative with respect to $s$ is similar.


\end{itemize}

An \underline{important special case} is the following. Suppose $f(x,y,z,t)$ is a function of four real variables and we \underline{also} have $x = x(t)$, $y = y(t)$ and $z = z(t)$ given as functions of $t$. Then, assuming all involved functions are $C^1$, the Chain Rule says
$$
\frac{d}{dt} f(x(t), y(t), z(t), t) = \frac{\partial f}{\partial x}\, x' (t) + \frac{\partial f}{\partial y}\, y'(t) + \frac{\partial f}{\partial z} \,z' (t) + \frac{\partial f}{\partial t}.
$$
This is one of the cases where notation does matter. The $\frac{d}{dt}$ on the left indicates the \underline{total} derivative of $f$ with respect to $t$. It takes into account all the ways in which $f$ depends on $t$, including through the intermediate dependent variables $x,y,z$. The derivative $\frac{\partial f}{\partial t}$ is the same as $f_4$, indicating differentiation of $f(x,y,z,t)$  in the fourth variable. 
You can think of it as being multiplied by a factor of $\frac{dt }{dt} = 1$.

\begin{example} Let $f(x,y,z,t)=x+2y+3z+t^2$ and
$$
x(t)=\sin t, \ y(t)= \cos t,\ z(t)=e^t.
$$
Then $\frac{\partial f}{\partial t}=f_4=2t$, but
$$
\frac{d}{dt} f(x(t),y(t),z(t),t)= \frac{d}{dt}(\sin t +2\cos t+3e^t+t^2)= \cos t-2\sin t +3e^t +2t.
$$
\end{example}



Again, as in the case of functions $f(x(t), y(t))$,  functions $f(x,y,z,t)$ can represent real-world phenomena.

\begin{example}
If $(x,y,z)$ are the spatial coordinates in a room and $t$ represents the time variable, we can define a function $f(x,y,z,t)$ as the temperature at the point $(x,y,z)$ in the room at time $t$.  Thinking of a drone flying around the room, with coordinates $(x(t), y(t), z(t))$ at time $t$, the function $f(x(t), y(t), z(t), t)$ represents the temperature measured by the drone at time $t$. 
\end{example}





We can also consider the \underline{higher order partials}. For this, we need to assume that our functions are $C^k$ for some $k > 1$, and iterate the Chain Rule as needed.

\section*{Worked Problems}
\begin{enumerate}[1.]
\item {\it Let $f(x,y) = \sin (3x + y)$ with $x(t) = 2t + 2$ and $y(t) = t^2$. Use the Chain Rule to find $\frac{d}{dt} f(x(t), y(t))$. }


\medskip
We have
\begin{eqnarray*}
\frac{\partial f}{\partial x} = 3 \cos (3 x + y) & , & \frac{\partial f}{\partial y} = \cos (3 x + y) \\[1ex]
\frac{dx}{dt} = 2 & , & \frac{dy}{dt} = 2t
\end{eqnarray*}
Thus,
\begin{eqnarray*}
\frac{d}{dt} f(x(t), y(t)) & = & \frac{\partial f}{\partial x} \frac{d x}{d t} + \frac{\partial f}{\partial y} \frac{d y }{d t} \\[1ex]
\quad & = & 3 \cos (3 x(t) + y(t)) \cdot 2 + \cos (3x(t) + y(t)) \cdot 2t \\[1ex]
\quad & = & (6 + 2t) \cos (t^2 + 6t + 6).
\end{eqnarray*}

\medskip
In this example, we could just have plugged in
$$
f(x(t), y(t)) = \sin  (3 (2t + 2) + t^2) = \sin (t^2 + 6t + 6),
$$
and differentiated in $t$.  We will now see an example where this would not work.

\bigskip

\item {\it At time $t = 0$, a hiker is at a point $(x_0, y_0)$, moving along a trajectory $(x(t), y(t))$ with $x'(0) = 2$ and $y'(0) = -1$. The altitude at $(x,y)$ is given by a function $f(x,y)$ with $\frac{\partial f}{\partial x} (x_0,y_0) = 0.02$ and $\frac{\partial f}{\partial y} (x_0, y_0) = 0.05$. How quickly does the hiker's altitude change?}

\medskip
We solve this using the Chain Rule.  That is,
\begin{eqnarray*}
\frac{d}{dt} f(x(t), y(t)) \vert_{t = 0} & = & \frac{\partial f}{\partial x} (x_0, y_0) \, x'(0) + \frac{\partial f}{\partial y} (x_0, y_0) \, y' (0) \\[1ex]
\quad & = & 0.02 \cdot 2 + 0.05 \cdot (-1) \\[1ex]
\quad & = & -0.01.
\end{eqnarray*}


\bigskip

\item {\it Let $f(x,y)$ be a $C^1$ function such that $f_1 (0,0) = 7$ and $f_2 (0,0) = 3$. Find $\frac{\partial f}{\partial t}$
at $(s,t) = (0,0)$ if $x = 4s - t$ and $y = 2s + 5t$.}

\medskip

When $(s,t) = (0,0)$, one readily checks that $(x(s,t), y(s,t)) = (0,0)$, so that
\begin{eqnarray*}
\frac{\partial f}{\partial t} \vert_{(s,t) = (0,0)} &= & f_1 (0,0) \frac{\partial x}{\partial t} + f_2 (0,0) \frac{\partial y}{\partial t} = 7 \cdot (-1) + 3 \cdot 5 \\[1ex]
\quad & = & 8
\end{eqnarray*}
\end{enumerate}









\section*{Practice Problems}
\begin{enumerate}[1.]
\item
Let $z=f(x,y)$, where $f(x,y)$ is $C^1$ for all $x,y$.
Suppose that $f_x(\sqrt{3},1)=3$ and $f_y(\sqrt{3},1)=5$. If we switch to
polar coordinates $r,\theta$ so that $x=r\cos\theta$, $y=r\sin\theta$, what is 
$\displaystyle \frac{\partial z}{\partial \theta }$ at $(r,\theta)=(2,\pi/6)$? 

\smallskip
\noindent
(Hint: $\sin(\pi/6)=1/2$, $\cos(\pi/6)=\sqrt{3}/2$.)

\bigskip

\item 
Suppose that the temperature at a point with coordinates $(x,y,z)$ and at time $t$
is given by $T(x,y,z,t)= 20+ 3x - 2y + 4 z^2 + xye^{0.03t}$. At time $t=3$, a drone is at the point
$(5,2,1)$ and flies along a trajectory such that $x'(3)=7$, $y'(3)=2$, $z'(3)=-1$. What is the
rate of change of the temperature measured by the drone at $t=3$?

\bigskip

\item 
Let $z=f(u,v)$, where $f(u,v)$ is $C^1$ for all $u,v$.
Let $u=xy$, $v=y/x$.

\begin{itemize}

\medskip

\item[(a)] Find $ \frac{\partial z}{\partial x}$ and 
$ \frac{\partial z}{\partial y}$ in terms of $f_1$ and $f_2$.

\medskip

\item[(b)]  If $ f_1( -6,-\frac{3}{2})= 4$ and
$f_2( -6,-\frac{3}{2}) = -1$, find
$ \frac{\partial z}{\partial x}$ and 
$ \frac{\partial z}{\partial y}$ at $(x,y)= (-2,3)$.
\end{itemize}


\bigskip

\item Suppose that a function $f(x,y)$ is defined everywhere in the plane and has continuous partial derivatives of all orders. Assume that $f(2,3)=2$, $f_1(2,3)=-1$, $f_2(2,3)=4$, $f_{11}(2,3)=0$, $f_{12}(2,3)=f_{21}(2,3)=3$, $f_{22}(2,3)=1$, Find ${ \frac{\partial }{\partial x} f(2x^2,x+y)}$ and
${ \frac{\partial^2 }{\partial x^2} f(2x^2,x+y)}$ at $(x,y)=(1,2)$. (Notice that $f_1$ does not denote the same derivative as $\partial f/\partial x$ in this problem! Same for $f_2,f_{11}$, and so on.)

\end{enumerate}





