Let $f$ be a $C^\infty$ function on $(c,d)$ ,and let $O=\cup_{n\in \mathbb{Z}^+} (a_n,b_n)$ where $(a_n,b_n)$ are disjoint open interval in $(c,d)$ and $O$ is dense in $(c,d)$. Suppose for each $n\in \mathbb{Z}^+$ ,$f$ coincides with a polynomial on $(a_n,b_n)$. Is it necessary that $f$ coincide with a polynomial on $(c,d)$?

1$\begingroup$ Note this question with a similar flavor: mathoverflow.net/questions/34059/… $\endgroup$ – Steven Landsburg Apr 14 '12 at 20:57

3$\begingroup$ I suspect one can build a $C^\infty(\mathbb{R})$ function supported on the unit interval, which is polynomial on each component of the complement of the Cantor set. $\endgroup$ – Pietro Majer Apr 14 '12 at 21:20
I believe the answer is "no". The key lemma is:
Lemma. Let $f: [c,d] \to {\bf R}$ be smooth, let $I$ be a compact subinterval of $(c,d)$, $q$ be an interior point of $I$, let $n \geq 1$, and let $\varepsilon > 0$. Then there exists a smooth perturbation $g: [c,d] \to {\bf R}$ of $f$ which agrees with $f$ outside of $I$, is a polynomial on a neighbourhood of $q$ of degree at least $n$, but is not a polynomial on all of $I$, and differs from $f$ by at most $\varepsilon$ in $C^n[c,d]$ norm.
If we apply this lemma iteratively for $n=1,2,\ldots$ with $\varepsilon = \varepsilon_n := 2^{n}$ and $n=0,1,2,\ldots$, starting with $f_0 = 0$, and setting $q = q_n$ to be the first rational (in some enumeration of the rationals) on which $f_n$ is not locally polynomial, one obtains a sequence $f_1, f_2, f_3,\ldots$ of smooth functions on $[c,d]$ which form a Cauchy sequence in $C^k$ for each $k$, and thus converge in the smooth topology to a limit $f$ which is equal to a polynomial on degree at least $n$ on an interval $I_n$, with the $I_n$ disjoint and covering all the rationals, thus dense in $[c,d]$, giving the claim.
To prove the lemma, recall from the Weierstrass approximation theorem that the polynomials are dense in $C^0[c,d]$; integrating this fact repeatedly we see that they are dense in $C^n[c,d]$ as well. So we can approximate $f$ to arbitrary accuracy by a polynomial $h$ in the $C^n$ norm; by a small perturbation one can ensure that $h$ has degree at least $n$. Now using a smooth partition of unity, one can create a merged function $g$ that equals $h$ near $q$ and equals $f$, which can be made arbitrarily close in $C^n$. By modifying $g$ a little bit in $I$ away from $q$ one can ensure that $q$ is not polynomial on all of $I$.
The problem here is superficially similar to that in the previous question If $f$ is infinitely differentiable then $f$ coincides with a polynomial , but the latter has qualitative control at every single point (allowing the powerful Baire category theorem to come into play), whereas here one only has qualitative control on a dense set, which is a far weaker statement, and one which allows for a great deal of flexibility.

$\begingroup$ In fact,i create this question while think about the question mathoverflow.net/questions/34059/…. I proved the function $f$ locally a polynomial and wondered if I can use that property to solve that problem. $\endgroup$ – Ben Apr 15 '12 at 5:21

$\begingroup$ Can you clarify your construction? What interval I do you use the lemma for? $\endgroup$ – Matthias Ludewig Apr 15 '12 at 21:23

$\begingroup$ At each stage, f_n is polynomial on some union of disjoint intervals. One picks a q = q_n outside of these intervals, then one can take I to be an interval around q which does not intersect any of the existing intervals. This way, f_{n+1} is polynomial on all the intervals that f_n was, plus an additional new interval containing q. $\endgroup$ – Terry Tao Apr 15 '12 at 21:43
No. Say that a function $f(x)$ is locally a polynomial at $x_0$ if there is some neighborhood of $x_0$ upon which $f(x)$ coincides with a polynomial. In
W. Donoghue, Jr., Functions which are polynomials on a dense set. J. London Math. Soc. 39 (1964), 533–536,
the author constructs an example of a $C^\infty$ function that is not a polynomial but is nonetheless locally a polynomial on a dense set. Since the set of points at which a function is locally a polynomial is open, hence a countable union of disjoint intervals, the answer to your question follows.
The existence of such functions being established by now, there remains a curiosity for the concrete situations that may generate them. Here is one, which is also interesting as an example of a $C^\infty$, nonanalytic solution, of a simple first order linear delay differential equation.
Let's consider the problem
$$f'(x)=\lambda f(3x),\qquad x < \frac{1}{2} $$ where we seek for a function $f\in C^1(\mathbb{R})$ with support in $I:=[0,1]$, and with the condition $f(x)=f(1x)$.
I will show that it has a simple eigenvalue $\lambda= \frac{9}{2}$, corresponding to an eigenfunction with $f(\frac{1}{2})=1$ (see the details below). Then, it is very easy to check that $f$ is locally polynomial on the complement of the Cantor set; and it is, of course, $C^\infty$.
Indeed, since $f (3x)=0$ for $ x > \frac{1}{3}$, from the equation we have that $f'(x)$ vanishes identically on the interval $(\frac{1}{3},\frac{2}{3})$, so that $f$ is the constant $1$ therein. By induction, it is easy to see that $f$ is polynomial of degree $k1$ on each component of the complement of the closed set $F_k$ in $I$, inductively defined by $F_0:=I$ and $F_{k+1}:= \frac{1}{3}F_k \cup\left(\frac{1}{3}F_k + \frac{2}{3}\right)$. Note that $\{F_k\} _ {k\in\mathbb{N}}$ is the wellknown nested sequence of closed sets whose intersection is the Cantor set.
$$*$$ Construction. Consider the linear operator $T$ on $L^\infty(0,1)$ (thought as subspace of $L^\infty(\mathbb{R})$ via extension by zero), defined by
$$Tu(x)= \cases{ \int_0^{3x}u(t)\, dt\qquad \qquad 0 < x < \frac{1}{3}\\\ 0 \qquad \qquad \qquad \qquad \frac{1}{3} < x < \frac{2}{3}\\\ \int_0^{3(1x)}u(t)\, dt \qquad\frac{2}{3}< x < 1.} $$ Since $T$ and $T ^ 2$ are integral operators with nonnegative kernels, their norms are attained on the constant function $1$ on $[0,1]$. We have, by simple computations $T1(x)=3\min(x,1x)\chi _ { F _ 1 }(x) $, $\T\ = \T1\ _ \infty=1$ and $\T^2\=\T(T1)\_\infty=\frac{1}{3}$. Therefore $\rho(T)\le\frac{1}{\sqrt 3} < \frac{2}{3}$ and $I\frac{3}{2}T$ is invertible. The function
$$f:= \left(I\frac{3}{2}T\right) ^ {1}\chi _ {[\frac{1}{3},\frac{2}{3}]} = \sum _ {k=0} ^ \infty \left( \frac{3}{2}\right) ^ k T ^ k \chi _ { [\frac{1}{3}, \frac{2}{3}] } $$
verifies
$$f(x)=\frac{3}{2} \int_0^{3x}f(t)\; dt\qquad \mathrm{for\; all}\quad 0 < x <
\frac{1}{3}\, ,$$
$$f(x)=1\qquad \mathrm{for\, all}\quad \frac{1}{3} < x < \frac{2}{3}\, ,$$
and $$f(x)=f(1x)\qquad \mathrm{for\, all}\quad x\in\mathbb{R} \, .$$ The only points in $\mathbb{R}$ where the continuity of $f$ is not immediate and has to be checked, are $\frac{1}{3}$ and $\frac{2}{3}$. We have
$$\int_ 0 ^ 1 f(x)dx=\int _ 0 ^ \frac{1}{3} f(x)dx+\int _ \frac{1}{3} ^ \frac{2}{3} f(x)dx+\int _ \frac{2}{3} ^ 1 f(x)dx= 2\int _ 0 ^ \frac{1}{3} f(x)dx+ \frac{1}{3}\, ,$$
and
$$ 2 \int _ 0 ^ \frac{1}{3} f(x)dx = 3\int _ 0 ^ \frac{1}{3} \int _ 0 ^ {3x} f(t) dt dx= \int _ 0 ^ 1 \int _ 0 ^ x f(t) dt dx=$$
$$= \int _ 0 ^ 1 (1t) f(t) dt = \int _ 0 ^ 1 tf(1t)dt= \int _ 0 ^ 1 tf(t)dt = $$
$$ =\frac{1}{2}\left(\int _ 0 ^ 1 (1t)f(t)+ tf(t)dt\right) =\frac{1}{2} \int _ 0 ^ 1 f(t)dt\, . $$
So
$$ \int _ 0 ^ 1f(t)dt = \frac{2}{3}\, ,$$
which implies the continuity of $f$ at $ \frac{1}{3}$ (and by symmetry at $
\frac{2}{3}$ ), since
$$f(\frac{1}{3})=\frac{3}{2}\int_ 0 ^ 1 f(x)dx =1= f(\frac{1}{3}+) \, . $$
As a consequence, $f$ actually satisfies
$$f(x)=\frac{3}{2} \int_0^{3x}f(t)\, dt $$
for all $ x < \frac{2}{3}\, ,$
and we conclude that $f$ is in $ C ^ 1(\mathbb{R})$, and has the stated properties.
Here is a Pudding Function $f$, and its integral function, $F(x):=\int_0^x f(t)dt$. Note how the latter coincides with the first third of the former, up to rescaling. Simple considerations based on odd and even symmetry show that $F(1)=\frac{2}{3}$.
The following is wrong, but the comments are really nice :)
Suppose That on $(a_1, b_1)$, $f$ is a polynomial of degree $N$. This means that in its Taylor series at any point $x \in (a_1, b_1)$, every coefficiant past the $(N+1)$st vanishes.
This must also be true for the border points, $x = a_1$ and $x=b_1$. However, because the intervals are dense in $O$, $a_1$ or $b_1$ lies in the closure of some other interval. The rest is something like an induction: It follows that on every set $(a_n, b_n)$, the coefficients past the $(N+1)$st vanish.
This shows that $f$ is a polynomial, by the fundamental theorem of calculous.

2$\begingroup$ It seems to me that there is a problem with the part where you say that $a_1$ and $b_1$ lie in the closure of some other interval. For example, say $b_1 = 0$, and $$ O \cap (0,1) = \bigcup_{k=1}^\infty \left(\frac1{k+1},\frac1{k}\right). $$ $\endgroup$ – Aaron Tikuisis Apr 14 '12 at 19:47

$\begingroup$ Exactly: the OP's partition of $(c,d)$ allows things as ugly as Aaron's partition, or even $$(0,1)=\bigcup_{k=1}^\infty \bigcup_{j=1}^\infty \left(\frac{1}{k+1}+\frac{1}{k(k+1)}\frac{1}{j+1},\frac{1}{k+1}+\frac{1}{k(k+1)}\frac{1}{j}\right)$$ though I'm not sure the process can be continued indefinitely. It's an interesting question, then: how far can this idea be pushed? How many points can there be that do not have a "next neighbour to the right"? Can every interval $(a_n,b_n)$ be made to not have a next neighbour? $\endgroup$ – Emilio Pisanty Apr 14 '12 at 20:47

$\begingroup$ Follow up: This answer shows you can. $\endgroup$ – Emilio Pisanty Apr 15 '12 at 15:33