TITLE: Functional equations $f(x+y)= f(x) + f(y)$ and $f(xy)= f(x)f(y)$
QUESTION [7 upvotes]: Let $f:\mathbb{R}\to \mathbb{R}$ is a function such that for all real $x$ and $y$, $f(x+y)= f(x) + f(y)$ and $f(xy)= f(x)f(y)$, then prove that $f$ must be one of the two following functions:

$f:\mathbb{R}\to \mathbb{R}$ defined by $f(x)=0$ for all real $x$

OR

$f:\mathbb{R}\to\mathbb{R}$ defined by $f(x)=x$ for all real $x$

I got to the point where putting the two equations together, you get $f(x+y)f(x)= f(xy) + f(x)^2$ and plugging in $f(x)=x$ checks with it. So am I going in the right direction or am I just doing some guess work? Is there a more elegant way of doing it? 
Thanks

REPLY [13 votes]: I am providing another answer without the use of the Axiom of Choice this time:
As already observed $f(x)=0$ is a solution of this functional equation.
Assuming that $f$ is not the identically zero solution we obtain that $f(1)=1$ since for every $x$:
$$
f(x)=f(x\cdot 1)=f(x)f(1).
$$ 
Next, obtain that $$f(n)=\underbrace{f(1)+\cdots+f(1)}_{n\,\,\text{times}}=n,$$ 
for every $n\in\mathbb N$. Also $f(0)=f(0+0)=f(0)+f(0)$, and thus $f(0)=0$, and
$$0=f(n-n)=f(n)+f(-n),$$ and thus $f(-n)=-f(n)$, and hence $f(k)=k$, for all $k\in\mathbb Z$. Finally $$f(1)=\underbrace{f(1/q)+\cdots+f(1/q)}_{q\,\,\text{times}},$$
and thus  $f(1/q)=1/q$ similarly $f(p/q)=p/q$ and 
$$
f(r)=r\quad \text{for every}\quad r\in\mathbb Q.\tag{1}
$$
Next, observe that, if $x\ge 0$, then $$f(x)=f\big(\sqrt{x}\big)\,f\big(\sqrt{x}\big),$$
and hence 
$$
x\ge 0\quad\Longrightarrow f(x)\ge 0.
$$
In particular, 
$$ 
\text{If}\,\,\,\,\, y \ge x\,\,\,\,\, \text{then}\,\,\,\,\, f(y)=f(x)+f(y-x)\ge f(x).
\tag{2}
$$
Finally, we shall show that $f(x)=x$ for all $x\in\mathbb R$. Suppose that for some $x\in\mathbb R$:
$$f(x)<x.$$
Then there is a rational $r$, such that   $$f(x)<r<x.\tag{3}$$ But $(1)$ and  $(2)$ imply that
$$
f(x)\le f(r)=r,
$$
which contradicts $(3)$. The case $f(x)>x$ is dealt with similarly.