TITLE: Formula for $1^2+2^2+3^2+...+n^2$
QUESTION [6 upvotes]: In example to get formula for $1^2+2^2+3^2+...+n^2$ they express $f(n)$ as:
$$f(n)=an^3+bn^2+cn+d$$ also known that $f(0)=0$, $f(1)=1$, $f(2)=5$ and $f(3)=14$
Then this values are inserted into function, we get system of equations solve them and get a,b,c,d coefficients and we get that $$f(n)=\frac{n}{6}(2n+1)(n+1)$$
Then it's proven with mathematical induction that it's true for any n.
And question is, why they take 4 coefficients at the beginning, why not $f(n)=an^2+bn+c$ or even more? How they know that 4 will be enough to get correct formula?

REPLY [6 votes]: It is a consequence of the following algebraic identity
$$1+2^{2}+3^{2}+\ldots +n^{2}=\frac{1}{3}\left( n^{3}+3n^{2}+3n+1\right) -
\frac{1}{3}n-\frac{1}{2}(n^2+n)-\frac{1}{3}.$$
$$\tag{1}$$
The RHS is a cubic function of $n$: $\frac{1}{3}n^{3}+\frac{1}{2}n^{2}+\frac{1}{6}n$.
Proof. From the algebraic identity
$$\left( 1+k\right) ^{3}=1+3k+3k^{2}+k^{3}$$
we get the following $n$ identities:
$$\begin{eqnarray*}
\left( 1+1\right) ^{3} &=&1+3+3+1 \\
\left( 1+2\right) ^{3} &=&1+3\cdot 2+3\cdot 2^{2}+2^{3} \\
\left( 1+3\right) ^{3} &=&1+3\cdot 3+3\cdot 3^{2}+3^{3} \\
&&\ldots  \\
\left( 1+n\right) ^{3} &=&1+3n+3n^{2}+n^{3}.
\end{eqnarray*}$$
Now if we sum these equalities and cancel the common terms, $\left(
1+1\right) ^{3}$ on the LHS of the first and $2^{3}$ on the RHS of the
second, $\left( 1+2\right) ^{3}$ on the LHS of the second and $3^{3}$ on the
RHS of the third, etc., and $(1+n-1)^3$ on the LHS of the second last and $n^3$ on the RHS of the last, we get:
$$\left( 1+n\right) ^{3}=n+3(1+2+3+\ldots +n)+3(1+2^{2}+3^{2}+\ldots +n^{2})+1,\tag{2}$$
and $(1)$ follows from $(2)$ and the sum formula for the arithmetic progression $$1+2+3+\ldots +n=\frac{\left( n+1\right) n}{2}.$$ 
(Adapted from Proof 1 in this answer to the question Prove that $\sum\limits_{k=1}^nk^2 = \frac{n(n+1)(2n+1)}{6}$? ; see the above Theo Buehler's comment.)  

Note: This is a particular case of the sum $1+2^{p}+3^{p}+\ldots +n^{p}$,
which is a polynomial of degree $p+1$.