TITLE: Erroneous proof that derivative of function is always continuous
QUESTION [16 upvotes]: Suppose that $f:\mathbb{R}\to \mathbb{R}$ is differentiable on the entire real line. (It is not difficult to give an example when $f'(x)$ is not continuous.)
Find the flaw in the following "proof" that $f'(x)$ is continuous.
Proof: Let $x_0$ be an arbitrary point on $\mathbb{R}$ and $f'(x_0)$ the derivative of $f$ at the point $x_0$. By definition of the derivative and Lagrange's(aka MVT) theorem
$$f'(x_0)=\lim \limits_{x\to x_0}\dfrac{f(x)-f(x_0)}{x-x_0}=\lim \limits_{x\to x_0}f'(\xi)=\lim \limits_{\xi \to x_0}f'(\xi), \qquad \qquad (*)$$ where $\xi$ is a point between $x_0$ and $x$ and therefore tends to $x_0$ as $x\to x_0$.
I have some difficulties to point out to the mistake in this "proof". But here is I was thinking.
The first equality in $(*)$ is just the definition of the derivative. The second equality follows from MVT. I do not think that the third equality is true. So basically we need to show the following:

If $\lim \limits_{x\to x_0}f'(\xi)=f'(x_0)$ then $\lim \limits_{\xi\to
 x_0}f'(\xi)=f'(x_0)$

I was trying to show it via $\varepsilon-\delta$ formalist and the fact that for any $x\in \mathbb{R}$ so that $x\neq x_0$ the $\xi$ is in between $x$ and $x_0$ but I failed.
Can anyone help me please?

Am I right that the third equality in $(*)$ is not valid.
And where is the flaw in this "proof"?

EDIT: Suppose that $\lim \limits_{x\to x_0}f'(g(x))=f'(x_0)$, where $g:\mathbb{R}\to \mathbb{R}$ defined by $$g(x)=
\begin{cases}
\xi_x, & \text{if } x\neq x_0, \\
x_0, & \text{if } x=x_0,
\end{cases}$$ and $g(x)$ has Intermediate Value property (every value between $g(x)$ and $x_0$ is taken somewhere between $x$ and $x_0$ by $g$). Then $$\lim \limits_{y\to x_0}f'(y)=f'(x_0).$$
Remark: I am trying to prove it in a rigorous way via $\varepsilon-\delta$ formalism but I have some issues.
My approach: Let $\varepsilon>0$ be given then $\exists \delta>0$ such that $\forall x\in \mathbb{R} (0<|x-x_0|<\delta \Rightarrow |f'(g(x))-f'(x_0)|<\varepsilon)$. I have no idea how to invoke the Intermediate value property to obtain the desired result.

REPLY [5 votes]: The two other answers sufficiently address the initial query of the post and ably explain the problems, and how to find/highlight them by using a known counterexmaple.
In comments, I noted that if we knew that the  association from $x$ to $\xi_x$ were continuous, then the argument would go through, and also noted that the Intermediate Value Property would suffice. This answer is only intended to address this minor point.
Again: $f(x)$ is assumed to be everywhere differentiable; we pick $x_0$. By the Intermediate Value Theorem, for every $x\neq x_0$, there exists $\xi_x$ between $x$ and $x_0$ such that
$$f'(\xi_x) = \frac{f(x)-f(x_0)}{x-x_0}.\tag{1}$$
Using AC, we define a function $g\colon \mathbb{R}\to \mathbb{R}$ by
$$g(x) = \left\{\begin{array}{ll}
\xi_x &\text{if }x\neq x_0\\
x_0 &\text{if }x=x_0,
\end{array}\right.$$
where $\xi_x$ is any point between $x$ and $x_0$ where $(1)$ holds.
In particular,
$$f'(x_0) = \lim_{x\to x_0}\frac{f(x)-f(x_0)}{x-x_0} = \lim_{x\to x_0}f'(g(x)).$$
In general, we cannot claim that because $\lim_{x\to x_0}g(x)=x_0$ (which it plainly does, by the Squeeze Theorem for example) this implies that $\lim_{y\to x_0}f'(y)=f'(x_0)$.  It certainly does if $f'(x)$ is continuous at $x_0$ (but this is what we are "trying" to "establish" by the argument). So setting this aside, I stated it holds in two situations:

$g(x)$ is continuous on an open interval including $x_0$; and
$g(x)$ satisfies the Intermediate Value Property on an open interval including $x_0$.

The Intermediate Value Property on an interval $I$ is:

We say $g(x)$ has the Intermediate Value Property on $I$ if and only if for all $a\lt b$, $a,b\in I$, if $k$ is a value between $g(a)$ and $g(b)$, then there exists $c$, $a\lt c\lt b$, such that $g(c)=k$.

The Intermediate Value Property is implied by continuity (the Intermediate Value Theorem), but is weaker; for example, Darboux's Theorem shows that the derivative function of a continuous function has the intermediate value property, even though we know it need not be continuous.

Theorem. Let $h$ and $g$ be functions, and let $a$ be a real number. If:

$g(a) = a$; and
If $x\neq a$, then $g(x)$ is strictly between $a$ and $x$; and
$g(x)$ has the Intermediate Value Property on an open interval containing $a$; and
$\lim_{x\to a}h(g(x)) = h(a)$;

then $h$ is continuous at $a$; that is, $\lim_{x\to a}h(x) = h(a)$.

The idea is this: take $\epsilon\gt 0$. We know that any point sufficiently close to $a$ will make $h(g(x))$ $\epsilon$-close to $h(a)$. Pick any such $x$, and see where $g(x)$ is; then every point $y$ between $g(x)$ and $a$ is the value of $g$ at some point between $x$ and $a$, and so it is the value at a point “sufficiently close” to $a$.  So then $h(y)$ is equal to $h(g(z))$ for some $z$ “sufficiently close” to $a$, which means $h(y)$ is $\epsilon$-close to $h(a)$. We now do this formally:
Proof. Consider $\lim_{x\to a^+}h(x)$.
Let $\epsilon>0$; we may assume $\epsilon$ is sufficiently small so that $(a,a+\epsilon)$ is contained inside the interval specified in item 3. We want to show that there exists $\delta\gt 0$ such that if $0\lt x-a\lt\delta$, then $|h(x)-h(a)|\lt\epsilon$.
We know that $\lim_{x\to a^+}h(g(x))=h(a)$, so there exists $\delta_1\gt 0$ (and again we may assume that $(a,a+\delta_1)$ is contained in the interval specified in item 3) such that:
$$\text{if } 0\lt y-a\lt\delta_1,\text{ then }|h(g(y))-h(a)|\lt \epsilon.\tag{2}$$
Let $x_1 = a+\frac{\delta_1}{2}$. Then $|h(g(x_1))-h(a)|\lt\epsilon$. Let $\delta = g(x_1)-a\gt 0$.  I claim that if $0\lt x-a\lt\delta$, then $|h(g(x))-h(a)|\lt \epsilon$.
Indeed, let $x$ be such that $0\lt x-a\lt\delta$. Because $x$ lies between $g(x_1)$ and $g(a)$, there exists $y$ between $x_1$ and $a$ where $g(y)=x$. In particular, $0\lt y-a\lt x_1-a\lt\delta_1$. Therefore, by $(2)$, we have
$$|h(x)-h(a)| = |h(g(y))-h(a)| \lt \epsilon,$$
as desired. Thus, $\lim_{x\to a^+}h(x)=h(a)$, as claimed.
The argument for the limit from the left is similar, which proves the theorem. $\Box$

Corollary. Let $h$ and $g$ be functions, and let $a$ be a real number. If:

$g(a) = a$; and
If $x\neq a$, then $g(x)$ is strictly between $a$ and $x$; and
$g(x)$ is continuous on an open interval containing $a$; and
$\lim_{x\to a}h(g(x)) = h(a)$;

then $h$ is continuous at $a$; that is, $\lim_{x\to a}h(x)=h(a)$.

Proof. Continuity implies the intermediate value property. $\Box$
Now apply the theorem with $a=x_0$, $h(x)=f'(x)$ and $g(x)$ a function that picks a point satisfying the conclusion of the Mean Value Theorem to get the desired conclusion: if that function is continuous, or if it has the Intermediate Value Property, then $f'$ is continuous at $x_0$.
Note that continuity of $g(x)$ at $a$ is not enough: for example, consider the function defined on $[0,1)$ by
$$g(x) = \left\{\begin{array}{ll}
\frac{1}{n} &\text{if }\frac{1}{n+1}\leq x\lt \frac{1}{n}, n=1,2,\ldots\\
0&\text{if }x=0.
\end{array}\right.$$
Extend it to take value $1$ on $[1,\infty)$, and extend it to negative values by $g(-x) = -g(x)$ if $x\gt 0$. This function is continuous at $0$, since $|g(x)|\lt|x|$ for all $x$, and $g(0)=0$.
Now let $h(x)$ take value $0$ at all numbers of the form $\frac{1}{n}$ with $n$ a nonzero integer, and value $1$ elsewhere. Then $\lim_{x\to 0}h(x)$ does not exist. However, $\lim_{x\to 0}h(g(x))=0$, because $h(g(x))=0$ for all $x\neq 0$. Thus, the intermediate value property cannot be replaced with "$g$ is continuous at $a$" in the Theorem.
Of course, there is no way to show that we can pick the points $\xi_x$ in a manner that will make this theorem work, simply because the desired conclusion is not true in general. We cannot strengthen the MVT to get us the desired properties.