# Comparison of sum and integral over Harmonic number

The sum of Harmonic numbers $H_n = \sum_{k=1}^n \frac{1}{n}, H_0 = 0$ defined by

$$f_s(n) = \sum_{k=0}^n H_k$$

is given by

$$f_s(n) = (n+1) H_n - n$$

Now define the integral

$$f_i(n) = \int_0^n H_x \, dx$$

Here $H_x$ is the analytic continuation of $H_n$ to real values provided for instance by the formula due to Euler

$$H_x = \int_0^1 \frac{1-t^x}{1-t} \, dt$$

We are interested in the difference

$$d_f(n) = f_s(n) - f_i(n)$$

The task is to determine the asyptotic behaviour of this differences as $n\to \infty$.

With $H_n= \psi(n+1)+\gamma\quad$ (where $\psi(x)=\frac{d}{dx} \ln(\Gamma(x))$ is the digamma function, $\gamma$ the Euler–Mascheroni constant) you get $$f_s(n) = \psi(n+2)(n+1)-n-1+\gamma(n+1)$$ $$f_i(n) = \ln(\Gamma(n+1))+\gamma n$$ Maple gives the asymptotics for $n\rightarrow \infty$ $$f_s(n)-f_i(n) \sim \frac{1}{2}+\frac{1}{2}\ln(n)+\gamma -\ln\sqrt{2\pi} + O\left(\frac{1}{n}\right)$$
Like you are probably aware of, $$\sum_{k=0}^{n}H_k = \sum_{k=1}^{n}\sum_{j=1}^k \frac{1}{j} = (n+1)H_n-n \tag{A}$$ simply follows from summation by parts, and $$H_n = \psi(n+1)+\gamma = \gamma+\log(n)+\frac{1}{2n}-\frac{1}{12n^2}+O\left(\frac{1}{n^3}\right) \tag{B}$$ follows from the Euler-MacLaurin summation formula or creative telescoping, with $\psi(z)=\frac{d}{dz}\log\Gamma(z)$. Since $$\int_{0}^{n} H_x\,dx = n\gamma + \log\Gamma(n+1)\tag{C}$$ is a straightforward consequence of $(B)$, by combining $(A),(B),(C)$ with Stirling's approximation we have: $$\sum_{k=0}^{n}H_k -\int_{0}^{n}H_x\,dx = \frac{1}{2}\log(n)+\left(\tfrac{1}{2}+\gamma-\log\sqrt{2\pi}\right)+\frac{1}{3n}-\frac{1}{12n^2}+O\left(\frac{1}{n^3}\right).\tag{D}$$