How do I evaluate the integral of the Dirichlet function on $[0,1]$? [duplicate]

This question already has an answer here:

Define

$f(x) = \left\{ \begin{array}{ll} 1 & \mbox{if } x \in \mathbb{Q} \\ 0 & \mbox{if } \notin \mathbb{Q} \end{array} \right.$

How to evaluate $\int_0^1 f(x)\,dx$ ?

I have no idea how to solve it, but all I think is that: since between any two rational numbers there exist an irrational number and vice versa, so the number of rational and irrational numbers are same in the interval of $[0,1]$ (or $[0,1)$ to be precise), and since the integral is equivalent to area under the function, so $\int_0^1 f(x)\,dx$ must be equal to $\frac{1}{2}$. Is that correct?

Thank you.

marked as duplicate by L.G., Jyrki LahtonenAug 14 '15 at 6:58

• Riemann or Lebesgue integral? math.stackexchange.com/questions/437711/…, math.stackexchange.com/questions/755576/… – Hans Lundmark Feb 27 '15 at 11:39
• @Hans Lundmark: Unfortunately I don't have knowledge of advanced real analysis (Riemann or Lebesgue integral), and by integration I mean what is in calculus. Is there some simple explanation for the solution? Thank you. – L.G. Feb 27 '15 at 11:43
• Then it's the Riemann integral, and your function $f$ is not integrable. – Hans Lundmark Feb 27 '15 at 11:46

For a given partition $\,P\colon0=x_0<x_1<\dots<x_{n-1}<x_n=1$, the upper and lower Darboux sums are, respectively:
\begin{align*} U_{f,P}&=\sum_{i=1}^n (x_{i}-x_{i-1})M_i && M_i=\sup_{x\in[x_{i},x_{i-1}]}f(x)\\ L_{f,P}&=\sum_{i=1}^n (x_{i}-x_{i-1})m_i && m_i=\inf_{x\in[x_{i},x_{i-1}]}f(x) \end{align*} Since any non-empty interval contains both rational and irrational numbers, $M_i=1,\enspace m_i=0$, hence $U_{f,P}=1$ and $L_{f,P}=0$ for any partition $P$.
For the Lebesgue integral, it's different: as $[0,1]\cap\mathbf Q$ has measure $0$, $f$ is equal to the null function almost everywhere, hence it is integrable and its integral is equal to $0$.
• If $m([0,1]\cap\mathbb {Q})=0$, can we say that ratio of number of irrational numbers to rational numbers is infinite in $[0,1]$? – L.G. Mar 1 '15 at 3:15
• That belongs to the theory of (transfinite) cardinals. In a sense, yes. Rational numbers are denumerable (i.e. they can be numbered) while real numbers can't. If you denote $\aleph_0$ the cardinal number of $\mathbf Q$ then the cardinal of $\mathbf R$ is (in a certain sense) $2^{\aleph_0}$. – Bernard Mar 1 '15 at 3:25
$$\int_0^1 f(x)dx=1\cdot m([0,1]\cap \mathbb Q)+0\cdot m([0,1]\cap (\mathbb R\backslash \mathbb Q))=0$$