12.2. URYSOHN’S LEMMA 283

Thus there exist open sets Vr for each r ∈Q∩ (0,1) with the property that if r < s,

H ⊆Vr ⊆V r ⊆Vs ⊆V s ⊆U.

Now letf (x) = min(inf{t ∈ D : x ∈Vt},1) , f (x)≡ 1 if x /∈

⋃t∈D

Vt .

(Recall D =Q∩ (0,1].) I claim f is continuous.

f−1 ([0,a)) = ∪{Vt : t < a, t ∈ D},

an open set.Next consider x ∈ f−1 ([0,a]) so f (x)≤ a. If t > a, then x ∈Vt because if not, then

f (x)≡ inf{t ∈ D : x ∈Vt}> a.

Thusf−1 ([0,a])⊆ ∩{Vt : t > a}= ∩{V t : t > a}

which is a closed set. If x ∈ ∩{V t : t > a}, then x ∈ ∩{Vt : t > a} and so f (x)≤ a.If a = 1, f−1 ([0,1]) = f−1 ([0,a]) = X . Therefore,

f−1 ((a,1]) = X \ f−1 ([0,a]) = open set.

It follows f is continuous. Clearly f (x) = 0 on H. If x ∈UC, then x /∈Vt for any t ∈ D sof (x) = 1 on UC. Let g(x) = 1− f (x). This proves the theorem.

In any metric space there is a much easier proof of the conclusion of Urysohn’s lemmawhich applies.

Lemma 12.2.2 Let S be a nonempty subset of a metric space, (X ,d) . Define

f (x)≡ dist(x,S)≡ inf{d (x,y) : y ∈ S} .

Then f is continuous.

Proof: Consider | f (x)− f (x1)|and suppose without loss of generality that f (x1) ≥f (x) . Then choose y ∈ S such that f (x)+ ε > d (x,y) . Then

| f (x1)− f (x)| = f (x1)− f (x)≤ f (x1)−d (x,y)+ ε

≤ d (x1,y)−d (x,y)+ ε

≤ d (x,x1)+d (x,y)−d (x,y)+ ε

= d (x1,x)+ ε.

Since ε is arbitrary, it follows that | f (x1)− f (x)| ≤ d (x1,x) and this proves the lemma.

Theorem 12.2.3 (Urysohn’s lemma for metric space) Let H be a closed subset of an openset, U in a metric space, (X ,d) . Then there exists a continuous function, g : X→ [0,1] suchthat g(x) = 1 for all x ∈ H and g(x) = 0 for all x /∈U.