Can a bounded function always attain its least upper bound on a bounded rectangle in $R^n$? Suppose we have a rectangle $Q$, and $Q\subset R^n$. Then $Q$ is bounded by the definition of higher dimensional rectangles. Suppose $f$ is a bounded function defined on $Q$. Since $f$ is bounded, we can produce its infimum $\inf_Q f$ and supremum $\sup_Q f$. My question is that is it always true that $\exists x_1,x_2\in Q$ with the property that $f(x_1)=\inf_Q f$ and $f(x_2)=\sup_Q f$?
If this does not always hold, please provide an example.
 A: No.  Consider $n=1$, $Q=[0,1]$, $f(x)=x$ for $x\ne 0$, $f(0)=1$.  Then $f$ does not attain its infimum, which is $0$.  If $f$ were required to be continuous, then the answer would be different  
Furthermore, you do not say whether $Q$ is open or closed.  On $Q=(0,1)$, $f(x)=x$ again does not attain its infimum (or its supremum).
A: Consider the rectangle $Q$ given by $(0,1)^n\subset \mathbb R^n$ with coordinates $x_1\cdots x_n$. Then the function $f(x_1\cdots x_n)=x_1$ is bounded on $Q$ but attains neither its supremum on $Q$ (which is $1$) nor its infimum on $Q$ (which is $0$).
A: If $Q$ is also closed, then it is compact (Heine-Borel theorem), and thus any continuous function realizes its extrema on it.
If $Q$ is an open rectangle, then for example any coordinate function gives you a counterexample.
If we do not ask $f$ to be continuous, take a countable number of points $\{x_n\}_{n\in\mathbb{Z}}\subset Q$, and consider the function
$$f(x) = \cases{1&if $x\notin\{x_n\}_{n\in\mathbb{Z}}$ or $x = x_0,$\\\frac{1}n & if $x = x_n$ and $n>0$,\\2+\frac{1}{n} & if $x=x_n$ and $n<0$.}$$
It provides a counterexample.
