# The function $f$ is discontinuous but $f\circ f$ is continuous

I have thought without a solution. Are there actually examples of a function $f:\Bbb{R}\to \Bbb{R}$ such that $f$ is discontinuous at every point but $f\circ f$ is continuous?

• $f(x)=0$ for $x$ irrational and $f(x)=1$ for $x$ rational. Then $f\circ f(x)=1$.
– user551819
May 4 '18 at 12:49
• @ totoro: Please, does it work? May 4 '18 at 12:50
• @ totoro: I've just seen that! Thanks! May 4 '18 at 12:51
• You have an example in front of your nose.
– user551819
May 4 '18 at 12:51
• No what you are looking for but a nice, related concept: en.wikipedia.org/wiki/Cantor_function May 4 '18 at 13:03

Consider $$f(x)=\left\{ \begin{array}{ll} x,&x\in\mathbb{Q},\\ -x,&x\in\mathbb{R}\setminus\mathbb{Q}. \end{array} \right.$$ This function yields $$f\circ f(x)=x.$$

Edit:

Let me fix the bug. Thanks to @totoro, the above example does not work, because it is continuous at $x=0$.

Considering this, let us make it as follows. $$f(x)=\left\{ \begin{array}{ll} 1/x,&x\in\mathbb{Q}\setminus\left\{0\right\},\\ 0,&x=0,\\ -1/x,&x\in\mathbb{R}\setminus\mathbb{Q}. \end{array} \right.$$ Now this function is everywhere discontinuous, and yields $$f\circ f(x)=x.$$

• This function is continuous at $x=0$.
– user551819
May 4 '18 at 12:53
• @totoro: You are right. So what about the template $1/x$? May 4 '18 at 12:56
• @ hypernova: Thanks for the edit. You have my respect for fixing this! @ totoro and hypernova: Thanks for the eagle eye. You are both good! May 4 '18 at 13:32
• Thank you. And I really appreciate @totoro for the crucial comment. I will keep my mistake as it was, in case it could be helpful here :-) May 4 '18 at 14:13