TITLE: The set of points of discontinuity is precisely an open set $U\subset \mathbb{R}^n$
QUESTION [5 upvotes]: For every open subset $U\subset \mathbb{R}^n$ does there exists a function $f :\mathbb{R}^n \to \mathbb{R}$ such that $f$ is discontinuous at each point of $U$ and continuous on $\mathbb{R}^n\setminus U$?

As I know, given any open set $U\subset \mathbb{R}^n$  there exists a function $f :\mathbb{R}^n\to \mathbb{R}$ such that $f$ is continuous at each point of $U$ and discontinuous on $\mathbb{R}^n\setminus U.$

REPLY [4 votes]: Let $g(x)$ be the distance from $x$ to $\mathbb R^n\setminus U$.  Let $h$ be the characteristic function of $\mathbb Q^n$.  Then $f(x)=g(x)h(x)$ has this property.  (This is assuming $U\neq \mathbb R^n$; otherwise take $f=h$.)