where S+T={a+b∣a∈S,b∈T}, g:[0,∞)∖(S+T)→T is arbitrary, and h:(−∞,0)∖(S+T)→S is arbitrary.
First, such functions work. For all x, we have f(x)∈S, and for all y, we have f(y2)∈T. Hence
f(x)+f(y2)∈S+T,
so
f(f(x)+f(y2))=f(x)+f(y2).
Conversely, let f be any solution and set
S=f(R),T=f(R≥0).
Then T⊆S and both sets are nonempty. If a∈S and b∈T, write a=f(x) and b=f(y2). If a+b≥0, then the equation gives
f(a+b)=a+b,
so a+b∈T. Thus the required closure property holds. Moreover, the same identity shows f(t)=t for all t∈S+T, while on [0,∞)∖(S+T) the only remaining condition is f(x)∈T, and on (−∞,0)∖(S+T) the only remaining condition is f(x)∈S. This is exactly the stated family.