6. (IND 2) ${ }^{\mathrm{IMO} 2}$ Find all functions $f: \mathbb{R} \rightarrow \mathbb{R}$ such that  
$$ f\left(x^{2}+f(y)\right)=y+f(x)^{2} \quad \text { for all } x, y \text { in } \mathbb{R} $$
6. It is easy to see that \( f \) is injective and surjective. From \( f\left(x^{2}+f(y)\right) = f\left((-x)^{2}+f(y)\right) \) it follows that \( f(x)^{2} = (f(-x))^{2} \), which implies \( f(-x) = -f(x) \) because \( f \) is injective. Furthermore, there exists \( z \in \mathbb{R} \) such that \( f(z) = 0 \). From \( f(-z) = -f(z) = 0 \) we deduce that \( z = 0 \). Now we have \( f\left(x^{2}\right) = f\left(x^{2} + f(0)\right) = 0 + (f(x))^{2} = f(x)^{2} \), and consequently \( f(x) = f(\sqrt{x})^{2} > 0 \) for all \( x > 0 \). It also follows that \( f(x) > 0 \) for all \( x > 0 \). Substituting \( x = \sqrt{x} \) and \( y = -f(x) \) in the given functional equation we obtain 
\[ f(x - f(x)) = f\left(\sqrt{x}^{2} + f(-x)\right) = -x + f(\sqrt{x})^{2} = -(x - f(x)). \]
But since \( f \) preserves sign, this implies that \( f(x) = x \) for \( x > 0 \). Moreover, since \( f(-x) = -f(x) \), it follows that \( f(x) = x \) for all \( x \). It is easily verified that this is indeed a solution.