how do simple function constructions solves the "bad function" problem in the Riemann case The picture at the link below finally helped me to understand the simple function construction of Lebesgue and how one can approximate a real function using simple functions.
https://www.geogebra.org/m/PRKqaF3Y
But I still don't understand how the constructions solves the standard bad function example where $f(x) = 0$ if $x$ is irrational and $1$ if $x$ is rational?
Can someone explain this? It seems to me like one will still have a rational between every irrational so why does slicing the function horizontally instead of vertically solve the issue? Thanks.
 A: The function you mention is nowhere continuous, and thus not riemann-integrable. 
Howerver when "slicing" horizontally you split the domain in two sets $\mathbb Q$ and $\mathbb R \setminus \mathbb Q$. The first set has lebesgue measure 0, and on the other set the integrand is 0. Thus the integral is 0. Thus slicing horizontally make us able to integrate your function.
\begin{equation*}
 \int_\mathbb R f d\mu = \mu(\mathbb Q) \cdot 1 + \mu(\mathbb R \setminus \mathbb Q) \cdot 0 = 0\cdot 1 + \infty\cdot 0 =0 \quad \mbox{(using extended reals as in Rudin).}
\end{equation*}
A: The integral is defined as 1*y(Q)+0*y(R/Q) which is 0, since the rationals are countable and therefore have measure 0. (in measure theory 0*inf is usually defined as 0).
Therefore there is no issue with this function.
To elaborate: It works, because you can seperate the rationals from the irratioanls in the calculation. If you slice vertically, each slice will contain a rational and a irrational number, therefore creating problems.
