TITLE: Necessary and sufficient conditions for differentiability.
QUESTION [9 upvotes]: Apologizes if I'm missing something in my question or if my question seems trivial; this is my first question on this site. As motivation for my question, consider the following standard first year calculus question.

Consider this piecewise function:
  $
   f(x) = \left\{
     \begin{array}{lr}
       ax^2+b & \text{ if } x \le-2\\
       12x-5 & \text{ if } x >-2
     \end{array}
   \right.
$
For what values of $a$ and $b$ will $f(x)$ be differentiable?

To solve this question, I would like to propose the following theorem:

$\mathbf{Theorem:}$ A function $f(x)$ is differentiable iff $f'(x)$ is continuous.

If this theorem is true, then I can solve for $a$ first by noting that:
$
   f'(x) = \left\{
     \begin{array}{lr}
       2ax & \text{ if } x \le-2\\
       12 & \text{ if } x >-2
     \end{array}
   \right.
$
Thus, since by my theorem $f'(x)$ must be continuous, we have:
$$\begin{align*}
\lim_{x \rightarrow -2^-}f'(x) &= \lim_{x \rightarrow -2^+}f'(x)\\
\lim_{x \rightarrow -2^-}2ax &= \lim_{x \rightarrow -2^+}12\\
2a(-2) &= 12\\
-4a &= 12 \\
a &= -3 \\
\end{align*}$$
Hence, since differentiability implies continuity, we can solve for $b$ as follows:
$$\begin{align*}
\lim_{x \rightarrow -2^-}f(x) &= \lim_{x \rightarrow -2^+}f(x)\\
\lim_{x \rightarrow -2^-}-3x^2+b &= \lim_{x \rightarrow -2^+}12x-5\\
-3(-2)^2+b &= 12(-2)-5\\
b-12 &= -29\\
b &= -17 \\
\end{align*}$$
so that our differentiable function is:

$$
   f(x) = \left\{
     \begin{array}{lr}
       -3x^2-17 & \text{ if } x \le-2\\
       12x-5 & \text{ if } x >-2
     \end{array}
   \right.
$$

Anyways. My question is: Is my proposed theorem actually a thing? I've looked through my calculus textbook and it doesn't seem to explicitly state it, yet I don't know how to solve this question otherwise. If this theorem turns out to be false, how else can you solve this problem? Thanks in advance. =]

REPLY [3 votes]: For that function to be differentiable you need 
$$f'(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}$$
to exist.
The only point where something "weird" is going on, is at -2. Thus we just need to find $a, b$ such that 
$$\lim_{h \to 0^+} \frac{f(-2 + h) - f(-2)}{h} =  \lim_{h \to 0^-} \frac{f(-2 + h) - f(-2)}{h}$$
The right hand side is simply $-4a$, by using the regular rules of derivatives. The weirdness happens on the other side of the limit.
$$\lim_{h \to 0^-} \frac{12(-2 + h) - 5- (4a + b)}{h} = \lim_{h \to 0^-} \frac{-29 - 4a -b + 12h}{h}$$
In order for this limit to exist we need $-29 -4a -b = 0$. Otherwise the limit will be $-\infty$ or $+\infty$. Once we have $-29 -4a -b = 0$, we get 
$$\lim_{h \to 0^-} \frac{-29 - 4a -b + 12h}{h} = \lim_{h \to 0^-} \frac{12h}{h} = 12.$$
Since we need the left and the right limit to be the same, we get 
$-4a = 12$. Thus $a = -3$. Then solving for $b$, we have $-29 + 12 - b = 0$, so $b = -17$.