Existence of non-constant continuous functions with infinitely many zeros [duplicate]
Solution 1:
[!!! There is an error in the following argument !!! ]
Since this answer has been accepted, I can no longer delete it, however. The comments below may be useful for anyone interested.
In fact every closed subset of $\mathbb R$ is the zero set of a smooth function:
First, suppose we are given an open interval $I = (a,b) \subset \mathbb R$. We will construct a smooth function $f: \mathbb R\to [0,1]$ satisfying $f(x)>0 \iff x \in I$.
Then, if we are given a closed set $K \subset \mathbb R$, the complement $U = \mathbb R\setminus K$ can be written as the disjoint union of countably many open intervals $I_n$ for $n\in \mathbb N$, i.e.
$$ U = \bigcup_{n=1}^\infty I_n, \quad \text{with } \; I_n \cap I_m = \varnothing \; \text{ for $m\ne n$}$$
Assuming the first part, we can find smooth functions $f_n: \mathbb R\to [0,1]$ such that $f_n(x) > 0$ if and only if $x \in I_n$. Now define
$$g(x) := \sum_{n=1}^\infty f_n(x)$$
Then $g$ is well-defined and smooth, because for any point $x\in \mathbb R$ there is a neighborhood $V$ such that only finitely many $f_n$ are nonzero on $V$ (in fact we can choose $V$ sufficiently small such that it intersects two intervals $I_m$ and $I_n$ at most).
Let us prove the first assertion: So, we are given $I=(a,b)\subset \mathbb R$ and want to construct $f: \mathbb R\to [0,1]$ such that $f(x) >0\iff x \in I$.
First, let
$$ h(x) = \begin{cases} e^{-1/x} & x>0 \\ 0 & x\le 0\end{cases}$$
I think, it is a standard exercise in Analysis to prove that $h$ is smooth, so I won't bother doing this here. Now define
$$f(x) = h(x-a)h(b-x)$$
This function is smooth and maps into $[0,1]$ ($h\le 1$). Furthermore $$f(x) \ne 0 \iff x-a >0 \text{ and } b-x>0 \iff a < x < b$$
This concludes our observation.
Solution 2:
You can take $$f(x) = \left\{\begin{array}{ll} (x-a)\sin\left(\frac{1}{x-a}\right)&\text{if }x\neq a\\ 0 &\text{if }x=a. \end{array}\right.$$
You can even make it differentiable on $[a,b]$ by replacing the $(x-a)$ factor with $(x-a)^2$. This function is not constant on any subinterval.
Solution 3:
It is well known that, with probability $1$, the zero set of Brownian motion is an uncountable closed set with no isolated points.
Solution 4:
And if you want a $C^\infty$-function, how about $f(x)=0$, if $x\le(a+b)/2$ and $f(x)=e^{-1/(a+b-2x)^2}$, whenever $x>(a+b)/2$.
Solution 5:
Such a functions does exists not only for interval $[a,b]$, but for inifinite general metric spaces.
Let $(X,\rho)$ be some infinite metric space. For each $A\subset X$ we define distance from $x$ to $A$ by equality $\rho(x,A)=\inf\{\rho(x,y):y\in A\}$. Since for all $x_1,x_2\in X$ we have $|\rho(x_1,A)-\rho(x_2,A)|\leq\rho(x_1, x_2)$, we see that $\rho(\cdot,A):X\to\mathbb{R}_{+}$ is uniformly continuous. Obviously $x\in\overline{A}$ iff $\rho(x,\overline{A})=0$.
Let $Y$ be some closed infinite subset of $X$. Since Y is closed then the zero set of $\rho(\cdot,Y)$ is $Y$. Thus we constructed a uniformly continuous function with zero set equal to infinite set $Y$.