What is $\int_0^{\infty} (-1)^{\lfloor x^2 \rfloor} \, \operatorname{d}\!x \ ?$ What is 
$$\int_0^{\infty} (-1)^{\lfloor x^2 \rfloor} \, \operatorname{d}\!x \ ?$$
 A: The integral is just a sum of the integrand value over an interval of a constant integer value times the length of that interval.  Note that $\lfloor x^2\rfloor$ is equal to the integer $k$ when $x \in [\sqrt{k},\sqrt{k+1}]$.  Therefore,
$$\int_0^{\infty} dx \: (-1)^{\lfloor x^2\rfloor} = \sum_{k=0}^{\infty} (-1)^k (\sqrt{k+1}-\sqrt{k}) = \sum_{k=0}^{\infty} \frac{(-1)^k}{\sqrt{k+1}+\sqrt{k}}$$
The sum converges by comparison with 
$$\sum_{k=1}^{\infty} \frac{(-1)^{k+1}}{\sqrt{k}}$$
A: Hint: Draw a picture of the graph of the integrand and shade the relevant regions.
A: My own answer was to substitute t=x^2 and to get Int( (-1)^floor(x) * 1/2sqrt(x) ) then trying to use the fact  Int( (-1)^floor(x) ) for x=0 to 2 is 0 and it's repeating, also 1/2sqrt(x) is monotonic to zero... Is it a right way of solving this question? How may I complete it on a formal way?
A: Let $f(x) = (-1)^{\lfloor x^2 \rfloor}$. Then you can show that
$$s_n=\int_0^{\sqrt{n}} f(t) \, dt = \sum_{k=0}^n \frac{(-1)^k}{\sqrt{k}+\sqrt{k+1}} \, .$$ Note that $s_n$ is a convergent sequence.
Now, for any fixed $x>0$, we can find some $n$ with $\sqrt{n}<x<\sqrt{n+1}$. Since the sign of $f$ is constant on $[\sqrt{n},\sqrt{n+1}]$, $\int_0^x f(t) \, dt$ lies between $s_n$ and $s_{n+1}$. The sequences $\{s_n\}$ and $\{s_{n+1}\}$ converge to the same value, and $n$ increases without bound as $x$ does; thus $\int_0^x f(t) \, dt$ converges by the squeeze theorem.
What lesson should you take from this in general? The only thing that can go wrong when you try to turn an improper integral into a sum is that you might be concealing some cancellation. In this case, we're breaking up the integral everywhere the sign of the integrand changes, so there's no way that could happen.
You are right to be somewhat worried, though. Notice that while $\sum_{k=0}^\infty \frac{(-1)^k}{\sqrt{k}+\sqrt{k+1}}$ converges, it doesn't converge absolutely. So there are certain things you can't do to this integral that you might want to (e.g., any substitution that amounts to a rearrangement of the sum).
A: 
Convergent.

And its value can be expressed as
$$
\sum_{n\geqslant0}\left(2\sqrt{2n+1}-\sqrt{2n}-\sqrt{2n+2}\right)
$$
or as
$$
\sum_{n\geqslant0}\frac2{(\sqrt{2n+1}+\sqrt{2n})(\sqrt{2n+2}+\sqrt{2n+1})(\sqrt{2n+2}+\sqrt{2n})}
$$
