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

If you were to take the following for-loop:

for (int i = 1; i <= 50; i++) {}

And write it in mathematical form, it would look something like this:

Each interval of the above sequence would be the same as each interval i of the above for-loop

the $50$ is the maximum number, the "$i=0$" is the starting point, but what about the iterations. all of them seem to have to do with $i$ being the current index of the sequence.

How would I write something that has iterations that are greater than one?


Is there a way of writing this:

for (int i = 1; i <= 50; i += 3) {}

in summation form?

share|cite|improve this question
$\sum f(1+3k)$, where the sum is over all $k$ such that $1 \le 1+3k \le 50$. Actually, your loop doesn't sum anything, it just increments $i$ until it reaches (or exceeds) $50$. – GEdgar May 4 '12 at 17:23
How is a for-loop with no action in any way "equivalent" to a summation over all integers from $1$ to $50$? – TMM May 4 '12 at 17:27
@TMM - System.out.println(i); – Ephraim May 4 '12 at 17:28
@Ephraim: Then your algorithm prints 1 2 3 ... 50 while $\sum_{i=1}^{50} i \equiv 1275$. – TMM May 4 '12 at 17:30
@TMM - I was referring to to each interval of interval of the sequence, not the actual final summation. but if you want it to be the summation, I would just add int v = 0; above the loop, v +=1 inside of the loop, and and system.out.println(v); after the loop. But the point of my question is still the same. – Ephraim May 4 '12 at 17:33
up vote 2 down vote accepted

To get a sequence of integers with a gap of $d$ and a starting point of $a$, you want $kd+a$ for $k=0,1,2,\dots$. In your example that would be $3k+1$ for $k=0,1,2,\dots$. Thus, you your summation is $$\sum_{k=0}^nx_{3k+1}=x_1+x_4+x_7+\ldots+x_{3n+1}\;.$$ (I'm using $x$ as the generic name of whatever you're summing.)

Now you want to find the right $n$. Here you want $3n+1$ to be as large as possible while not exceeding $50$. $3n+1\le 50$ if and only if $3n\le 49$ if and only if $n\le\frac{49}3$, but you want $n$ to be an integer, so $n=16$: $$\sum_{k=0}^{16}x_{3k+1}\;.$$

In general, if the upper limit on the subscript is $L$, you'll want $n=\left\lfloor\frac{L}d\right\rfloor$.

share|cite|improve this answer

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.