Solution by benjaminchew13.
The solutions are
f(x)=xandf(x)=−x.
The function is nonconstant. Choose a with f(a)=0. Then P(a,y) shows that f is surjective, and comparing P(a,u) and P(a,v) shows that f is injective.
From P(x,0) and P(−x,0),
f(x)f(0)=f(−x)f(0).
If f(0)=0, injectivity gives x=−x for all x, impossible. Hence f(0)=0, and
f(f(x2))=x2.(1)
Comparing P(x,−x) and P(−x,x) gives f(−x)=−f(x), so f is odd. Thus (1) implies
f(f(t))=t
for every real t.
Now compare P(f(x),x) and P(x,f(x)). The right sides are both f(x)2+x2, so injectivity gives
f(f(x)2)=f(x2).
Applying injectivity once more yields
f(x)2=x2.(2)
Squaring the original equation and using (2), we get
(f(x2)+f(x)f(y))2=(x2+yf(x))2.
After cancellation,
f(x2)f(x)f(y)=x2yf(x).
For x=0, divide by f(x) and then put x=1:
f(1)f(y)=y.
Since f(1)=±1, we get f(y)=y for all y, or f(y)=−y for all y. Both functions work.