A continuous function, with discontinuous derivative, but the limit must exist. I was reading this question. 
The simplest examples of continuous functions, with discontinuous derivatives in some point, are usually of the form:
$$
f(x) = \begin{cases} 
  x^2 \sin(1/x) &\mbox{if } x \neq 0 \\
0 & \mbox{if } x=0. 
\end{cases}
$$
The derivative of $f$ is 
$$
f'(x) = \begin{cases} 
  2 x \sin \left(\frac{1}{x}\right)-\cos \left(\frac{1}{x}\right)&\mbox{if } x \neq 0 \\
0 & \mbox{if } x=0,
\end{cases}
$$
The derivative is discontinuous because the limit of $\cos \left(\frac{1}{x}\right)$ does not exist for $x\rightarrow 0$. 
Is there an example where the derivative is still discontinuous but with existing limit?
Thanks
 A: Suppose $f$ is differentiable in some neighborhood $(x-\delta,x+\delta)$ of $x$, and $\lim\limits_{t\rightarrow x}{f'(t)}$ exists. Define $y:(x-\delta,x+\delta)\rightarrow\mathbb{R}$ such that $y(t)$ is strictly between $x$ and $t$ and
$$f(t)-f(x) = f'(y(t))(t-x)$$
for every $t\in(x-\delta,x+\delta)$. The existence of such a function is guaranteed by the Mean Value Theorem. Since $y(t)$ is between $x$ and $t$ for every $t$, this implies that $\lim\limits_{t\rightarrow x}{y(t)} = x$, and since $y(t)\ne x$ for $t\ne x$ as well, we have $\lim\limits_{t\rightarrow x}{f'(y(t))}=\lim\limits_{s\rightarrow x}{f'(s)}$ by the composition law (think of $s = y(t)$ in this substitution). This implies that
$$f'(x) = \lim\limits_{t\rightarrow x}{\frac{f(t)-f(x)}{t-x}} = \lim\limits_{t\rightarrow x}{f'(y(t))} = \lim\limits_{t\rightarrow x}{f'(t)},$$
i.e. $f'$ is continuous at $x$.

Remark: Typically, the composition law is phrased as follows: if $\lim\limits_{x\rightarrow c}{g(x)} = a$ and $f$ is continuous at $a$, then $\lim\limits_{x\rightarrow c}{f(g(x))} = \lim\limits_{u\rightarrow a}{f(u)}$. In our problem, we obviously cannot assume $f'$ is continuous at $x$, since that is what we are trying to show. However, the above conclusion still holds if we merely require that $g(x)\ne a$ if $x\ne c$ in some neighborhood of $c$. A proof of this can be found here (look for "Hypothesis 2").
