TITLE: If $f \circ g$ and $g \circ h$ are smooth, is $f \circ g \circ h$ smooth?
QUESTION [5 upvotes]: Given functions $f, g,$ and $h$ on some smooth manifold M such that $f \circ g$ and $g \circ h$ are $C^\infty$, must $f\circ g\circ h$  be $C^\infty$?
I can't imagine this is true, but I'm having trouble coming up with a counterexample. I've also had no luck in coming up with a proof, but I haven't been focusing on it for too long.

REPLY [6 votes]: As @Lord Shark the Unknown suggested, pick 
$$f=g=h= \left\{ \begin{array}{lc}
x & \mbox{ if } x \in \mathbb Q \\
-x & \mbox{ if } x \notin \mathbb Q \\
\end{array}
\right. 
$$
More generally, pick any non-smooth bijection $f$ and set $g=f^{-1}$ and $h=f$.