f(x)=x+c for some constant c.
We first check that all such functions are solutions. Indeed, if f(x)=x+c, then
f(x+f(y))=f(x+y+c)=x+y+2c=f(f(x))+y
for any x,y∈R.
Next, we prove that these are the only solutions. Replacing x by x−f(y), the given condition means
f(x)=xorf(x)=f(f(x−f(y)))+y
for any x,y∈R. We are done if f(x)=x for all x∈R. Assume f(a)=a for some a∈R. Then we have
f(a)=f(f(a−f(y)))+y(1)
for any y∈R. Note that f is injective, since if f(α)=f(β), then
α=f(α)−f(f(α−f(α)))=f(α)−f(f(α−f(β)))=β
by (1). Setting y=0 in (1), we have f(a)=f(f(a−f(0))), and hence
a=f(a−f(0))(2)
as f is injective. In particular, this implies f(0)=0 (as f(a)=a).
* If f(x)=x for all x∈R, then (2) holds for all a∈R. Replacing a by x+f(0), this gives f(x)=x+c for all x∈R, where c=f(0) is a constant as desired.
* Suppose f(b)=b for some b. Note that f(f(a))=f(a) since f(a)=a and f is injective. It follows that (1) holds if we replace a by f(a). Thus, we obtain
f(f(a))=f(f(f(a)−f(y)))+y.
Putting y=a, this yields
f(f(a))=f(f(0))+a.(3)
Next, putting y=b in (1), we have f(a)=f(f(a−b))+b. Recall that f(a)=a, so we cannot have f(a−b)=a−b. Therefore, using (3) with a replaced by a−b, we deduce
f(a)=f(f(a−b))+b=f(f(0))+(a−b)+b=a+f(f(0)).(4)
Recall that f(0)=0. Thus, we may take a=0 in (4). This implies f(0)=f(f(0)). But then this yields 0=f(0) by the injectivity, which is a contradiction.