TITLE: Why is the "correct" proof of the chain rule correct? What is actually happening here?
QUESTION [7 upvotes]: There is a correct and an incorrect proof going around when it comes to the Chain Rule (see below). The problem with the incorrect proof is that $g(x)-g(a)$ might be $0$ if $x\to a$ creating a division by zero.
Question
I can't get my head around why the correct proof solves the problem of the incorrect proof. Why can we just define a function $E$ and suddenly all our problems disappear?
I just don't really get what actually happens in the correct proof. It just didn't "click" in my brain yet. Any help would be much appreciated. 
By the way; is my "correct proof" below indeed correct?
Incorrect proof:
$$\lim \limits_{x \to a}\frac{f(g(x))-f(g(a))}{x-a}=\lim \limits_{x \to a}\frac{f(g(x))-f(g(a))}{g(x)-g(a)}\times\frac{g(x)-g(a)}{x-a}=f'(g(x))g'(x)$$
Correct proof:
We first define a function $E$
$$E(0)=0$$
$$E(g(x)-g(a))=\frac{f(g(x))-f(g(a))}{g(x)-g(a)}-f'(g(x))$$
In any case:
$$f(g(x))-f(g(a))=(E(g(x)-g(a))+f'(g(x)))\times(g(x)-g(a))$$
Dividing by $x-a$ and taking the limit we get:
$$\begin{align}
\frac{d}{dx}f(g(x))&=\lim \limits_{x \to a}\frac{f(g(x))-f(g(a))}{x-a}\\
&=\lim \limits_{x \to a}(E(g(x)-g(a))+f'(g(x)))\times\frac{g(x)-g(a)}{x-a}\\&=f'(g(x)g'(x)
\end{align}$$

EDIT: In other words: we basically state that when $g(x)=g(a)$:
$$\frac{f(g(x))-f(g(a))}{g(x)-g(a)}-f'(g(x))=0$$
But why can we state that? As I understand it, this is true for the limit, but why are we allowed to also state it for the actual value?

REPLY [2 votes]: Here is one proof which does not require you to have any special definition for the difference quotient. Consider the ratio $$\frac{f(g(x)) - f(g(a))} {x-a} \tag{1}$$ It can be written as $$\frac{f(g(x))-f(g(a))}{g(x)-g(a)}\cdot \frac{g(x) - g(a)} {x-a} \tag{2}$$ provided $g(x) - g(a) \neq 0$ for all $x$ in some deleted neighborhood of $a$. Under this assumption the usual proof works and we get the result $(f\circ g) '(a) =f' (g(a)) g'(a) $ by taking limit as $x\to a$ in equation $(2)$.
Let's see what happens when this assumption does not hold. It means that in every deleted neighborhood of $a$ we have some $x$ for which $g(x) =g(a) $. It is easy to prove that in this case we have $g'(a) =0$ (prove this and let me know if you need help here, you can start by assuming $g'(a) >0$ and try to get a contradiction and similarly handle $g'(a) <0$). Now we can see that if $g(x) =g(a) $ then the difference quotient in $(1)$ is $0$. And if $g(x) \neq g(a) $ then the difference quotient can be written as in $(2)$ and the first factor is bounded (because $f'(g(a)) $ exists) and second factor tends to $0$ so that the overall product also tends to $0$ as $x\to a$ and thus $(f\circ g) '(a) =0$. The reasoning in the last sentence can be formalized with the definition of limit as shown below.

Let $\epsilon >0$ be arbitrary. There exists a $\epsilon' >0$ such that $$\left|\frac{f(y) - f(g(a))} {y-g(a)} - f'(g(a)) \right|<1$$ for all $y$ with $0<|y-g(a)|<\epsilon '$. Therefore $$\left|\frac{f(y) - f(g(a))} {y-g(a)} \right|<|f' (g(a)) |+1=K\text{(say)}\tag{3}$$ whenever $0<|y-g(a)|<\epsilon '$. Next note that $g$ is continuous at $a$ (because it is differentiable at $a$) therefore we have a $\delta_{1}>0$ such that $$|g(x) - g(a) |<\epsilon' \tag{4}$$ whenever $|x-a|<\delta_{1}$. Further since $g'(a) =0$ there is a $\delta_{2}>0$ such that $$\left|\frac{g(x) - g(a)} {x-a} \right|<\frac{\epsilon} {K}\tag{5} $$ whenever $0<|x-a|<\delta_{2}$. Let $\delta=\min(\delta_{1},\delta_{2})$. If $0<|x-a|<\delta$ then both the inequalities $(4)$ and $(5)$ hold. Further if $g(x) =g(a)$ then difference quotient in $(1)$ is $0$ and if $g(x)\neq g(a) $ then by all the previous equations we can see that the difference quotient in $(1)$ is less than $\epsilon$ in absolute value. In other words we have $$\left|\frac{f(g(x)) - f(g(a))} {x-a} \right|<\epsilon$$ whenever $0<|x-a|<\delta$. Thus $(f\circ g) '(a) =0$.

The above proof is taken from Hardy's A Course of Pure Mathematics and it avoids the trick used by Spivak (defining the difference quotient $(1)$ in a continuous manner when $g(x) =g(a) $). The essential idea of the proof is easy to understand and the last part of the proof dealing with $\epsilon, \delta$ is necessary only to satisfy those who insist.