Is the indicator function of the rationals Riemann integrable? $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.
 A: 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). 
A: The answer depends in which sense you want to integrate the function.
The function is not Riemann integrable. The problem is that you consider finite partitions there to form the Riemann sums; so, roughly speaking, you cannot make a choice for each rational as you consider finite partitions. (Your first argument is correct.)
The function is however Lebesgue integrable. There the argument using measure is relevant. 
The function is also integrable in the Henstock-Kurzweil sense. Very roughly, this is similar as Riemann but in fact allows to make "more choices." 
A: Recall that a function is Riemann integrable if and only if, for any $\varepsilon > 0$, there exists a partition $P$ such that $U(f, P) - L(f, P) < \varepsilon$. 
Now consider any partition $P$ of $[0,1]$.  The lower sum is always zero since the infimum of the function values along any interval is zero.  Further, the supremum of the function values along any interval is $1$ as every interval contains a rational number, so we have:
$$U(f, P) - L(f, P) = U(f, P) = \sum_{k = 1}^n (x_k - x_{k-1}) = 1$$
And so the integrability criterion in the first line fails for any $\varepsilon < 1$.
A: What you showed is that the function is not Riemann integrable, while it is Lebesgue integrable. 
