TITLE: Is the indicator function of the rationals Riemann integrable?
QUESTION [15 upvotes]: $f(x) =
\begin{cases}
1  & x\in\Bbb Q \\[2ex]
0 & x\notin\Bbb Q
\end{cases}$
Is this function Riemann integrable on $[0,1]$?
Since rational and irrational numbers are dense on $[0,1]$, no matter what partition I choose, there will always be rational and irrational numbers in every small interval. So the upper sum and lower of will always differ by $1$.
However, I know rational numbers in $[0,1]$ are countable, so I can index them from 1 to infinity. For each rational number $q$ in $[0,1]$, I can cover it by $[q-\frac\epsilon{2^i},q+\frac\epsilon{2^i}]$. So all rational numbers in $[0,1]$ can be covered by a set of measure $\epsilon$. On this set, the upper sum is $1\times\epsilon=\epsilon$. Out of this set, the upper sum is 0. So the upper sum and lower sum differ by any arbitrary $\epsilon$. Thus, the function is integrable.
One of the above arguments must be wrong. Please let me know which one is wrong and why. Any help is appreciated.

REPLY [6 votes]: An important theorem about Riemann integrability is known as Lebesgue's Criterion. It says that if we have a function $f(x)$ defined on a closed interval $I$, then $f$ is integrable on $I$ if and only if $f$ is bounded and the set of discontinuities of $f(x)$ has measure zero.
In this case, the set of discontinuities will be the entire interval $[0,1]$, so by Lebesgue's criterion the function is not integrable. 
The definition of "measure zero" is closely related to your flawed proof: a set has measure zero if for every $\epsilon > 0$ the set can be covered by a sequence of open intervals such that the sum of the widths of the open intervals is less than $\epsilon$.
So the real issue is how to prove that this cannot be done for the unit interval -- how to prove that the unit interval does not have measure $0$. That proof uses compactness, which you may or may not be familiar with. The compactness of $[0,1]$ shows that if we cover $[0,1]$ with a sequence of open intervals, in fact some finite number of those open intervals already cover $[0,1]$. But you can show that any finite sequence of open intervals that covers $[0,1]$ has to have total length greater than $1$, and in particular cannot have total length less than $1/2$ (the easiest way to prove this is by induction on the number of intervals).