Approximation by smooth function while preserving the zero set Let $\mathbb{T}$ denote the unit circle. Given $f \in \mathcal{C}(\mathbb{T})$, can we approximate $f$ by smooth functions having the same zero set ? i.e. for $\varepsilon >0$, can we find $g \in \mathcal{C}^\infty(\mathbb{T})$ such that


*

*f(x) = 0 if and only if $g(x) = 0$;

*$\|f-g\|_\infty < \varepsilon$.


Both tasks can easily be performed separately. But can they be performed simultaneously ?
 A: Yes, we can. If you're considering complex-valued functions, separately approximate the real and imaginary part, so it suffices to consider real-valued $f$.
As a first step, decompose $f$ into its positive and negative parts, let $f^+(z) = \max \{ f(z),0\}$ and $f^-(z) = \max \{ - f(z),0\}$. If we find a smooth non-negative $g^+$ with $g^+(z) = 0 \iff f^+(z) = 0$ and $\lVert g^+ - f^+\rVert_{\infty} < \varepsilon$, and a similar $g^-$ approximating $f^-$, then $g = g^+ - g^-$ solves the approximation problem.
As a difference of smooth functions, $g$ is smooth, at every $z \in \mathbb{T}$ at most one of $g^+,g^-$ is nonzero ($g^+(z) > 0 \iff f(z) > 0$, $g^-(z) > 0 \iff f(z) < 0$), and so
$$g(z) = 0 \iff g^+(z) = g^-(z) = 0 \iff f^+(z) = f^-(z) = 0 \iff f(z) = 0,$$
and
$$\lvert f(z) - g(z)\rvert = \max \{ \lvert f^+(z) - g^+(z)\rvert, \lvert f^-(z) - g^-(z)\rvert\} < \varepsilon$$
for all $z\in \mathbb{T}$.
So we have reduced the problem to approximating a non-negative continuous function, and we assume $f \geqslant 0$ in the following.
First, using convolution with a smooth function, we can find a smooth $g_1$ with $\lVert f - g_1\rVert_{\infty} < \varepsilon/4$. If our smooth convolution kernel was non-negative, which we can arrange, then $g_1 \geqslant 0$. Let $g_2(z) = g_1(z) + \varepsilon/4$, so $g_2(z) \geqslant \varepsilon/4$ for all $z$ and $\lVert g_2 - f\rVert_{\infty} < \varepsilon/2$. If $f$ never vanishes on $\mathbb{T}$, we're done already. So suppose $Z = \{ z \in \mathbb{T} : f(z) = 0\} \neq \varnothing$. Let $F = \{ z \in \mathbb{T} : f(z) \geqslant \varepsilon/2\}$. Let $\varphi$ a smooth function with $Z = \varphi^{-1}(0)$, $F \subset \varphi^{-1}(1)$ and $0 \leqslant \varphi(z) \leqslant 1$ for all $z\in \mathbb{T}$. The existence of such a $\varphi$ will be shown below.
Then $g = \varphi\cdot g_2$ has the desired properties. It is smooth as a product of smooth functions, we have $g(z) = 0 \iff \varphi(z) = 0 \iff f(z) = 0$, and
$$\lVert g - f\rVert_{\infty} \leqslant \lVert g - g_2\rVert_{\infty} + \lVert g_2 - f\rVert_{\infty} < \frac{\varepsilon}{2} + \frac{\varepsilon}{2},$$
since $g(z) \neq g_2(z)$ implies $g_2(z) < \varepsilon/2$, and then $0 \leqslant (1-\varphi(z))g_2(z) \leqslant g_2(z)$.
It remains to prove the existence of $\varphi$. Let $A \subset \mathbb{T}$ a nonempty closed set, and for $n \in \mathbb{N}\setminus \{0\}$, let $U_n = \bigl\{ z : \operatorname{dist}(z,A) > \frac{1}{n}\bigr\}$. Let $\{ W_k : k\in \mathbb{N}\}$ a locally finite refinement of $\{U_n : n \in \mathbb{N}\setminus \{0\}\}$. Since $\mathbb{T}\setminus A$ is paracompact, locally finite refinements exist, and since the space is second countable, any locally finite family of sets is countable, so we can use $\mathbb{N}$ to index the family. Let $\{\psi_k : k \in \mathbb{N}\}$ a smooth partition of unity (on $\mathbb{T}\setminus A$) subordinate to $\{W_k: k\in \mathbb{N}\}$. For each $k$, let
$$M_k = \max \{ \lvert D^{\alpha}\psi_k(z)\rvert : z \in \mathbb{T}, \alpha \leqslant k\},$$
where the derivatives are with respect to $t$ in the coordinate $z = e^{it}$. Then
$$\varphi_A \colon z \mapsto \sum_{k = 0}^{\infty} \frac{1}{2^k(1+M_k)}\psi_k(z)$$
is clearly a continuous non-negative function on $\mathbb{T}$ with $\varphi_A^{-1}(0) = A$, and we note that for every $m$ the series
$$\sum_{k = 0}^{\infty} \frac{1}{2^k(1+M_k)} D^m\psi_k$$
converges uniformly on $\mathbb{T}$, so $\varphi_A$ is smooth.
If $F = \varnothing$, let $\varphi = \varphi_Z$, otherwise let
$$\varphi = \frac{\varphi_Z}{\varphi_Z + \varphi_F}.$$
