This question already has an answer here:


$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 Lahtonen Aug 14 '15 at 6:58

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 4
    $\begingroup$ Riemann or Lebesgue integral? math.stackexchange.com/questions/437711/…, math.stackexchange.com/questions/755576/… $\endgroup$ – Hans Lundmark Feb 27 '15 at 11:39
  • $\begingroup$ @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. $\endgroup$ – L.G. Feb 27 '15 at 11:43
  • 3
    $\begingroup$ Then it's the Riemann integral, and your function $f$ is not integrable. $\endgroup$ – Hans Lundmark Feb 27 '15 at 11:46

It is not Riemann-integrable, as the upper and lower Darboux sums do not converge to the same limit:

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

  • $\begingroup$ 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]$? $\endgroup$ – L.G. Mar 1 '15 at 3:15
  • $\begingroup$ 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}$. $\endgroup$ – 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$$


Not the answer you're looking for? Browse other questions tagged or ask your own question.