# Composition of a continuous function with functions that converge uniformly

Here is problem that appeared in one of the past final exams for my introductory real analysis course, that I am having hard time to solve. It is Question 5 in 8 of the following file:

Let $\{f_n\}_{n\in\mathbb{N}}$ be a uniformly convergent sequence of continuous real–valued functions defined on a metric space $M$ and let $g$ be a continuous function on $\mathbb{R}.$ Define, for each $n\in\mathbb{N}$, $h_n(x) = g(f_n(x))$.

(a) Let $M = [0, 1]$. Prove that the sequence $\{h_n\}_{n\in\mathbb{N}}$ converges uniformly on $[0, 1]$.

(b) Let $M = \mathbb{R}$. Either prove that the sequence $\{h_n\}_{n\in\mathbb{N}}$ converges uniformly on $\mathbb{R}$ or provide a counterexample.

I have proved part (a). I am having trouble with part (b). It seems to me that part (b) has a counterexample. This is because, the key point in part (a) is that $g$ is uniformly continuous on $[0,1]$ (because $[0,1]$ is compact), but in part (b) compactness is removed. So my guess is that counter-example will involve something like $g(x)=x^2$ (which is an example of continuous function which is not uniformly continuous on $\mathbb{R}$). Is this guess correct? What would be an example of uniformly convergent sequence $\{f_n\}$ of functions in this case?

I would very much appreciate any help!

Hint: Put $f_n=x-\frac 1n$ for each $n$.
Using Alex Ravsky's hint, one such counterexample for part (b) is $f_n(x)=x-\frac{1}{n}$ for each $n$, and $g(x)=x^2$. Here is my full solution:
First of all, $f_n(x)$ converges uniformly to $f(x)=x$, since $$\sup_{x\in R} |f_n(x)-f(x)|=\frac{1}{n}\to 0 \ \ \ \ \ \textrm{as } n\to\infty$$
We claim that the sequence of functions defined by $h_n(x)=g(f_n(x))=(x-\frac{1}{n})^2$ converges pointwise, but not uniformly to $h(x)=x^2$. Indeed, for given $\epsilon>0$ and $x\in\mathbb{R}$, we can choose $N$ so large that $$\frac{|2x|}{N}+\frac{1}{N^2}<\epsilon$$ Then for any $n\ge N$, we get $$|h_n(x)-h(x)|=\left|x^2-\frac{2x}{n}+\frac{1}{n^2} - x^2\right|\le \frac{|2x|}{n}+\frac{1}{n^2}\le\frac{|2x|}{N}+\frac{1}{N^2}<\epsilon$$ which proves pointwise convergence. The convergence is not uniform because $$|h_n(n)-h(n)|=\left|\left(n-\frac{1}{n}\right)^2-n^2\right|=2-\frac{1}{n^2}\ge 1$$ for each $n\in\mathbb{N}$. In particular, $$\sup_{x\in R} |h_n(x)-h(x)|\not\to 0\ \ \ \ \ \textrm{as } n\to\infty$$