TITLE: Integral of rationals
QUESTION [11 upvotes]: Define $f(x)$ as
$$f(x)=\begin{cases}0,&\text{if }x\in \mathbb{Q}\\
1,&\text{if }x\notin \mathbb{Q}\;.
\end{cases}$$
Considering the fact that there is a countable infinity of rationals yet an uncountable infinity of irrationals between $0$ and $1$, can the following statement be made? If yes, why? if not, why not?
$$\int_0^1f(t) dt=1$$

REPLY [21 votes]: It depends if you're talking about a Riemann integral or a Lebesgue integral. 
If we are talking about a Riemann integral, the answer is that we cannot define the integral because any sub-interval of $[0,1]$ - no matter how small - contains a rational and an irrational. For this reason the upper integral and lower integral will not be the same (here the $\sup f = 1$ and $\inf f = 0$ on any sub-interval). 
If you are talking about a Lebesgue integral, the answer is yes. This is because integrating over $[0,1]$ and $[0,1] \setminus \mathbb Q$ will give the same answer under certain conditions. You'd need to know a little bit of measure theory to completely understand the details, but the formulation of the Lebesgue integral tells you that integrating over a set of measure zero (the rationals for example)  will be zero, and thus 
$$\int_{[0,1]} f(t) dt = \int_{[0,1] - \mathbb Q} f(t) dt + \int_{\mathbb Q} f(t) dt = \int_{[0,1]- \mathbb Q} 1 dt  + 0 = 1$$ 
I'm omitting some details, but hopefully this provides some insight.