Let $f:\mathbb{R} \longrightarrow \mathbb{R}$ be a locally polynomial function, that is, for each $x \in \mathbb{R}$ there exist $\delta>0$ such that $f$ coincides with some polynomial on $(x-\delta,x+\delta)$. I want to show that $f$ is indeed a polynomial. Here is my attempt:
Proof: By hypothesis, $f$ is locally polynomial at $x=0$ and therefore there exist $\delta_1>0$ and $p_1 \in \mathbb{R}[X]$ such that $$ f|_{(-\delta_1,\delta_1)}=p_1|_{(-\delta_1,\delta_1)} $$ Now, let's consider the set $$ M:=\left\{{ y\in \mathbb{R}: y>0 \textrm{ and } f|_{[0,y)}=p_1|_{[0,y)} }\right\} $$ I claim that $M$ has not an upper bound. Suppose otherwise that $M$ has an upper bound, therefore, $M$ has a least upper bound $y^* \in (0,\infty)$. We have that $f$ is locally polynomial at $y^*$ and therefore there exist $\delta^*>0$ and $p^* \in \mathbb{R}[X]$ such that $$ f|_{(y^* - \delta^*,y^* + \delta^*)}=p^{*}|_{(y^* - \delta^*, y^* + \delta^*)} $$ Since $y=\sup M$ we have that for $\epsilon \in (0,\delta^*)$ there exist $y \in M$ such that $y^*-\epsilon<y$ and $$ f|_{[0,y)}=p_1|_{[0,y)} $$ Let $m=\min(y^*-\epsilon,0)$, then $p_1$ and $p^*$ coincide on $(m,y)$ (that is, they are equal at infinitely many points) and therefore $p_1=p^*$. This tell us that $$ f|_{[0,y^*+\delta^*)}=p_1|_{[0,y^* + \delta^*)} $$ which contradicts the fact that $y^*=\sup M$. Thus, $M$ hasn't an upper bound which implies that $f|_{[0,\infty)}=p_1|_{[0,\infty)} $. A similar argument would show that $f|_{(-\infty,0]}=p_1|_{(-\infty,0]} $ and hence $f=p_1$.
Do you think that this proof is correct?
In advance thank you very much.
Edit: As the user Robert Shore well noted, it may be that $(y^*-\delta^*,y^*+\delta^*) \cap M=\left\{{y^*}\right\}$. Let's consider that case. If $y-\delta^* \leq 0$ then $p_1$ and $p^*$ are equal on $[0,y^*)$ and again we have that $p_1=p^*$ which tell us again that $f|_{[0,y^*+\delta^*)}=p_1|_{[0,y^* + \delta^*)} $. If $y^*-\delta^*>0$ then $p_1$ and $p^*$ agree on $(y^*-\delta^*,y^*-\epsilon)$ which again entails that $p_1=p^*$ and therefore we conclude again that $f|_{[0,y^*+\delta^*)}=p_1|_{[0,y^* + \delta^*)} $.
You could also prove it in a slightly simplier way. Here is my proof:
First we will show that the function is a polynomial on every open ball.
For any bounded nonempty open ball $B$ let's consider a covering of its (compact) closure by open sets $B_i$ such that $f$ is a polynomial when restricted to $B_i$. Then we can find a finite subcovering $B_{ik}$.
Let $n$ denote the maximum degree of the polynomials in $B_{ik}$; so $n$ is finite. Thus $f^{(n+1)} = 0$ on $B$ and thus $f$ is a polynomial on $B$.
Now, for every nonempty bounded open ball centered at $0$ it has to be the same polynomial, because different polynomials can have only finite number of intersections. But for every two such balls their polynomials restricted to the smaller ball (on which we know, that both are indeed polynomials) are intersecting on an infinite set (on the whole smaller ball).
Thus we have a unique polynomial $p$ such that $f|_B = p|_B$ for every open bounded ball $B$ centered at $0$. But this means $p(x) = f(x)$ for every finite $x$, Q.E.D.