Constructing a choice function in a complete & separable metric space

Let $(x_n)_{n\in \mathbb N}$ be a dense sequence.

Given a closed non-empty set $E$, define $f(E)$ as follows:

a) If $E\cap \{x_n\mid n\in \mathbb N\}$ is non-empty, let $f(E)=x_m$ where $m=\min\{n\in\mathbb N\mid x_n\in E\}$.

b) If on the other hand $E\cap \{x_n\mid n\in \mathbb N\}=\emptyset$, define $A_0=E$, $r_0=1$ and recursively $$\tag1m_n=\min\{k\in\mathbb N\mid d(x_k,A_n)<2^{-n}\},$$ $$\tag2r_{n+1} = d(x_{m_n}, A_n),$$ $$\tag3A_{n+1}=\{a\in A_n\mid d(x_{m_n},a)\le 2r_{n+1}\}.$$ Note that we will always have $2^{1-n}\ge r_n>0$ and $E=A_0\supseteq A_1\supseteq\ldots$ is a descending chain of closed sets. Let $A=\bigcap_{n\in \mathbb N} A_n$. By completeness, $A$ is not empty. And because the diameter of $A_n$ is at most $4r_{n}\to0$, there can be at most one element in $A$. Define $f(E)$ as the only element of $A$.

Remark: Note that it is possible that no point $a\in A$ exists with $d(x,A)=d(x,a)$, but at least we have that $d(x,A)=0$ implies $x\in A$ for closed sets $A$, an dthat special case is covered in part a) so that we indeed have $r_n>0$ in part b).


Edit (after commments by Nate et. al.): The above proof used as the following definition of completeness: Every decreasing sequence of nonempty closed sets withvanishing diameter has nonempty intersection. The same construction also works with the definition Every Cauchy sequence converges.

In fact, the sequence $(y_n)_{n\in\mathbb N}$ with $y_n:=x_{m_n}$ as constructed above is Cauchy: By $(1)$ there exists $a\in A_{n+1}$ such that $d(y_{n+1},a)<2^{-(n+1)}$. On the other hand, $(3)$ and $(2)$ imply $d(y_n,a)\le 2r_{n+1}=2d(y_n,A_n)<2\cdot2^{-n}$ for this $a$. Consequently, $d(y_n,y_{n+1})<\frac5{2^{n+1}}$, which leads to $d(y_n,y_m)< \frac5{2^n}$ for $m>n$. Hence $y=\lim_{n\to\infty}y_n$ exists and from $d(y_n,E)\le d(y_n,A_n)\to 0$ we conclude $d(y,E)=0$ and by closedness $y\in E$ as required.


Edit: After a night of good sleep, the construction can be simplified (no cases, work directly with Cauchy sequences): Let $(x_n)_{n\in \mathbb N}$ be a dense sequence. Given a closed non-empty set $E$, define $f(E)$ as follows: Let $m_0=\min\{n\in \mathbb N\mid d(x_n,E)<1\}$ and $y_0=x_{m_0}$. Extend this recursively to a sequence $(y_n)_{n\in\mathbb N}$ with the properties $$\tag4d(y_n,y_{n+1})<2^{1-n}$$ and $$\tag5d(y_n,E)<2^{-n}.$$ To achieve this note that $d(y_n,E)<2^{-n}$ implies that the set $C_n=\{a\in E\mid d(y_n,a)<2^{-n}\}$ is nonempty, hence the union of open balls $U_n=\bigcup_{a\in C_n} B(a,2^{-1-n}\}$ is a nonempty open set. Let $m_{n+1}=\min\{n\in\mathbb N\mid x_n \in U_n\}$ and set $y_{n+1}=x_{m_{n+1}}$. From $y_{n+1}\in U_n$ we conclude that there exists $a\in C_n$ with $d(y_{n+1},a)<2^{-(n+1)}$. But for any such $a$ we see from $a\in C_n\subseteq E$ that $d(y_{n+1},A)<2^{-(n+1)}$ and $d(y_n,y_{n+1})\le d(y_n,a)+d(y_{n+1},a)<2^{-n}+2^{-(n+1)}<2^{1-n}$. Hence we can construct our sequence $(y_n)$ recursively such that $(1)$ and $(2)$ hold. By $(4)$ and the triangle inequality, it is a Cauchy sequence, hence has a limit $y$. From $(5)$ we conclude that $d(y,E)=0$, hence $y\in E$ because $E is closed.