TITLE: Is Dirichlet function Riemann integrable?
QUESTION [31 upvotes]: "Dirichlet function" is meant to be the characteristic function of rational numbers on $[a,b]\subset\mathbb{R}$. 
On one hand, a function on $[a,b]$ is Riemann integrable if and only if it is bounded and continuous almost everywhere, which the Dirichlet function satisfies.
On the other hand, the upper integral of Dirichlet function is $b-a$, while the lower integral is $0$. They don't match, so that the function is not Riemann integrable.
I feel confused about which explanation I should choose...

REPLY [13 votes]: There are two different definitions of the Dirichlet function:
$$ D(x) = \begin{cases}1:& x\in\mathbb Q \\ 0:&x\in\mathbb R\setminus\mathbb Q\end{cases}$$
which is obviously nowhere continuous. And then there is the "reduced" version, also known as Thomae's function
$$ D(x) = \begin{cases} \frac{1}{b}:& x=\frac{a}{b}\in\mathbb Q \quad\text{is a reduced fraction} \\ 0:&x\in\mathbb R\setminus\mathbb Q\end{cases}$$

which turns out to be continuous at the irrationals, since any approximation of an irrational number by rationals forces the denominator to become large. It can be shown that the former is not Riemann integrable whereas the latter is and its integral vanishes.