Riemann integral by definition Someone asked me this question, and I thought it was a good idea to post the answer here. 
Let $$f(x)=\begin{cases}\sin\left(\frac1q\right),&\ \frac pq\in\mathbb Q, \ q\neq0, \ \ p,q \text{ coprime }\\ 0,&\ \text{ otherwise}\end{cases} $$
Show that $f$ is Riemann integrable and find $\int_0^1f(x)\,dx$. 
 A: For anyone who knows measure theory, it is obvious that $f=0$ a.e., and the answer is trivial.  But the point is to do this at the level of Riemann integrals. 
Because of the density of the irrationals, it is clear that any lower sum will be zero; so we only need to work with upper sums. 
Fix $\varepsilon>0$, and choose $n_0\in\mathbb N$ such that $n_0>2/\varepsilon$. Let $P$ be a partition  $0=x_0<x_1<\cdots<x_n=1$, with $\max\{x_{j+1}-x_j:\ j=0,\ldots,n-1\}<1/n_0^3$. For each interval, we have 
$$
f_j:=\max\{f(x):\ x\in[x_j,x_{j+1}]\}=\sin\left(\frac 1{q_j}\right),
$$
with $p_j/q_j\in[x_j,x_{j+1}]$. Let $A=\{j:\ q_j<n_0\}$; since the number of rationals in $[0,1]$, with denominator less than $n$, is $n(n-1)/2$, we have $|A|\leq n_0(n_0-1)/2\leq n_0^2$. Then, writing $\Delta_j=x_{j+1}-x_j$,
\begin{align}
U(f,P)&=\sum_{j=0}^{n-1} f_j\,\Delta_j=\sum_{j\in A} f_j\Delta_j+\sum_{j\not\in A}f_j\,\Delta_j
\leq \frac{|A|}{n_0^3}+\frac1{n_0}\sum_{j\not\in A}\,\Delta_j\\ \ \\
&\leq\frac{n_0^2}{n_0^3}+\frac1{n_0}=\frac2{n_0}<\varepsilon.
\end{align}
The above computation shows that given $\varepsilon>0$, there exists $\delta>0$ such that, for every partition $P$ with diameter less than $\delta$, $U(f,P)<\varepsilon$. Thus the infimum of the upper sums is zero, $f$ is integrable, and $$\int_0^1f(x)\,dx=0.$$ 
