Elementary topology problem A function $f: \mathbb{R} \to \mathbb{R}$ is said to be bounded at a point $x_0$ provided that there are positive numbers $\varepsilon$ and $M$ so that $|f (x)| < M$ for all $x \in (x_0 - \varepsilon, x_0 + \varepsilon)$. 


*

*Show that the set of points at which a function is bounded is open. 

*Let $E$ be an arbitrary closed set. Is it possible to construct a function $f: \mathbb{R} \to \mathbb{R}$ so that the set of points at which $f$ is not bounded is precisely the set $E$?
I am not sure what to do with this problem. I am having a lot of trouble understanding this part of the course so any topology-related help would be greatly appreciated!
 A: For the first part: 
Let $B$ be the set of points at which $f$ is bounded, and choose an arbitrary $x_0\in B$.  You have to find a $\delta$ such that $(x_0-\delta,x_0+\delta)\subseteq B$. 
Since $x\in B$, we know that there is an $M$ and a $\varepsilon>0$ such that 
$$f\big[(x_0-\varepsilon,x_0+\varepsilon)\big]\subseteq [-M,M].$$
So, if you put $\delta=\varepsilon/2$, then what can you say about an arbitrary element $x\in (x_0-\delta/2,x_0+\delta/2)$?

For the second part:
Important note:  On reflection, I needed to be a bit more subtle here.  I have left my original answer below, for reference, but it is flawed.  This answer avoids the earlier error, and is more elegant to boot!
I should note that the differences are slight.  The new answer is only a modification of the original one, not a complete rewrite.  However, I thought it would be easier to present it in isolation, rather than explain how I got from one to the other. 
The answer is still yes.  And we still work by constructing a suitable function.  However, we have to be careful that no points in $\mathbb{R}\setminus E$ are limit points of the sequences used to approximate members of $\partial E$. This can be done, but requires a little more finesse than I used the first time. 
I dyadic rational number is one which can be expressed in the form $m/2^{n}$, where $m$ is odd.  The dyadic rationals are dense in $\mathbb{R}$, meaning that every real number can be expressed as a limit of a sequence of dyadic rational numbers.  In fact, we can go further, by defining, for each real $x$, a canonical dyadic sequence converging to $x$:

Let $x$ be a real number.  The canonical dyadic sequence approximating $x$ is the sequence $\langle d_{n}\vert n\in\mathbb{N}\rangle$ given by $$d_{n}=\max_{m\in\mathbb{N}}\left\{\frac{m}{2^{n}} \, \left \vert \frac{m}{2^{n}}< x\right.\right\}.$$  Let $\mathcal{D}_{x}$ denote the set of dyadic rationals in the canonical sequence associated with $x$.

We now construct our function $f$.  Let $A=\bigcup_{x\in E}\mathcal{D}_{x}$.  Then for each dyadic rational $x=(2p+1)/2^{n}\in A$, define $f(x)=n$. For all $x\notin A$, define $f(x)=0$.   
All you have to do now is prove the following:


*

*If $x$ is a limit point of $A$, then $f$ is unbounded at $x$.

*If $x$ is not a limit point of $A$, then $f$ us bounded at $x$. 

*The set of limit points of $A$ is $E$.
(You might first want to prove that the canonical dyadic sequence converging to $x$ is a non-decreasing sequence that really does converge to $x$.  The fact that $E$ is closed is used when proving that $x\notin E$ is not a limit point of $A$.)
Note that instead of dyadic rationals, we could just as well have used finite decimals. You may find that more intuitive.
Note also that my term canonical dyadic sequence is not actually canon!  It makes sense in this context, but don't go around using it in public without defining it first.

Original answer
The answer is yes.  We now construct such a function.
Note that any closed set $E$ can be written 
$$ E= \partial E \cup E^{\circ}.$$
Start by defining $f(x)=0$ for all $x\notin E$.  Now we need to ensure that the function is unbounded in every neighborhood of every element of $E$. To do this, consider the rational points inside $E$.  Suppose that $q=m/n\in E^{\circ}$, with $m$ and $n$ relatively prime.  Put $f(q)=n$.  It is pretty easy to see that for $x\in\ E^{\circ}$ (or indeed for any $x\in\overline{E^{\circ}}$), $f$ is unbounded in every neighborhood of $x$. You can just leave $f(x)=0$ when $x\in E$ is irrational.
But what about the isolated points of $E$?  To ensure that $f$ is unbounded in the neighborhoods of these points, we need to overwrite some of the values we defined earlier. 
For points  $x\in\partial E$ (the boundary of $E$): there is necessarily a sequence in $\mathbb{R}\setminus E$ (the complement of $E$) which converges to $E$.  
Let $\langle x_{n}\vert n\in\mathbb{N}\rangle$ be one such sequence.  We just need to ensure that $\limsup f(x_{n})=\infty$.  The easiest way to do this is simply to define $f(x_{n})=n$, but this could potentially cause problems if we have overlapping sequences.  The easiest way I can think of to get around this problem is to use the same trick with rationals that we used before. Since the rationals are dense in $\mathbb{R}$, we can assume without loss of generality that all the $x_{n}$ are rationals.  If $x_{n}=a_{n}/b_{n}$, with $a_n$ and $b_n$ being relatively prime, we can avoid any ambiguities concerning the value of $f$ by simply setting $f(x_n)=b_n$.
It is immediate from its construction that $f$ is unbounded at every point in $E$. I'll leave you to prove that $E$ is bounded at every $x\notin E$.  It is at this point in the argument that you will have to use the fact that $E$ is closed.  
