# Are there any functions that are differentiable but not continuously-differentiable?

Let $$U$$ be an open set on $${\mathbb R}^{n}$$ (but $$U$$ is not an empty set), $$\textbf{p}\in{U}$$, and $$f:U\to \mathbb R$$ is continuously-differentiable on $$U$$. Then, it is known that, "the function $$f$$ can be differentiable for all $$\textbf{q}\in U$$." (See Spivac)

And I know that, there is a function $$f$$ such that it is differentiable at $$\textbf{p}$$ but, for any $$r> 0$$, $$f$$ is not differentiable (and continuously differentiable) on $$U_{\textbf{p}} (r)$$ . Here, $$U_{\textbf{p}} (r)$$ is an open ball of radius $$r$$ centered on $$\textbf{p}$$.
For example, if $$f:{\mathbb R}^{2}\to \mathbb R$$ is defined as follows, $$f$$ is differentiable at $$\textbf{0}$$,, but is not differentiable (and not continuous) at any other point. Here $$\mathbb Q$$ is the set of all rational numbers, and $$U_{\textbf{p}} (r)$$ is an open ball of radius $$r$$ centered on $$\textbf{p}$$.

$$f(x,y):=\left\{ \begin{array}{rr} 0, & (x,y)\in \mathbb Q^{2} \\ x^2 + y^2, & (x,y)\notin \mathbb Q^{2} \\ \end{array} \right.$$

Therefore, there is at least one function that does not have a continuously-differentiable region, even if it can be differentiable at one point. But I cannot imagine whether are there any functions that are differentiable on $$U$$ but not continuously-differentiable.

My question
Let $$U$$ be an open set of $$\mathbb R^n$$ (but is not an empty set), and $$\ \textbf{p}\in U$$.
Then, are there any functions $$f:U\to \mathbb R$$ such that, $$f$$ is differentiable on $$U$$, but for any $$r> 0$$, $$f$$ is not continuously-differentiable on $$U_{\textbf{p}} (r)$$ ?
If so, give an example. If not, please explain why.
Here, $$U_{\textbf{p}} (r)$$ is an open ball of radius $$r$$ centered on $$\textbf{p}$$.

Here, the definitions of differentiable and continuously differentiable are as follows.

Def1 (Differentiable at $$\textbf{p}$$)
Let $$U$$ be an open set (but not empty set) of $${\mathbb R}^{n}$$, $$\textbf {p} \in \mathbb R^n$$, and $$f$$ is a function whose domain is $$U$$. At this time, $$f$$ is differentiable at $$\textbf{p}$$ iff the following is satisfied.
$${\exists} A:{\mathbb R}^{n}\to \mathbb R$$: a linear map such that
$${\lim}_{\textbf{x}\to\textbf{p}}\frac{|f(\textbf{x}) - A(\textbf{x}-\textbf{p}) - f(\textbf{p})|}{|\textbf{x}-\textbf{p}|} = 0$$

Def2 (Differentiable on $$\textbf{U}$$)
Let $$U$$ be an open set (but not empty sets) of $${\mathbb R}^{n}$$, and $$f$$ is a function which domain is $$U$$.
At this time, $$f$$ is differentiable at $$U$$ iff "for all $$\textbf{q}\in{\mathbb R}^{n}$$, $$f$$ is differentiable at $$\textbf{q}$$".

Def3 (Continuously-differentiable on $$U$$)
Let $$U$$ be an open set (but is not empty sets) of $${\mathbb R}^{n}$$, and $$f$$ is a function which domain is $$U$$. At this time, $$f:U\to \mathbb R$$ is continuously-differentiable on $$U$$ iff

• $$f$$ is partially differentiable for all direction, $${x}_{1}, {x}_{2}, ..., {x}_{n}$$ (that mean, we can define $$\frac{\partial f}{\partial{x}_{1}}, \cdots\frac{\partial f} {\partial{x}_{n}}$$ on $$U$$). and,
• $$\frac{\partial f} {\partial{x}_{1}}, \cdots\frac{\partial f} {\partial{x}_{n}}$$ are continuous on $$U$$.

P.S.
I'm not very good at English, so I'm sorry if I have some impolite or unclear expressions.

Post-hoc Note:【Verification of the function taught by Thomas Shelby】
The following are the confirmation that the following function $$f$$ meets my requirement (Is it correct as proof?):

$$f(x,y)=\begin{cases}(x^2+y^2)\sin\left(\frac1 {\sqrt{x^2+y^2}}\right),&(x,y)\neq 0\\0,&(x,y)=0\end{cases}.$$

My proof:
$${\lim}_{\|\textbf{x}\|\to 0} \frac{f(\textbf{x}) - f(\textbf{0})}{\|\textbf{x}\|}= {\lim}_{\|\textbf{x}\|\to 0} \frac{{\|\textbf{x}\|}^{2}\sin(1/ \|\textbf{x}\| - 0)}{\|\textbf{x}\|}=$$ $${\lim}_{\|\textbf{x}\|\to 0} \|\textbf{x}\|\sin(1/ \|\textbf{x}\|) = 0$$
Therefore, the $$f$$ is differntiable at $$(0,0)$$ and $$Jf(0,0)=(0,0)$$.

On the other hand, for $$\textbf{x}\neq\textbf{0}$$,
Let $$g$$ and $$h$$ be $$g(x,y):=\sqrt{{x}^2 + {y}^2}\$$ and $$\ h(t):={t}^{2}\sin(1/t)$$ (for $$t\neq 0$$) respectively, then

$$\frac{d\sqrt{t}}{dt} = \frac{1}{2\sqrt{t}}$$ and, $$(J\|\textbf{x}\|^2)(x,y) = (2x,2y) ,$$ Therefore, $$(Jg)(x,y) = \left(\frac{x}{\|\textbf{x}\|} , \frac{y}{\|\textbf{x}\|}\right)\quad (\textrm{for all \textbf{x}\neq\textbf{0}\ }),$$ and $$\ \frac{d\sin(1/t)}{dt} = -\frac{\cos(1/t)}{t^2}\ \ \ (\textrm{at t\neq 0}).$$ Therefore, $$\frac{dh}{dt} ={t}^{2}\frac{d\sin(1/t)}{dt} + 2t\sin(1/t) = -\cos(1/t) + 2t\sin(1/t).$$

Therefore, at $$\textbf{x}\neq \textbf{0}$$,
$$Jf(x,y) = \left(\left.\frac{dh}{dt}\right|_{t=||\textbf{x}||}\right)(Jg)(x,y) = (-\cos(1/||\textbf{x}||) + 2t\sin(1/||\textbf{x}||))\left(\frac{x}{||\textbf{x}||} , \frac{y}{||\textbf{x}||}\right).$$

Therefore,
$$\frac{\partial f}{\partial x} = -\frac{x\cos(1/||\textbf{x}||)}{||\textbf{x}||} + 2x\sin(1/||\textbf{x}||),\,\textbf{x}\neq\textbf{0}$$and $$\frac{\partial f}{\partial y} = -\frac{y\cos(1/||\textbf{x}||)}{||\textbf{x}||} + 2y\sin(1/||\textbf{x}||),\,\textbf{x}\neq\textbf{0}.$$

However, both $$\dfrac{x\cos(1/||\textbf{x}||)}{||\textbf{x}||}$$ and $$\dfrac{y\cos(1/||\textbf{x}||)}{||\textbf{x}||}$$ do not get converted at $$(0,0)$$.

So, both $$\frac{\partial f}{\partial x}$$ and $$\frac{\partial f}{\partial y}$$ are not continuous at $$(0,0)$$. ■

• I am guessing you are looking for something less continuously differentiable that the one here math.stackexchange.com/q/1391544/27978? Aug 30 '19 at 4:07
• Related (maybe, I'm not sure I exactly understand what your question is): math.stackexchange.com/questions/112067/… Aug 30 '19 at 6:35
• @copper.hat: Thank you for your comment. The answer from Thomas Shelby satisfies my requirement. It was unexpected that there was such a simple example. Actually, I didn't realize that, we could make "multivariable functions that is continuously-diffentiable" from "univariate function that is differentiable but not continuously-diffentiable." But, as you say, his answer looks equivalent to your link. Aug 30 '19 at 10:21
• @BlueVarious Overall, the proof is good. But I think $(Jg)(x,y) = \left(\frac{x}{\|\textbf{x}\|} , \frac{y}{\|\textbf{x}\|}\right)$. So you should swap $\frac{\partial f}{\partial y}$ and $\frac{\partial f}{\partial x}$. Aug 30 '19 at 13:41

An example for $$n = 1$$ from the theory of random walks. Let $$f$$ be a (-n everywhere) discontinuous Lebesgue measurable function on $$\mathbb{R}$$. Here's an example with $$f$$ bounded by $$1$$, just showing the part $$x \in [-3,3]$$. (Note that I have only barely subsampled the graph in this interval. If I were to fully sample it, this finite resolution representation would almost surely appear to be a solid rectangle of points of the graph. Actually produced by generating $$10^6$$ uniformly distributed reals in $$[-1,1]$$ assigned to evenly spaced abscissae, then plotting a subsample of size $$10^4$$.)

This function is almost surely nowhere continuous (as any open interval almost surely contains points of heights arbitrarily close to $$-1$$ and $$1$$). The integral of this function, $$\int_{0}^x \; f(t) \,\mathrm{d}t$$ is differentiable, but there's no hope of continuous differentiability. Graph of the integral (actually, Riemann sum approximations using $$10^6$$ intervals in $$[-3,3]$$):

Picking a different instance of a bounded by $$1$$ discontinuous Lebesgue measurable function on $$\mathbb{R}$$ and integrating it the same way, we can graph the integral.

These are almost everywhere differentiable by construction (by Lebesgue's differentiation theorem); we know the derivative is $$f$$. (The theorem generalizes to $$n > 1$$ and the integral to $$\int_{[0,x_1]\times [0,x_2] \times \cdots \times [0,x_n]} \; f(t) \,\mathrm{d}t$$ where we understand the intervals to be $$[0,a]$$ when $$0 \leq a$$ and $$[a,0]$$ when $$a < 0$$.) In some way, "most" functions are everywhere discontinuous messes, so "most" functions can be integrated to a differentiable, but not continuously differentiable, function.

(This construction can be iterated to get a function that is several times continuously differentiable, but whose "last" derivative is not continuous.)

• Thank you for your answer. Is it correct to understand that "your function $f$ is differentiable at any point, but cannot be continuously-differentiable almost everywhere"? Aug 30 '19 at 10:38
• @BlueVarious : My $f$ is the derivative function. We have chosen $f$ to be everywhere discontinuous. Then $\int f$ is a continuous function with a known derivative and that known derivative is everywhere discontinuous by construction. (It is also almost everywhere discontinuous since the empty set has measure zero, but this is a weaker statement.) Aug 30 '19 at 14:31
• Thank you for your comment. So, your function F=∫f is differentiable at all points, but not continuously-differntiable at all points? Aug 31 '19 at 11:34
• @BlueVarious : Yes. Aug 31 '19 at 15:45
• Thank you for your answer. Thank you for teaching me a very “morbid” but very interesting function. Aug 31 '19 at 16:31

Consider $$f:\mathbb R^2\to \mathbb R$$ defined by $$f(x,y)=\begin{cases}(x^2+y^2)\sin\left(\frac1 {\sqrt{x^2+y^2}}\right),&(x,y)\neq 0\\0,&(x,y)=0\end{cases}.$$ Then $$f$$ is differentiable everywhere but $$\dfrac{\partial f}{\partial x}(x,y)$$ and $$\dfrac{\partial f}{\partial y}(x,y)$$ are not continuous at $$(0,0)$$.

A detailed calculation for the above example can be found in the book Functions of Several Real Variables.