Solution:
It can be easily checked that the functions f(x)=x, f(x)=−x and f(x)=21−x satisfy the given condition. We will show that these are the only functions doing so. Let y=−f(x) in the original equation to obtain
f(2f(x)2+2xf(−f(x)))=0
for all x. In particular, 0 is a value of f. Suppose that u and v are such that f(u)=0=f(v). Plugging x=u or v and y=u or v in the original equations we get f(u2)=u2, f(u2)=uv, f(v2)=uv and f(v2)=v2. We conclude that u2=uv=v2 and hence u=v. So there is exactly one a mapped to 0, and
f(x)2+xf(−f(x))=2a
for all x.
Suppose that f(x1)=f(x2)=0 for some x1 and x2. Using (*) we obtain x1f(−f(x1))=x2f(−f(x2))=x2f(−f(x1)) and hence either x1=x2 or f(x1)=f(x2)=−a. In the second case, letting x=a and y=x1 in the original equation we get f(x12−2a2)=0, hence x12−2a2=a. Similarly, x22−2a2=a, and it follows that x1=x2 or x1=−x2 in this case.
Using the symmetry of the original equation we have
f(f(x)2+y2+2xf(y))=(x+f(y))(y+f(x))=f(f(y)2+x2+2yf(x))
for all x and y. Suppose f(x)2+y2+2xf(y)=f(y)2+x2+2yf(x) for some x and y. Then by the observations above, (x+f(y))(y+f(x))=0 and f(x)2+y2+2xf(y)=−(f(y)2+x2+2yf(x)). But these conditions are contradictory as the second one can be rewritten as (f(x)+y)2+(f(y)+x)2=0.
Therefore from (∗∗) now it follows that
f(x)2+y2+2xf(y)=f(y)2+x2+2yf(x)
for all x and y. In particular, letting y=0 we obtain f(x)2=(f(0)−x)2 for all x. Let f(x)=s(x)(f(0)−x) where s:R→{1,−1}. Plugging this in (∗∗∗) gives
x(ys(y)+f(0)(1−s(y)))=y(xs(x)+f(0)(1−s(x)))
for all x and y. So s(x)+f(0)(1−s(x))/x must be constant for x=0.
If f(0)=0 it follows that s(x) is constant for x=0, and therefore either f(x)=x for all x or f(x)=−x for all x. Suppose that f(0)=0. If s(x) is −1 for all x=0, then −1+2f(0)/x must be constant for all x=0, which is not possible. On the other hand, if there exist nonzero x and y such that s(x)=−1 and s(y)=1, then −1+2f(0)/x=1. That is, there can be only one such x, that x is f(0), and hence f(x)=f(0)−x for all x. Putting this back in the original equation gives 2f(0)2=f(0) and hence f(0)=1/2. We are done.