How to apply the definition of a derivative with a piecewise function? Given the function:
$$f(x) = \begin{cases} x^2+1 & \text{if $x\ge0$} \\ x^2-1 & \text{if $x < 0$} \end{cases}$$
Question: are we justified to say that the derivative at $f(0)$ exists? If so, what is $f'(0)$? And how do we justify it?
Of course I do realize that the function isn't continuous at $x=0$ but still since the slope near $x=0$ seems equal near $0+$ and $0-$ I wondered why we can't say that $f'(0)=0$
What I tried is this:
$f_+'(0)=\lim\limits_{h \to 0+}\frac{(x+h)^2+1-(x^2+1)}{h}=\lim\limits_{h \to 0+}\frac{(0+h)^2+1-(0^2+1)}{h}=\lim\limits_{h \to 0+}\frac{h^2}{h}=h=0$
$f_-'(0)=\lim\limits_{h \to 0-}\frac{(x+h)^2+1-(x^2+1)}{h}=\lim\limits_{h \to 0-}\frac{(0+h)^2+1-(0^2+1)}{h}=\lim\limits_{h \to 0-}\frac{h^2}{h}=h=0$
My conclusion is that since both the right and left limit using the definition of the derivative exist and generate the same answer the limit exists such that $f'(0)=0$.
Apparently this is not true, so what is my mistake?
 A: Any function which is differentiable at a point $x_0$ must also be continuous at $x_0$.  Since the left and right hand limits of $f$ do not agree, your function is not continuous at $0$.  Therefore the derivative does not exist at $0$ even though the derivative seems to be approaching the same value from both directions.
In more detail,
$$\lim_{h\to 0^+}\frac{f(0+h)-f(0)}h=\lim_{h\to 0^+}\frac{h^2+1-1}h=\lim_{h\to 0^+}h=0.$$
But
$$\lim_{h\to 0^-}\frac{f(0+h)-f(0)}h=\lim_{h\to 0^-}\frac{h^2-1-1}h=\lim_{h\to 0^-}\frac{h^2-2}h=\infty.$$
A: If a function $g: \Bbb R \to \Bbb R$ is differentiable at some point $x_0 \in \Bbb R$, then $f$ is also continuous in $x_0$. 
Now, let's consider the left- and right-sided limits of your function $f$ at the point $0$. We see that 
$$ \lim_{x \to 0^+} f(x) = \lim_{x \to 0^+} (x^2 + 1) = 1 \; ,$$
and 
$$ \lim_{x \to 0^-} f(x) = \lim_{x \to 0^-} (x^2 - 1) = -1 \; , $$
which means that $f$ is not continuous at the point $0$. So $f$ is not differentiable at the point $0$ and $f'(0)$ is not defined.
A: To be differentiable a function must be continuous.  Let's go back to the definition of a derivative.  NOT the calculation via limits of derivatives but the conceptual meaning of derivative.
"The derivative of a function of a real variable measures the sensitivity to change of a quantity (a function value or dependent variable) which is determined by another quantity (the independent variable)."  
So at x = 0, the functions sensitivity to change as x decreases is infinite.  The function "jumps" from value 1 to value -1 in no measurable change at all.  This is infinite, huge, and unmeasurable sensitivity.
In short, no derivative can exist at x = 0.
=========================
Also your calculation is in error:
$f_-'(0)=\lim\limits_{h \to 0-}\frac{(x+h)^2+1-(x^2+1)}{h}=\lim\limits_{h \to 0-}\frac{(0+h)^2+1-(0^2+1)}{h}=\lim\limits_{h \to 0-}\frac{h^2}{h}=h=0$  is incorrect.
$f_-'(0)=\lim\limits_{h \to 0-}\frac{f(0 -h)-f(0)}{h} =\frac{[(0+h)^2-1]-[(0^2+1)]}{h}$ (Note: $0 - h < 0$ BUT $0 \ge 0$ so $f(0-h) = (0-h)^2 -1 = h^2 -1$ but $f(0) = 0^2 + 1 = 1$) 
$=\lim\limits_{h \to 0-}\frac{h^2-2}{h}=\lim\limits_{h \to 0-}\frac{h^2 -2}{h}=h - \frac 2 h= -\infty$
Which is really much more to the point.
As one can't define a discontinuous function as two different values at the discontinuity there will be one direction where $\lim f(x \pm h) - f(x)$ will NOT equal 0.  If so you get $\lim f(x \pm h) - f(x)/h = \text{not_zero}/0 = \pm \infty$
A: You can differentiate any locally integrable function if you view it as a generalized function - in other views as a distribution. The main concept to remember is 
$$u'=\delta$$
where $u$ is the standard step-function and $\delta$ is Dirac's delta. Hence $$f'(x)=2x+2\delta(x).$$
