# Is my derivation of the summation formula of the first squares correct?

I have been thinking about the problem of finding the sum of the first squares for a long time and now I have an idea how to do it. However, the second step of this technique looks suspicious.

1. $$\sum_{i=1}^n i = \frac{n^2+n}{2}$$

2. $$\int\sum_{i=1}^{n}idi=\int\frac{\left(n^{2}+n\right)}{2}dn$$

3. $$\sum_{i=1}^{n}\left(\frac{i^{2}}{2}+C_{1}\right)=\left(\frac{n^{3}}{3}+\frac{n^{2}}{2}\right)\cdot\frac{1}{2}+C_{0}$$

4. $$\sum_{i=1}^{n}i^{2}=\frac{n^{3}}{3}+\frac{n^{2}}{2}-2nC_{1}+2C_{0}$$

5. Assuming $$C_{0}=0$$. Next, we are going to find the constant $$C_{1}$$

6. From step 4, we can conclude that: $$C_{1}=\frac{n^{2}}{6}+\frac{n}{4}-\sum_{i=1}^{n}\frac{i^{2}}{2n}$$. We can fix $$n$$, at any value, it is more convenient to take one($$n=1$$) then $$C_{1}=-\frac{1}{12}$$

7. $$\sum_{i=1}^{n}i^{2}=\frac{n^{3}}{3}+\frac{n^{2}}{2}+\frac{n}{6}$$

Using the induction method, we can prove the correctness of this formula and that the value of the constant $$C_{0}$$ is really zero. But I created this question because the second step looks very strange, since the left part was multiplied by differential $$di$$, and the right by $$dn$$. If we assume that the second step is wrong, then why did we get the correct formula of summation of first squares?

Note: The technique shown based on the integrated one is really interesting for me, using the same reasoning we can get the formula of the first cubes and so on

EDIT1

According to @DatBoi's comment, we can calculate constants $$C_{0}$$ and $$C_{1}$$ by solving a system of linear equations. The desired system must contain two equations, since we have two unknown values($$C_{0}$$ and $$C_{1}$$). To achieve this, we need to use the right part of the statement from step 4 twice, for two different n. For simplicity, let's take $$n=1$$ for first equation and $$n=2$$ for second equation, then the sum of the squares for these $$n$$ is 1 and 5, respectively.

1. The main system $$\left\{ \begin{array}{c} \frac{1}{3}+\frac{1}{2}-2C_{1}+2C_{0}=1 \\ \frac{8}{3}+\frac{4}{2}-4C_{1}+2C_{0}=5 \\ \end{array} \right.$$
2. After simplification $$\left\{ \begin{array}{c} \ C_{0}-C_{1}=\frac{1}{12} \\ \ C_{0}-2C_{1}=\frac{1}{6} \\ \end{array} \right.$$
3. Roots: $$C_{0}=0$$ and $$C_{1}=-\frac{1}{12}$$

EDIT2

Considering @epi163sqrt's answer, the second step should be changed and it will take this form:

1. $$\sum_{i=1}^{n}\int_{ }^{ }idi=\int_{}^{}\frac{\left(n^{2}+n\right)}{2}dn$$

My hypothesis. If we have: $$\sum_{i=1}^{n}i^{p}=f\left(n,p\right)$$ Where $$f$$ is a closed form for summation, then this should be true for any natural degree

$$\sum_{i=1}^{n}\int_{}^{}i^{p}di=\int_{}^{}f\left(n,p\right)dn\ \to\ \sum_{i=1}^{n}\frac{i^{\left(p+1\right)}}{p+1}=\int_{}^{}f\left(n,p\right)dn-nC_{1}$$ Can you prove or disprove this hypothesis? My questions above are no longer relevant

EDIT3. Time for fun. Let's try to get a formula for summing the first cubes

1. $$\sum_{i=1}^{n}i^{2}=\frac{n^{3}}{3}+\frac{n^{2}}{2}+\frac{n}{6}$$

2. $$\sum_{i=1}^{n}\int_{ }^{ }i^{2}di=\int_{ }^{ }\frac{n^{3}}{3}+\frac{n^{2}}{2}+\frac{n}{6}dn$$

3. $$\sum_{i=1}^{n}\frac{i^{3}}{3}=\frac{n^{4}}{12}+\frac{n^{3}}{6}+\frac{n^{2}}{12}-nC_{1}+C_{0}$$

4. $$\left\{ \begin{array}{c} \frac{1}{4}+\frac{1}{2}+\frac{1}{4}-3C_{1}+3C_{0}=1 \\ \frac{16}{4}+\frac{8}{2}+\frac{4}{4}-6C_{1}+3C_{0}=9 \\ \end{array} \right.$$ Roots: $$C_{0}=0$$ and $$C_{1}=0$$

5. $$\sum_{i=1}^{n}i^{3}=\frac{n^{4}}{4}+\frac{n^{3}}{2}+\frac{n^{2}}{4}$$

GREAT EDIT4 19.01.2022

So far I have no proof, however, the calculation of constants($$C_{0}$$ and $$C_{1}$$) can be significantly simplified by changing the lower index of summation to 0.

1b. Let $$M_{p}(n)$$ be a closed form to obtain the summation, with degree of $$p$$. I. e. $$\sum_{i=0}^{n}i^{p}=M_{p}\left(n\right)$$

2b. Now let's assume that the statement written below is true $$\sum_{i=0}^{n}\int_{ }^{ }i^{p}di=\int_{ }^{ }M_{p}\left(n\right)dn$$

3b. For now, we'll just take the integrals. $$\sum_{i=0}^{n}\left(\frac{i^{p+1}}{p+1}+C_{1}\right)=\int_{ }^{ }M_{p}\left(n\right)dn$$

4b. Now let's express the sum explicitly. Also, we will move the $$C_{1}$$ without changing its sign, this is a valid action, since multiplying the constant by (-1) leads to another constant $$\sum_{i=0}^{n}i^{p+1}=\left(\int_{ }^{ }M_{p}\left(n\right)dn+nC_{1}\right)\left(p+1\right)$$

5b. So we got the recurrent formula: $$M_{p}(n) = \left(\int_{ }^{ }M_{p-1}\left(n\right)dn+nC_{p}\right)p$$ $$M_{0}(n) = n+1$$

6b. Now we have to build and resolve a system for two unknown constants. Therefore, the number of equations is two, we are also going to take n=0 and n=1: $$\left\{ \begin{array}{c} M_{p}(0)=0 \\ M_{p}(1)=1 \end{array} \right.$$ 7b. As I said, we have two constants. In order to see this, we will add a new definition for $$W_{p-1}(n)$$ that satisfies the following expression: $$\int_{ }^{ }M_{p-1}\left(n\right)dn=W_{p-1}\left(n\right)+C_{-p}$$. $$\left\{ \begin{array}{c} \left(W_{p-1}\left(0\right)+C_{-p}+0C_{p}\right)p=0 \\ \left(W_{p-1}\left(1\right)+C_{-p}+1C_{p}\right)p=1 \end{array} \right.$$

8b. I will skip the formal proof of the fact, but the intuition is that $$W_{p}(n)$$ is a polynomial that does not have a constant term. Therefore, we can safely know that $$W_{p}(0)=0$$. let's rewrite and simplify the system:

8b.1. $$\left\{ \begin{array}{c} \left(C_{-p}\right)p=0 \\ \left(W_{p-1}\left(1\right)+C_{-p}+C_{p}\right)p=1 \end{array} \right.$$

8b.2. $$\left\{ \begin{array}{c} C_{-p}=0 \\ \left(W_{p-1}\left(1\right)+C_{p}\right)p=1 \end{array} \right.$$

8b.3 $$C_{p}=\frac{1}{p}-W_{p-1}\left(1\right)$$

9b. We have completed the study of the constant. The last action is to match everything together. $$M_{p}\left(n\right)=p\left(\left(\int_{ }^{ }M_{p-1}\left(n\right)dn\right)_{n}-n\left(\int_{ }^{ }M_{p-1}\left(n\right)dn\right)_{1}\right)+n$$ $$M_{0}(n) = n+1$$

10b. (New step 29.04.2022) The previous step was not recorded correctly. I will also proceed to the calculation of definite integrals: $$M_{p}(n) = \begin{cases} n+1, & \text{if p is zero } \\ p\int_{0}^{n}M_{p-1}\left(t\right)dt-np\int_{0}^{1}M_{p-1}\left(t\right)dt+n, & \text{otherwise} \end{cases}$$

• Very interesting. A minor nitpick: you could actually prove that $C_0$ is zero by solving the system of equations in $C_0,C_1$ that you obtain by substituting two $n$s Dec 20, 2021 at 13:26
• @DatBoi Thanks. This is a useful comment for me Dec 20, 2021 at 14:21
• My first observation is that step 2 can't possibly work for all sums. Consider $$\sum_{i=1}^n i \cos(2\pi i) = \frac{n(n+1)}{2}.$$ Here, the RHS stays the same (and is cubic in $n$) but the LHS becomes $$\sum_{i=1}^n \int i \cos(2\pi i)\,di = \sum_{i=1}^n \left(\frac{\cos(2\pi i)+ i \sin (2\pi i)}{4\pi^2}+C\right) = \sum_{i=1}^n \left(\frac1{4\pi^2}+C\right).$$ These can't possibly be equal for all $n$, even with the right constants. Dec 20, 2021 at 15:55
• However, experimentally, step 2 seems to work for many sums that aren't specifically designed to make it fail? Up to the constants, it's true according to Mathematica for all polynomials, and even for weird things like integrating both sides of $$\sum_{i=1}^n \log i = \log \Gamma(n+1).$$ Dec 20, 2021 at 16:00
• @MishaLavrov Thanks. I think it will be useful if you publish your code for Mathematica. Just provide link to github or other service Dec 20, 2021 at 16:15

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*}

• I agree on the note about variable scope. In fact, your answer integrate the closed formula. It does not follow from this that the resulting expressions summarize the first squares Dec 20, 2021 at 21:03
• @PavelDev: I agree. Dec 20, 2021 at 21:04
• @epi163sqrt from the answer, what I interpret is that it makes no sense to call the result, by integrating the LHS, the sum of squares. However im afraid it doesnt explain why this actually works for many cases, as noticed in the comments. Dec 21, 2021 at 5:25
• @DatBoi: I've added some information providing a relation between sums and integrals. Dec 21, 2021 at 7:14
• @epi163sqrt the new info is very intriguing. Its quite unfortunate that it would take me some time to get to that level of mathematics to completely understand that :P Dec 21, 2021 at 12:37

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)$$

• @bonson: This approach was actually already known to the ancient greek. They used gnomons to show the relationship as indicated in this answer. Dec 21, 2021 at 20:04

After 4 months, I suspect that the proof of this assumption is very simple. Currently, this answer is a draft, but it will demonstrate all the necessary ideas to generalize to an arbitrary case. We will start with the next special case:

1. $$\sum_{i=1}^{n}i=\frac{n^{2}+n}{2}$$

2. To perform the integration operation, we will add the function variable $$x$$: $$\sum_{i=1}^{n}\left(x+i\right)=\frac{\left(n+x\right)^{2}+\left(n+x\right)-x^{2}-x}{2}$$

3. Now we can actually perform the integration of both parts with respect to the variable $$x$$: $$\int_{ }^{ }\sum_{i=1}^{n}\left(x+i\right)dx=\int_{ }^{ }\frac{\left(n+x\right)^{2}+\left(n+x\right)-x^{2}-x}{2}dx$$

4. $$\sum_{i=1}^{n}\left(\frac{\left(x+i\right)^{2}}{2}+C_{1}\right)=\frac{\frac{\left(n+x\right)^{3}}{3}+\frac{\left(n+x\right)^{2}}{2}-\frac{x^{3}}{3}-\frac{x^{2}}{2}+C_{0}}{2}$$

5. Now we just assume that $$x=0$$ and move $$C_1$$ to right side: $$\sum_{i=1}^{n}i^{2}=\frac{n^{3}}{3}+\frac{n^{2}}{2}+2nC_{1}+C_{0}$$

6. After solving a system of two equations (for details, see my question), we get $$C_0=0, C_1=\frac{1}{12}$$, the formula for summation of first squares is equivalent: $$\sum_{i=1}^{n}i^{2}=\frac{n^{3}}{3}+\frac{n^{2}}{2}+\frac{n}{6}$$

Note section:

This proof looks correct, but contains a few oddities:

1. In the second step, the right part of the expression was not specially simplified. Otherwise, it would have affected the integration result and probably the presented proof was not completed.

2. In step 4, when integrating the left part, we should use only this result: $$\int_{ }^{ }\left(x+i\right)dx=\frac{\left(x+i\right)^{2}}{2}$$. However, it can be writteln in another way: $$\int_{ }^{ }\left(x+i\right)dx=\frac{x^{2}}{2}+ix$$. Relative integration rules, two answers is correct, but choosing the second option would not give the desired results.