solving functional equation $f(x+y) +f(x)f(y)=f(x)+f(y)+f(xy)$ for all real numbers The functional equation to be solved is
$$ f ( x + y ) + f ( x ) f( y ) = f ( x ) +f ( y ) + f ( x y ) $$
for $ f : \mathbb R \to \mathbb R $.
I found about four possible solutions to the equation but ran into a fundamental problem with all of them. For example I found one of the solutions to be $ f ( x + 1 ) = f ( x ) + 1 $ with $ f ( 0 ) = 0 $. By induction I proved that $ f ( x ) = x $ for all integers and by setting $ x = \frac m n $, $ y = n $ in the original equation with $ m $ and $ n $ integers, I proved that $ f ( x ) = x $ for all rational numbers. My main problem is that I am not able to think of any way to extend the argument to all real numbers. A search on the internet told me that one way to prove this would be using the density of rational numbers but this method requires the function to be continuous, too. Could anyone help me in extending the argument to real numbers? Maybe if we could prove the continuity of the function?
 A: The only solutions to the functional equation
$$f(x+y)+f(x)f(y)=f(x)+f(y)+f(xy)\tag0\label0$$
are the identity function, and constant functions $f(x)=0$ and $f(x)=2$.
To observe this, if we set $x=y=2$ in \eqref{0} we get $f(2)=0$ or $f(2)=2$.
By setting $x=y=1$ in \eqref{0} we get $f(1)^2-3f(1)+f(2)=0$. So if $f(2)=0$ then $f(1)=0$ or $f(1)=3$, and if $f(2)=2$ then $f(1)=1$ or $f(1)=2$.

*

*If $f(2)=0$ and $f(1)=3$, by letting $y=1$ in \eqref{0}, we have $f(x+1)=3-f(x)$ which yields $f(x+2)=3-f(x+1)=3-\big(3-f(x)\big)=f(x)$. Now if we put $x=\frac{1}{2}$ and $y=2$ in \eqref{0} we get $f(1)=0$ which leads to a contradiction. So this case can't happen.

*If $f(2)=0$ and $f(1)=0$, by letting $y=1$ in \eqref{0}, we have $f(x+1)=2f(x)$ which inductively yields $f(x+n)=2^nf(x)$ for any nonnegative integer $n$. Now if we put $y=2$ in \eqref{0} we get $f(2x)=3f(x)$ and then $f(4x)=3f(2x)=9f(x)$. Againg, putting $y=4$ in \eqref{0} we conclude that $f(4x)=15f(x)$ since $f(4)=2^2f(2)=0$. Hence $9f(x)=15f(x)$ and so $f$ is the constant zero function.

*If $f(2)=2$ and $f(1)=2$, by letting $y=1$ in \eqref{0}, we have $f(x+1)=2$. So $f$ is the constant two function.

*If $f(2)=2$ and $f(1)=1$, by letting $y=1$ in \eqref{0}, we have $f(x+1)=f(x)+1$ which inductively yields $f(x+n)=f(x)+n$ for any integer $n$. By putting $y=n$ in \eqref{0} we have $f(nx)=nf(x)$ since $f(n)=f\big(1+(n-1)\big)=n$. Substituting $2x$ for $x$ and $2y$ for $y$ in \eqref{0} we get
$$f(2x+2y)+f(2x)f(2y)=f(2x)+f(2y)+f(4xy)\text;$$
$$\therefore 2f(x+y)+4f(x)f(y)=2f(x)+2f(y)+4f(xy)\text.$$
Multiplying \eqref{0} by $2$ and subtracting the last equation, we get
$$f(xy)=f(x)f(y)\text.\tag1\label1$$
Subtracting \eqref{0} and \eqref{1} we have
$$f(x+y)=f(x)+f(y)\text.\tag2\label2$$
It's well known that if $f$ satisfies \eqref{1} and \eqref{2}, then it's either the constant zero function or the identity function (hint: \eqref{1} implies that $f(x)$ is nonnegative for nonnegative $x$. By \eqref{2} we conclude that $f$ is increasing).

A: You say: “My main problem is that I am not able to think of any way to extend the argument to all real numbers” I show you a way here.
You have for $x\in\mathbb R$ the equality  $f(x+x) +f(x)f(x)=f(x)+f(x)+f(x^2)$ and you know that $f(2x)=2f(x)$  (you don’t know by now that $f(x)=x$); hence $f(x^2)=(f(x))^2$ for $x$ real.
Any $x\geq0$ has a square root in $\mathbb R$ therefore $f(x)\geq 0$ for $x\geq0$ and 
for $a,b\in\mathbb {R}$ the inequality $a\leq b$  implies $f(a)\leq f(b)$ because $f$ is (in particular) linear.
In order to go to  $\mathbb R$ you try with $\epsilon>0$. 
Let $\epsilon$ be a positive rational; there are two rational $r_1, r_2$ such that $r_2-r_1\leq\epsilon$ and $r_1\leq x\leq r_2$. It follows $r_1\leq f(x)\leq r_2$ (you have proved before that $f(r_1)=r_1$ and $f(r_2)=r_2$) with $r_2-r_1\leq\epsilon$.
Hence$|f(x)-x|\leq\epsilon$ with $\epsilon>0$ arbitrary. Thus $f(x)=x$ for $x$ real. 
