Extending a function by continuity from a dense subset of a space

In the light of Alex Youcis's comment, I will assume that $X$ and $Y$ are metric spaces. The following approach has been taken verbatim (apart from notation changes) from John Erdman, A ProblemText in Advanced Calculus (Chapter 24, pp. 146-147).

  1. If $f : X \to Y$ is a uniformly continuous map between two metric spaces and $(x_n)$ is a Cauchy sequence in $X$, then $f(x_n)$ is a Cauchy sequence in $Y$.

  2. Let $X$ and $Y$ be metric spaces, $S \subseteq X$, and $f : S \to Y$ be uniformly continuous. If two sequences $(x_n)$ and $(y_n)$ in $S$ converge to the same limit in $X$ and if the sequence $f(x_n)$ converges, then the sequence $f(y_n)$ converges and $\lim f(x_n) = \lim f(y_n)$.

Proof Hint. Consider the "interlaced" sequence $(x_1, y_1, x_2, y_2, x_3, y_3, \ldots)$.

Now, the main theorem.

Theorem. Let $X$ and $Y$ be metric spaces, $S$ a subset of $X$, and $f : S \to Y$. If $f$ is uniformly continuous and $Y$ is complete, then there exists a unique continuous extension of $f$ to $\overline S$. Furthermore, this extension is uniformly continuous.

Proof Hint. Define $g : \overline S \to Y$ by $g(a) = \lim f(x_n)$ where $(x_n)$ is a sequence in $S$ converging to $a$. First show that $g$ is well defined. To this end you must show that

  • $\lim f(x_n)$ does exist, and
  • the value assigned to $g$ at $a$ does not depend on the particular sequence $(x_n)$ chosen. That is, if $x_n \to a$ and $y_n \to a$, then $\lim f(x_n) = \lim f(y_n)$.

Next show that $g$ is an extension of $f$.

To establish the uniform continuity of $g$, let $a$ and $b$ be points in $\overline S$. If $(x_n)$ is a sequence in $S$ converging to $a$, then $f(x_n) \to g(a)$. This implies that both $d(x_j , a)$ and $d (f(x_j ), g(a))$ can be made as small as we please by choosing $j$ sufficiently large. A similar remark holds for a sequence $(y_n)$ in $S$ which converges to $b$. From this show that $x_j$ is arbitrarily close to $y_k$ (for large $j$ and $k$) provided we assume that $a$ is sufficiently close to $b$. Use this in turn to show that $g(a)$ is arbitrarily close to $g(b)$ when $a$ and $b$ are sufficiently close.

The uniqueness argument is very easy.


(I also assume that we work with metric spaces.)
If you only need continuity of $g$, then continuity (not uniform) of $f$ is enough*. Let a sequence $x_n \in X$ converge to some point $x$. We will show that $g(x_n)$ converges to $g(x)$. I will write '(#)' in places, where we use the definition of $g$ for better readibility.

For every $x_n$ ($n$ is fixed) there exists a sequence $(w_n^m)_{m=1}^\infty \in D$ that converges to $x_n$. Since $f(w_n^m) \ \to g(x_n)$ (#) and $w_n^m \to x_n$, we may choose such $m_n$ that $d_X(w_n^{m_n}, x_n)$ and $d_Y(f(w_n^{m_n}), g(x_n))$ are smaller then $\frac{1}{n}$.
Now (from $d_X(w_n^{m_n}, x_n) < \frac{1}{n}$) you have: $\lim_{n \to \infty} w_n^{m_n} = x $, so (#):
$\lim_{n \to \infty} f(w_n^{m_n}) = g(x) $,
but we have also $d_Y(f(w_n^{m_n}),g(x_n)) < \frac{1}{n}$, so:
$\lim_{n \to \infty} g(x_n) = g(x) $, which gives us the continuity of $g$.

*However you still need uniform continuity to show that $g$ is uniquely defined, so my approach is not better, it is just different.