how to prove $f(x)=x^2$ is uniformly continuous on an infinite union of closed sets

Need to prove that $f(x)=x^2$ is uniformly continuous on $\bigcup_{n=1}^\infty \left[n, n+\frac1{n^2}\right]$

I know I can prove that f is uniformly continuous on $\left[n,n+\frac{1}{n^2}\right]$ but I'm not sure if it'll apply to this infinite union. Also this union is open, not closed so it's not compact, right?

• For the second question: that union not only it is not open, but it's also closed. However, it is not compact, because it is not bounded. – user228113 Mar 24 '17 at 18:30
• The set is not compact (otherwise this would be easy), because it is unbounded. To prove that the function is uniformly continuous, let $S_n = [n, n+1/n^2]$ and $S = \cup_n S_n$. Then use the fact that if $|x-y| < \delta$ and $x,y \in S_n$, then also $|x-y| \le n^{-2}$ and therefore $|x^2-y^2| = |x+y||x-y| \le 3nn^{-2} = 3/n$, for any $n$. – Hans Engler Mar 24 '17 at 18:36
• Sorry I don't really get the $|x−y|≤n^−2$. Can you give me more detail? – Emmie Ruta Mar 24 '17 at 18:38
• If $x,y \in S_n$, then $n \le x,y \le n + n^{-2}$, hence $|x-y| < n^{-2}$. And then $|x+y| \le |x| + |y| \le n+1 + n+1 \le 3n$, at least if $n > 1$. – Hans Engler Mar 24 '17 at 18:46
• Hi Hans, so for this I will set $delta=1/n^2$, so that $|x^2-y^2|$ is smaller than all epsilon? – Emmie Ruta Mar 24 '17 at 19:51

Lets define $M_l:=\bigcup_{n=1}^l \left[n, n+\frac1{n^2}\right]$ and let $\varepsilon>0$ be arbitrary. Since $$\lim_{n\to\infty}f(n+\frac1{n^2})-f(n) = \lim_{n\to\infty}\frac2n+\frac1{n^4}=0,$$ we can choose $k\in\Bbb N$ with $\varepsilon>f(n+\frac1{n^2})-f(n)>0$ for all $n>k$. It is easy to see now that one can find $\delta>0$, such that $|f(x)-f(y)|<\varepsilon$ for all $|x-y|<\delta$ with $x,y\in M_\infty\setminus M_k$. (This follows from the monotonicity of $f$ and the fact that the intervals $\left[n, n+\frac1{n^2}\right]$ is not getting arbitrarily close to each other.) Since $M_k$ is compact and $f$ is continuous, the restriction of $f$ to $M_k$ is uniformly continuous. Thus, by (possibly) sufficiently shrinking $\delta$, we can achieve $|f(x)-f(y)|<\varepsilon$ with $|x-y|<\delta$ and $x,y\in M_k$. Now we have $f$ uniformly down pat on the whole set $M_\infty$.