Finite-dimensional rational image implies algebraic? 
If $f: X \to \mathbb{R}$ is continuous on an open set $X \subseteq \mathbb{R}$ and such that $\dim_\mathbb{Q} \text{span}_\mathbb{Q} \, f(X \cap \mathbb{Q}) < \infty$, then $f$ is
  algebraic. True or false?

If it's false, what if we take $f$ to be smooth? This question arose for me in the context of showing $\dim \text{span} \log(\mathbb{Q^+}) = \infty$, but the techniques used there don't seem to generalise easily to other transcendental $f$. 
Note for interest that the converse implication doesn't hold; consider the square root on $\mathbb{R}^+$.
 A: Here's a simple way of getting lots of counterexamples.  Split $X$ into infinitely many subintervals with rational endpoints, and consider piecewise functions which are polynomials with rational coefficients on each of the subintervals.  If infinitely many of these polynomials are different, it is easy to see such a function cannot be algebraic.  But by choosing the polynomials appropriately, we can arrange that $f$ is continuous, or even $C^k$ for any finite $k$.
Here's another source of examples.  If $X=\mathbb{R}$ (or more generally any open interval), then any order-preserving bijection $\mathbb{Q}\to\mathbb{Q}$ extends to a homeomorphism $\mathbb{R}\to\mathbb{R}$.  You can construct such order-preserving bijections inductively one element at a time to "diagonalize" and avoid a countable set of constraints.  For instance, you can easily construct an order-preserving bijection $\mathbb{Q}\to\mathbb{Q}$ which grows faster than $x^n$ for all $n$ as $x\to\infty$, and the resulting homeomorphism $\mathbb{R}\to\mathbb{R}$ cannot be algebraic.
I suspect $C^\infty$ counterexamples exist as well, but I don't see a way to construct one at the moment.
