I have a function $$f(x)=(x+1)^2+(x+2)^2 + \dots + (x+n)^2 = \sum_{k=1}^{n}(x+k)^2$$ for some positive integer $n$. I started wondering if there is an equivalent expression for $f(x)$ that can be calculated more directly (efficiently).
I began by expanding some terms to look for a pattern.
$$
(x^2+2x+1) + (x^2+4x+4) + (x^2+6x+9) + (x^2+8x+16) + \dots
$$
By regrouping the $x^2$, $x$, and constant terms, I can see that
$$
f(x) = \sum_{k=1}^{n}x^2 + \sum_{k=1}^{n}2kx + \sum_{k=1}^{n} k^2
$$
for which I've found some identities to get
$$
f(x) = n x^2 + n(n+1)x + \frac{1}{6}n(n+1)(2n+1)
$$
and simplifying some (attempting to make it computationally efficient)
$$
f(x) = n \left[ x^2 + (n+1)x + \frac{1}{6}(n+1)(2n+1) \right]
$$
$$
f(x) = n \left[ x^2 + (n+1) \left( x + \frac{2n+1}{6} \right) \right]
$$
Is this a particular type of summation (maybe just exponential?), and if so is there a standard way to write it?
Along those lines, is there a more direct derivation than what I've attempted here, perhaps using an identity I don't know?
$f(x)$ is just a second-degree polynomial, so its coefficients can be found by computing $f(0),\,f'(0),\,f''(0)$, where: $$ f(0)=\sum_{k=1}^{n}k^2,\qquad f'(0)=2\sum_{k=1}^{n}k,\qquad f''(0)=2n$$ are associated with pretty well-known sums. Have a look at the hockey stick identity and Stirling numbers of the second kind to get an idea about computing $\sum_{k=1}^{n}k^p$ through $$ \sum_{k=m}^{M}\binom{k}{m}=\binom{M+1}{m+1}.$$