Integral of Thomae's function

Define the following function $f : \mathbb{R} \to \mathbb{R}$ as follows:

$f(x) = 0$ if $x$ is irrational

$f(x) = 1/n$ if $x$ is rational and $x = \frac{m}{n}$ in lowest terms.

Some googling comes up that this is known as "Thomae's function." I need to prove the integrability of this function AND find its integral over $[0,1]$.

The integrability is shown by proving that the function is continuous at irrationals and discontinuous at rationals and then using the Lebesgue criterion for integrability. However, I'm having trouble finding the value of the integral.

I'm not sure if it is zero or not, which is making it hard for me to come up with a proof method. While the similarly defined Dirichlet function has a integral of 1, the reason I suspect this function might be zero is that the value of many points are, in this case, negligible due to large denominators.


In fact, the function is even Riemann integrable. This is actually easy to see: Since there are only finitely many points where the function is larger than $1/n$, it is possible to choose a step function $g$ such that $0 \leq f \leq g$ and $\int_0^1 g(x) dx \leq 2/n$.

Note also that a bounded function if Riemann integrable if the set of points where it is not continuous has Lebesgue measure zero.


The function is nonnegative and zero almost everywhere. So the integral is zero. In particular, let $\{r_n\}$ be an enumeration of the rational numbers. Then as $f(x)\leqslant 1$ for all $x$, we have $$ \int_{\mathbb R}f\mathrm d m =\int_{\mathbb Q}f\mathrm dm \leqslant \int_{\mathbb Q}\mathrm dm = \int_{\bigcup_{n=1}^\infty\{r_n\}}\mathrm dm=\sum_{n=1}^\infty m(\{r_n\}) = 0,$$ where $m$ is Lebesgue measure.