First see the first comment on this post
and this post in general
So we begin by proving the chain rule by assuming we have $f,g$ where $f$ is differential at $x_0$ and $g$ at $f(x_0)$. We consider
$$\frac{g(f(x))-g(f(x_0))}{x-x_0}=\frac{g(f(x))-g(f(x_0))}{f(x)-f(x_0)}\frac{f(x)-f(x_0)}{x-x_0}$$
So we need to avoid the cases where $f(x)=f(x_0)$. Of course, if there are finitely many of them, we just toss them out and we are good to go. So my book defines $y_0=f(x_0)$
$$\frac{g(y)-g(y_0)}{y-y_0}$$ and, for each $y \in D'$ (the domain of $g$), and defines $h(y_0)=g'(y_0)$ so we have
$$lim_{y\to y_0}h(y)=g'(y_0)=h(y_0)$$ so $h$ is continuous as defined and they assert this gives us our result since the resulting products will have limits and so on.
How do we deal with the case where say $f(x)=f(x_0)$ everywhere? How do we deal with it when there are infinitely many points $f(x)=f(x_0)$. If someone could be very rigorous in proving and explaining the chain rule it would be greatly appreciated.