$f(x+1)=f(x)+1$ and $f(x^2)=f(x)^2$

A function that satisfies both $f(x+1)=f(x)+1$ and $f(x^2)=f(x)^2$ for all real $x$ is known to be the identity over $\mathbb Q$, but is it also the identity over $\mathbb R$? If not, can you provide me an example of such a function? Thanks.

-
Could you provide a reference or sketch a proof for the statement over $\mathbb{Q}$? –  Jason DeVito Aug 16 '11 at 23:30
The proof goes as follows : f(0)=f(0²)=f(0)² implies f(0)=0 or f(0)=1. If f(0)=1, then f(1)=2 but then we have a contradiction : 2=f(1)=f(1²)=f(1)²=4. So f(0)=0 and f(n)=n for all integer n. One can then write $f((\frac{p}{q}+q)²)$ in two ways so to deduce f(q)=q for all rational q. –  Dijkschneier Aug 17 '11 at 0:07
Nice - the idea of using $\frac{p}{q} + q$ is what I was missing. –  Jason DeVito Aug 17 '11 at 0:42
Very intriguing! +1 –  Pierre-Yves Gaillard Aug 17 '11 at 2:52
Thank you very much all of you ! –  Dijkschneier Aug 17 '11 at 13:49

if $f(x)<x$ for some $x$, you can suppose $x$ and $f(x)$ being greater than 1. Then $f(x^{2^n})< m < x^{2^n}$ for some m,n integers, then $f(x^{2^n} - m) < 0$ being $x^{2^n} - m > 0$ and that's a contradiction. You can do a similar argument with the other inequality , the argument is very close to the one in the previous answer.
Ahhh, perfect! This does it, and with this in place it's easy to handle the $f(x)\gt x$ case. Thank you! –  Steven Stadnicki Aug 17 '11 at 4:22
I was just about to supply a counter-example (e.g., set $f(\pi)=e$ and then assign the values at all of the points 'algebraically related' to $\pi$ according to the value of the same algebraic relation applied to $e$) when I realized that this has a clear flaw - for $f$ to be well-defined over $\mathbb{R}$, it must satisfy $f(x)\gt 0$ for all $x\gt 0$ (otherwise $f(\sqrt{x})$ is ill-defined). I suspect this is enough to prove that $f$ must be the identity because you can use the maps $x\rightarrow x+1$, $x\rightarrow x^2$ and their inverses to map each $x$ down into some arbitrarily small neighborhood of $0$ and bound its values there (the positivity condition bounds the value from below and I suspect that clever manipulations will let you use it to bound the value from above), forcing f to be continuous in a neighborhood of $0$ and thus (by 'blowing up' the neighborhood to $[0,1)$ using $f(\sqrt{x}) = \sqrt{f(x)}$ and then translating up and down the line) to be the identity.
EDIT: shurtados's version of this argument does the trick. As noted there, if $f(x) \lt x$ for some $x\gt 0$, we can derive a contradiction because we can find integers $m$ and $n$ such that $f(x^{2^n}) \lt m \lt x^{2^n}$ and thus find a value $y\gt 0$ with $f(y)\lt 0$, giving us the contradiction above.
Now, we can finish with this argument: suppose $f(x)\gt x$ for some $x\gt 0$; choose an integer $m$ with $f(x)\lt m$. We get $(x-m)\lt f(x-m) \lt 0$, so $0\lt f((x-m)^2) = (f(x-m))^2 \lt (x-m)^2$, and with $y = (x-m)^2$ we have $f(y) \lt y$, giving the needed contradiction; ergo, $f(x)=x$ for all $x\in\mathbb{R}$.