How do I calculate an integral that contains the floor function? I am trying to get my head around Abel's summation formula (here), but I am confused about how to deal with an integral involving the floor function.
Let $a_1, a_2, a_3, ... , a_n, ...$ be a sequence of real or complex numbers, and define a partial sum function $A$ by
$$A(t) = \sum_{1 \le n \le t} a_n$$
Further, fix real numbers $x < y$ and let $\phi$ be continuously differentiable function on $[x, y]$. Then
$$\sum_{1 \le n \le x} a_n \phi(n) = A(x) \phi(x) - \int_1^x A(u) \phi '(u) \, du$$
EXTRA INFO: My aim is find a formula of this form for a sum $\sum_{1 \le n \le x} \phi(n)$. So (back to original post):
Let the sequence $a_n$ be $a_0 = 0, a_1 = 1, a_2 = 1, ... $ . Then $\sum_{1 \le n \le x} a_n \phi(n) = \sum_{1 \le n \le x} \phi(n)$ and $A(x) = \lfloor x \rfloor$. So,
$$\sum_{1 \le n \le x} \phi(n) = \lfloor x \rfloor \phi(x) - \int_1^x \lfloor u \rfloor \phi '(u) \, du$$
But how do I calculate the integral $\int_1^x \lfloor u \rfloor \phi '(u) \, du$? Obviously $\lfloor u \rfloor$ is a constant for any given value of $u$, but I don't know how to tackle the indefinite integral - not even for something as simple as $\phi(x) := x^2$. (Note that this is just an example of $\phi$; I am after a more general solution.)
 A: There is a useful guide here which contains several applications of Abel's summation formula where $a_n = 1$ for $n = 1,2,3,...$, and the integral terms therefore contains a floor function. The feature they all have in common is their use of the identity
$$
\begin{aligned}
\int_1^x \lfloor u \rfloor \phi '(u) \, du &= \int_1^x \bigl(u - \{u\} \bigr) \phi '(u) \, du
\\&= \int_1^x u \phi '(u) \, du - \int_1^x \{u\} \phi '(u) \, du
\end{aligned}
$$
where $\{u\}$ denotes the fractional part of $u$.
The function $\int_1^x u \phi '(u) \, du$ can often be defined and, since $0 \le \{u\} < 1$, in many cases we can set limits on $\int_1^x \{u\} \phi '(u) \, du$.
The suggestion made in several comments, and in more detail by @Sayan Dutta, that one can break up the integral containing the floor function into
$$\int_1^x \lfloor u \rfloor \phi '(u) \, du = \int_1^2 \lfloor u \rfloor \phi '(u) \, du + \int_2^3 \lfloor u \rfloor \phi '(u) \, du + ... + \int_{\lfloor x \rfloor}^x \lfloor u \rfloor \phi '(u) \, du$$
while perfectly correct, will generally lead straight back to the original sum.
The advantage of noting that $\int_1^x \lfloor u \rfloor \phi '(u) \, du = \int_1^x u \phi '(u) \, du - \int_1^x \{u\} \phi '(u) \, du$ is that the two integrals on the right hand side can be dealt with separately, providing two distinct terms, neither of which are not directly related to the original summation. It is this separation of terms which allows us to express the summation in a different and potentially useful form.
Example
Let $H_x = \sum_{1 \le n \le x} \frac{1}{n}$ be the harmonic number function. Set $\phi(x) = \frac{1}{x}$ and $a_n = 1$ for all $n = 1,2,3,...$.
Splitting the integral into unit steps produces
$$\begin{aligned}
H_x &= \frac{\lfloor x \rfloor}{x} - \int_1^x \frac{\lfloor u \rfloor}{u^2} \, du
\\&= \frac{\lfloor x \rfloor}{x} - \biggl( \int_1^2 \frac{\lfloor u \rfloor}{u^2} \, du + \int_2^3 \frac{\lfloor u \rfloor}{u^2} \, du + \int_{3}^4 \frac{\lfloor u \rfloor}{u^2} \, du + ... \biggr)
\\&= \frac{\lfloor x \rfloor}{x} - \biggl( 1 \bigl( \frac{1}{2} - \frac{1}{1} \bigr) + 2 \bigl( \frac{1}{3} - \frac{1}{2} \bigr) + 3 \bigl( \frac{1}{4} - \frac{1}{3} \bigr) + ... \biggr)
\\&= \frac{1}{1} + \frac{1}{2} + \frac{1}{3} + ...
\\&= \sum_{1 \le n \le x} \frac{1}{n}
\\&= H_x
\end{aligned}
$$
On the other hand, writing $\lfloor x \rfloor = x - \{x\}$ gives us
$$\begin{aligned}
H_x &= \frac{\lfloor x \rfloor}{x} + \int_1^x \frac{\lfloor u \rfloor}{u^2} \, du
\\&= \frac{x - \{x\}}{x} + \int_1^x \frac{u - \{u\}}{u^2} \, du
\\&= 1 - \frac{\{x\}}{x} + \int_1^x \frac{1}{u} \, du - \int_1^x \frac{\{u\}}{u^2} \, du
\\&= 1 - \frac{\{x\}}{x} + \log x - \int_1^x \frac{\{u\}}{u^2} \, du
\\&= 1 - \frac{\{x\}}{x} + \log x - \biggl( \int_1^\infty \frac{\{u\}}{u^2} \, du - \int_x^\infty \frac{\{u\}}{u^2} \, du \biggr)
\end{aligned}
$$
Since $\{x\} = O(1)$ we can write $\frac{\{x\}}{x} = \frac{O(1)}{x} = O \bigl(\frac{1}{x} \bigr)$ and (after checking for issues of convergence)
$$
\begin{aligned}
\int_x^\infty \frac{\{u\}}{u^2} \, du &= \int_x^\infty \frac{O(1)}{u^2} \, du
\\&= O(1)\int_x^\infty \frac{1}{u^2} \, du
\\&= O(1) \frac{1}{x}
\\&= O \bigl(\frac{1}{x} \bigr)
\end{aligned}
$$
So, now we have
$$H_x = \log x + 1 - \int_1^\infty \frac{\{u\}}{u^2} \, du + O \bigl(\frac{1}{x} \bigr)$$
Here, $1 - \int_1^\infty \frac{\{u\}}{u^2} \, du$ is the Euler-Mascheroni constant $\gamma = 0.5772156649...$. Thus
$$H_x = \log x + \gamma + O \bigl(\frac{1}{x} \bigr)$$
A: Assuming $x$ is NOT an integer
\begin{align*}
&\int_1^x \lfloor u \rfloor \phi '(u) \, du \\
= &\int_1^2 \lfloor u \rfloor \phi '(u) \, du + \int_2^3 \lfloor u \rfloor \phi '(u) \, du + \dots \int_{\lfloor x \rfloor-1}^{\lfloor x \rfloor} \lfloor u \rfloor \phi '(u) \, du +\int_{\lfloor x \rfloor}^x \lfloor u \rfloor \phi '(u) \, du\\
=&1\cdot \int_1^2 \phi '(u) \, du + 2\cdot \int_2^3 \phi '(u) \, du +\dots (\lfloor x \rfloor-1)\int_{\lfloor x \rfloor-1}^{\lfloor x \rfloor} \phi '(u) \, du +\lfloor x \rfloor\cdot\int_{\lfloor x \rfloor}^x \phi '(u) \, du\\
=&(\phi(2)-\phi(1))+2(\phi(3)-\phi(2))+\dots +(\lfloor x \rfloor-1)(\phi(\lfloor x \rfloor)-\phi(\lfloor x \rfloor-1))+\lfloor x \rfloor (\phi(x)-\phi(\lfloor x \rfloor))\\
=&-\phi(1)+(\phi(2)-2\cdot \phi(2))+(2\cdot \phi(3)-3\cdot \phi(3))+\dots +(\lfloor x \rfloor\phi(\lfloor x \rfloor)-(\lfloor x \rfloor-1)\phi(\lfloor x \rfloor))+\lfloor x \rfloor\phi(x)\\
=&-\phi(1)-\phi(2)-\phi(3)-\dots -\phi(\lfloor x \rfloor)+\lfloor x \rfloor\phi(x)
\end{align*}
The first equality is due to linearity of integral, and the second one is due to Fundamental Theorem of Calculus.
If $x$ is an integer, the last term won't be counted.
Hope that helps.
