Calculating the given integral 
Define $f:[0,1] \rightarrow \mathbb{R}$ by 
  $$f(x)=\begin{cases}1& \text{ $x$ is algebraic}\\0 
&\text{otherwise}\end{cases}$$
The question is to find $\int_0^1 f(x) dx$.

My Try:
Take a partition $P=\Bigl\{0=\frac{0}{n},\frac{1}{n},\frac{2}{n},\frac{3}{n},...,\frac{n}{n}=1\Bigr\}$ of $[0,1]$.
Since every transcentendal number is irrational and irrational are dense, so the minimum over each subinterval is $0$. Hence $L(P,f)=0$.
On the other hand, to calculating $U(P,f)$, we see that $\Delta x_i=\frac{1}{n}, \forall i.$. Also the maximum over each subinterval is $1$, so $U(P,f)=\Sigma_1^n M_i \Delta x_i \neq 0$. So lower integral and upper integral are different. 
But the answer was  $\int_0^1 f(x) dx=0$.
Where I'm doing wrong? 
Any help will be appreciated! 
 A: The Riemann integral doesn't exist, well spotted. The Lebesgue integral is 0, because the integrand is 0 almost everywhere (except for algebraic arguments, but that's a countable set having Lebesgue measure 0).
EDIT: Let's make that a bit more detailed. The Riemann integral $\int^1_0f(x)\,dx$ can't exist, and we wouldn't even need upper and lower sums: both algebraic and transcendental numbers are dense, so for any partition $(x_i)$ of $[0,1]$, we can find $\xi_i\in[x_i,x_{i+1}]$ both with $f(\xi_i)=0$ or with $f(\xi_i)=1$, so the Riemann sums $\sum_i f(\xi_i)(x_{i+1}-x_i)$ can't converge.
So the integral in your given answer can't be a Riemann integral. You don't say which one, but the most common generalization is the Lebesgue integral. That's uniquely defined by some properties: the integral of an indicator function $\chi_A(x)$ of a Borel set $A$ is the Lebesgue measure $\mu(A)$ of that set, the integral is linear in the integrand, and positive for positive integrands.
In your case,  it's simpler, because your integrand is the indicator function  of a set, the set $A$ of algebraic numbers in $[0,1]$. That's a countable set, so $\int^1_0f(x)\,dx=\mu(A)=0$.
All countable sets have Lebesgue measure zero, and it's easy to see why: the measure is uniquely defined by the requirement $\mu([a,b])=b-a$, so $\mu(\{a\})=\mu([a,a])=a-a=0$, and since it is $\sigma$-additive (additive for countable unions of disjoint sets), we see $\mu(A)=\sum_{a\in A}\mu(\{a\})=0$.
A: What you're trying to do is Riemann-integrate this function. However, this function cannot be Riemann-integrated, for the following reason:
What is a Riemann integral? It's just the limit of a Riemann sum. However, this Riemann sum will only accurately reflect the actual integral if the function is piecewise continuous - otherwise, there are many points $x$ where the value being taken for $f(x)$ in the Riemann sum doesn't actually approach $f(x)$. This is one such case.
To integrate it, we must use the Lebesgue integral. As Professor Vector said, the Lebesgue integral of a function that is $0$ almost everywhere is $0$. And, this function is $0$ almost everywhere because the set of places where it isn't (algebraic numbers) has countable cardinality, while we are integrating over an uncountable set.
