If $f:\mathbb{R}^2\rightarrow\mathbb{R}$ is a polynomial on every line, is it a polynomial itself? The question:
If $f:\mathbb{R}^2\rightarrow\mathbb{R}$ is a function such that for every "linear" function $\varphi:\mathbb{R}\rightarrow\mathbb{R}^2$ (i.e. an affine line in $\mathbb{R}^2$) we have that $f\circ\varphi$ is a polynomial, then is $f$ a polynomial itself?
Discussion (only for curious readers):
What I have already proved is that if $f\circ\varphi$ is a polynomial of degree at most $n$ then $f$ is a polynomial of degree at most $n$ too. Although, I just proved it for $n=2$ and assumed that the similar construction exists and can be made for higher $n$. The proof goes like this:

 Substract from $f$ the polynomial that is at the line $x=0$. For example, if at $x=0$ we have the polynomial $ay^2+by+c$ then substract that from $f$. So, if $f=x+xy+y^2$, then after substracting we are left with $x+xy$. We have that this new $f$ is a quadratic polynomial iff the old $f$ was. Do that for $y=0$ too. Now the new $f$ is equal to $0$ on both axes. Substract now from $f$ the function $f(1,1)\cdot xy$. The new $f$ is zero on the axes and on the line $x+y=2$ because it is zero at $3$ points on it: $(0,2)$, $(1,1)$ and $(2,0)$. Now every line (that is not parallel to these $3$ nor is concurrent with two of them) intersects all $3$ of them (at $3$ different points) so $f$ is zero on them too. These lines pass through each point, so the new $f$ is $0$ everywhere, and that is equivalent to the original $f$ being a quadratic form.

My idea for my original question was that there will be simply too many lines for $f$ to not be a polynomial, i.e. if the number of lines at which $f$ is a polynomial of the degree exactly $n$ is too big (in some sense) then $f$ must be a polynomial of degree $n$ too. I thought maybe some argument similar to the one in the spoiler would work, but I couldn't find it.
 A: It is enough to use only horizontal and vertical lines.
F. W. Carroll, "A polynomial in each variable separately is a polynomial." Amer. Math. Monthly 68 (1961) 42.

A: Let $(x_1,y_1),\ldots,(x_n,y_n)$ be any finite sequence of distinct points. Then there is a polynomial $p\in \mathbb{R}[x,y]$ such that $p(x_i,y_i)=f(x_i,y_i)$ (by multivariate Lagrange interpolation). So we may assume without loss of generality that $f(x_i,y_i)=0$ for all $i$.
With this we can do the following: fix some $d\geq 0$. Let $D$ be the maximal degree of the polynomials $f(x,0),\ldots,f(x,d)$ and $f(0,y),\ldots,f(d,y)$. On each of these $2(d+1)$ lines, choose $D+1$ points. With the above procedure, we can assume that $f$ is equal to $0$ at all of these points, and hence is equal to $0$ on all of these lines. As then on any line we have at least $d+1$ points where $f$ vanishes, we conclude that on every line where $f$ is a polynomial of degree $\leq d$, it must in fact be $0$.
This can now be completed to a full solution: for every $n\in\mathbb{Z}_{\geq 0}$, let $P_n:=\{c\in\mathbb{R}\mid \deg f(x,c)=n\}$ (as a special convention here I declare the zero polynomial to have degree $0$ as well). As $\bigcup_{n\geq 0} P_n=\mathbb{R}$, there exists an $n$ such that $P_n$ is uncountable. Now if we perform the above procedure for $d=n$, we obtain that $f$ is equal to $0$ on every line $x\mapsto (x,c)$ with $c$ in the uncountable set $P_n$. Hence $f$ is equal to $0$ on every vertical line $y\mapsto (c',y)$, as it is a polynomial with uncountably many zeros (every $c\in P_n$). Hence $f=0$ everywhere, so we must have started with a polynomial.
Note that this solution only used horizontal and vertical lines, so we obtain the result also for the slightly weaker assumption that $f$ is a polynomial on all horizontal and vertical lines.
A: Partial counterexample: We can find $f$ such that $f\circ\varphi$ is a polynomial (in cartesian coordinates) for all $\varphi$ passing through the origin. Written in polar coordinates for convenience, $f$ has the form: $$f(r,\theta)=g(\theta)r^2$$
where $g$ is any function defined for all $\theta\in[0,2\pi)$, such that $g(\theta+\pi)=g(\theta)$ for all $\theta\in[0,\pi)$.
For each line $\varphi$ through the origin (with slope angle $\theta$), $f\circ\varphi=g(\theta)(x^2+y^2)$ which is a polynomial.
Idea: in this case, we just need to make sure $f$ is a polynomial on each line individually, since the lines do not interfere each other (except at the origin).
