Consider the following function on $[0,1]$: $$f(x)=\begin{cases}1&x\in\{a_1,a_2,\dots,a_n\}\\0 &\text{otherwise}\end{cases}$$ The $a_i$ are fixed and all in $[0,1]$. Determine whether $f$ is Rieman integrable or not.
My attempt : I found the answer here
Here is the outline of the given answer
Take a partition $P$ of $[0,1]$ that is defined as: $$ P = \left\{0,a_1-\frac{\epsilon}{2},a_1+\frac{\epsilon}{2},\dots,a_n-\frac{\epsilon}{2},a_n+\frac{\epsilon}{2},1\right\}. $$ Clearly, $U(P,f) = \epsilon N$ and $L(P,f) = 0$. Since for any given $\epsilon>0$, a partition that could yield $$ U(P,f) - L(P,f) < \epsilon $$ can be found, $f$ is Riemann integrable.
My confusion :Here $$U(P,f)=\sum_{i=1}^{n}M_i(x_i- x_{i-1})= n\epsilon$$ and
$$L(P,f)=\sum_{i=1}^{n}m_i(x_i- x_{i-1})= 0$$
$$\implies U(P,f) - L(P,f) > \epsilon \implies n\epsilon -0 > \epsilon $$
My confusion is that why $U(P,f) - L(P,f) < \epsilon ?$
You have the right to be confused here. That answer is misleading (at best).
Given $\varepsilon>0$, that answer shows that there is a partition $P$ such that $U(f,P)-L(f,P)=n\varepsilon$ (not $N\varepsilon$; there is no $N$ here). So, given $\varepsilon>0$, take $\varepsilon'<\frac\varepsilon n$ and consider the partition$$P=\left\{0,a_1-\frac{\varepsilon'}2,a_1+\frac{\varepsilon'}2,\ldots,a_n-\frac{\varepsilon'}2,a_n+\frac{\varepsilon'}2,1\right\}.$$Then$$U(f,P)-L(f,P)=n\varepsilon'<\varepsilon.$$