4. Determine all functions $f: \mathbb{R} \rightarrow \mathbb{R}$ such that

$$
f(f(x)+f(y))=f(x)+y, \text { for all } x, y \in \mathbb{R} \text {. }
$$
Solution. I method. Let $x_{1}, x_{2}$ be real numbers for which $f\left(x_{1}\right)=f\left(x_{2}\right)$. By substituting, sequentially $y=x_{1}$ and $y=x_{2}$ in the given equation, we get $f\left(f(x)+f\left(x_{1}\right)\right)=f(x)+x_{1}$ and $f\left(f(x)+f\left(x_{2}\right)\right)=f(x)+x_{2}$. Since the left sides of the last two equations are equal, we have $f(x)+x_{1}=f(x)+x_{2}$, from which $x_{1}=x_{2}$. We have obtained that the function $f(x)$ is an injection. By substituting $y=0$, in the initial equation, we get $f(f(x)+f(0))=f(x)$, for every real number $x$. Since $f(x)$ is an injection, we have that $f(x)+f(0)=x$. If we put $x=0$, from the last equation we get $2 f(0)=0$, that is, $f(0)=0$. From this, we obtain that the function $f(x)=x$ satisfies the initial equation.

II method. By swapping the places of $x$ and $y$ in the initial equation, we get

$$
f(f(y)+f(x))=f(y)+x
$$

Since the left side of the last equation is the same as the left side of the initial equation, we get $f(x)+y=f(y)+x$. By substituting $y=0$, in the last equation, we get $f(x)=x+f(0)$. Now by substituting in the initial equation, we get

$$
x+f(0)+y+f(0)+f(0)=x+f(0)+y
$$

from which it follows that $f(0)=0$. Now from $f(x)=x+f(0)$, we get that $f(x)=x$.