Prob. 21, Chap. 5 in Baby Rudin: Given a closed set $E$ in $\mathbb{R}$, there is an infinitely differentiable function whose zero set is $E$

Here is Prob. 21, Chap. 5 in the book Principles of Mathematical Analysis by Walter Rudin, 3rd edition:

Let $E$ be a closed subset of $\mathbb{R}^1$. We saw in Exercise 22, Chap. 4, that there is a real continuous function $f$ on $\mathbb{R}^1$ whose zero set is $E$. Is it possible, for each closed set $E$, to find such an $f$ which is differentiable on $\mathbb{R}^1$, or one which is $n$ times differentiable, or even one which has derivatives of all orders on $\mathbb{R}^1$?

And, here is Prob. 22, Chap. 4 in Baby Rudin, 3rd edition:

Let $A$ and $B$ be disjoint nonempty closed sets in a metric space $X$, and define $$f(p) = \frac{ \rho_A(p) }{ \rho_A(p) + \rho_B(p) } \qquad (p \in X).$$ Show that $f$ is a continuous function on $X$ whose range lies in $[0, 1]$, that $f(p) = 0$ precisely on $A$ and $f(p)=1$ precisely on $B$. This establishes a converse of Exercise 3: Every closed set $A \subset X$ is $\mathrm{Z}(f)$ for some continuous real function $f$ on $X$. Setting $$V = f^{-1} \left( \left[0, \frac{1}{2} \right) \right), \qquad W = f^{-1} \left( \left( \frac{1}{2}, 1 \right] \right),$$ show that $V$ and $W$ are open and disjoint, and that $A \subset V$, $B \subset W$. (Thus pairs of disjoint closed sets in a metric space can be covered by pairs of disjoint open sets. This property of metric spaces is called normality.)

Finally, here is Prob. 3, Chap. 4 in Baby Rudin, 3rd edition:

Let $f$ be a continuous real function on a metric space $X$. Let $\mathrm{Z}(f)$ (the zero set of $f$) be the set of all $p \in X$ at which $f(p) = 0$. Prove that $\mathrm{Z}(f)$ is closed.

The most trivial example is the function $f$ defined on $\mathbb{R}^1$ by $f(x) = 0$ for all $x \in \mathbb{R}^1$.

Is there a less trivial (but not-too-intricate) example, in particular any example that can be discussed within the machinery developed by Rudin up to this point in the book?

What about the function $f$ defined on $\mathbb{R}^1$ by $$f(x) = \begin{cases} 0 \ & \ (x \in E) \\ x \ & \ (x \not\in E)? \end{cases}$$

• What kinds of $f$ are you looking for? What is "example that can be discussed within the machinery developed by Rudin up to this point in the book" which point? – user99914 May 21 '17 at 8:57
• @JohnMa I mean a function which has a closed set as its zero set and which is differentiable, $n$ times differentiable, or infinitely many times differentiable. However, I would prefer a function whose derivatives can be found rigorously enough (i.e. only using the results that Rudin has established until Chap. 5 in the book). – Saaqib Mahmood May 21 '17 at 9:26
• So your question is really the first one. The next two results seem unrelated. – user99914 May 21 '17 at 9:28
• And the $f$ you defined is not even continuous in general – user99914 May 21 '17 at 9:28
• @JohnMa why is this function not continuous in general? – Saaqib Mahmood May 21 '17 at 11:05