This question is inspired by [the MO query here](https://mathoverflow.net/questions/260169/lower-bound-for-frac-sum-i-j-minf-i-f-j2-g-i-g-j2-sum-i-j-max), although it has no direct implications.


Define the family of polynomial functions
$$f\_n(x)=n^2x^{n-1}-\frac{d}{dx}\left(\frac{x^n-1}{x-1}\right),$$
and the associated family of algebraic functions
$$g\_n(x)=\frac{\sqrt{f\_n(x)}}n+\sum\_{j=1}^{n-1}\frac{\sqrt{f\_j(x)}}{j(j+1)}.$$



> 
> **Question.** Despite the complicated expressions for $f\_n$ and $g\_n$, does 
>  $$h\_n(x)=\sum\_{k=0}^n\left(g\_n(x)-g\_k(x)\right)^2$$
>  have a neat (closed) formula? 
> 
> 
> **UPDATE.** user64494 (see below) has found $h\_n(x)=nx^{n-1}$. Any proof?
> 
> 
> 


**Convention:** $g\_0:=0$ and empty sums are zero.


For example, $h\_2(x)=g\_2(x)^2+(g\_2(x)-g\_1(x))^2+(g\_2(x)-g\_2(x))^2=2x$.



what is this sum of squares of algebraic functions?
A large part of the result doesn't really depend on $f\_n$. For an arbitrary sequence $(a\_n)$, define two sequences by $G\_0=0$, $H\_0=0$, and for $n\ge1$,
$$G\_n=\frac{a\_n}{n}+\sum\_{j=1}^n{\frac{a\_j}{j(j+1)}}\quad\text{and}\quad H\_n=\sum\_{k=0}^n{(G\_n-G\_k)^2}.$$
Then 
$$H\_{n+1}-H\_n=G\_{n+1}^2-G\_n^2+\sum\_{k=1}^n{(G\_{n+1}-G\_n)(G\_{n+1}+G\_n-2G\_k)}.$$
The right-hand side simplifies to
$$(G\_{n+1}-G\_n)\big((n+1)(G\_{n+1}+G\_n)-2\sum\_{k=1}^n{G\_k}\big),$$
where the last sum simplifies a lot:
$$\sum\_{k=1}^n{G\_k}=(n+1)\sum\_{j=1}^n{\frac{a\_j}{j(j+1)}}$$
so that in the end everything telescopes and
$$H\_{n+1}-H\_n=\frac{1}{n+1}(a\_{n+1}^2-a\_n^2).$$
Applying this with $a\_n=\sqrt{f\_n(x)}$ gives 
$$h\_{n+1}(x)-h\_n(x)=\frac{1}{n+1}(f\_{n+1}(x)-f\_n(x))=\frac{1}{n+1}\left((n+1)^2x^n-n^2x^{n-1}-\frac{d}{dx}\left(\frac{x^{n+1}-x^n}{x-1}\right)\right)=
\frac{1}{n+1}\left((n+1)^2x^n-n(n+1)x^{n-1}\right)=(n+1)x^n-nx^{n-1},$$
whence the proof by induction.


