# Sum of Squares of Harmonic Numbers

Let $H_n$ be the $n^{th}$ harmonic number,

$$H_n = \sum_{i=1}^{n} \frac{1}{i}$$

Question: Calculate the following

$$\sum_{j=1}^{n} H_j^2.$$

I have attempted a generating function approach but could not solve this.

This is an interesting exercise in partial summation. For first, we have: $$\begin{eqnarray*}\sum_{j=1}^{n}H_j &=& n H_n-\sum_{j=1}^{n-1} \frac{j}{j+1} = n H_n - (n-1)+\sum_{j=1}^{n-1}\frac{1}{j+1}\\&=& n H_n-n+1+(H_n-1) = (n+1)\,H_n-n\tag{1}\end{eqnarray*}$$ hence: $$\begin{eqnarray*}\color{red}{\sum_{j=1}^n H_j^2} &=& \left((n+1)H_n^2-nH_n\right)-\sum_{j=1}^{n-1}\frac{(j+1)\,H_j-j}{j+1}\\&=&\left((n+1)H_n^2-nH_n\right)-\sum_{j=1}^{n-1}H_j+(n-1)-(H_n-1)\\&=&(n+1)\,H_n^2-nH_n-(n+1)\,H_n+n+H_n+(n-1)-H_n+1\\&=&\color{red}{(n+1)\,H_n^2-(2n+1)\,H_n+2n\phantom{\sum_{j=0}^{+\infty}}}.\tag{2}\end{eqnarray*}$$ Notice the deep analogy with: $$\int \log^2 x\,dx = x\log^2 x -2x\log x +2x.$$
• @NilMal: the first terms of the asymptotic for $H_n$ are $\log(n)+\gamma$, and we may compute our sum by partial summation, as well as we may compute $\int_{1}^{n}\log^2(x)\,dx$ through integration by parts. That is the tight analogy. – Jack D'Aurizio Jul 23 '16 at 13:31