Problem:
Let $g : \mathbb{R} \to \mathbb{R}$ be continuous, and let
\begin{align}
g(x) \to a \quad &\text{for} \quad x \to -\infty, \\
g(x) \to b \quad &\text{for} \quad x \to \infty.
\end{align}
Prove that $g$ is uniformly continuous.
My attempt at a solution:
The first limit says that $$ \forall x \in \mathbb{R} \ \forall\varepsilon > 0 \ \exists A < 0 : x < A \ \Rightarrow \ |g(x) - a| < \varepsilon, $$ and the second limits says that $$ \forall x \in \mathbb{R} \ \forall \varepsilon > 0 \ \exists B > 0 : x > B \ \Rightarrow \ |g(x) - b| < \varepsilon. $$ The way I have attempted to solve this is by looking at the interval $[A, B]$ and diving the problem into cases. If I can prove that $g$ is uniformly continuous for wherever $x$ and $y$ are in $\mathbb{R}$, then I will be done.
$g$ is uniformly continuous in $x, y \in [A, B]$ by the Heine-Cantor theorem.
For $x, y < A$ or $x, y < B$ (outside of $[A, B]$), that $g$ is uniformly continuous follows from using the limits and then the triangle inequality:
\begin{align} x, y &< A \ \Rightarrow \ |g(y) - g(x)| \leq |g(y) - a| + |a - g(x)| < \frac{\varepsilon}{2} + \frac{\varepsilon}{2} = \varepsilon, \\ x, y &> B \ \Rightarrow \ |g(y) - g(x)| \leq |g(y) - b| + |b - g(x)| < \frac{\varepsilon}{2} + \frac{\varepsilon}{2} = \varepsilon. \end{align}
- For $x \in [A, B]$ and $y > B$ (or $y < A$) where one is inside the interval and the other is outside, I don't know what to do.
I have tried using the triangle inequality twice:
\begin{align} |g(y) - g(x)| = |g(y) - g(B) + g(B) - g(x)| &\leq |g(y) - g(B)| + |g(B) - g(x)| \end{align} Since $x, B \in |A, B|$, $|g(B) - g(x)| \leq \frac{\varepsilon}{3}$. Using the triangle inequality on the first term, we get $$ |g(y) - g(B)| = |g(y) - b + b - g(B)| \leq |g(y) - b| + |b - g(B)|... $$ I am stuck here and have no idea if this is what I am supposed to do.