Is it really true that "if a function is discontinuous, automatically, it's not differentiable"? I while back, my calculus teacher said something that I find very bothersome. I didn't have time to clarify, but he said:

If a function is discontinuous, automatically, it's not differentiable.

I find this bothersome because I can think of many discontinuous piecewise functions like this:
$$f(x) =
\begin{cases}
x^2, & \text{$x≤3$} \\
x^2+3, & \text{$x>3$}
\end{cases}$$
Where $f'(x)$ would have two parts of the same function, and give:
$$\begin{align}
f'(x) = &&
\begin{cases}
2x, & \text{$x≤3$} \\
2x, & \text{$x>3$}
\end{cases} \\
= && 2x
\end{align}$$
So I'm wondering, what exactly is wrong with this? Is there something I'm missing about what it means to be "continuous"? Or maybe, are there special rules for how to deal with the derivatives of piecewise functions, that I don't know about.
 A: The problem is when you gave the derivative for $x \leq 3.$ What you gave is correct for $x < 3,$ but not for $x=3.$ Consider secant slopes to nearby points with one point fixed at $(3,9),$ which is what the definition of the derivative requires. Looking to the left, you get secant slopes that converge to $6$ as you approach the fixed point $(3,9).$ But looking to the right you get secant slopes that approach $+\infty$ as you approach the fixed point $(3,9).$
A: The derivative depends of the behavior of the function in a neighborhood of the point. In this case, you can only say
$$
f'(x) =
\begin{cases}
2x, & x<3\\
2x, & x>3
\end{cases}\\
= 2x,\qquad x\ne 3.
$$
And $f'(3)$ does not exist.
A: Draw the picture.  To the left of the vertical line $x=3$ you see half of a parabola that opens upward.  To the right you see half of another parabola that opens upward, but it is vertically shifted.  That means there is no slope of the curve at that point.  The slope approaches the same thing on either curve as you approach that vertical line, and that is what you've shown.  But look at the vertical jump at that point.
Suppose that as $x\to3$ we have
$$
\frac{f(x) - f(3)}{x-3} \to L
$$
so that $f'(3)=L$.  Then
\begin{align}
\lim_{x\to 3} (f(x)-f(3)) & = \lim_{x\to 3} \left( (x-3) \frac{f(x)-f(3)}{x-3} \right) \\[10pt]
& = \left( \lim_{x\to 3} (x-3) \right) \left( \lim_{x\to 3} \frac{f(x)-f(3)}{x-3} \right) = 0 \cdot L \\[6pt]
& \qquad\qquad (\text{where } L = f'(3) ) \\[10pt]
& = 0,
\end{align}
which would imply $f(x)\to f(3)$, so that $f$ is continuous at $3$.  Hence if $f'(3)$ exists, then $f$ is continuous at $3$.
A: Your idea of continuity is fine but your idea of differentiable has a niave and easy to make oversight.
$f$ is differentiable at $x$ if the following limits exist and are equal:
1) $\lim_{x_0\rightarrow x^+}\frac{f(x_0) - f(x)}{x_0 - x} = \lim_{h\rightarrow 0}\frac{f(x+h) - f(x)}{h}$.
2)$\lim_{x_0\rightarrow x^-}\frac{f(x) - f(x_0)}{x - x_0} = \lim_{h\rightarrow 0}\frac{f(x) - f(x-h)}{h}$.
In your function the second limit is fine: $\lim_{x_0\rightarrow 3^-}\frac{f(3) - f(x_0)}{3 - x_0} = \lim_{h\rightarrow 0}\frac{f(3) - f(3-h)}{h}= (9^2 - 9^2 + 2*3h - h^2)/h = 6$.
But the first limit is screwed: $\lim_{x_0\rightarrow 3^+}\frac{f(x_0) - f(3)}{x_0 - 3} = \lim_{h\rightarrow 0}\frac{[f(3+h)] - f(3)}{h} = ([(3+h)^2 + 3] - 3^2]/h = [(9 + 6h + h^2 + 3) - 9]/h = (3 + 6h + h^2)/h = \infty.$
A: Let's look at your function.
$$f(x) =
\begin{cases}
x^2, & \text{$x≤3$} \\
x^2+3, & \text{$x>3$}
\end{cases}$$
Clearly, the only interesting point is when $x = 3$. So let's see differentiability at $3$. Then we look at
$$ \frac{f(3+h) - f(3)}{h} = \frac{(3+h)^2 + 3 - 3^2}{h} = \frac{3 + 6h + h^2}{h}.$$
As $h \to 0$ (from the right), you can see that this last term goes to $\infty$, and so the function is not differentiable at $3$.
If you think about it, this makes sense. The derivative gives the best local linear approximation, and the rate of change at $3$ isn't defined --- it's a jump discontinuity, and there is no tangent line there.
Do you now see where you went wrong?
A: Flagrantly ignoring your specific example: suppose a function $f$ is differentiable at a point $x$. Then by definition of differentiability:
$$\lim_{h\rightarrow0}\frac{f(x+h) - f(x)}{h}$$
must exist (and by this notation I mean the limits exist in both the positive and negative directions and are equal). Since the bottom of that fraction approaches $0$, it's necessary for the top also to approach $0$, or else the fraction diverges. But the top approaching $0$ is just the definition of $f$ being continuous at $x$. So a function that isn't continuous can't be differentiable.
So, your example fails to be differentiable for the same reason that it fails to be continuous, which is that top of that fraction tends to $3$, not $0$, when approached from the positive direction.
