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

$$
f(x+y f(x))=f(f(x))+x f(y)
$$
Solution. If we set $x=0$ in (1), then $f(y f(0))=f(f(0))$. If $f(0) \neq 0$, then for $y=\frac{t}{f(0)}$, we get $f(t)=f(f(0))=c$, which means that $f$ is a constant function and $c=f(0) \neq 0$. However, then by substitution in (1) we get $c=c+C x$, for every $x \in \mathbb{R}$, i.e., $c x=0$, for every $x \in \mathbb{R}$, which is a contradiction. From the obtained contradiction, it follows that $f(0)=0$.

Let us assume that $f(a)=0$ for some $a \neq 0$. Then by substitution in (1) we get $a f(y)=0$ for every $y \in \mathbb{R}$, from which it follows that $f(y)=0$ for every $y \in \mathbb{R}$, which is a contradiction. It is easily verified that the function $f(x)=0$, for every $x \in \mathbb{R}$ is a solution to (1).

If we set $y=0$ in (1), we get $f(f(x))=f(x)$, and by substitution in (1) we find

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

Let $f(1)=a \neq 0$. If we set $x=y=1$ in (2) we get $f(1+a)=2 a$. Further, if we first set $x=1, y=-1$, and then set $x=1+a, y=-1$, and use that $f(1+a)=2 a$, we respectively get

$$
\begin{aligned}
& f(1-a)=a+f(-1) \\
& f(1-a)=2 a+(1+a) f(-1)
\end{aligned}
$$

Now from the system of equations (3) and (4) we find $f(-1)=-1$ and $f(1-a)=a-1$. On the other hand, for $x=1-a, y=1$ from (2) we get $0=a-1+(1-a) a$, from which we find $a=1$. Now first for $x=1$, and then for $x=-1$ from (2) we get

$$
\begin{aligned}
& f(1+y)=1+f(y) \\
& f(-1-y)=-1-f(y)
\end{aligned}
$$

From (5) and (6) it follows that $f(1+y)=-f(-1-y)$, so $f(t)=-f(-t)$ for every $t \in \mathbb{R}$. Now, from (2) for $y=-1$, we get $f(x-f(x))=f(x)-x$.

Finally,

$$
\begin{aligned}
& f(x-f(x))=f(f(x-f(x))=f(f(x)-x)=-f(x-f(x)) \\
& f(x-f(x))=0 \\
& x-f(x)=0 \\
& f(x)=x
\end{aligned}
$$

It is easily verified that the function $f(x)=x$ is a solution to (1).