# Mike's Toolbox

## Sum of Consecutive Powers

In mathematics, a frequently occurring computation is to find the sum of consecutive powers of a number. For example, we may need to find the sum of powers of a number x:

Sum = x5 + x4 + x3 + x2 + x + 1

Recall that a power such as x3 means to multiply 3 x's together (3 is called the exponent):

x3 = x · x · x

If you knew the value of x, it would be possible to compute all of the powers and add them together to find the sum. For example, if x had the value 2, Sum would be:

 Sum = 25 + 24 + 23 + 22 + 2 + 1 = 32 + 16 + 8 + 4 + 2 + 1 = 63

Even though it is possible to compute the sum as just shown, it is both tedious and error prone. Fortunately there is a compact equation that computes the sum without needing to calculate all of the powers. To derive the formula, we just need to notice what happens when we multiply both sides of the original equation by x:

 Sum · x = (x5 + x4 + x3 + x2 + x + 1) · x = x6 + x5 + x4 + x3 + x2 + x

All of the exponents increased by one. Notice that most of the terms on the right side of the equation are the same as in the original Sum above. In fact, they are all there except for the value 1, so let's add one to both sides:

 Sum · x + 1 = x6 + x5 + x4 + x3 + x2 + x + 1 = x6 + (x5 + x4 + x3 + x2 + x + 1) = x6 + Sum

We can rearrange this equation so that all terms containing Sum end up on the left side:

Sum · (x − 1) = x6 − 1

Dividing both sides by (x − 1) gives us a nice compact formula for the sum of consecutive powers of a number:

 Sum = x6 − 1 x − 1

Note that the power in the compact formula is just one more than the highest power in the sum that you are trying to determine. If we evaluate the equation with x set equal to 2 we see that it computes the correct answer:

 Sum = 26 − 1 = 64 − 1 = 63 2 − 1 1

One caveat to this is that the equation does not work when x = 1. This is because we divided both sides of the above equation by (x − 1). When x = 1, this term evaluates to zero, and you can't divide by zero. Fortunately it is easy to see what the value of the Sum would be if x was equal to one. Each of the powers in the Sum evaluate to 1, so the Sum is just the number of terms added together, which in this case would be 6, or one more than the highest exponent in the Sum.