Integral in greatest integer and absolute functions $$ \tag{1} \int_{1}^{4} \ln [x]\,dx $$
now we are given this problem , what i did was to write function as $$\int_1^4 1\cdot\ln [x]\,dx $$ and integral by parts yielded $[x]\ln [x]-[x]$ now we can enter limits to get the integral , have i done it correctly or am i missing something ?
 $$ \tag{2} \int_0^\pi |\cos(x)-\sin(x)|\,dx $$ 
what i did was $$\int_0^\pi |\cos(x)| -\int_0^\pi|\sin(x)|\,dx $$
now since $\cos(x) \lt 0$ in $(-\pi/2,\pi)$ i wrote the integral
$$\int_0^{\pi/2} \cos(x) \, dx-\int_{\pi/2}^\pi \cos(x) \, dx-\int_0^\pi \sin(x)\,dx$$
did i made any mistake ? 
 A: For the first integral, just note that the function you're integrating is constant on $[1, 2]$, $[2, 3]$ and $[3, 4]$. Just sketch the graph and add the areas.
For the second integral, it's not valid to state that
$$|\cos{x} - \sin{x}| = |\cos{x}| - |\sin{x}|$$
It is necessary to consider when the quantity inside the absolute value bars is positive and negative; we have that
$$\cos{x} - \sin{x} \geq 0$$
for all $x \in [0, \frac{\pi}{4}]$, so the integrand is just $\cos{x} - \sin{x}$ on that interval.
On the other hand, $\cos{x} - \sin{x} \le 0$ on $[\frac{\pi}{4}, \pi]$, so the integrand is $-(\cos{x} - \sin{x})$ on that interval. So the relevant integrals to consider are
$$\int_0^{\pi} |\cos{x} - \sin{x}| dx = \int_0^{\pi/4} \cos{x} - \sin{x} dx + \int_{\pi/4}^{\pi} -(\cos{x} - \sin{x}) dx$$
A: \begin{align}
&\int_{0}^{\pi}\left\vert\cos\left(x\right) - \sin\left(x\right)\right\vert\,{\rm d}x
\\[3mm]&=
\sum_{\sigma = \pm}\sigma\int_{0}^{\pi}
\left\lbrack\cos\left(x\right) - \sin\left(x\right)\vphantom{\Large A}\right\rbrack
\Theta\left(\sigma\cos\left(x\right) - \sigma\sin\left(x\right)\right)\,{\rm d}x
\\[3mm]&=
\sum_{\sigma = \pm}\sigma
\left.\left\lbrack\sin\left(x\right) + \cos\left(x\right)\right\rbrack
\Theta\left(\sigma\cos\left(x\right) - \sigma\sin\left(x\right)\right)
\vphantom{\LARGE A}\right\vert_{0}^{\pi}
\\[3mm]&-
\sum_{\sigma = \pm}\sigma\int_{0}^{\pi}
\left\lbrack\sin\left(x\right) + \cos\left(x\right)\vphantom{\Large A}\right\rbrack
\delta\left(\sigma\cos\left(x\right) - \sigma\sin\left(x\right)\right)
\left\lbrack
-\sigma\sin\left(x\right) - \sigma\cos\left(x\right)
\right\rbrack\,{\rm d}x
\\[3mm]&=
\sum_{\sigma = \pm}\sigma\left\lbrack%
-\Theta\left(-\sigma\right) -\Theta\left(\sigma\right)
\right\rbrack
+
\sum_{\sigma = \pm}\int_{0}^{\pi}
\left\lbrack\sin\left(x\right) + \cos\left(x\right)\vphantom{\Large A}\right\rbrack^{2}\,
{\delta\left(x - \pi/4\right)
 \over
 \left\vert\vphantom{\Large A}
 -\sigma\sin\left(\pi/4\right) - \sigma\cos\left(\pi/4\right)\right\vert}
\,{\rm d}x
\\[3mm]&=
2\int_{0}^{\pi}
\left\vert\vphantom{\Large A}\sin\left(\pi/4\right) + \cos\left(\pi/4\right)\right\vert\
\delta\left(x - \pi/4\right)
\,{\rm d}x
=
{\large 2\,\sqrt{2}}
\end{align}
