Differentiability of a scalar function of two variables --- problems with Stewart’s definition. I’m feeling uncomfortable about how Stewart’s Calculus makes the transition from differentiability of functions of one variable to differentiability of functions of two variables. Namely, Stewart gives the following definition:

Definition. A function $ f $ of two variables is said to be differentiable at $ (a,b) $ if the first-order partial derivatives of $ f $ at $ (a,b) $ exist and
  \begin{align}
  & ~ f(a + \Delta x,b + \Delta y) - f(a,b) \\
= & ~ {f_{\operatorname{x}}}(a,b) \Delta x +
      {f_{\operatorname{y}}}(a,b) \Delta y +
      {\epsilon_{1}}(\Delta x,\Delta y) \Delta x +
      {\epsilon_{2}}(\Delta x,\Delta y) \Delta y,
\end{align}
  where $ \displaystyle \lim_{(\Delta x,\Delta y) \to (0,0)} {\epsilon_{1}}(\Delta x,\Delta y) = \lim_{(\Delta x,\Delta y) \to (0,0)} {\epsilon_{2}}(\Delta x,\Delta y) = 0 $.

Note. Later on, he shows that this will follow if the partial derivatives exist and are continuous near $ (a,b) $, and I am fine with this.
What first irked me is that I didn’t remember learning this definition, so I spent a while trying to understand it. Moreover, the only functions that I’ve found to motivate the need for such a definition are those that are not continuous at the point in question. For example, consider the function $ f: \mathbb{R}^{2} \to \mathbb{R} $ defined by
$$
\forall (x,y) \in \mathbb{R}^{2}: \qquad
f(x,y) \stackrel{\text{df}}{=}
\begin{cases}
\dfrac{x y}{x^{2} + y^{2}} & \text{if $ (x,y) \neq (0,0) $}; \\
0                          & \text{if $ (x,y) = (0,0) $}.
\end{cases}
$$
Then $ f_{\operatorname{x}} $ and $ f_{\operatorname{y}} $ are defined at $ (0,0) $, but $ f $ is not continuous there.
Here’s my quarrel. I don’t think that this is a natural extension from the one-dimensional case. In one dimension, differentiability at a point implies continuity at that point, but two dimensions, the existence of $ f_{\operatorname{x}} $ and $ f_{\operatorname{y}} $ at a point don’t imply the continuity of $ f $ at that point. My intuition, then, is that to extend the definition of differentiability to two dimensions, we should say that $ f_{\operatorname{x}} $ and $ f_{\operatorname{y}} $ exist and that $ f $ is continuous at the relevant point.
This seems nice and simple, so I can’t imagine why Stewart would go with the awkward definition given at the beginning of this post, if this was indeed the case. It therefore seems that I should be wrong. If I am, can you give me an example of a function $ f $ that is continuous at $ (a,b) $, and $ f_{\operatorname{x}} $ and $ f_{\operatorname{y}} $ are defined at $ (a,b) $, but it isn’t differentiable there?
Additionally, I have a rough outline of a proof in my head of why it should be true. The definition of a directional derivative gives
$$
  {D_{\mathbf{u}} f}(a,b)
= \lim_{h \to 0} \frac{f(a + h \Delta x,b + h \Delta y) - f(a,b)}{h},
$$
but expressing it as a gradient implies that
$$
  \lim_{h \to 0} \frac{f(a + h \Delta x,b + h \Delta y) - f(a,b)}{h}
= {f_{\operatorname{x}}}(a,b) \Delta x + {f_{\operatorname{y}}}(a,b) \Delta y.
$$
However, for this limit to be true, it seems like the original awkward definition must follow, i.e.,
$$
  \frac{f(a + h \Delta x,b + h \Delta y) - f(a,b)}{h}
= {f_{\operatorname{x}}}(a,b)\Delta x + {f_{\operatorname{y}}}(a,b) \Delta y,
$$
which implies that
$$
  f(a + h \Delta x,b + h \Delta y) - f(a,b)
= {f_{\operatorname{x}}}(a,b)h \Delta x + {f_{\operatorname{y}}}(a,b)h \Delta y
$$
without even the need for the functions $ \epsilon_{1} $ and $ \epsilon_{2} $.

Edit 1
zhw. has given a nice counter example below. However, I’d now like to alter my questions.

  
*
  
*Would an alternative definition be that all the directional derivatives of $ f $ exist and that $ f $ is continuous at a given point?
  
*What if I now extend my original approach to say that $ f $ is continuous on a neighborhood of $ (a,b) $ and that $ {f_{\operatorname{x}}}(a,b) $ and $ {f_{\operatorname{y}}}(a,b)$ exist? Could you give me a counterexample now?


Edit 2
zhw. has knocked down Question 2 of Edit 1 in his response to my comment to his original answer, so now I’m just wondering if

Would an alternative definition be that all the directional derivatives of $ f $ exist and that $ f $ is continuous at a given point?

I’m motivated to ask because (a) zhw.’s counter examples all have some directional derivatives that don’t work and (b) my attempted proof relied on the existence of directional derivatives.
 A: There are functions for which all directional derivatives exist and are still not differentiable. A web search will turn up several examples such as this one, in which not only do they all exist but are equal. It fails to be differentiable because all paths need to be considered, not just the straight lines. Requiring continuity as well likely does the trick, but to me that seems like using a bigger and bigger hammer to deal with each issue as it arises.  
I think the awkwardness in the text’s definition comes from treating $x$ and $y$ separately. If you formulate the definition of differentiability in terms of vectors, it doesn’t seem all that awkward to me: A function $f:\mathbb R^m\to\mathbb R^n$ is differentiable at $\mathbf v\in\mathbb R^m$ if there exists a linear map $L_{\mathbf v}:\mathbb R^m\to\mathbb R^n$ such that $f(\mathbf v+\mathbf h) = f(\mathbf v)+L_{\mathbf v}(\mathbf h)+o(\mathbf h)$. If such a map exists, it isn’t hard to show that it is unique. This linear map is the differential of $f$ at $\mathbf v$, often denoted by $\mathrm df_{\mathbf v}$ or simply $\mathrm df$. This captures the essential notion that a derivative/differential is the best linear approximation to the the change in function’s value near a given point.  
Note that when $f:\mathbb R\to\mathbb R$ this definition reduces to that of the derivative from elementary calculus (in one dimension, a linear map is just multiplication by a scalar). In addition, gradient, directional derivative, &c can all be defined in terms of this differential.
A: Define $f$ to be $0$ on the axes, and $f(x,y) = \sqrt { x^2+y^2}$ elsewhere. Then $f$ is continuous at $(0,0),$ and $\partial f/\partial x (0,0) = 0 = \partial f/\partial y (0,0).$ Suppose $f$ is differentiable at $(0,0).$ Verify that the definition would then yield $f(x,x)=o(x)$ as $x\to 0.$ But $f(x,x) = \sqrt 2 |x|,$ contradiction, showing $f$ is not differentiable at $(0,0).$
A: This is too long for a comment, so I have decided to make it into a post instead.

Throughout this discussion, let us fix the following objects:


*

*A natural number $ n $.

*A subset $ D $ of $ \mathbb{R}^{n} $.

*A point $ \mathbf{a} $ in the interior of $ D $.

*A function $ f: D \to \mathbb{R} $.



According to certain textbooks, $ f $ is differentiable at $ \mathbf{a} $ if and only if there exists a $ \mathbf{v} \in \mathbb{R}^{n} $ such that
$$
\forall r \in \mathbb{R}_{> 0}: \qquad
\mathbb{B}(\mathbf{a};r) \subseteq D \quad \Longrightarrow \quad
  \lim_{\substack{0 < \| \mathbf{h} \| < r \\ \mathbf{h} \to \mathbf{0}}}
  \frac{|
       f(\mathbf{a} + \mathbf{h}) - f(\mathbf{a}) - \mathbf{v} \bullet \mathbf{h}
       |}
       {\| \mathbf{h} \|}
= 0.
$$
A simple argument using the standard basis vectors of $ \mathbb{R}^{n} $ shows that if $ f $ is differentiable at $ \mathbf{a} $, then the first-order partial derivatives of $ f $ at $ \mathbf{a} $ exist, and furthermore, $ \mathbf{v} = {\nabla f}(\mathbf{a}) $. Hence, when $ n = 1 $, we recover the definition of differentiability for single-variable functions.
I shall now proceed to show that the standard definition above is equivalent to Stewart’s.

Suppose that $ f $ is differentiable at $ \mathbf{a} $ in the sense of Stewart. Choose any $ r \in \mathbb{R}_{> 0} $ with $ \mathbb{B}(\mathbf{a};r) \subseteq D $. Then the following are true:


*

*The first-order partial derivatives of $ f $ at $ \mathbf{a} $ exist.

*There exists a function
$ \epsilon: \mathbb{B}(\mathbf{0};r) \to \mathbb{R}^{n} $ such that
$$
  \forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r): \qquad
    f(\mathbf{a} + \mathbf{h}) - f(\mathbf{a})
  = {\nabla f}(\mathbf{a}) \bullet \mathbf{h} +
    \epsilon(\mathbf{h}) \bullet \mathbf{h}
  $$
and
$$
  \forall k \in \mathbb{N}_{\leq n}: \qquad
    \lim_{\substack{0 < \| \mathbf{h} \| < r \\ \mathbf{h} \to \mathbf{0}}}
    {\epsilon_{k}}(\mathbf{h})
  = 0.
  $$


By the Cauchy-Schwarz Inequality, we have
\begin{align}
\forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r) \setminus \{ \mathbf{0} \}: \qquad
       \frac{|
            f(\mathbf{a} + \mathbf{h}) - f(\mathbf{a}) -
            {\nabla f}(\mathbf{a}) \bullet \mathbf{h}
            |}
            {\| \mathbf{h} \|}
& =    \frac{|\epsilon(\mathbf{h}) \bullet \mathbf{h}|}{\| \mathbf{h} \|} \\
& \leq \frac{\| \epsilon(\mathbf{h}) \| \| \mathbf{h} \|}{\| \mathbf{h} \|} \\
& =    \| \epsilon(\mathbf{h}) \|.
\end{align}
It then follows from the Squeeze Theorem that
$$
  \lim_{\substack{0 < \| \mathbf{h} \| < r \\ \mathbf{h} \to \mathbf{0}}}
  \frac{|
       f(\mathbf{a} + \mathbf{h}) - f(\mathbf{a}) -
       {\nabla f}(\mathbf{a}) \bullet \mathbf{h}
       |}
       {\| \mathbf{h} \|}
= 0.
$$
As $ r $ was chosen arbitrarily, $ f $ is therefore differentiable at $ \mathbf{a} $ by the standard definition.

Suppose that $ f $ is differentiable at $ \mathbf{a} $ by the standard definition. As mentioned earlier, the first-order partial derivatives of $ f $ at $ \mathbf{a} $ exist. Picking any $ r \in \mathbb{R}_{> 0} $ with $ \mathbb{B}(\mathbf{a};r) \subseteq D $, we now commit ourselves to finding a function $ \epsilon: \mathbb{B}(\mathbf{0};r) \to \mathbb{R}^{n} $ that satisfies Stewart’s definition.
Firstly, define $ e: \mathbb{B}(\mathbf{0};r) \to \mathbb{R} $ by
$$
\forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r): \qquad
                        e(\mathbf{h})
\stackrel{\text{df}}{=} f(\mathbf{a} + \mathbf{h}) - f(\mathbf{a}) -
                        {\nabla f}(\mathbf{a}) \bullet \mathbf{h}.
$$
Secondly, define $ \phi: \mathbb{B}(\mathbf{0};r) \to \mathbb{R} $ by
$$
\forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r): \qquad
\phi(\mathbf{h}) \stackrel{\text{df}}{=}
\begin{cases}
e(\mathbf{h}) / \| \mathbf{h} \| & \text{if $ \mathbf{h} \neq \mathbf{0} $}; \\
0                                & \text{if $ \mathbf{h} = \mathbf{0} $}.
\end{cases}
$$
By the definition of differentiability, $ \phi $ is continuous on $ \mathbb{B}(\mathbf{0};r) $.
Thirdly, define $ C: \mathbb{R}^{n} \to \mathbb{R}_{\geq 0} $ by
$$
\forall \mathbf{x} \in \mathbb{R}^{n}: \qquad
C(\mathbf{x}) \stackrel{\text{df}}{=}
\begin{cases}
  \| \mathbf{x} \| / \| \mathbf{x} \|_{1}
& \text{if $ \mathbf{x} \neq \mathbf{0} $}; \\
  0
& \text{if $ \mathbf{x} = \mathbf{0} $}.
\end{cases}
$$
Here, $ \| \cdot \|_{1} $ denotes the taxicab norm on $ \mathbb{R}^{n} $. It is not hard to see that $ 0 \leq C(\mathbf{x}) \leq 1 $ for all $ \mathbf{x} \in \mathbb{R}^{n} $.
Next, observe that
$$
\forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r): \qquad
  e(\mathbf{h})
= \sum_{k = 1}^{n}
  [\phi(\mathbf{h}) C(\mathbf{h}) \operatorname{sgn}(\mathbf{h}_{k})]
  \mathbf{h}_{k},
$$
where $ \operatorname{sgn} $ denotes the signum function. We may thus define $ \epsilon: \mathbb{B}(\mathbf{0};r) \to \mathbb{R}^{n} $ by
$$
\forall k \in \mathbb{N}_{\leq n}, ~
\forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r): \qquad
                        {\epsilon_{k}}(\mathbf{h})
\stackrel{\text{df}}{=} \phi(\mathbf{h}) C(\mathbf{h})
                        \operatorname{sgn}(\mathbf{h}_{k}).
$$
Using the fact that both $ C $ and $ \operatorname{sgn} $ are bounded pointwise in absolute value by $ 1 $, we obtain
$$
\forall k \in \mathbb{N}_{\leq n}, ~
\forall \mathbf{h} \in \mathbb{B}(\mathbf{0};r): \qquad
|{\epsilon_{k}}(\mathbf{h})| \leq |\phi(\mathbf{h})|.
$$
It then follows from the continuity of $ \phi $ and the Squeeze Theorem that
$$
\forall k \in \mathbb{N}_{\leq n}: \qquad
  \lim_{\substack{0 < \| \mathbf{h} \| < r \\ \mathbf{h} \to \mathbf{0}}}
  {\epsilon_{k}}(\mathbf{h})
= 0.
$$
As $ r $ was chosen arbitrarily, $ f $ is therefore differentiable at $ \mathbf{a} $ by Stewart’s definition.


Conclusion: The two definitions of differentiability are equivalent.

