For $x \in \mathbb{R}$, define $r(x)$ as follows: $$ r(x)= \begin{cases} 1 &\text{if $x$ is rational},\\ 0 &\text{if $x$ is irrational}. \end{cases} $$
Q. What is $\int_0^1 r(x) dx$ ?
I know the rationals are dense in an interval, but countable, and so "sparse."
My motivation is a desire to average over the rationals, and in some sense this integral would be the denominator. If the integral is zero, then I'll have to think of another route. Thanks!
It depends on whether you're considering the Riemann integral or Lebesgue integral.
Note that every interval of any partition of $[0,1]$ contains a rational point, so any upper sum for $r(x)$ is $1$. Similarly, any lower sum for $r(x)$ is 0. Thus, $r(x)$ is not Riemann integrable.
However, $r(x)$ is the indicator function for $\mathbb{Q}$, which is a measurable set, so $r(x)$ is Lebesgue integrable on $[0,1]$. Unfortunately, since $\mathbb{Q} \cap [0,1]$ is countable, it has measure zero. Thus, we may compute the Lebesgue integral: $$\int_{0}^{1} \mathbb{1}_{\mathbb{Q}} \, d\mu = \mu(\mathbb{Q} \cap [0,1]) = 0$$