Question about proving existence of a function $f$ such that $f \circ f = g$ for an odd function $g$ I have been reading a book on elementary mathematics and have come to a problem where I don't understand where the solution comes from. The problem goes :
"Let $g : \mathbb{R} \rightarrow \mathbb{R}$ be an odd function, such that $g(x) > 0$
whenever $x > 0$. Show that there exists a function $f : \mathbb{R} \rightarrow \mathbb{R}$
for which $g = f \circ f$."
In the answer key they just say :
"Take $f(x) = -g(x)$ for $x \leq 0$ and $f(x) = -x$ for $x \geq 0$."
I am wondering what the reasoning is behind this answer. The truth is that I just want to see a more detailed solution to the problem. Can anyone help with this ?
 A: Interesting question, as an example consider the identity function for $g$, then $f$ is either trivially the identity function or more interestingly the negative the identity function (or more generally Babbage's functional equation, but that takes us off topic). What about $f(x)=x^3$? Well it's just as easy to solve the general case.
Now consider $f\circ f(x)=g(x)$ the naive attempt would be to let $f(x)=g(x)$ but then things wouldn't workout, so to fix the issue we need to define $f(x)=x$ sometimes, and $f(x)=g(x)$ other times. If we let $f(x)=x$ if $x>0$ then we get stuck because $f\circ f(x)=x\neq g(x)$ if $x>0$, so to avoid getting stuck we let $f(x)=-x$ if $x>0$, and once we do that we know that $f(x)$ must equal $g(-x)$ if $x<0$. so that $f\circ f(x)=g(-(-x))=g(x)$ if $x>0$, or $f\circ f(x)=-g(-x)=g(x)$ if $x<0$.(Since $g$ is odd)
Notice the solution is not unique, since we could have defined $f(x)=-x$ if $x<0$ then we would define $f(x)=-g(x)$ if $x<0$. Are there more?
A: Here's the reasoning: Since $g$ is odd, we really only need to know how it maps positive numbers to know all of $g$. We set up $f$ so that the first application gets the correct $g$ value, if you ignore the sign, and the second application fixes the sign. At least that's what it does for negative numbers. For positive numbers, it does roughly the same two steps, but in the other order.
It's pretty clever -- it's as if $f$ uses the sign to both encode and decide whether or not $g$ has applied yet.
