TITLE: Infinitely differentiable function with given zero set?
QUESTION [20 upvotes]: For each closed set $A\subseteq\mathbb{R}$, is it possible to construct a real continuous function $f$ such that the zero set, $f^{-1}(0)$, of $f$ is precisely $A$, and $f$ is infinitely differentiable on all of $\mathbb{R}$?
Thanks!

REPLY [9 votes]: The open set ${\mathbb R} \backslash A$ is the union of at most countably many intervals $J_k$, of which at most two are unbounded.  Let $f_k$ be a $C^\infty$ "bump" function that is positive on $J_k$ and $0$ everywhere else.  If $J_k$ is unbounded, I'll require also that $f_k$ is constant outside some bounded interval. 
Take $f(x) = \sum_k c_k f_k(x)$ where $c_k > 0$ is small enough so that $|c_k f_k^{(j)}(x)| < 2^{-k}$ for $0 \le j \le k$ and all $x$.  Then each series 
$\sum_k c_k f_k^{(j)}(x)$ converges absolutely and uniformly for all $x$, so that its sum is $f^{(j)}(x)$ and $f$ is $C^\infty$.