TITLE: Existence of smooth function that characterizes boundary and interior of set
QUESTION [6 upvotes]: It is well known that every closed set $A \subset \mathbb{R}^{n}$ is the zero level set of some smooth function. It follows that every closed set is also the zero sublevel set of some smooth function, i.e.
\begin{align*}
A  &= \{x \in \mathbb{R}^{n} : f(x) \le 0 \}.
\end{align*}
I am wondering if one can easily characterize closed sets for which there exist a smooth function $f$ such that the following stronger conditions hold
\begin{align*}
\partial A  &= \{x \in \mathbb{R}^{n} :  f(x) = 0 \}, \text{ and}\\
A^{\circ}   &= \{x \in \mathbb{R}^{n} : f(x) < 0 \}?  
\end{align*}

REPLY [5 votes]: I think every closed set $A \subset \mathbb{R}^{n}$ has this property. Let $\{\phi_k\}_{k\in\mathbb{N}}\subset C^\infty_c(\mathbb{R}^{n})$ a countable collection  of non-negative smooth functions with compact support  such that $A^\circ=\bigcup_{k\in\mathbb{N}}\{\phi_k>0\}$ (for instance, $\{\phi_k>0\}$ may be balls of some countable  covering of $A^\circ$). Then  the series
$$ \sum_{k=0}^\infty\,  {2^{-k}\| \phi_k\|_{C^k}^{-1}}\,\, \phi_k$$
normally converges with derivatives of any order to a smooth function $f_-$ with  $\{f_->0\}=A^\circ$. Here $\displaystyle\| \phi \|_{C^k}=\max_{  \alpha\in\mathbb{N}^n\atop |\alpha|\le k  }\|\partial^\alpha\phi \|_{\infty,\mathbb{R}^{n}}$  is the standard ${C^k}$-norm. The same construction for $A^c$ produces a smooth $f_+$ with $\{f_+>0\}=\mathbb{R}^{n}\setminus \overline{A}$; then $f:=f_+-f_-$ has the required properties, that is $\{f<0\}=A^\circ$, $\{f>0\}=\mathbb{R}^{n}\setminus \overline{A}$, and $\{f=0\}=\partial A$.