Can every continuous function be continuously ''transformed'' into a differentiable function?

Edit 1. I realized my proof has a mistake. Because I use the inverse function theorem on $g \circ f$, my answer only checks out if $g \circ f$ is required to be continuously differentiable.


Original answer. Here's a counterexample.

We say a function $f$ is locally injective at a point $x$ if there exists a small interval $(x - \delta, x + \delta)$ where $x$ is injective. Suppose we have a function $f$ that is not locally injective at a point $x$. Also, suppose we have a function $g$ where the composition $g \circ f$ is differentiable at $x$. Note that because $f$ is not locally injective at $x$, $g \circ f$ cannot be locally injective by $x$. So by the inverse function theorem, its derivative $(g \circ f)'$ must necessarily vanish at $x$. This leads us to the following question:

Question. Can we find a function that is everywhere continuous, but nowhere locally injective?

If we can find such a function $f$, then any composition $g \circ f$ must be have an identically zero derivative. This means $g \circ f$ must be constant, implying $g$ is constant (at least in the range of $f$)!

We can achieve this with a function $f$ that is everywhere continuous, but nowhere differentiable. There are many such functions, the most famous being the “pathological” Weierstrass function. To prove $f$ is nowhere locally injective, suppose toward a contradiction that it is locally injective at a point $x$. Then there is in a small interval $I$ about $x$ where $f$ is injective and continuous, and hence monotone. By Lebesgue's monotone function theorem referenced in this post, $f$ must be differentiable almost everywhere in $I$. This is a contradiction because $f$ is nowhere differentiable.


Edit 2. Instead of examining local injectivity, we can maybe examine a slightly stronger condition. Let's say a function $f$ has a corner (not an actual term) at a point $x$ if for all $\delta > 0$, there exists $x_1, x_2 \in (x - \delta, x + \delta)$ such that $x_1 < x < x_2$ and $f(x_1) = f(x_2)$. The key here is that a “corner” requires the points breaking injectivity to lie on both sides of $x$.

We can show that if $f$ has a corner at $x$ and $g \circ f$ is differentiable at $x$, then $(g \circ f)'$ must vanish at $x$. For all $\delta > 0$, let $x_{1, \delta} < x < x_{2, \delta}$ be as in the definition of a corner. Taking the left-side points, we get $$ \tag{1} (g \circ f)'(x) = \lim_{\delta \to 0^+} \frac{(g \circ f)(x_{1, \delta}) - (g \circ f)(x)} {x_{1, \delta} - x}, $$ and taking the right-side points, we get $$ \tag{2} (g \circ f)'(x) = \lim_{\delta \to 0^+} \frac{(g \circ f)(x_{2, \delta}) - (g \circ f)(x)} {x_{2, \delta} - x}. $$ Note that the numerators of $(1)$ and $(2)$ are equal because $(g \circ f)(x_{1, \delta}) = (g \circ f)(x_{2, \delta})$. However, the denominators $x_{1, \delta} - x$ and $x_{2, \delta} - x$ have opposite signs, so we must have $(g \circ f)'(x) = 0$. Therefore, we can instead ask the question:

Question. Can we find a function that is everywhere continuous, but has a corner at every point in $\mathbb{R}$?

Because the Weierstrass function behaves like a fractal, this seems like it would be true (but maybe it only has corners densely packed in $\mathbb{R}$, in which continuous differentiability comes back to bite us). I'm not sure how to prove this though.


Gillis, Note on a conjecture of Erdos, Quart. J. of Math.,Oxford 10, (1939),151-154, has an example of a continuous function $f$, all of whose level sets are Cantor sets. Unless $g$ is a constant function, it seems $g \circ f$ won't be differentiable. (Gillis made other claims that were false, but his function does have every level set being a Cantor set).

Foran also has an example, but I don't think he published it. He constructs its graph as the intersection of a nested sequence of rectangles in the unit square.


Inspired by Frank's notion of "corner", let's define

  • The function $f$ has a "flat" at $x$ iff for every $\delta>0$ there is an $x_1$ with $0<|x-x_1|<\delta$ such that $f(x_1)=f(x)$. (In other words, $x$ is a limit point of the fiber of $f$ it's a member of).

One easily proves:

  1. If $f$ is differentiable at $x$ and has a flat at $x$, then $f'(x)=0$.

  2. The points where $f$ has flats depend only on the set of fibers of $f$ -- or, in other words, on the equivalence relation $x\sim_f y \Leftrightarrow f(x)=f(y)$.

  3. If $f$ has a flat at $x$ and $g$ is an arbitrary function, then $g\circ f$ also has a flat at $x$.

I will construct a continuous surjection $f:\mathbb R\to \mathbb R$ where every $x$ is flat (that is, in more dignified terms, a function whose fibers are all perfect sets). This property guarantees that $g\circ f$ can only be differentiable if it is constant.


First, let $w:[0,1]\to[0,1]$ be a zig-zag function that goes from $0$ up to $1$, then down to $0$ and back up to $1$:

$$ w(x) = \begin{cases} 3x & 0 \le x \le 1/3 \\ 2 - 3x & 1/3 \le x \le 2/3 \\ 3x - 2 & 2/3 \le x \le 1 \end{cases} $$

Stack an infinite sequence of $w$s to get $u:\mathbb R\to \mathbb R$: $$ u(x) = \lfloor x\rfloor + w\bigl(x-\lfloor x\rfloor\bigr) $$ We note that $u$ is continuous and $|u(x)-x|<1$ everywhere.

Now for each $n\ge 0$, let $$ h_n(x) = \frac{u(2^n x)}{2^n} $$ This looks like $u$, except that we have "zoomed out" by a factor of $2^n$ so we have more and smaller wiggles around $x=y$. In particular, $|h_n(x)-x|\le 2^{-n}$.

Now form the infinite composition of all the $h_n$'s: $$ f = \lim_{n\to\infty} h_n \circ h_{n-1} \circ \cdots \circ h_1 \circ h_0 $$ or, written in more detail: $$ f_0(x) = x \qquad\qquad f_{n+1}(x) = h_n(f_n(x)) \qquad\qquad f(x) = \lim_{n\to\infty} f_n(x) $$ The limit exists pointwise because the bound on the wiggles on each $h_n$ makes the sequence Cauchy -- and this argument actually bounds the difference uniformly. So $f$ is continuous, being a uniform limit of continuous functions.


To see that $f$ has flats everywhere, it is convenient to define $$ k_n(x) = 2^n f_n(x) $$ We then have the recurrence $$ k_0(x) = x \qquad\qquad k_n(x) = 2u(k_{n-1}(x)) $$ In other words, we're just iterating $2u$. We don't need to worry about taking the limit anymore, because the fibers of the $k_n$s (and therefore also of $f_n$) will tell us enough to conclude that $f$ has flats everywhere.

Note that $k_n$ is piecewise linear, with each linear piece having slope $\pm 6^n$, and it changes direction only at points where $k_n(x)$ is an (even) integer.

Now suppose we're given $x$ and we're looking for a $x_1$ within $\delta=6^{-n}$ of $x$ where $f(x_1)=f(x)$. We fast-forward to $k_n$ and find that $x$ lies in a closed interval $[y,y+6^{-n}]$ where $k_n(x)$ either ascends linearly from an integer to the next or descends from an integer to the previous (namely, $y=6^{-n}\lfloor 6^n x\rfloor$ will work). This means that $k_{n+1}$ restricted to this interval attains each value in its image at least twice. So we can find an $x_1\ne x$ in the interval such that $k_{n+1}(x_1) = k_{n+1}(x)$ and therefore also $f(x_1)=f(x)$, as required.