# Constructing a function discontinuous precisely in a given closed/open set.

I have to find a real function which is discontinuous in a given closed set $$F.$$
I defined $$f : \mathbb{R} \to \mathbb{R}$$ by $$f(x) = \begin{cases} 0&\text{if}\, x\in \mathbb{R}\setminus F\\ 1&\text{if}\, x \in F\cap{\mathbb{Q}}, \;\mathbb{Q}\;\text{being the set of the rationals}\\ 2&\text{if}\, x\in F\cap{\mathbb{I}}, \;\mathbb{I}\;\text{being the set of the irrationals} \end{cases}$$ This function is discontinuous on $$F.$$

Also, I have to find another function that is discontinuous on a given open set $$O.$$ So I replaced $$F$$ with $$O$$ in the above construction.

Am I right? Is my construction okay as I don't use the closed or open property of the sets? Thank you.

• It won’t work for an open set if you want the set in question to be exactly the set of points at which $f$ is discontinuous. Try it with the open set $(0,1)$, for instance: you’ll find that your $f$ is discontinuous on $[0,1]$ rather than on $(0,1)$. Jan 19, 2021 at 2:55
• Yes, I got it. So how to construct the function for an open set? Jan 19, 2021 at 3:02
• One way to construct such a function for an open set is to prove first that every open is the union of countably many pairwise disjoint open intervals or open rays. Then you just have to figure out how to handle an open interval $U$. One possibility is to let $f(x)=0$ for $x\in U\setminus\Bbb Q$ as well as for $x\notin U$, and to let the graph of $f$ on $U\cap\Bbb Q$ look like $\land$, approaching $0$ at the endpoints. (If $U$ is an open ray, you need only half of the $\land$.) Jan 19, 2021 at 3:15

Let $$U$$ be the open set. Set $$f(x)=d(x,\mathbb R \setminus U)\cdot\chi_{U\cap\mathbb Q}(x).$$