Solution 1:

I don't understand what you say about derivatives and I will assume that you want the following result.

Let $f: \mathbb{R}^2 \rightarrow \mathbb{R}$ be a function such that for every $a, b \in \mathbb{R}$, $x \mapsto f(x,b)$ and $y \mapsto f(a,y)$ are polynomial functions; then $f$ is a polynomial in two variables.

This is not obvious because we don't have a good representation of $f$. The idea of the proof is to show that $f$ coincides with a polynomial at sufficiently many points.

1) There exists an infinite set $I \subset \mathbb{R}$ and an integer $N$ such that for any $a,b \in I$, the polynomials $y \mapsto f(a,y)$ and $x \mapsto f(x,b)$ are of degree bounded by $N$. This follows from the fact that $\mathbb{R}$ is not countable: if $K_n$ is the set of $z \in \mathbb{R}$ such that $x\mapsto f(x,z)$ and $y \mapsto f(z,y)$ are of degree bounded by $n$, then $\cup_{n\in \mathbb{N}} K_n = \mathbb{R}$ and one of the $K_n$ must be infinite (in fact uncountable but I don't need it).

2) Let $I$ and $N$ be as in the previous point. Let $z_1,\dots,z_{N+1}$ be $N+1$ arbitrary elements in $I$. I claim that there exists a polynomial $Q$ in two variables, of degree in $x$ and $y$ at most $N$ such that $Q$ takes the same values than $f$ in all points of the form $(z_i,z_j)$, for $1 \leq i,j \leq N+1$. Indeed, this is the analog of Lagrange interpolation in two variables. This polynomial $Q$ is defined by:

$$ Q(x,y) = \sum_{i=1}^{N+1} \sum_{j=1}^{N+1} f(z_i,z_j) \prod_{i' \neq i} \prod_{j' \neq j} \frac{(x-z_{i'})(y-z_{j'})}{(z_i-z_{i'})(z_j-z_{j'})}.$$

3) I claim that $f(x,y) = Q(x,y)$ everywhere. First, $y \mapsto f(z_i,y)$ and $y \mapsto Q(z_i,y)$ are both polynomial of degree bounded by $N$, which coincide in $N+1$ points. This shows that $f = Q$ on sets of the form $z_i \times \mathbb{R}$. Now, take any $y$ in $I$. Then $x \mapsto f(x,y)$ and $x \mapsto Q(x,y)$ are polynomial of degree bounded by $N$ and they are equal for $x$ equal to one of the $z_i$. So they are equal everywhere. This shows that $f = Q$ on $\mathbb{R} \times I$. Finally, consider an arbitrary $x \in \mathbb{R}$. Then $y \mapsto f(x,y)$ and $y \mapsto Q(x,y)$ are both polynomial, equal when $y \in I$. Since $I$ is infinite, they are equal everywhere. This concludes the proof of $Q = f$.

Solution 2:

F. W. Carroll, "A polynomial in each variable separately is a polynomial." Amer. Math. Monthly 68 (1961) 42.

True for the reals, or any uncoutable (or finite) field. But false for the rationals (or any countably infinite field)...

Richard S. Palais, "Some analogues of Hartogs' theorem in an algebraic setting." Amer. J. Math. 100 (1978), no. 2, 387--405.

Solution 3:

Set $f(\cdot, y):x\mapsto f(x,y)$. Since this $f(\cdot, y)$ is $x$-continuous, when $y_n\to y$ the polynomials $f(\cdot, y_n)$ converge pointwise everywhere. Hence, for fixed $N$, the sets $\{y| \deg f(\cdot, y)\leq N \}$ are closed. By Baire there exist $N$ and $Y\subset \Bbb R$ open, such that $\deg f(\cdot, y)\leq N, \forall y\in Y$. Interchanging $x$ and $y$ we have $M$ and $X\subset \Bbb R$ with analogous properties. Fix arbitrarely $x_0<\dots <x_N$ in $X$, $y_0<\dots <y_N$ in $Y$ and take the polynomial $g$ of bi-degree $(N,M)$ which equals $f$ at the $(N+1)(M+1)$ points $(x_j,y_k)$. If $h=f-g\equiv 0$ we are done. For any $y\in Y$, $h(\cdot, y)$ vanishes identically because its degree is $\leq N$ and it vanishes at $x_0,\dots , x_N$. Thus, $\forall x\in\Bbb R$ $h(x,\cdot)$ vanishes identically because it vanishes in the open set $Y$. This means $h\equiv 0$.