How much can two polynomials agree on? Let $f(x,y)$ be a polynomial in $\mathbf R[x, y]$ such that $f(x, x^3) = 0$ for all $1< x< 2$.

Question. Then is it necessary that $f(x, x^3) = 0$ for all $x$?

(As pointed out by @dvix in the comments, this question has answer YES. The reason is that $f(x, x^3)$ is a single variabel polynomial vanishing on infinitely many points, and hence must be identically zero).
More generally what I want to know is the following:

Question. Suppose $X\subseteq \mathbf R^n$ is an irreducible affine variety and $f\in \mathbf R[x_1, \ldots, x_n]$ be a polynomial which vanishes on an open subset of $X$.
  Then is it forced that $f$ vanishes on all of $X$. Or at least on all smooth points of $X$?

Here "open" is with respect to Euclidean topology.
 A: In the following, when we write $\dim$, we mean dimension as a topological space, and when we write varieties, we mean schemes of finite type over a field, and when we write $\dim$ of a scheme, we mean dimension of the associated topological space.
Let $U\subset X(\Bbb R)$ be the open set on which $f$ vanishes. $f=0$ is a closed set in $X$, so if $X$ is reduced and $U$ is of dimension $\dim X$, then $f$ must be identically zero ($\{f=0\}$ is a closed set containing $U$, so $\dim \{f=0\} \geq \dim U=\dim X$, and the only closed subset of an irreducible, reduced variety of dimension $\dim X$ is $X$).
It is important that $\dim U = \dim X$: it may happen that $\dim U < \dim X$, such as the case when $X = V(x^2-y^2z)$ - here, $X$ is two-dimensional, irreducible, and reduced, but it is possible to pick a $U\subset X(\Bbb R)$ which is open but has dimension 1: consider $X(\Bbb R)\cap ((-1,1)\times(-1,1)\times(-2,-1)).$ If $U$ consists entirely of smooth points, you are ensured that $\dim U=\dim X$, by the implicit function theorem.
A: This can be proven using basic linear algebra concepts.
Consider a generic polynomial $p(x)$ of degree $n$:
$$p(x) = \sum_{i=0}^n a_i x^i.$$
Suppose that you don't know the coefficient $a_i$ (they are $n+1$), but you know the value of the polynomial for $n+1$ different values of $x$, let's say $$p(x_j) = y_j.$$
for $j=1, \ldots, n+1.$
Under this assumption, you can try to find the coefficients $a_i$ by solving the following linear system:
$$\begin{cases}
a_0x_1^0 + a_1x_1^1 + \ldots + a_nx_1^n & = & y_1\\
a_0x_2^0 + a_1x_2^1 + \ldots + a_nx_2^n & = & y_2\\
\ldots \\
a_0x_{n+1}^0 + a_1x_{n+1}^1 + \ldots + a_nx_{n+1}^n & = & y_{n+1}\\
\end{cases}.$$
It can be easily proven that the square matrix of this linear system
$$\begin{bmatrix}
1 & x_1 & x_1^2 & \ldots & x_{1}^n \\
1 & x_2 & x_2^2 & \ldots & x_{2}^n \\
\ldots\\
1 & x_{n+1} & x_{n+1}^2 & \ldots & x_{n+1}^n
\end{bmatrix}$$
is a Vandermonde matrix, which is invertible if and only if all $x_j$s are different.
Suppose now that for all (the different) $x_j$s, the value of the polynomial is $y_j = 0$. Then, the unique solution of the linear system (which now is homogeneous), is given by:
$$a_0 = a_1 = \ldots = a_n = 0.$$
Now, if $p(x) = 0$ for $x \in I$, where $I$ is an uncountable set, then you can always find $n+1$ points $x_j$ inside $I$ such that $p(x_j) = 0 (=y_j)$, implying that $a_0 = a_1 = \ldots = a_n = 0.$
Therefore, $p(x) = 0$ for all $x \in \mathbb{R}$.
