# How to convert this into a single closed form?

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

-

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