For which continuous functions $f:\mathbb R\to\mathbb R$ does there exist a discontinuous function $g$ such that $f=g\circ g$? Inspired by a bad approach to a homework problem, I'm wondering for which which continuous functions $f:\mathbb R\to\mathbb R$ does there exist a discontinuous function $g$ such that $f=g\circ g$.
Maybe I'm missing something immediate, but I'd like to show that there exists no continuous functions $f$ satisfying this.
Just kidding, it's apparently immediate.
 A: An easy example is $f(x) = x$ and 
$$ g(x) = \begin{cases} x & \text{for } x \neq \pm 1 \\ -x & \text{for } x = \pm 1 \end{cases}. $$
A: For examples of a function $f$ that has no $g$ with $f = g \circ g$ (continuous or not), consider a case where $f$ has exactly one fixed point $p$ and exactly one point $q \ne p$ such that $f(q) = p$.  Since $g(p)$ would have to be a fixed point of $f$, we need $g(p) = p$, and since $f(g(q)) = g(f(q)) = p$ we need $g(q) = q$.  But then $f(q) = g(g(q)) = q$, contradiction.
A simple example of this is $f(x) = x + \dfrac{1-e^x}{1-e^{-1}}$ with $p =0$ and $q=-1$. 
EDIT: Oops, as Dark Malthorp pointed out we could have $g(q) = p$.  OK, suppose in addition there is exactly one $r$ with $f(r) = q$.  Since $f(g(r)) = g(f(r)) = g(q)=p$, we must have $g(r) = q$.  But then $f(r) = g(g(r)) = g(q) = p$, contradiction.  
A: Take the dirichlet's function:
g:$\mathbb{R} \rightarrow \mathbb{R}$
g($x$)=0 ; $x\in \mathbb{Q}$
g($x$)=1 ; $x\in \mathbb{R}- \mathbb{Q}$ 
Then f=g$\circ$g is the zero function.
A: Your wording is ambiguous. You ought to include
$$ f(x) = -x. $$
I cannot recall, but there is a simple argument for no continuous $g.$ However, if we include complex numbers and take
$$ h(x) = ix, $$ we do get
$$ h(h(x)) = -x. $$
