Ask a question on construction continuous function? Let E and F be disjoint closed sets of real numbers. Prove that there is a continuous function f with domain the real numbers such that {x : f(x)=0}=E and{x:f(x)=1}=F.
The textbook gives the solution. Now E ∪ F is closed so the complement of (E ∪ F ) is open. Therefore, the complement of (E ∪ F ) can be expressed as pairwise disjoint union
of open
intervals. I can understand until here.
Write $I_j = (a_j , b_j)$. Now define

I feel very confused on this solution. f(x) is defined on R, hence we need to consider E, F, and $I_j$. But the solution discusses $a_j , b_j$. The last case is $a_j \in F , b_j \in F$. If this is true, then x is in F?
 A: No, when $a_i,b_i\in F,$ $x\notin F.$
For example, if $E=\{0\}$ and $F=\{1,2\}.$ Then one of the intervals in the complement is $(1,2).$ The intervals are the complement of $E\cup F,$ so the intervals never have points in $E$ or $F.$
The big problem in the answer is that it fails to deal with the case where $a_i=-\infty$ or $b_i=+\infty.$
There should also be a case when $a_i,b_i\in E.$

I prefer this answer:
Define first, for non-empty closed $G,$ the function $d_G(x)=\inf_{g\in G}|x-g|.$ Then show $d_G$ is continuous, non-negative, and $d_G(x)=0$ if and only if $x\in G.$
Then, define $$f(x)=\frac{d_E(x)}{d_E(x)+d_F(x)}$$
This argument works in any metric space.
This argument  does requires $E,F$ non-empty.
If $E=\emptyset,F\neq \emptyset$ you can define $f(x)=\frac{1}{d_F(x)+1}.$
If $E\neq \emptyset,F=\emptyset$ then $f(x)=\frac{d_E(x)}{1+d_E(x)}.$
If both are empty, you can pick $f(xj=\frac12.$

Proving $d_G$ is continuous:
Since $|y-g|\leq |y-x|+|x-g|$ you get:
$$d_G(y)\leq |y-x| +d_G(x).$$
Similarly:
$$d_G(x)\leq |y-x|+d_G(y)$$
Together, this means $$|d_G(x)-d_G(y)|\leq |x-y|.$$
So given $\epsilon>0$ You can choose $\delta=\epsilon.$ You actually get $d_G$ is uniformly continuous.
