<s>[INST] integral $\int_{0}^{1}\left( \left\lfloor{\frac{2}{x}} \right\rfloor-2 \left\lfloor{\frac{1}{x}} \right\rfloor \right)dx$ Evaluate $$\int_{0}^{1}\left( \left\lfloor{\frac{2}{x}} \right\rfloor-2 \left\lfloor{\frac{1}{x}} \right\rfloor \right)dx$$
My Attempt
$$I_{1}=\int_{0}^{1}\left\lfloor{\frac{2}{x}} \right\rfloor dx$$
Put $x=2t$
$$I_{1}=\int_{0}^{\frac{1}{2}}2\left\lfloor{\frac{1}{t}} \right\rfloor dt=\int_{0}^{\frac{1}{2}}2\left\lfloor{\frac{1}{x}}\right\rfloor dx$$
let $$I_{2}=\int_{0}^{1} \left\lfloor{\frac{1}{x}} \right\rfloor dx=\int_{0}^{\frac{1}{2}}\left\lfloor{\frac{1}{x}}\right\rfloor dx+\int_{\frac{1}{2}}^{1}\left\lfloor{\frac{1}{x}}\right\rfloor dx$$
Given integral 
$$
\begin{align}
\int_{0}^{1}\left(\left\lfloor{\frac{2}{x}}\right\rfloor-2\left\lfloor{\frac{1}{x}}\right\rfloor \right)dx&=I_{1}-2I_{2}\\
&=2\int_{0}^{\frac{1}{2}}\left\lfloor{\frac{1}{x}}\right\rfloor dx-2\int_{0}^{\frac{1}{2}}\left\lfloor{\frac{1}{x}}\right\rfloor dx-2\int_{\frac{1}{2}}^{1}\left\lfloor{\frac{1}{x}}\right\rfloor dx\\
&=-2\int_{\frac{1}{2}}^{1}\left\lfloor{\frac{1}{x}}\right\rfloor dx\\
&=(-2)(1)=-2.
\end{align}
$$
But answer given is $\ln(\frac{4}{e})$
What mistake am I making?
 [/INST] $$\begin{align*}\int_0^1 \left( \left\lfloor \dfrac{2}{x} \right\rfloor - 2\left\lfloor \dfrac{1}{x} \right\rfloor \right)dx & = \sum_{n=1}^\infty \left[\int_{\tfrac{1}{n+1}}^{\tfrac{2}{2n+1}}\left( \left\lfloor \dfrac{2}{x} \right\rfloor - 2\left\lfloor \dfrac{1}{x} \right\rfloor \right)dx + \int_{\tfrac{2}{2n+1}}^{\tfrac{1}{n}}\left( \left\lfloor \dfrac{2}{x} \right\rfloor - 2\left\lfloor \dfrac{1}{x} \right\rfloor \right)dx \right] \\ & = \sum_{n=1}^\infty \left[ \left( \dfrac{2}{2n+1}-\dfrac{1}{n+1} \right)(2n+1-2n) + \left(\dfrac{1}{n}-\dfrac{2}{2n+1} \right)(2n-2n) \right] \\ & = \sum_{n=1}^\infty \left(\dfrac{2}{2n+1}- \dfrac{1}{n+1} \right) = \ln\left( \dfrac{4}{e} \right)\end{align*}$$
The mistake you made was assuming the integral could be evaluated directly over intervals of length 1/2 (because neither $I_1$ nor $I_2$ is finite). Instead, you could use an infinite number of intervals (each time that $\left\lfloor \dfrac{2}{x} \right\rfloor > 2\left\lfloor \dfrac{1}{x} \right\rfloor$, which occurs when $\dfrac{1}{n+1} < x < \dfrac{2}{2n+1}$ for any positive integer $n$ because on that interval, $2n+1=\left\lfloor \dfrac{2}{x} \right\rfloor < 2n+2$ and $2n=2\left\lfloor \dfrac{1}{x}\right\rfloor < 2n+2$).
</s>