\section{More on Differentiability}
\subsection{Nondifferentiability Happens} We start with the example

\smallskip

$$
f(x,y) =
\begin{cases}
{\displaystyle \frac{x^3}{x^2 + y^2}} \textrm{ if } (x,y) \neq (0,0) \\[1ex]
0  \quad \quad \, \textrm{if } (x,y) = (0,0).
\end{cases}
$$
Let us try to determine whether $f$ is differentiable at $(0,0)$. 

Some preliminary  remarks:
\begin{enumerate}
\item First notice that the function $f(x,y)$ is continuous at the origin. We already looked at this example earlier (see Worked Problems in Section 2.2), but let us recap it briefly. We have
$$
|f(x,y)| = \bigg| \frac{x^3}{x^2 + y^2} \bigg| = |x| \bigg| \frac{x^2}{x^2 + y^2} \bigg| \leq |x| \rightarrow 0, \textrm{ as } (x,y) \rightarrow (0,0),
$$
so that by the Squeeze Theorem,
$$
\lim_{(x,y) \rightarrow (0,0)} f(x,y) = 0 = f(0,0).
$$
However, this does not tell us whether $f$ is differentiable at $0$.

\medskip

\item We could try to use the Theorem saying that if $f_x$ and $f_y$ are continuous in a neighbourhood of $(0,0)$, then $f$ is differentiable at $(0,0)$.  Yet:

\smallskip

\begin{itemize}
\item It is possible for $f$ to be differentiable at $(0,0)$ even if $f_x$ or $f_y$ are not continuous in a neighbourhood of $(0,0)$, so this might not be a conclusive test.

\smallskip

\item Checking that $f_x$ and $f_y$ are continuous in a neighbourhood of $(0,0)$, in cases like this (functions defined by a piecewise formula), is \underline{more} difficult than just checking the definition of differentiability at $(0,0)$.
\end{itemize}
\end{enumerate}


\medskip

Returning to the example, we need to determine whether
$$
\lim_{(x,y) \rightarrow (0,0)} \frac{f(x,y) - L(x,y)}{\sqrt{x^2 + y^2}} = 0,
$$
where $L(x,y)$ is the linear approximation
$$
L(x,y) = f(0,0) + f_x (0,0) x + f_y (0,0) y.
$$
Clearly, $f(0,0) = 0$.  Using the definition of partial derivatives, we obtain
$$
f_x (0,0) = \lim_{h \rightarrow 0} \frac{1}{h} \left[f(h,0) - f(0,0) \right] = \lim_{h \rightarrow 0} \frac{1}{h} \left[\frac{h^3}{h^2} - 0 \right] = 1
$$
$$
f_y (0,0) = \lim_{h \rightarrow 0} \frac{1}{h} \left[f(0,h) - f(0,0) \right] = \lim_{h \rightarrow 0} \frac{1}{h} \left[ 0 - 0 \right] = 0
$$
so that
$$
L(x,y) = x.
$$
So, for $(x,y) \neq (0,0)$ we have
$$
\frac{f(x,y) - L(x,y)}{\sqrt{x^2 +  y^2}} = \frac{\frac{x^3}{x^2 + y^2} - x}{\sqrt{x^2 + y^2}} = - \frac{x y^2}{(x^2 + y^2)^{3/2}}.
$$
For differentiability, this needs to have a limit of zero as $(x,y) \rightarrow (0,0)$ along all possible paths. But let us consider what happens when we set $y = x$ and let $(x,x) \rightarrow (0,0)$.  Then,
$$
\frac{f(x,x) - L(x,x)}{\sqrt{x^2 +  x^2}} - \frac{x \cdot x^2}{(2 x^2)^{3/2}} = - \frac{x^3}{2^{3/2} |x|^3 }
=
\begin{cases}
- 2^{-3/2}, \textrm{ if } x > 0 \\[1ex]
2^{-3/2} ,  \, \,  \, \, \textrm{ if } x < 0
\end{cases}
$$
Therefore the limit is not equal to zero---even worse, the limit does not exist. So, our function cannot be differentiable at the origin.

\subsection{Proving Differentiability} We rework the same argument to prove that
$$
g(x,y) =
\begin{cases}
\displaystyle{\frac{x^4}{x^2 + y^2}} & \textrm{ if } (x,y) \neq (0,0) \\[1ex]
0 &\textrm{ if } (x,y) = (0,0)
\end{cases}
$$
is, in fact, differentiable at the origin.  


Since $f(x,0)=\frac{x^4}{x^2}=x^2$ for $x\neq 0$, 
$f(0,y)=\frac{0}{y^2}=0$ for $y\neq 0$, and 
$f(0,0)=0$, we get
\begin{align*}
f_1(0,0)&=\lim_{x\to 0} \frac{f(x,0)-f(0,0)}{x}
=\lim_{x\to 0} \frac{x^2 }{x} =0,
\\
f_2(0,0)&=\lim_{y\to 0} \frac{f(0,y)-f(0,0)}{y}
=\lim_{y\to 0} \frac{0}{y}=0.
\end{align*}
Hence the linear approximation to $f$ at $(0,0)$ is $L(x,y)=0$.
For $f$ to be differentiable at $(0,0)$, we need
\begin{align*}
\lim_{(x,y)\to (0,0)} \frac{f(x,y)-L(x,y)}{\sqrt{x^2+y^2}}
= \lim_{(x,y)\to (0,0)} \frac{x^4}{(x^2+y^2)^{3/2}}=0.
\end{align*}
Since $\sqrt{x^2+y^2}\geq |x|$, we have 
$$
0\leq  \left| \frac{x^4}{(x^2+y^2)^{3/2}} \right|
\leq \frac{x^4}{|x|^3}= |x|
$$
so that the limit is 0 by the Squeeze Theorem, and the function is 
differentiable.



\subsection{A Proof of the Chain Rule Using Differentiability}
We now give a proof of the following special case of the  Chain Rule.


\begin{theorem}\label{32-thm-chainrule}
Assume that $z = f(x,y)$ is differentiable at $(a,b)$. Further, suppose $x(t_0) = a$ and $y(t_0) = b$ and that both $x' (t_0)$ and $y' (t_0)$ exist. Then we have
\begin{equation}\label{eq:32eq1}
\frac{dz}{dt} = \frac{\partial z}{\partial x} \frac{dx}{dt} + \frac{\partial z}{\partial y} \frac{d y}{dt}
\end{equation}
\end{theorem}





\begin{remark}
Notice that the assumptions of Theorem \ref{32-thm-chainrule} are actually weaker than those of the corresponding theorem in Section 2.6! There, we assumed for simplicity that all functions are $C^1$ so that we could focus on the statements and applications of the Chain Rule. That was also before we introduced the rigorous concept of differentiability for multivariate functions. Now that we have that concept, we can use it instead of the $C^1$ assumption. 

The fact that it is enough here for $f$ to be differentiable at $(a,b)$---and not necessarily $C^1$ in its neighbourhood---will be important in the next section when we compute directional derivatives of differentiable functions.
\end{remark}

\begin{proof}[Proof of Theorem \ref{32-thm-chainrule}]
We approximate $f$ near $(a,b)$ by the linear function
$$
L(x,y) = f(a,b) + f_x (a,b) (x - a) + f_y (a,b) (y - b).
$$
Differentiability means that the error 
$
R(x,y) = f(x,y) - L(x,y)
$
satisfies
$$
\lim_{(x,y) \rightarrow (0,0)} \frac{R(x,y)}{\sqrt{(x - a)^2 + (y - b)^2}} = 0.
$$
If we could actually \underline{replace} $f(x,y)$ by $L(x,y)$, then the Chain Rule would be very easy to prove. This is because
\begin{eqnarray*}
\frac{d}{dt} \big[L\big(x(t), y(t) \big) \big] & = & \frac{d}{dt} \big[f(a,b) + f_x (a,b) (x(t) - a) + f_y (a,b) ( y(t) -b) \big] \\[1ex]
\quad & = & f_x (a,b) x' (t) + f_y (a,b) y'(t)
\end{eqnarray*}
We cannot \textit{replace} $f$ by $L$. However, we can \underline{approximate} $\frac{df}{dt}$ by $\frac{dL}{dt}$, by writing
$$
\frac{d}{dt} f = \frac{d}{dt} \big[L + (\underbrace{f- L}_{R}) \big] = \frac{d L}{dt} + \frac{dR}{dt}.
$$
So, to prove \eqref{eq:32eq1}, it suffices to show that
\begin{equation}\label{eq:32eq2}
\frac{d R}{dt}\bigg|_{t = t_0} = 0.
\end{equation}
We do this now. Let
$$
x = a + \Delta x, \quad y = b + \Delta y, \quad t = t_0 + \Delta t.
$$
We have
$$
\frac{d R \big( x(t), y(t) \big)}{dt} \bigg|_{t = t_0} = \lim_{\Delta t \rightarrow 0} \frac{1}{\Delta t} \big[R\big(x(t), y(t)\big) - \underbrace{R\big(x(t_0),y(t_0)\big)}_{\textrm{ zero since } f(a,b) = L(a,b)}  \big].
$$
Now, recalling that $x = a + \Delta x$ and $y = b + \Delta y$,
$$
\frac{R\big( x(t), y(t) \big)}{\Delta t} = \bigg(\underbrace{\frac{R(a + \Delta x, b + \Delta y)}{\sqrt{(\Delta x)^2 + (\Delta y)^2}}}_{I_1 (\Delta x, \Delta y)} \bigg) \cdot \bigg(\underbrace{\frac{\sqrt{(\Delta x)^2 + (\Delta y)^2}}{\Delta t}}_{I_2 (\Delta x, \Delta y)}\bigg)
$$
The assumption that $f(x,y)$ is differentiable at $(a,b)$ implies
$$
\lim_{(\Delta x, \Delta y) \rightarrow (0,0)} I_1 (\Delta x, \Delta y) = 0.
$$
The function $I_2$ can be rewritten as
$$
I_2 (\Delta x, \Delta y) = \pm \, \sqrt{\bigg(\frac{\Delta x}{\Delta t} \bigg)^2 + \bigg(\frac{\Delta y}{\Delta t} \bigg)^2}.
$$
(The $\pm$ sign depends on whether $\Delta t$ is positive or negative.) This has the limit 
$$
I_2 \rightarrow \pm \, \sqrt{\big[ x' (t_0) \big]^2 + \big[y'(t_0) \big]^2}, \textrm{ as } \Delta t \rightarrow 0^{\pm}.
$$
In particular,  the function $I_2(\Delta x, \Delta y)$ must remain bounded by some constant $C$ on a neighbourhood of $t = t_0$. Putting these two statements for $I_1$ and $I_2$ together, we obtain \eqref{eq:32eq2}.
\end{proof}



\section*{Practice Problems}
\begin{enumerate}[1.]


\item (In this question, you have to use the definitions of partial derivatives and
differentiability.) 
Let
$$f(x,y)=\left\{\begin{matrix}
\displaystyle{\frac{x^3-\sin^3 x}{x^2 + y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{matrix}
\right.
$$

(a) Find the first order partial derivatives of $f$ at $(0,0)$. 


\smallskip

(b)  Is $f$ differentiable at $(0,0)$? Prove your answer.

\bigskip





\item{(a) Prove that there exist positive constants $c,C$ (independent of $x,y$) such that
 $$
 c(x^2+y^2) \leq x^2 - xy + 4 y^2 \leq C (x^2+y^2).
 $$
 
\noindent
(b) 
Let 
$$f(x,y)=\left\{\begin{matrix}
\displaystyle{\frac{xy^3}{x^2- xy+ 4 y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{matrix}
\right.
$$
Prove that $f$ is differentiable at $(0,0)$. (Hint: You have to use the definition
of differentiability. You may also have to use the estimate from (a).)}



\bigskip

\item
Let 
$$f(x,y)=\left\{\begin{matrix}
\displaystyle{\frac{x^3-y^3+2xy}{x^2+y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{matrix}
\right.
$$
(a)
Find the partial derivatives $f_1(0,0)$, $f_2(0,0)$.



\bigskip

(b) 
Is $f(x,y)$ differentiable at $(0,0)$? Prove your answer. 


\bigskip

\item{
Let
$$f(x,y)=\begin{cases}
\displaystyle{\frac{(x-e^x+1)y^2}{x^2 + y^2}}&\hbox{ if }(x,y)\neq (0,0)\\
0&\hbox{ if }(x,y)=(0,0)\\
\end{cases}
$$
Is $f$ differentiable at $(0,0)$? Prove your answer.}

\bigskip

\item
{Let
$$f(x,y)=\begin{cases}
\displaystyle{x^2\sin(1/y)}&\hbox{ if }y\neq 0\\
0&\hbox{ if } y=0\\
\end{cases}
$$
Prove that:
\medskip

(a)  $f$ is differentiable at $(0,0)$  
(you will have to use the definition of differentiability).}

\medskip

{(b) $f$ is not continuous in any neighbourhood of $(0,0)$. (For every neighbourhood of $(0,0)$, prove that there is a point in that neighbourhood where $f$ is not continuous.)}




\bigskip

\item 
Let
$$f(x,y)=\begin{cases}
xy &\hbox{ if }x,y \hbox{ are both rational,}\\
-xy &\hbox{ if at least one of }x,y\hbox{ is irrational.}\\
\end{cases}
$$

(a) Find all points where $f$ is continuous. Prove your answer {\bf using the epsilon-delta definition} of continuity. (You may have to consider several cases separately.)


\medskip

(b) Find all points where $f$ is differentiable. Prove your answer. (You may have to consider several cases separately, and you will have to use the definition of differentiability at least once. Epsilon-delta proofs are not required in this part, but may be useful depending on how you solve the question.)









\end{enumerate}





