Integrability of Thomae's Function on $[0,1]$. Consider the function $f: [0,1] \to \mathbb{R}$ where
f(x)=
\begin{cases}
\frac 1q & \text{if } x\in \mathbb{Q} \text{ and } x=\frac pq \text{ in lowest terms}\\
0 & \text{otherwise}
\end{cases}
Determine whether or not $g$ is in  $\mathscr{R}$ on $[0,1]$ and prove your assertion. For this problem you may consider $0= 0/1$ to be in lowest terms.
Here's an attempt. I may have abused a bit of notation here, but the ideas are there. 
Proof:
Let $M_i = \sup \limits_{x \in [x_{i-1},x_i]} f(x)$.
Notice first that the lower Riemann sums are always $0$, since every interval contains an irrational number. Thus, to prove $f \in \mathscr{R}$, it suffices to prove that, given any $\epsilon >0$, $\sum \limits_{i \in P} M_i \Delta x_i < \epsilon$ for some partition.   
Let $\epsilon > 0 $ and $M  > \frac{2}{\epsilon}$. We first show that there exists $\eta(x,\frac{1}{M})$ so that $|f(x) - f(y)| < \frac{1}{M}$ if $|x-y| < \eta$. Fix $x \in (\mathbb{R} \setminus \mathbb{Q}) \cap [0,1]$. Now, consider the set $$R_{M} := \{ r \in \mathbb{Q} : r = \frac{p}{n}, n \leq M, p \leq n, p \in \mathbb{N} \}.$$ Clearly this set is finite, enumerate it as $\{q_1,\ldots, q_m\}$. So, let $$\eta(x,\frac{1}{M}) = \min_{i=1,\ldots, m} |x- q_i|.$$ We see then, $|f(x) - f(y)| < \frac{1}{M}$ on this $\eta$-neighborhood.  
After we choose that $\eta$ so that $x \in (\mathbb{R} \setminus \mathbb{Q}) \cap [0,1]$, is continuous in a $\eta$-neighborhood, we see 
$$ A:= [0,1] \setminus R_M \subset \left( \bigcup_{ x \in ( \mathbb{R} \setminus \mathbb{Q}) \cap [0,1]} B_{\eta(x)} (x) \right) \cap [0,1].$$ 
Since $A$ is compact, we may take finite sub-covering, and let $\delta = \min \limits_{i=1,\ldots,n} \{\eta(x_i)\}$. Take a partition $P_1$ of $A$ so that $\Delta x_i < \delta$. Since $R_M$ is non-empty, we can take a partition $P_2$ of $R_M$ so that $\Delta x_i < \frac{\epsilon}{2m}.$ Moreover, we see that,  on $[0,1]$, $f$ is at most $1$. Let $P = P_1 \cup P_2$. Thus, 
\begin{eqnarray*}
\sum_{i \in P} M_i \Delta x_i &=& \sum_{i \in P_1} M_i \Delta x_i + \sum_{i \in P_2} M_i \Delta x_i \\
&\leq& \frac{1}{M} \sum_{i \in P_1} \Delta x_i + \sum_{i \in P_2} \Delta x_i \\
&<& \frac{\epsilon}{2} + \frac{\epsilon}{2} = \epsilon 
\end{eqnarray*}  
Comments?  
EDITED I think I resolved the issue.
 A: For an alternative approach, choose $N \in \mathbb{N}$ such that $1/(N+1) < \epsilon/2$ and let
$$B_N = \left\{1,\frac{1}{2},\frac{1}{3},\frac{2}{3}, \ldots, \frac{1}{N}, \ldots, \frac{N-1}{N} \right\}.$$
If $x \notin B_N$, then $f(x) \leqslant 1/(N+1) < \epsilon/2$.  With $m = \#(B_N)$, choose a partition $P = (x_0,x_1, \ldots, x_n)$ where $n > m$ and $\|P\| < \frac{\epsilon}{4m}.$  There are at most $2m$ subintervals such that $[x_{j-1},x_j] \cap B_n \neq \varnothing.$
Let $M_j = \sup_{x \in [x_{j-1},x_j]} f(x).$ 
Then, the upper sum satisfies
$$U(P,f) = \sum_{j=1}^n M_j(x_j-x_{j-1}) = \\ \sum_{[x_{j-1},x_j] \cap B_N \neq \varnothing} M_j(x_j-x_{j-1}) + \sum_{[x_{j-1},x_j] \cap B_N = \varnothing} M_j(x_j-x_{j-1}) \\ \leqslant 2m \cdot 1 \cdot \frac{\epsilon}{4m} + \frac{1}{N+1}(1-0) \\ \leqslant  \epsilon.$$
A: I just wanted to note that using Lebesgue's criterion for Riemann integrability, the proof is easy: 
The criterion says that a bounded function on a compact interval $[a,b]$ is Riemann integrable if and only if it is continuous almost everywhere (the set of its points of discontinuity has measure zero).
Since the rationals have measure zero, it is enough to show $f$ is continuous in at all irrational points.
Let $x \in \mathbb{R} \setminus \mathbb{Q}$. Then $f(x)=0$. Suppose $x_n \to x$. We need to show $f(x_n) \to 0$. We can assume W.L.O.G that all the $x_n$ are rational. Since a sequence of rationals with an irrational limit have denominators going to infinity, we get the desired result.
Admittedly, Lebesgue's criterion is a rather "heavy gun" to use here, but for those who already know it, it is very nice:)
A: The lowest sums are easily seen to be zero. We are going to prove that with a suitable selection of the partitions the upper sums tend to zero. For this, take $p$ a prime number and let $k=\max \{n \mid 1+\frac{n(n+1)}{2}\leq p\}$. So $p=1+\frac{k(k+1)}{2}+q$, where $0\leq q< k+1$. We consider now the partition $P=\{0<1/p<2/p<...<(p-1)/p<1\}$ and let $m_i=\sup\{f(x)\mid x\in [(i-1)/p,i/p]$; $i=0,1,...p-1\}$. Now we reorder the sequence $M=\{m_1,m_2,...,m_p\}$ in decreasing order (not strictly) to obtain the finite sequence of $p$ terms $R=\{1,....1/p\}$. $1$ appear as the supreme in the subinterval $[(p-1)/p,1]$ and $1/p$ as the supreme in the subinterval $[0,1/p]$. Then we have
A-) If $a<b<p$ and $a/b\in [(l-1)/p,l/p]$ then $a/b\in ((l-1)/p,l/p)$. In other words, with the above conditions $a/b$ can not be of the form $n/p, n<p$ because if so, $p\mid bn \Rightarrow p\mid b$ or $p\mid n$ which is absurd since $b,n<p$. This prevent $1/b$ from being the supreme of two consecutive subintervals. For example if $p=4$ then $1/2$ is the supreme in the subintervals $[1/4,1/2]$ and $[1/2,3/4]$ and we don't want this to happen. That's the reason for which we choose p to be a prime number.
B-) As a consequence of A-) we have then that $1/b$ could appear at most $b-1$ times in the sequence $M$ (or $R$). Therefore, the first $1+k(k+1)/2$ terms of $R$ can be upper bounded (not strictly) term-to-term by the sequence $\{1,1/2,1/3,1/3,1/4,1/4,1/4,...,1/(k+1),...,1/(k+1)\}$ (note that in fact there are $1+1+2+...+k=1+k(k+1)/2$) terms). For the remaining $q$ terms we can take $1/(k+2)$ as an upper bound. Then we have
C-) $$U(f;P)\leq \frac{1}{p}[1+1/2+2/3+...+k/(k+1)+q/(k+2)]=\frac{1}{p}[1+1-1/2+1-1/3+...+1-1/(k+1)+q/(k+2)]=\frac{1}{p}[k+1-S+q/(k+2)]$$ where  $S=1/2+...+1/(k+1)$.
Since $S>0$, $p>\frac{k(k+1)}{2}$ and $q<k+1$,then  $$U(f;P)<\frac{1}{p}[k+1+q/(k+2)]<\frac{2}{k(k+1)}[k+1+q/(k+2)]=\frac{2}{k}+\frac{q}{k(k+1)(k+2)}<\frac{2}{k}+\frac{1}{k(k+2)}$$
If $p\rightarrow \infty \Rightarrow k\rightarrow \infty \Rightarrow \frac{2}{k}+\frac{1}{k(k+2)}\rightarrow 0$. So we have proved that if $p\rightarrow \infty \Rightarrow U(f;P)\rightarrow 0 $
