Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

Possible Duplicate:
How to convert this loop into a closed form expression?

I have the following code in Python

    for x in range(lowerBound,upperBound+1,2):

This iterates from x=lowerBound to the maximum value of x=upperBound (going by intervals of 2 at a time), tossing the value of $\lfloor(x^3+5x)/3\rfloor+2$ into the total (all division is floor division in Python unless using decimals, which I'd like to avoid if possible for precision's sake).

How can I convert this to a closed form expression?

share|improve this question

marked as duplicate by joriki, Martin Argerami, copper.hat, mixedmath Nov 26 '12 at 6:46

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

up vote 0 down vote accepted

What you want is, for $L$ and $U$ gotten from your lower and upper bounds, $S = \sum_{x=L}^U \lfloor((2x)^3+5(2x))/3\rfloor+2$.

mod 3, $x^3+5x = x^3-x = x(x-1)(x+1)$, and one of these is always divisible by 3, so we can ignore the floor. You can also argue that $x^3+5x = 0, 6, $ and $18$ for $x = 0, 1, $ and $2$.

The $2$ contributes $2(U-L+1)$, so it will also be ignored.

We are left with $T = \sum_{x=L}^U ((2x)^3+5(2x))/3 = (1/3)\sum_{x=L}^U 8x^3+10x $.

Applying the usual formulae for the sums of integers and cubes will give you the answer.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.