TITLE: Why doesn't $\int\lfloor {x}\rfloor~dx=x\lfloor x\rfloor +C$?
QUESTION [9 upvotes]: Why doesn't $$\int\lfloor {x}\rfloor~dx=x\lfloor x\rfloor +C?$$

When I tried integrating $\lfloor {x}\rfloor$ initially, I thought of the integral as representing the area beneath the graph and so was successful in finding its indefinite integral. However, when I tried thinking about it from a 'formulaic' perspective, ie without thinking about what the integral really meant, I've become confused:
If we try integrating by parts, we seem to get
$$\int\lfloor {x}\rfloor~dx=x\cdot\lfloor {x}\rfloor-\int x\cdot\frac{d}{dx}(\lfloor {x}\rfloor)~dx=x\lfloor {x}\rfloor+C$$
since I would think that $\frac{d}{dx}(\lfloor {x}\rfloor)=0$.
Please can you explain why my result is wrong? I would guess that it has something to do with the derivative of the floor function being undefined at places where there is jump discontinuity, but I'm not sure.

REPLY [3 votes]: One nice way to integrate such a function is to break it up into a summation, notice that:
$$\lfloor x\rfloor=\begin{cases}0&0\le x<1\\1&1\le x<2\\\vdots\end{cases}$$
and so if you have an integral like:
$$\int_0^b\lfloor x\rfloor\,dx\qquad b>0$$
you can split this up into:
$$\sum_{n=0}^{\lfloor b\rfloor-1}\int_n^{n+1}\lfloor x\rfloor\,dx+\int_{\lfloor b\rfloor}^b\lfloor x\rfloor\,dx$$
now you can just rewrite this as:
$$\sum_{n=0}^{\lfloor b\rfloor-1}\int_n^{n+1}n\,dx+\int_{\lfloor b\rfloor}^b\lfloor b\rfloor\,dx$$