Why is Dirichlet function not Riemann integrable, and Thomae's function is? I've seen proofs stating Dirichlet is not Riemann Integrable, and the intuition for that was that the function was discontinuous in every point. My doubt is why the Thomae's function doesn't act in a similar way? I would really like to know the intuition that could guide through the usual proof of this fact. 
Any help would be appreciated. 
 A: Thomae's function is defined by $f(x):={1\over q}$ when $x={p\over q}$ in lowest terms, and $f(x):=0$ otherwise, i.e., if $x$ is irrational. 
Claim: This $f$ is Riemann integrable over $[0,1]$, and $\int_0^1 f(x)\>dx=0$.
Proof: Let an $\epsilon>0$ be given. There is an $n\in{\mathbb N}$ with ${1\over n}<\epsilon$. The points $x\in[0,1]$ with $f(x)\geq\epsilon$ have denominator $<n$. There are at most
$$2+\sum_{k=2}^{n-1}(k-1)\leq {n^2\over2}$$
such "bad" points. Consider now the partition ${\cal P}_N$ of $[0,1]$ into $N>{n^2\over\epsilon}$ equal parts of width $h:={1\over N}$. At most $n^2$ of the subintervals can contain a "bad" point $x$, and in any case $f(x)\leq1$ there. There are less than $N$ "good" intervals, and $f(x)<\epsilon$ for all $x$ in a "good" interval. It follows that
$$0=L(f,{\cal P}_N)<U(f,{\cal P}_N)<n^2\cdot1\cdot\>h +N\cdot\epsilon\cdot h={n^2\over N}+\epsilon<2\epsilon\ .\tag{1}$$ 
As $\epsilon>0$ was arbitrary this proves the claim; and $(1)$ then immediately implies $\int_0^1 f(x)\>dx=0$, as well.
A: Proof of continuity of Thomae Function at irrationals. 
This can be helpful. 
And anyway the idea is that the Thomae's function is continuous in all irrational numbers, but discontinuous in rational. Then, we have that the measure of rational numbers is $0$, and our function is bounded on $[0,1]$, hence it is Riemann integrable. 
A: A bounded function $f$ is said to be Riemann integrable if and only if $f$ is continuous almost everywhere, which is the same thing as saying that $f$ is Riemann integrable if and only if $f$ is continuous everywhere except for a null set.
The Thomae's function is not continuous in the rationals. But the rationals are a null set.
On the other hand the Dirichlet function is not continuous in the irrationals and the irrationals are not a null set, therefore it is not continuous almost everywhere, so it is not Riemann integrable.
