# Bounded function in $[0,1]$ that does not attain its supremum and infimum.

I'm asked to give an example of a function that is bounded in $A=[0,1]$ but it doesn't attain its infimum or supremum, i.e. there is no $y\in A$ such that $f(y)=\sup\{f(x)\mid x\in A\}$ and similarly with infimum.

Clearly, since I have compact and connected domain it is necessary that such function must be discontinuous.

I have got an idea, to define $f$ as it follows: \begin{align} f(x)=\begin{cases} \frac{1}{2^{k}}-1 &\text{if }x=\frac{m}{2^{k}},\, 0<m<2^{k},\,m\neq2\ell\\ \frac{1}{3^{k}}+1 &\text{if }x=\frac{m}{3^{k}},\, 0<m<3^{k},\,m\neq3\ell\\ 0 &\text{anywhere else} \end{cases} \end{align}

Again, is clear that this is not continuous since this rationals are dense in $[0,1]$. The infimum and supremum are $-1,1$ respectively.

But my happiness ended when i see that maybe the supremum and infimum are attained since every rational of that form is in $[0,1]$. If this is true what other example of such a function can be constructed. Thanks in advance.

-
I do think your example works, but it is more complicated than necessary. – Alex Becker May 28 '12 at 17:15
The thing to notice is that open intervals are good for making functions that don't achieve their extrema. – Austin Mohr May 28 '12 at 17:33
Thanks @AlexBecker, for let me see ground safely. I'll remember that. – elessartelkontar May 28 '12 at 17:45

A simple example: \begin{align} f(x)=\begin{cases} x &\text{ if } x\neq 0,1\\ 1/2 &\text{otherwise} \end{cases} \end{align} which has infimum $0$ and supremum $1$ but attains neither.
How about $f(x) = x-\frac{1}{2}$ for $x \in (0,1)$ and $f(0)=f(1)=0$. The supremum is $\frac{1}{2}$ and the infimum is $-\frac{1}{2}$ but by construction, $f$ does not achieve these values.