A closed form of $\sum_{n=1}^\infty\left[ H_n^2-\left(\ln n+\gamma+\frac1{2n} \right)^2\right]$

Just some considerations for now.

I have proved here that $$ \sum_{n=1}^{N}H_n^2 = (N+1) H_N^2-(2N+1)H_N+2N \tag{$\color{blue}{1}$} $$ and we have: $$ \mathcal{L}^{-1}\left(\frac{\log x+\gamma}{x}\right)(s)=-\log(s)\tag{2} $$ $$ \mathcal{L}^{-1}\left(\frac{\left(\log x+\gamma\right)^2}{x}\right)(s)=-\zeta(2)+\log^2(s)\tag{3} $$ hence the partial sums of the given series can be rearranged as follows:

$$\begin{eqnarray*}\sum_{n=1}^{N}\left[H_n^2-\left(\log n+\gamma+\frac{1}{2n}\right)^2\right]&=&(\color{blue}{1})-\frac{H_N^{(2)}}{4}-\sum_{n=1}^{N}\frac{\log n+\gamma}{n}-\sum_{n=1}^{N}n\frac{(\log n+\gamma)^2}{n}\\&=&(\color{blue}{1})-\frac{H_N^{(2)}}{4}+\int_{0}^{+\infty}\frac{\log(s)(1-e^{-Ns})}{e^s-1}\,ds\\&-&\int_{0}^{+\infty}\frac{e^{-N s} \left(e^{(1+N) s}+N-e^s (1+N)\right)\left(\zeta(2)-\log^2 s\right)}{\left(-1+e^s\right)^2}\,ds\end{eqnarray*}$$

If we find a way to distribute $(\color{blue}{1})$ over the last two integrals, in a way ensuring they are convergent integrals as $N\to +\infty$, we are done. At first sight the closed form of the LHS appears to be related with $\zeta(2)$, $\zeta'(0)=-\frac{1}{2}\log(2\pi)$ and $$ \zeta''(0)=\frac{\gamma^2}{2}-\frac{\pi ^2}{24}-\frac{1}{2}\log^2(2\pi)+\gamma_1$$ with $\gamma_1$ being a Stieltjes constant. An alternative, brute-force way is just to compute the asymptotic expansions of $$ \sum_{n=1}^{N}\log^2(n),\qquad \sum_{n=1}^{N}\frac{\log(n)}{n} $$ with the sufficient degree of accuracy (I guess that to stop at the $O\left(\frac{1}{N^3}\right)$ term is enough), that is just a tedious exercise about summation by parts.


The given series admits a closed form.

Proposition.$$ \sum_{n=1}^\infty \color{grey}{\left[\color{#151515}{\: H_n^2-\left(\ln n+\gamma+\frac1{2n} \right)^2}\: \right]}=\frac12\ln^2(2\pi)-\gamma\ln (2\pi)-\frac12\gamma^2-2\gamma_1-1. \qquad (\star) $$

where $\gamma_1$ is a Stieltjes constant.

(Sketch of a proof).

Let us consider, for $a\ge 0$, $$ S(a):=\sum_{n=1}^\infty \color{grey}{\left[\color{#151515}{\: \left(\psi(n+a+1)+\gamma\right)^2-\left(\ln (n+a)+\gamma+\frac1{2(n+a)} \right)^2}\: \right]}, \tag1 $$ where throughout $\displaystyle \psi :=\left(\text{Log}\: \Gamma \right)'$ is the digamma function. From the standard identity $$ \psi(n+1)+\gamma=H_n\qquad n=1,2,\cdots,\tag2 $$ we have $$ S(0)=\sum_{n=1}^\infty \color{grey}{\left[\color{#151515}{\: H_n^2-\left(\ln n+\gamma+\frac1{2n} \right)^2}\: \right]}. \tag3 $$ One is allowed to differentiate $S(a)$ termwise obtaining $$ \begin{align} S'(a)=\sum_{n=1}^\infty &\left[2\:\psi'(n+a+1)\left(\psi(n+a+1)+\gamma\right)\color{#FFFFFF}{\frac2{(n+a)}}\right. \\&-\left.\left(\frac2{(n+a)}-\frac1{(n+a)^2}\right)\!\left(\ln (n+a)+\gamma+\frac1{2(n+a)} \right)\right], \tag4 \end{align} $$ then we are lead to consider the partial sum, $$ \begin{align} S_N'(a)=&\sum_{n=1}^N 2\:\psi'(n+a+1)\left(\psi(n+a+1)+\gamma\right) \\-&\sum_{n=1}^N\left(\frac2{(n+a)}-\frac1{(n+a)^2}\right)\left(\ln (n+a)+\gamma+\frac1{2(n+a)} \right).\tag5 \end{align} $$ We have proved here that $\displaystyle \sum_{n=1}^N \psi'(n)\psi(n)$ has a closed form, this result can be extended as follows.

Theorem. Let $a$ be any non-negative real number. We have $$ \begin{align} &\sum_{n=1}^N \psi'(n+a+1)\psi(n+a+1) \\&=\left((N+a+1) \psi(N+a+2)-(a+1)\psi(a+2)\right)' \psi(N+a+1) \\\\&-\left((N+a+1) \psi(N+a+2)-(a+2)\psi(a+3)\right)' \\\\&+\left((a+1)\psi(a+2)\right)'\left(\psi(N+a+1)-\psi(a+2)\right) \tag6 \\\\&+\frac12 \psi'(N+a+1)-\frac12\psi'(a+2)-\frac12 \left(\psi'(N+a+1)\right)^2+\frac12 \left(\psi'(a+2)\right)^2. \end{align} $$

Proof. One uses a summation by parts with $$ f_n(a)=\psi(n+a+1),\quad g_n(a)=\psi'(n+a+1),\quad n\ge1, $$ taking into account that $$ \begin{align} &\sum_{n=1}^N \psi'(n+a+1)=\left((N+a+1) \psi(N+a+2)-(a+1)\psi(a+2)\right)'. \tag7 \end{align} $$ Then the second sum on the right hand side of $(5)$ satisfies $$ \begin{align} &\sum_{n=1}^N\left(\frac2{(n+a)}-\frac1{(n+a)^2}\right)\left(\ln (n+a)+\gamma+\frac1{2(n+a)}\right) \\\\&=2\gamma_1(a+1)-2\gamma_1(N+a+1)+2\gamma \psi(N+a+1)-2\gamma\psi(a+1) \tag8 \\\\&+\frac14 \psi''(N+a+1)-\frac14\psi''(a+2)+\gamma_1'(a+1)-\gamma_1'(N+a+1) \\\\&+(\gamma+1)\psi'(N+a+1)-(\gamma+1)\psi'(a+1), \end{align} $$ where we have used the generalized Stieltjes constant, $$ \begin{align} \gamma_1(a+1)=\lim_{N \to \infty}\left(\sum_{n=1}^N\frac{\ln(n+a)}{n+a}-\frac12\:\ln^2 \left(N+a\right)\right). \end{align} $$ We then insert $(6)$, $(7)$ and $(8)$ into $(5)$ and let $N \to \infty$ to get

$$ \begin{align} S'(a)=&\:\left(2a-2(a+2)\psi(a+3)\right)'+\left(2\gamma a-2\gamma(a+1)\psi(a+2)\right)' \\\\-&\:\left(\psi(a+2)-(a+1) \left(\psi(a+2)\right)^2\right)'-2\gamma_1(a+1)+2\gamma\psi(a+1) \tag9 \\\\+&\frac14\psi''(a+2)-\gamma_1'(a+1)+(\gamma+1)\psi'(a+1). \end{align} $$ Finally, integrating $(9)$ using $$ 2\int_1^{1+a}\gamma_1(t)\:dt=\zeta''(0,a+1)-\zeta''(0), $$ where $\zeta(\cdot,\cdot)$ denotes the Hurwitz zeta function and where $\zeta''(0,a+1)=\left.\partial_s^2\zeta(s,a+1)\right|_{s=0}$, determining the constant of integration by letting $a \to \infty$ and using $(3)$ yields $(\star)$.


An integral representation for the series

Let,

$\begin{align} u_n:=H_n-\ln n-\gamma-\dfrac{1}{2n}\\ v_n:=H_n+\ln n+\gamma+\dfrac{1}{2n}\\ \end{align}$

Observe that,

$\begin{align}u_n+v_n\end{align}=2H_n$

Since,

$\displaystyle H_n=-n\int_0^1 x^{n-1}\ln(1-x)\ dx$

and,

$\displaystyle u_n=-\int_0^1 \left(\frac{1}{\ln x}+\frac{1}{1-x}-\frac{1}{2}\right)x^{n-1}\ dx$

then,

$\begin{align}v_n&=2H_n-u_n\\ &=-2n\int_0^1 x^{n-1}\ln(1-x)\ dx+\int_0^1 \left(\frac{1}{\ln x}+\frac{1}{1-x}-\frac{1}{2}\right)x^{n-1}\ dx \end{align}$

therefore,

$\begin{align}\sum_{n=1}^{\infty}u_nv_n&=\sum_{n=1}^{\infty}\left(2n\int_0^1 \int_0^1\ln(1-x)\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\right)(xy)^{n-1}\ dx\ dy-\\ &\int_0^1\int_0^1 \left(\frac{1}{\ln x}+\frac{1}{1-x}-\frac{1}{2}\right)\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)(xy)^{n-1}\ dx\ dy\\ &=2\int_0^1\int_0^1 \frac{\ln(1-x)}{(1-xy)^2}\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\ dx\ dy-\\ &\int_0^1\int_0^1\frac{1}{1-xy} \left(\frac{1}{\ln x}+\frac{1}{1-x}-\frac{1}{2}\right)\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\ dx\ dy\\ &=\int_0^1 \int_0^1 \left(\frac{2\ln(1-x)}{(1-xy)^2}-\frac{1}{1-xy}\left(\frac{1}{\ln x}+\frac{1}{1-x}-\frac{1}{2}\right)\right)\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\ dx\ dy\\ &=\boxed{2A-B} \end{align}$

and,

$\begin{align}A&=\int_0^1 \int_0^1 \frac{\ln(1-x)}{(1-xy)^2}\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\ dx\ dy\\ B&=\int_0^1 \int_0^1 \frac{1}{1-xy}\left(\frac{1}{\ln x}+\frac{1}{1-x}-\frac{1}{2}\right)\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\ dx\ dy \end{align}$

( Computation of A )

( Computation of B )

Addenda:

1) $\begin{align}A=\int_0^1 \frac{\ln(1-y)}{y(1-y)}\left(\frac{1}{\ln y}+\frac{1}{1-y}-\frac{1}{2}\right)\ dy \end{align}$

(one can simplify this integral)

$A\approx -0.1932$

( Computation of A )

$\begin{align}B&=\int_0^1 \int_0^1 \frac{1}{1-xy}\left(\frac{1}{\ln x}+\frac{1}{1-x}\right)\left(\frac{1}{\ln y}+\frac{1}{1-y}-1\right)\ dx\ dy+\frac{\pi^2}{24} \end{align}$

2) Since,

$\displaystyle \gamma=\int_0^1 \left(\frac{1}{\ln x}+\frac{1}{1-x}\right)\ dx$

then

$\begin{align}B&=\int_0^1 \int_0^1 \frac{xy}{1-xy}\left(\frac{1}{\ln x}+\frac{1}{1-x}\right)\left(\frac{1}{\ln y}+\frac{1}{1-y}-1\right)\ dx\ dy+\gamma^2-\gamma+\frac{\pi^2}{24}\end{align}$

$B\approx 0.00651229$

(Computation of B )

3) $\begin{align}A&=\int_0^1\left[\left(\frac{\ln(1-x)}{x}+\frac{\ln(1-x)}{1-x}\right)\left(\frac{1}{\ln x}+\frac{1}{1-x}\right)-\frac{1}{2}\times \frac{\ln(1-x)}{1-x}\right]\ dx+\frac{\pi^2}{12}\end{align}$

( Computation of A )