Is my derivation of the summation formula of the first squares correct?
Solution 1:
Here we look at steps (1) and (2) and we will see that the left-hand side of (2) needs to be revised somewhat. We start with the identity \begin{align*} \sum_{i=1}^n i=\frac{n^2+n}{2}\tag{0} \end{align*}
Step 1.:
We consider the left-hand side of (0) as function in $n$ and define the function \begin{align*} &f:\mathbb{N}\to\mathbb{R}\tag{1.1}\\ &f(n)=\sum_{i=1}^n i \end{align*}
We observe (1.1) defines a function in the variable $n$. The index $i$ is an index variable with validity defined by the scope of the sigma symbol $\sum$. We know the sum formula (0) and can simplify the function by writing it as closed form.
\begin{align*} f(n)=\sum_{i=1}^n i=\frac{n^2+n}{2}\tag{1.2} \end{align*}
Since $f$ is a polynomial function we can integrate it.
Step 2.:
We obtain from (1.2) by integrating $f$ \begin{align*} \int f(n)\,dn=\int \sum_{i=1}^n i\,dn = \int \frac{n^2+n}{2}\,dn = \left(\frac{n^3}{3}+\frac{n^2}{2}\right)\frac{1}{2}+C_0\tag{2.1} \end{align*}
Note the integration in (2.1) is written using $n$ as integration variable: \begin{align*} \color{blue}{\int} \sum_{i=1}^n i\,\color{blue}{dn} \end{align*} and this can be used for further considerations.
Note: When writing the expression instead in the form \begin{align*} \color{blue}{\int}\left(\sum_{i=1}^{n}i\right)\color{blue}{di}\tag{3} \end{align*} we use the symbol $i$ for two different variables. The scope of the index variable $i$ is restricted to scope of the sigma symbol indicated by parentheses. The integration variable $i$ is a different symbol than the index variable $i$ and also independent of $n$. We can use instead $x$ as integration variable and (3) can be written as \begin{align*} \color{blue}{\int}\left(\sum_{i=1}^{n}i\right)\color{blue}{di}&=\int \sum_{i=1}^n i\,dx\\ &=\int\,dx \sum_{i=1}^n i\\ &=\left(x+C_1\right)\frac{n^2+n}{2} \end{align*} which is not what we intend.
Conclusion: We can stick at (2.1) and can use it as basis for further calculations.
Hint: There is a famous relationship between sums and Riemann integrals known as the Euler - MacLaurin summation formula which gives for Riemann-integrable functions
\begin{align*} \sum_{i=1}^nf(i)=\int_{0}^n f(x)\,dx+\frac{f(n)-f(0)}{2}+\sum_{k=1}^{\left\lfloor\frac{p}{2}\right\rfloor}\frac{B_{2k}}{(2k)!}\left(f^{(2k-1)}(n)-f^{(2k-1)}(0)\right)+R_p\tag{4} \end{align*}
$B_k$ are the Bernoulli numbers and $R_p$ is a remainder term. In case $f$ is a polynomial the remainder $R_p$ vanishes if $p$ is big enough.
In the current case $\sum_{i=1}^n i^2$ we can set $p=2$ and we obtain from (4) with $f(x)=x^2$ \begin{align*} \color{blue}{\sum_{i=1}^n i^2}&=\int_{0}^nx^2\,dx+\frac{n^2-0}{2}+\frac{B_2}{2}\left(2n-0\right)\\ &\,\,\color{blue}{=\frac{1}{3}n^3+\frac{1}{2}n^2+\frac{1}{6}n} \end{align*}
Solution 2:
Just to add a possibly well-known way (thought not necessarily as generalizable as above) of showing the sum of consecutive squares, in the spirit of apocryphal story of Gauss:
Note that $$1^2 = 1\\ 2^2= 2+2 \\ 3^2 = 3+3+3 \\ 4^2 = 4+4+4+4 \\\vdots$$ etc.
So we have $\sum_{i=1}^n i^2$ is the sum of the above pyramid of numbers. In particular, when $n=4$, we have by rotating this pyramid of numbers in three ways: $$ \sum_{i=1}^4 i^2=\frac{1}{3}\left(\begin{array}{cccccc} 1+\\ 2+ & 2+\\ 3+ & 3+ & 3+\\ 4+ & 4+ & 4+ & 4 \end{array}+\begin{array}{cccccc} 4+\\ 3+ & 4+\\ 2+ & 3+ & 4+\\ 1+ & 2+ & 3+ & 4 \end{array}+\begin{array}{cccccc} 4+\\ 4+ & 3+\\ 4+ & 3+ & 2+\\ 4+ & 3+ & 2+ & 1 \end{array}\right)\\=\frac{1}{3}\left(\begin{array}{cccc} 9+\\ 9+ & 9+\\ 9+ & 9+ & 9+\\ 9+ & 9+ & 9+ & 9 \end{array}\right) = \frac{1}{3}(1+2+3+4)(9) $$
So one can believe that $$ \sum_{i=1}^n i^2 = \frac{1}{3}\left( \begin{array}{cccccc} 1+\\ 2+ & 2+\\ \vdots & & \ddots\\ n+ & n+ & \cdots & n \end{array}+\begin{array}{cccccc} n+\\ (n-1)+ & n+\\ \vdots & & \ddots\\ 1+ & 2+ & \cdots & n \end{array}+\begin{array}{cccccc} n+\\ n+ & (n-1)+\\ \vdots & & \ddots\\ n+ & (n-1)+ & \cdots & 1 \end{array}\right) \\=\frac{1}{3}\left(\begin{array}{cccc} (2n+1)+\\ (2n+1)+ & (2n+1)+\\ \vdots & & \ddots\\ (2n+1)+ & (2n+1)+ & \cdots & (2n+1) \end{array}\right) \\=\frac{1}{3}(1+2+\cdots+n)(2n+1) \\=\frac{1}{3}\frac{n(n+1)}{2}(2n+1) $$