Example (Thomae's function is integrable)

Thomae's function $$ \begin{align*} f: [0,1] &\to \R \\ f(x) &= \begin{cases} 1/q, & x=p/q, \quad \text{$p,q$ are coprime integers} \\ 0, &\text{otherwise}. \end{cases} \end{align*} $$

For any $\mathcal{D}$, $L(f,\mathcal{D}) = 0$ since each subinterval contains an irrational number.

By Cauchy criterion, it suffices to show that for any $\epsilon > 0$, we can find a $\mathcal{D}$ with $U(f,\mathcal{D}) < \epsilon$.

Pick $N\in\N$ such that $1/N < \epsilon/2$. Consider the set $$ \begin{align*} P = \sb{x\in[0,1]}{f(x) \geq 1/N} = \sb{p/q}{1\leq q\leq N, 0\leq p\leq q}. \end{align*} $$ $P$ is finite, so let $$ \begin{align*} P = \set{p_1, \ldots, p_m} \quad \text{with } 0=p_1 < p_2 < \ldots < p_m = 1. \end{align*} $$

Consider a dissection $\mathcal{D}$ of $[0,1]$ such that for each $p_k$, $k=1,2,\ldots,m$,

We'll abuse notation and write $I\in \mathcal{D}$ to mean $I=[x_{j-1}, x_{j}]$ for some $j=1,2,\ldots,n$ and write $|I| = x_j - x_{j-1}$. $$ \begin{align*} U(f,\mathcal{D}) &= \sum_{I\in \mathcal{D}} |I| \sup_{x\in I} f(x) \\ &= \sum_{\substack{I\in \mathcal{D} \\ I\cap P=\emptyset}} |I| \sup_{x\in I} f(x) + \sum_{\substack{I\in \mathcal{D} \\ I\cap P\neq \emptyset}} |I| \sup_{x\in I} f(x) \\ &\leq 1\cdot \frac{1}{N} + m\cdot \frac{\epsilon}{2m}\cdot 1 \\ &< \epsilon. \end{align*} $$