6-161 Let $R$ be the set of all real numbers. Find all functions $f: R \rightarrow R$ such that for all $x$ and $y$ in $R$, we have
$$f\left(x^{2}+f(y)\right)=y+(f(x))^{2}$$
[Solution] Let $t=f^{2}(0), f^{(2)}(x)=f[f(x)]$. In the functional equation
$$f\left(x^{2}+f(y)\right)=y+f^{2}(x)$$

let $x=0$, we get
$$f^{(2)}(y)=y+t$$

Thus, from (2) and (1),
$$\begin{aligned}
x^{2}+f^{(2)}(y)+t & =f^{(2)}\left[x^{2}+f^{(2)}(y)\right] \\
& =f\left[f(y)+(f(x))^{2}\right] \\
& =f\left[f^{2}(x)+f(y)\right] \\
& =y+\left[f^{(2)}(x)\right]^{2}
\end{aligned}$$

which is $x^{2}+y+2 t=y+(x+t)^{2}$,
or equivalently, $2 t=t^{2}+2 t x$.
Since this equation holds for any $x \in \mathbb{R}$, it must be that $t=0$, i.e., $f(0)=0$. Thus, (2) becomes
$$f^{(2)}(y)=y \quad(y \in \mathbb{R})$$

For any $x \geqslant 0$, by (3) and (1) we have:
$$\begin{aligned}
f(x+y) & =f\left(x+f^{(2)}(y)\right) \\
& =f(y)+f^{2}(\sqrt{x})
\end{aligned}$$

Let $y=0$, we get $f(x)=f^{2}(\sqrt{x}) \geqslant 0 \quad(x \geqslant 0)$.
Therefore, $f(x+y)=f(x)+f(y) \geqslant f(y) \quad(x \geqslant 0)$.
This means that $f(x)$ is a non-decreasing function on $\mathbb{R}$, i.e., if $x \geqslant y$, then $f(x) \geqslant f(y)$.

Finally, we prove that for all $x \in \mathbb{R}$, $f(x)=x$.
Indeed, if there exists $z \in \mathbb{R}$ such that $f(z) \neq z$, if $z<f(z)$, then $f(z) \leqslant f^{(2)}(z)=z$, which is a contradiction; if $f(z)<z$, then $z=f^{(2)}(z) \leqslant f(z)$, which is also a contradiction.

It is easy to verify that the function $f(x)=x$ satisfies (1).