Functional equations $f(x+y)= f(x) + f(y)$ and $f(xy)= f(x)f(y)$ 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
 A: Easier way from the first identity:
$$
f(x) = f(x+0) = f(x) + f(0)
$$
so $f(0) = 0$ and similarly
$$
f(x) = f(x \cdot 1) = f(x) f(1)
$$
so $f(x) = 0$ or $f(1) = 1$.
In the first choice, you are done. Suffices to prove that if $f(1)=1$ then $f(x) = x$. Can you take it from here?
EDIT
Another hint: Note that if $f(1)=1$,
$$
f(n) = f(1 + 1 \ldots + 1) = n f(1) = n
$$
for all integer $n$...
EDIT 2 Another hint... to do rational numbers,
$$f(1) = f(1/n)  + f(1/n) + \ldots + f(1/n) = n f(1/n),$$
so $f(1/n) = f(1)/n = 1/n$ and similarly $f(a/b) = a/b$.
You can use a similar technique to show $f(\sqrt[b]{a}) = \sqrt[b]{f(a)}$.
There must be a more direct way to prove $f(ax) = af(x)$ for all real $a$...
A: If $f(x+y)=f(x)+f(y)$, then $f(px+qy)=pf(x)+qf(y)$, for all $p,q\in\mathbb Q$, and thus $f$ is  a linear functional on the vector space $\mathbb R$ over $\mathbb Q$. 
Therefore, $f$ is fully determined once its values are known on a Hamel basis of $\mathbb R$ over $\mathbb Q$. A Hamel basis in this case is a set $B\subset\mathbb R$, such that every $x\in\mathbb R$ can be written uniquely as a linear combination of elements of this $B$ with rational coefficients. (Such basis exists as a consequence of Zorn's Lemma.)
But for every $x\ge 0$ $$f(x)=f\big(\sqrt{x}\big)\,f\big(\sqrt{x}\big),$$ which means that 
$$f(x)\ge 0\quad\text{whenever} \quad x\ge 0.\tag{1}$$ In the case $f$ is not a continuous linear functional on $\mathbb R$ over $\mathbb Q$, there exist $a,b\in\mathbb R$, linearly independent over $\mathbb Q$, such that  the values
$$
f(a),\, f(b),
$$
are not proportional to the values
$$
a,\,b.
$$
In no such pair existed, then $f$ would be $f(x)=cx$. Using these values we can create a linear combination of them 
$$
pa+qb>0,
$$
such that
$$
f(pa+qb)<0,
$$
which contradicts $(1)$.
Thus $f$ is continuous, which implies that $f(x)=cx$, for some $c\ge 0$, and since
$$
cxy=f(xy)=f(x)f(y)=c^2xy,
$$
then the only acceptable values of $c$ are $0$ and $1$. Thus
$$
f(x)=x \quad\text{or}\quad f(x)=0.
$$
A: These functional equations are rather famous and you can read more here. Actually:
$$f(x+y) = f(x) + f(y)$$
is called Cauchy functional equation and its solutions are $f(x) = cx$; $\forall c \in R$
Now substitute into the second functional equations and we have:
$$f(xy) = f(x)f(y) \implies cxy = c^2xy$$
So we have two cases: $c = 0$ or $c=1$. So we have $f(x) = 0$ and $f(x) = x$ as solutions.
Hence the proof.
A: 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.
