Here are some pretty mathematical identities that I found while trying to answer a programming question. Let’s say you want to find a sum of the following form:
Or, in other words, you want to find:
Now, the boring and slow way of doing this would be to write a computer program to iterate through all those possibilities and sum the results. But there’s a way we can calculate that result directly, without doing all those multiplies and adds.
First, let’s get some intuition as to what form a solution to this problem might take. Now an integral is not exactly the same as a finite sum, but the two are related. For a monotonically increasing finite sum like the one above, the definite integral from 0 to n might resemble the formula we’re looking for:
Now we’re not lucky enough to have this ballpark estimate be equal to the answer. However, this estimate gives us a hint that we might be able to find a solution in the form of a cubic polynomial of n:
So let’s start by manually calculating the first few answers to equation 1:
Plugging these answers back into equation 1 we get:
Which we can immediately simplify to:
Now before we begin solving this particular system of equations, just look at the first one, which has all of a, b, and c being multiplied by 0. So they can have no effect on the result of the equation, regardless of n. Therefore we know, without doing any real work, that:
Plugging in zero for d, back into the system of equations, simplifies things a little more for us:
Okay, so we have reduced the problem to finding the three unknowns a, b, and c. Now there are a bunch of ways we can solve this system of simultaneous equations. Good old fashioned algebra works here, but we just have to be patient with carefully shuffling symbols around. From equations 3 and 4:
And from equations 4 and 5:
Now — coming into the home stretch — from equations 6 and 7:
Finally! Now we have values for a and d. Now we can solve for b, from equation 6:
And from equation 3, we can get c:
So we’ve figured out all the coefficients for the simultaneous equations:
And we can insert those into equation 2 to find the characteristic equation, and hence we discover a couple pretty identities:
Now that’s one way to do it. But this identity can be proven in multiple other ways.