Show Riemann integrability of an alternating function I am looking at the following function:
$$f(x) = \cases{ \frac{(-1)^p}{\sqrt{q}} \ \ \ \ \text{if } x = \frac{p}{q} \text{ with } \gcd(p,q)=1 \\ 0 \ \ \ \ \ \ \ \ \ \  \text{if} x \text{ irrational} }$$
I have to show wheter the function is Riemann integrable, and if it is RI, I need to compute the result of it on the interval $[0,1]$. In other words, I have to compute $$\int_0^1 f(x) \ \text{d}x$$
I tried to find the lower sum and the upper sum. First, I thought that the lower sum was equal to $0$, but that is not true since if $m$ is odd, $f(x)$ will be negative. So I tried to make a dissection, which I made as follows:
$$D = \{y_0, y_0+\delta, y_1 - \delta, y_1 + \delta, \dots, y_j-\delta, y_j \}$$ But this doesn't seem to work aswell, since I cannot specify the upper and lower sum of it. I can only give upper bounds and lower bounds of $U$ and $L$ (upper and lower sum respectively). The integral will probably be $0$. I also tried to find an $\epsilon$ where there are finitely $f(x)$ above it. But even that does not work.
Can someone please tell me how I can do this? Since I am stuck for a long time right now.
 A: Given $\epsilon > 0$, take a positive integer $N > 16/\epsilon^2$ and let $m$ be the number of elements in the set
$$A_N = \left\{ \frac{p}{q} \in \mathbb{Q}\cap [0,1]: (p,q) = 1, \,\,\,\ 1\leqslant q \leqslant N\right\}$$
We have $|f(x)| \leqslant 1$ for all $x \in [0,1]$ and $\frac{-1}{\sqrt{N}} < f(x) < \frac{1}{\sqrt{N}}$ for $x \in [0,1] \setminus A_N$.
Let $P= (x_0,x_1, \ldots, x_n)$ be a partition of $[0,1]$ with $\|P\| < \frac{\epsilon}{8m}$ and $M_j = \sup \{f(x) : x \in [x_{j-1}, x_j]\}$. The upper Darboux sum is
$$U(P,f) = \sum_{A_N \cap [x_{j-1},x_j] \neq \phi} M_j(x_j - x_{j-1})+ \sum_{A_N \cap [x_{j-1},x_j] = \phi} M_j(x_j - x_{j-1})$$
The $m$ elements of the set $A_N$ are contained in at most $2m$ subintervals. Hence, there are at most $2m$ terms in the first sum where $M_j \leqslant 1$ and $(x_j - x_{j-1})< \frac{\epsilon}{8m}$, and we have
$$\sum_{A_N \cap [x_{j-1},x_j] \neq \phi} M_j(x_j - x_{j-1}) < 2m \cdot 1 \cdot \frac{\epsilon}{8m} = \frac{\epsilon}{4}$$
In the second sum, we have $M_j \leqslant \frac{1}{\sqrt{N}}$ since only subintervals where  $[x_{j-1},x_j] \cap A_N = \phi$ contribute, and
$$\sum_{A_N \cap [x_{j-1},x_j]= \phi} M_j(x_j - x_{j-1}) \leqslant \frac{1}{\sqrt{N}}\sum_{A_N \cap [x_{j-1},x_j]= \phi} (x_j - x_{j-1})<  \sqrt{\frac{\epsilon^2}{16}}\cdot 1 = \frac{\epsilon}{4}$$
Thus, $U(P,f) < \frac{\epsilon}{2}$ for the chosen partition $P$. Since every subinterval must contain an irrational point where $f(x) = 0$ we also must have  $0 \leqslant U(P,f) <  \frac{\epsilon}{2}$.
In a similar way, it can be shown that $-\frac{\epsilon}{2} \leqslant L(P,f) \leqslant 0$. Therefore, $f$ is Riemann integrable by the Riemann criterion since for any $\epsilon > 0$ there is a partition such that $U(P,f) - L(P,f) < \epsilon$.
Since $L(P,f) \leqslant 0 \leqslant U(P,f)$ for every partition it is clear that the integral must be $0$.
