TITLE: Urysohn's function on a metric space
QUESTION [9 upvotes]: Let $(X,d)$ be a metric space and $A\subset B\subset X$. $A$ is closed, $B$ is open. If there are developed methods to find at least one (or describe the whole class) of Urysohn's functions for $A$ and $B^c$?
Edited: Martin has already presented a nice example of an Urysohn's function. Now I would like to focus on my second question about the whole class $\mathcal U(A,B^c)$ of Urysohn's functions. I had a function $u$ which is $0$ on $B^c$ and $1$ on A - and I would like to check if it is continuous (so if it is in $\mathcal U(A,B^c)$ class). If there are any sufficient conditions to prove that this function is $\mathcal{U}(A,B^c)$ which allow me pass direct verifying of continuity of $u$, or this question is meaningless and all that I can do - is to verify continuity without theory of Urysohn's functions?

REPLY [11 votes]: Consider $f: X \to [0,1]$ given by
$$f(x) = \frac {d(x,A)} {d(x,A) + d(x,B^c)} \ .$$
$f$ is well-defined because the denominator is $0$ if and only if $x \in \bar A \cap \overline {B^c} = A \cap B^c = \emptyset$ (because $A$ is assumed closed and and $B$ assumed open).
We have $f(x) = 0$ if and only if $x \in \bar A = A$, and $f(x) = 1$ if and only if $x \in \overline {B^c} = B^c$.
Finally, $f$ is continuous because the "distance to a closed subset" function is continuous.