Give an example of a function $h$ that is discontinuous at every point of $[0,1]$, but with $|h|$ continuous on $[0,1]$

Give an example of a function $h:[0,1]\to\mathbb{R}$ that is discontinuous at every point of $[0,1]$, but such that the function $| h |$ that is continuous on $[0,1]$.

I don't really even know where to start with this one. I would have to prove that the function $| h |$ is continuous on $[0,1]$, ie if we're given any $\varepsilon>0$, there exists $\delta>0$ such that if $x$ and $c$ are any two points in $[0,1]$ with $|x-c| < \delta$, then $|f(x) - f(c)| < \varepsilon$. Alternatively I could use the limit definition. But I can only think of functions that are discontinuous at some points in $[0,1]$ rather than all... I feel like I'm missing something obvious here, but any help is greatly appreciated. This is a question on a past final.


I would start with a function which I know is discontinuous at every point in $[0, 1]$. The standard one is

$$f(x) = \begin{cases} 1 & x \in \mathbb{Q}\cap[0, 1]\\ 0 & x \notin \mathbb{Q}\cap[0, 1] \end{cases}$$

which is the indicator function of the set $\mathbb{Q}\cap[0, 1]$. See if you can somehow adjust it for your purpose.


You can reverse engineer an example. You want $|f|$ to be continuous, so what is the simplest example of a continuous function? Of course it the constantly $0$ function. So, let's assume $|f(x)|=0$. But then, what can $f(x)$ possibly be? It has to be that $f(x)=0$ as well, which is a continuous function. So this does not work. Ok, then taking $|f(x)|=0$ was too hopeful. Let's try another example of a very simple continuous function, let's assume $|f(x)|=1$ for all $x\in [0,1]$. Now, for any given $x\in [0,1]$, what can $f(x)$ be? Now there are two possibilities: $f(x)=\pm 1$. Good, we have some freedom to play with the values of $f$. Now, playing with just the two values $\pm 1$, how do we make sure $f$ will not be continuous at any point? Well, we need to alternate like crazy between these two values. So we want to say something like $f(x)=1$ if $x$ is of type I, and $f(x)=-1$ if $x$ is not of type I, and such that points of type I are dense and points of type not I are also dense. Of course the rationals $\mathbb Q\cap [0,1]$ are dense and the irrationals $[0,1]-\mathbb Q$ are dense, so that will do the trick.