# Integrability of a piecewise function on $[0,1]$

Consider the function $f(x)=\begin{cases} x & x\in \mathbb{Q}\cap [0,1] \\ -x & x\in [0,1]-\mathbb{Q} \\ \end{cases}$

I argue that this function is not integrable since given any partition $P$ of $[0,1]$, between any two points $x_n, x_{n+1}$ in the partition there is a rational number $r$ so that $U(f,P)>0.$ Similarly, $L(f,P)<0$. Therefore, $U-L>0$.

Am I correct? Is this function Lebesgue integrable? The latter is my main question.

-

You are correct this function is not Riemann integrable on $[0,1]$. Your reasoning is (almost, see edit) correct, but another quick way to check is to note that its set of discontinuity points, namely $(0,1]$, does not have Lebesgue measure zero.
It is, however, Lebesgue integrable. We have $f(x) = x\chi_{\mathbb{Q} \cap [0,1]}(x) -x\chi_{[0,1]\setminus\mathbb{Q}}(x)$ which is a sum of bounded measurable functions. Since $[0,1]$ has finite measure bounded and measurable implies integrable.
Edit: Your reasoning is almost correct. Showing $U-L>0$ always does not imply the function is not Riemann integrable. You need to show $U-L > \epsilon$ always, for some $\epsilon >0$.
Also, another quick way to see that $f$ is Lebesgue integrable is that $f(x)=-x$ almost everywhere. Since the Lebesgue measure is complete, this implies $f$ is integrable if and only if $g(x):= -x$ is integrable, which of course it is.