$f(x)=\cos(x)$ if $x=1/n$ for $n\geqslant1$ and $f(x)=-1$ if not. Show that $f(x)$ is Riemann integrable on$ [0,1]$ Let $f:[0,1] \rightarrow \mathbb{R}$ such that$f(x)=\cos(x)$ if $x=1/n$ for $n\geqslant1$ and $f(x)=-1$ if not.
So, to show that $f$ is integrable, i need to proof that $\bar{S}_{\sigma}(f) \leqslant \underline{S}_{\sigma}(f) + \epsilon$ $\forall \epsilon > 0$. $\sigma$ denotes a subdivision of $[0,1]$, $\bar{S}$ superior Darboux sum and $\underline{S}$ lower Darboux sum.
I remarked that by density of irrational numbers i can write that $\underline{S}_{\sigma}(f)=-1$ for all subdivision $\sigma$. So, i have to show that
$\bar{S}_{\sigma}(f) +1 \leqslant\epsilon$.
So now i don't really see how to choose correctly the subdivision of $[0,1]$.. If someone could explain it with details i would appreciate it. Thanks in advance.
 A: Fix $\epsilon > 0$.

Let $M=m^2$ where $m > 1$ is an integer such that ${\large{\frac{6}{m}}} < \epsilon$. 

Let $\sigma$ be the partition of $[0,1]$ consisting of the $M+1$ intervals $I_1,...,I_{M+1}$ with $I_k=[x_{k-1},x_k]$ where
$$
0=x_0 < x_1 < \cdots < x_{M+1}=1
\;\;\;\;\;
$$
and $x_1,...,x_M$ are defined by 
\begin{align*}
x_1&=\frac{1}{m}\\[4pt]
x_k&=x_1+(k-1)d,\;\,\text{for}\;2\le k\le M\\[4pt]
d&=\frac{1-x_1}{M}=\frac{m-1}{m^3}\\[4pt]
\end{align*}
If $A,B$ are given by
\begin{align*}
A&=\left\{{\small{\frac{1}{n}}}{\;{\Large{\mid}}\;}1\le n\le m\right\}
\qquad\qquad\;\;\;\,
\\[4pt]
B&=\left\{{\small{\frac{1}{n}}}{\;{\Large{\mid}}\;}n > m\right\}
\\[4pt]
\end{align*}
then the following claims are immediate:

*

*Each element of $B$ lies in the interior of $I_1$.$\\[4pt]$

*Each element of $A$ lies in at most two of $I_2,...,I_{M+1}$.$\\[4pt]$

Now let $S$ be the Riemann sum given by
$$
S=\sum_{k=1}^{M+1}f(x_k^*)\Delta x_k
$$
where $x_k^*\in I_k$ and $\Delta x_k=x_k-x_{k-1}$.

Then we get the lower bound
\begin{align*}
S
&=
\sum_{k=1}^{M+1}f(x_k^*)\Delta x_k
\\[4pt]
&\ge
\sum_{k=1}^{M+1}(-1)\Delta x_k
\\[4pt]
&=
(-1)\sum_{k=1}^{M+1}\Delta x_k
\\[4pt]
&=
(-1)(1)
\\[4pt]
&=
-1
\end{align*}
and since

*

*$f(x_k^*)\le 1$ for all $k$.$\\[4pt]$

*For $2\le k\le M+1$, we have $f(x_k^*)=-1$ with at most $2m$ exceptions.

we get the upper bound
\begin{align*}
S
&=
\sum_{k=1}^{M+1}f(x_k^*)\Delta x_k
\\[4pt]
&=
f(x_1^*)\Delta x_1+\sum_{k=2}^{M+1}f(x_k^*)\Delta x_k
\\[4pt]
&=
f(x_1^*)x_1+d\sum_{k=2}^{M+1}f(x_k^*)
\\[4pt]
&\le
(1)(x_1)+d\bigl((1)(2m)+(-1)(M-2m)\bigr)
\\[4pt]
&=
-1+\frac{2(3m-2)}{m^2}
\\[4pt]
&<
-1+\frac{6}{m}
\\[4pt]
&<
-1+\epsilon
\\[4pt]
\end{align*}

Thus $-1\le S < -1+\epsilon$.

It follows that $f$ is Riemann integrable on $[0,1]$ and ${\displaystyle{\int_0^1 f(x)\,dx = -1}}$.
