TITLE: what fails in this proof of limits?
QUESTION [5 upvotes]: I always thought that this theorem was true, but today when asking about the proof of the chain rule in calculus I realized that it is false. I understand the counterexample, but now I don't understand where my proof fails. (Here is my attempt to prove the chain rule in calculus and the counterexample is in the answer).
Theorem:

Let $A,B\subseteq \mathbb{R}$, $f:A\longrightarrow B$, and $g:B\longrightarrow \mathbb{R}$ functions. Let $a\in R$ be an accumulation point of $A$. Let's suppose that $\lim_{x\to a}f(x)=b$ and $\lim_{x\to b} g(x)=l$. Then $\lim_{x\to a}(g\circ f)(x)$ exists and equals $l$.

Proof:
Let $\epsilon>0$ be an arbitrary number in $\mathbb{R}$. Since  $\lim_{x\to b} g(x)=l$ then there is $\delta >0$ in $\mathbb{R}$ such that $\forall x\in B (0<|x-b|<\delta \longrightarrow |g(x)-l|<\epsilon)$. Since $\lim_{x\to a}f(x)=b$ then there is $\delta '>0$ such that $\forall x\in A(0<|x-a|<\delta '\longrightarrow |f(x)-b|<\delta)$. But then $\forall x\in A(0<|x-a|<\delta '\longrightarrow |g(f(x))-l|<\epsilon)$. This means that $\lim_{x\to a}(g\circ f)(x)$ exists and equals $l$.

REPLY [3 votes]: Suppose that $g$ is not continuous at $b$, so that $l \neq g(b)$, and suppose that for any choice of $\varepsilon$, is some $x^\ast_\varepsilon$ satisfying $0 < |x^\ast_\varepsilon - a| < \delta'(\varepsilon)$ and $f(x^\ast_\varepsilon) = b$ (this can happen, for example, if $f$ is the constant function $f(x) \equiv b$). If both of these things happen, then
$$|g(f(x^\ast_\varepsilon)) - l| = |g(b) - l| > 0.$$
It then follows that if we choose $\varepsilon < |g(b) - l|$, we have
$$|g(f(x^\ast_\varepsilon)) - l| = |g(b) - l| > \varepsilon \text{ even though } |x^\ast_\varepsilon - a| < \delta'(\varepsilon).$$
Hence your choice of $\delta'(\varepsilon)$ doesn't work in this scenario.
If you assume that either $g$ is continuous or $f(x) \neq b$ for $x$ close to $a$, then your proof will work.