Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a loop that iterates a variable $i$ from 0 to some boundary $b$. Let $p=4i+4$. Each iteration of the loop I add $(p^3+5p)/3+2$ to a sum variable $s$ which is initially set to 0.

Question: Instead of this loop, how can I convert this all into a closed form expression that gives me the same $s$ based on the value of $b$?

share|cite|improve this question
up vote 2 down vote accepted

In the end of the loop, if I understand correctly, you have: $$\begin{align*}s&=\sum_{i=0}^b \left(\frac{(4i+4)^3+5(4i+4)}{3}+2\right)=\sum_{i=0}^b \left(4\frac{16i^3+48i^2+53i+21}{3}+2\right)\\&=\frac{64}{3}\sum_{i=0}^b i^3+64\sum_{i=0}^b i^2+\frac{212}{3}\sum_{i=0}^b i+30\sum_{i=0}^b 1 \end{align*}$$ Using the formulas (which you can prove by induction, if you want): $$\sum_{i=0}^b 1=b+1, \hspace{10pt} \sum_{i=0}^b i=\frac{b(b+1)}{2}, \hspace{10pt} \sum_{i=0}^b i^2=\frac{b(b+1)(2b+1)}{6}, \hspace{10pt} \sum_{i=0}^b i^3=\frac{b^2(b+1)^2}{4}$$ You can get: $$\begin{align*}s&=\frac{64}{3}\frac{b^2(b+1)^2}{4}+64\frac{b(b+1)(2b+1)}{6}+\frac{212}{3}\frac{b(b+1)}{2}+30(b+1)\\&=\frac{16}3 b^4+32 b^3+\frac{218}3 b^2+76 b+30=\frac23(b+1)(8 b^3+40 b^2+69 b+45)\end{align*}$$

share|cite|improve this answer
This is not technically a closed form expression. Closed form means the only variable involved should be $b$, without loops. $i$ is an iterator variable that only makes sense in the context of a loop. – MyNameIsKhan Nov 26 '12 at 23:36
How is that not a closed form? – Dennis Gulko Nov 26 '12 at 23:42
I made that comment before your final edit; checking it now – MyNameIsKhan Nov 26 '12 at 23:43
Is there any way to generalize this to arbitrary p (maybe in another equation p=5i+6 instead, etc)? I'll accept this as answer anyway in the meantime, just curious – MyNameIsKhan Nov 26 '12 at 23:47
As you can see, you can expand the way i did in the beginning until you can use the formulas I mentioned. Try to do what I did for $p=5i+6$ (just open the parenthesis). There is no 'magic' formula where you can just plug-in $p$ and have an answer without some computations. – Dennis Gulko Nov 26 '12 at 23:53

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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