# Existence of continuous function on compact interval

Suppose we have a compact set $A$ and a bounded open set $O$ such that $A\subset O$. How would I go about showing the existence of a continuous function $f: \mathbb{R}\to\mathbb{R}$, such that the function $f$ has the properties: that $f=1$ on the compact interval, and $f$ vanishes on $O^c$, and $f(x)\in[0,1]$?

Not really sure where to begin.

A few things I know (not sure if they're useful here but here I go anyway...)

I notice that $O\subset A\subset \mathbb{R}$, so by the Heine-Borel Thm, it must be the case that $A$ is both closed and bounded.

$f$ needs to be shown to be continuous so it has to obey that $\forall\epsilon>0\exists\delta>0: |x-c|<\delta\implies |f(x)-L|<\epsilon$

(or that ) $f^{-1}(O)$ is open for all open sets $O$.

Now, for the one theorem that I think will be of help: Borel s Thm.

Let $f:[a,b]\to \overline{\mathbb{R}}$ be (Lebesgue )measurable and finite almost everywhere. [is there any gurantee here that our $f$ is measurable in order to employ this theorem?]

Then $\forall\epsilon>0\exists g:\text{ g is continuous on [a,b]}$ such that $|f-g|<\epsilon$ (except possibly on a set of measure less than $\epsilon$. Furthermore, if $f(x)\in[k,K]$ for $k,K\in\mathbb{R}$, it can be arranged for $g(x)\in[k,K]$ as well.

Any help to start would be appreciated. Thanks.

• Are you familiar with Urysohn's lemma for normal spaces? – jvnv Aug 6 '16 at 6:34
• I am not, but I'm always up for learning new things. :) I have never taken a course in topology yet though, so I'm not sure what a normal space is though. – Marshant Aug 6 '16 at 6:35
• Seems to me that Uryshon'a lemma is an overkill here. – Peter Franek Aug 6 '16 at 6:40
• Somewhat related: math.stackexchange.com/questions/47360/… – Martin Sleziak Aug 6 '16 at 11:45

By compactness of $A$, there exists $\epsilon>0$ such that any an $\epsilon$-neighborhood of $A$ is contained in $O$. Then define $f$ to be $$f(x)=\max\{0,1-\frac{1}{\epsilon}\mathrm{dist}(x,A)\}.$$ The distance from $A$ is a continuous function that is obviously zero on $A$.

• If I may ask, for future reference, how did you arrive at such a function? Is there some sort of trick or anything to recognize, or is this purely something I might pickup with experience? – Marshant Aug 6 '16 at 6:56
• I'm sure I have seen something similar somewhere, maybe even on MSE. But it is natural: you want the function to be $1$ on $A$ and to decrease to $0$ if you go farther from $A$. – Peter Franek Aug 6 '16 at 6:59

$$f(x) = \frac{dist(x.O^c)}{dist(x.O^c) + dist(x.A)}$$ You don't need $A$ compact, only that $A$ is closed, and disjoint from the closed set $O^c$.

• If I may ask, for future reference, how did you arrive at such a function? Is there some sort of trick or anything to recognize, or is this purely something I might pickup with experience? – Marshant Aug 6 '16 at 6:56
• This problem is classical, and this particular $f$ is too. I submitted the answer for the record, but I did not came up with it. :) – VictorZurkowski Aug 6 '16 at 11:01

Applying Ursyohn's lemma to this case is not very elegant and you probably want a more direct proof. However, because I mentioned it, I just want to state it and show how you can apply it:

Urysohn's Lemma

Let $(X, \mathcal{I})$ be a normal topological space, and let $F, G \subset X$ be disjoint closed subsets. Then there is a continuous function $f : X \to [0,1]$ with $f|_F = 0$ and $f|_G = 1$.

In your case, take $X = \mathbb{R}$, $G = A$ and $F = O^c$.