# “Length” of rationals in an interval

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!

• Is this a Riemann or Lebesgue integral? – Alberto Debernardi Apr 24 '15 at 10:43
• What you actually want is put a measure on the set of rational numbers. This can be done in many ways; however maybe you find that none suits your purposes (it depends one those purposes). In any case there is no uniform measure on the rationals (nor is there on the integers) so every choice is biased in some way. – Marc van Leeuwen Apr 24 '15 at 11:31
• @AlbertoDebernardi And let us not forget about the Henstock-Kurzweil integral as well, which in many cases serves as the generalization of the Lebesque integral: en.wikipedia.org/wiki/Henstock%E2%80%93Kurzweil_integral – AnlamK Apr 24 '15 at 11:40

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$$

• $r(x)$ is the indicator function for $\Bbb Q$, not just for $\mathbb{Q} \cap [0,1]$. – CiaPan Apr 24 '15 at 11:26
• Fixed it, thanks. – Sameer Kailasa Apr 24 '15 at 11:35
• Personally, I'd call that "fortunate" since it makes the integral easy to compute, but to each their own. – Kevin Apr 24 '15 at 14:52
• Well, unfortunate since the OP was hoping it would have nonzero integral. – Sameer Kailasa Apr 24 '15 at 18:35
• Does that mean that the integral from 0 to 1 of a function that is 1 when x is irrational and 0 otherwise, is 1? – JLagana Apr 24 '15 at 22:37

Others have focused on the specific value of the integral itself. However, it is clear from your description that you wish to evaluate something along the lines of $$\frac{\int_0^1 f(x)r(x)dx}{\int_0^1 r(x)dx}$$ where $r(x)$ is the rational indicator function.

While the component integrals cannot be evaluated, the overall concept is still meaningful. It is likely best to think of this in terms of a Riemann sum restricted to subsets of the rationals. In effect, you seek $$\lim_{n\to\infty} \frac{1}{n!}\sum_{i=1}^{n!} f\left(\frac{i}{n!}\right)$$ where we restrict $n$ to integer values. Note that I have chosen $n!$ to ensure that subsequent sums will always include every point from the previous term. Also note that this is using the right-side value for each point, which means that f(0) does not affect the sum at any point.

It should be noted that this expression may not be well defined for some functions, and for others it may not be uniquely defined. A more rigorous definition would involve $\limsup$ and $\liminf$, and a requirement that these be equal for the "average" to exist.

The integral exists in the Lebesgue sence and it is zero. That is because the rationals have measure zero, being a countable set. $r$ is the characteristic function of the rationals, and for such function the integral is given by $$\int_0^1 r(x) \, dx = \lambda([0,1] \cap \mathbf Q)$$ where $\lambda$ is the Lebesgue measure. We have for measurable sets $A \subseteq \mathbf R$ that $$\lambda(A) = \inf \left\{ \sum_{i=1}^\infty (b_i - a_i) \mid A \subseteq \bigcup_i [a_i, b_i) \right\}$$ Now for a countable $A = \{c_n \mid n \in \mathbf N\}$ (for example $A = [0,1]\cap \mathbf Q$), and any $\epsilon > 0$, let $b_i = c_i + \epsilon 2^{-(i+1)}$, $a_i = c_i - \epsilon 2^{-(i+1)}$ then $A \subseteq \bigcup_i [a_i, b_i)$ and $$\sum_i (b_i - a_i) = \sum_i \epsilon 2^{-i} = \epsilon.$$ Hence $\lambda(A) \le \epsilon$ for every $\epsilon$, giving $\lambda(A) = 0$. Hence $$\int_0^1 r(x) \, dx = \lambda(\mathbf Q \cap [0,1]) = 0.$$