[proofplan]
We construct the extension $\bar{f}$ pointwise: for each $x \in X$, choose a sequence in $D$ converging to $x$ (possible since $D$ is dense), show that the image sequence is Cauchy in $Y$ (using uniform [continuity](/page/Continuity) of $f$), define $\bar{f}(x)$ as the limit (using completeness of $Y$), and verify the definition is independent of the approximating sequence. We then prove $\bar{f}$ is uniformly continuous by a three-segment estimate, and establish uniqueness from density and the Hausdorff property.
[/proofplan]
[step:Approximate each point $x \in X$ by a sequence in $D$ and show its image is Cauchy]
Let $x \in X$. Since $D$ is dense in $X$, there exists a sequence $(d_k)_{k=1}^\infty$ in $D$ with $d_k \to x$ in $(X, d_X)$.
We show that $(f(d_k))_{k=1}^\infty$ is a [Cauchy sequence](/page/Cauchy%20Sequence) in $(Y, d_Y)$. Let $\varepsilon > 0$. Since $f: D \to Y$ is uniformly [continuous](/page/Continuity), there exists $\delta > 0$ such that
\begin{align*}
d_X(a, b) < \delta \implies d_Y(f(a), f(b)) < \varepsilon \quad \text{for all } a, b \in D.
\end{align*}
Since $d_k \to x$, there exists $K \in \mathbb{N}$ such that $d_X(d_k, x) < \delta / 2$ for all $k \ge K$. For $k, l \ge K$, the triangle inequality gives
\begin{align*}
d_X(d_k, d_l) \le d_X(d_k, x) + d_X(x, d_l) < \frac{\delta}{2} + \frac{\delta}{2} = \delta.
\end{align*}
Since $d_k, d_l \in D$ and $d_X(d_k, d_l) < \delta$, uniform continuity of $f$ yields $d_Y(f(d_k), f(d_l)) < \varepsilon$. Therefore $(f(d_k))$ is Cauchy in $(Y, d_Y)$.
[guided]
Let $x \in X$. Since $D$ is dense in $X$, the closure $\overline{D} = X$, which means every open ball $B(x, r)$ in $X$ intersects $D$. In particular, for each $k \in \mathbb{N}$, the ball $B(x, 1/k)$ contains some point $d_k \in D$. The sequence $(d_k)_{k=1}^\infty$ satisfies $d_X(d_k, x) < 1/k$, so $d_k \to x$.
We now ask: does the image sequence $(f(d_k))_{k=1}^\infty$ converge in $Y$? We cannot answer this directly without knowing the limit, but we can show the sequence is Cauchy and then invoke completeness.
Let $\varepsilon > 0$. Since $f: D \to Y$ is uniformly continuous, there exists $\delta > 0$ (depending only on $\varepsilon$, not on the choice of points) such that
\begin{align*}
d_X(a, b) < \delta \implies d_Y(f(a), f(b)) < \varepsilon \quad \text{for all } a, b \in D.
\end{align*}
Since $d_k \to x$, there exists $K \in \mathbb{N}$ with $d_X(d_k, x) < \delta / 2$ for all $k \ge K$. For any $k, l \ge K$, the triangle inequality in $(X, d_X)$ gives
\begin{align*}
d_X(d_k, d_l) \le d_X(d_k, x) + d_X(x, d_l) < \frac{\delta}{2} + \frac{\delta}{2} = \delta.
\end{align*}
Both $d_k$ and $d_l$ lie in $D$, so the uniform continuity estimate applies: $d_Y(f(d_k), f(d_l)) < \varepsilon$. Since $\varepsilon > 0$ was arbitrary, $(f(d_k))$ is Cauchy in $(Y, d_Y)$.
The crucial point is that we used *uniform* continuity, not mere continuity. Ordinary continuity would only give $\delta = \delta(\varepsilon, a)$ depending on the base point, which is insufficient since the base point $x$ may not even lie in $D$ (so $f(x)$ is not defined). Uniform continuity provides a single $\delta$ that works uniformly over all of $D$, allowing us to transfer the Cauchy property from the domain to the codomain.
[/guided]
[/step]
[step:Define $\bar{f}(x)$ as the limit and verify well-definedness]
Since $(Y, d_Y)$ is complete and $(f(d_k))$ is Cauchy, the limit $\lim_{k \to \infty} f(d_k)$ exists in $Y$. Define
\begin{align*}
\bar{f}: X &\to Y \\
x &\mapsto \lim_{k \to \infty} f(d_k)
\end{align*}
where $(d_k)$ is any sequence in $D$ converging to $x$.
We verify that $\bar{f}(x)$ does not depend on the choice of approximating sequence. Let $(d_k')_{k=1}^\infty$ be another sequence in $D$ with $d_k' \to x$. The interleaved sequence $(d_1, d_1', d_2, d_2', \ldots)$ also converges to $x$ in $(X, d_X)$. By the argument above, its image under $f$ is Cauchy in $(Y, d_Y)$, hence convergent. Since every convergent sequence has a unique limit ($(Y, d_Y)$ is a [metric space](/page/Metric%20Space), hence Hausdorff by [Metric Spaces are Hausdorff](/theorems/290)), the subsequences $(f(d_k))$ and $(f(d_k'))$ — being subsequences of the same convergent sequence — share the same limit. Therefore $\bar{f}(x)$ is well-defined.
For $x \in D$, the constant sequence $d_k = x$ converges to $x$, so $\bar{f}(x) = \lim_{k \to \infty} f(x) = f(x)$. Hence $\bar{f}|_D = f$.
[guided]
Since $(Y, d_Y)$ is complete and $(f(d_k))$ is a [Cauchy sequence](/page/Cauchy%20Sequence) in $Y$, the sequence $(f(d_k))$ converges to some point in $Y$. We define $\bar{f}(x)$ to be this limit:
\begin{align*}
\bar{f}: X &\to Y \\
x &\mapsto \lim_{k \to \infty} f(d_k).
\end{align*}
But this definition depends on the choice of sequence $(d_k)$ in $D$ converging to $x$, and there are many such sequences (since $D$ is dense, any neighbourhood of $x$ contains infinitely many points of $D$). We must show the limit is the same for all choices.
Let $(d_k')_{k=1}^\infty$ be another sequence in $D$ with $d_k' \to x$. Consider the interleaved sequence $e_k$ defined by $e_{2k-1} = d_k$ and $e_{2k} = d_k'$ for $k \in \mathbb{N}$. Then $e_k \to x$ in $(X, d_X)$ (since both subsequences converge to $x$, every subsequence does, and hence the full sequence converges). By the same Cauchy argument as in the previous step, $(f(e_k))$ is Cauchy in $(Y, d_Y)$ and therefore convergent in $Y$.
Now $(f(d_k))$ and $(f(d_k'))$ are subsequences of the convergent sequence $(f(e_k))$. In a metric space, subsequences of a convergent sequence converge to the same limit (this follows from [Metric Spaces are Hausdorff](/theorems/290) and the [Uniqueness of Limits in Hausdorff Spaces](/theorems/291)). Therefore $\lim_k f(d_k) = \lim_k f(d_k')$, and $\bar{f}(x)$ is well-defined.
**Extension property.** For $x \in D$, the constant sequence $d_k = x$ for all $k$ lies in $D$ and converges to $x$. Therefore $\bar{f}(x) = \lim_k f(d_k) = \lim_k f(x) = f(x)$. This gives $\bar{f}|_D = f$.
[/guided]
[/step]
[step:Prove $\bar{f}$ is uniformly continuous via a three-segment estimate]
Let $\varepsilon > 0$. By uniform [continuity](/page/Continuity) of $f$, there exists $\delta_0 > 0$ such that $d_X(a, b) < \delta_0$ implies $d_Y(f(a), f(b)) < \varepsilon / 3$ for all $a, b \in D$. Set $\delta := \delta_0 / 3$.
Let $x, x' \in X$ with $d_X(x, x') < \delta$. Choose sequences $(d_k)$ and $(d_k')$ in $D$ with $d_k \to x$ and $d_k' \to x'$. By definition, $\bar{f}(x) = \lim_k f(d_k)$ and $\bar{f}(x') = \lim_k f(d_k')$.
For $k$ sufficiently large, $d_X(d_k, x) < \delta$ and $d_X(d_k', x') < \delta$. Then
\begin{align*}
d_X(d_k, d_k') \le d_X(d_k, x) + d_X(x, x') + d_X(x', d_k') < \delta + \delta + \delta = 3\delta = \delta_0.
\end{align*}
Since $d_k, d_k' \in D$ and $d_X(d_k, d_k') < \delta_0$, uniform continuity gives $d_Y(f(d_k), f(d_k')) < \varepsilon / 3$.
Taking the limit as $k \to \infty$ and using continuity of the metric $d_Y$:
\begin{align*}
d_Y(\bar{f}(x), \bar{f}(x')) = \lim_{k \to \infty} d_Y(f(d_k), f(d_k')) \le \frac{\varepsilon}{3} < \varepsilon.
\end{align*}
Since $\varepsilon > 0$ was arbitrary and $\delta = \delta_0 / 3$ depends only on $\varepsilon$ (not on $x$ or $x'$), $\bar{f}$ is uniformly continuous.
[guided]
We must show $\bar{f}: X \to Y$ is uniformly continuous, meaning for every $\varepsilon > 0$ there exists $\delta > 0$ (independent of the points) such that $d_X(x, x') < \delta$ implies $d_Y(\bar{f}(x), \bar{f}(x')) < \varepsilon$.
The strategy is a three-segment estimate: connect $\bar{f}(x)$ to $\bar{f}(x')$ through approximating points in $D$, using the triangle inequality in $Y$ to split the distance into three controllable pieces.
Let $\varepsilon > 0$. Since $f: D \to Y$ is uniformly continuous, there exists $\delta_0 > 0$ such that
\begin{align*}
d_X(a, b) < \delta_0 \implies d_Y(f(a), f(b)) < \frac{\varepsilon}{3} \quad \text{for all } a, b \in D.
\end{align*}
Set $\delta := \delta_0 / 3$. This choice accounts for the three segments in the triangle inequality that follows.
Let $x, x' \in X$ with $d_X(x, x') < \delta$. Choose sequences $(d_k)$ and $(d_k')$ in $D$ with $d_k \to x$ and $d_k' \to x'$. Since these sequences converge, for all sufficiently large $k$ we have $d_X(d_k, x) < \delta$ and $d_X(d_k', x') < \delta$.
Now we bound $d_X(d_k, d_k')$ using the triangle inequality in $(X, d_X)$:
\begin{align*}
d_X(d_k, d_k') &\le d_X(d_k, x) + d_X(x, x') + d_X(x', d_k') \\
&< \delta + \delta + \delta \\
&= 3\delta = \delta_0.
\end{align*}
Since $d_k, d_k' \in D$ and $d_X(d_k, d_k') < \delta_0$, the uniform continuity of $f$ yields
\begin{align*}
d_Y(f(d_k), f(d_k')) < \frac{\varepsilon}{3}.
\end{align*}
We now pass to the limit. The metric $d_Y: Y \times Y \to [0, \infty)$ is continuous (as a map between [metric spaces](/page/Metric%20Space)), so
\begin{align*}
d_Y(\bar{f}(x), \bar{f}(x')) &= d_Y\!\left(\lim_{k \to \infty} f(d_k),\, \lim_{k \to \infty} f(d_k')\right) \\
&= \lim_{k \to \infty} d_Y(f(d_k), f(d_k')) \\
&\le \frac{\varepsilon}{3} < \varepsilon.
\end{align*}
The inequality $\le \varepsilon/3$ holds because the sequence $d_Y(f(d_k), f(d_k'))$ is eventually bounded above by $\varepsilon/3$, and a limit of a sequence bounded above by a constant is at most that constant.
Since $\delta = \delta_0/3$ depends only on $\varepsilon$ and not on the choice of $x, x' \in X$, this establishes uniform continuity of $\bar{f}$.
[/guided]
[/step]
[step:Establish uniqueness of the extension]
Suppose $\bar{g}: X \to Y$ is another [continuous](/page/Continuity) map with $\bar{g}|_D = f$. For any $x \in X$, choose a sequence $(d_k)$ in $D$ with $d_k \to x$. Since $\bar{f}$ and $\bar{g}$ are both continuous and agree on $D$:
\begin{align*}
\bar{g}(x) = \lim_{k \to \infty} \bar{g}(d_k) = \lim_{k \to \infty} f(d_k) = \lim_{k \to \infty} \bar{f}(d_k) = \bar{f}(x).
\end{align*}
Since $x$ was arbitrary, $\bar{g} = \bar{f}$.
[guided]
Suppose $\bar{g}: X \to Y$ is another continuous map (not necessarily uniformly continuous — mere continuity suffices for uniqueness) with $\bar{g}|_D = f = \bar{f}|_D$.
Let $x \in X$ and choose any sequence $(d_k)$ in $D$ with $d_k \to x$. Since $\bar{f}$ is continuous and $d_k \to x$:
\begin{align*}
\bar{f}(x) = \lim_{k \to \infty} \bar{f}(d_k) = \lim_{k \to \infty} f(d_k).
\end{align*}
Similarly, since $\bar{g}$ is continuous and $d_k \to x$:
\begin{align*}
\bar{g}(x) = \lim_{k \to \infty} \bar{g}(d_k) = \lim_{k \to \infty} f(d_k).
\end{align*}
Therefore $\bar{f}(x) = \bar{g}(x)$. Since $x \in X$ was arbitrary, $\bar{f} = \bar{g}$.
The uniqueness argument uses only two ingredients: continuity of both extensions and density of $D$. In particular, the uniqueness holds among *all* continuous extensions, not just uniformly continuous ones. Any continuous extension from a dense subset into a Hausdorff space is unique (a fact that follows more generally from the observation that two continuous maps into a Hausdorff space that agree on a dense subset must agree everywhere).
[/guided]
[/step]