TITLE: A smooth function $\mathbb{R}\to\mathbb{R}$ agrees with an analytic function on a bounded infinite set
QUESTION [6 upvotes]: Fix a smooth function $f:\mathbb{R}\to\mathbb{R}$. Do there exist real numbers $a<b$, an infinite set $S\subset (a, b)$ and an analytic function $g$ defined on $(a-\epsilon, b+\epsilon)$ for some $\epsilon>0$ such that $f|_S=g|_S$?
If $g$ is only required to be defined on $(a, b)$ the question has a positive answer. In fact, we can take any $(a, b)$ we like and set $g=f(a)+\mathrm{sin}(\frac{1}{x-a})$.
We can not require $g$ to be defined on all of $\mathbb{R}$ since we can take $f(x)=\mathrm{exp}(-\frac{1}{|x|})$ for $x\neq 0$ and $f(0)=0$. Then by the pigeonhole principle $S$ must contain infinitely many positive numbers or infinitely many negative numbers; in either case $g$ does not extend to $\mathbb{R}$. Coincidentally, this shows that an arbitrary $(a, b)$ won't do in the original problem.

REPLY [3 votes]: The answer is no, not necessarily.
Let $f$ be any smooth function such that the Taylor series of $f$ about any point $p$ has zero radius of convergence; see this MO answer for an explicit example.
Suppose that $g$ is a smooth function such that for some sequence $(x_n)$ convergent to $p$ (and such that $x_n \ne p$) we have $f(x_n) = g(x_n)$. It is rather easy to see that $f^{(k)}(p) = g^{(k)}(p)$ for every $k \geqslant 0$, and hence the Taylor series of $f$ and $g$ about $p$ coincide. In particular, the Taylor series of $g$ about $p$ has zero radius of convergence, and consequently $g$ is not real-analytic at $p$.