Differentiating piecewise functions. Say we have the piecewise function $f(x) = x^2$ on the interval $0 \le x < 4$; and it equals $x+1$ on the interval $ x \ge 4$. Why is it that, when I take the derivative, the intervals loose their equality and become strictly greater or strictly less than?

Note that $\displaystyle \lim_{x\to 4^-}(f(x))=\lim_{x\to 4^-}(x^2)=16$ while $\displaystyle\lim_{x\to 4^+}(f(x))=f(4)=5.$ Therefore $f$ isn't continuous on $x=4$ and so it can't be differentiable there. Hence the domain of the derivative doesn't include $4$.
Around $0$ the left lateral derivative isn't even defined, therefore $f$ can't be differentiable there.
Since $f$ is clearly differentiable on the interior of its domain, it follows that the domain of $f'$ is the interior of $f$'s domain, that is $\textbf{]}0,4[\cup \textbf{]}4+\infty[=\textbf{]}0,+\infty[\setminus \{4\}$.
