There´s a very common finite series, that use to be, at the begining on every book:

$latex \displaystyle S_{n}(z)=\sum _{k=0}^n z^k =\frac{z^{n+1}-1}{z-1}$

Where $latex z$ can be real or complex.

There is a, very well known, particular case of this series where $latex z=2$:

$latex \displaystyle S_{n-1}(2)=\sum _{k=0}^{n-1} 2^{k} =2^{n}-1=M_n$

$latex \displaystyle M_n$ are the

Mersenne Numbers, and due to this sum, is easy to see that the

**Mersenne numbers** consist of all 1s in base-2 (they are base 2

repunits)

But this entry is about another particular case of this finite sum:

$latex \displaystyle S_{n}(\textbf{i})=\sum _{k=0}^{n} \textbf{i}^k$

Where: $latex \textbf{i}=\sqrt{-1}$, is the complex unit.

$latex \displaystyle S_{n}( \textbf{i} ) =\frac{1}{2}(1+\textbf{i}) \left(1-\textbf{i}^{n+1}\right)$

This sum shows periodical behaviour with a period of $latex 4$, and its values changes from one vertex to another in a square of side equal to $latex 1$, if we plot them in the complex plane:

$latex \displaystyle S_{n}( \textbf{i} )=\{1,1+\textbf{i},\textbf{i},0,1,1+\textbf{i},\textbf{i},...\}$

$latex \displaystyle S_{n}(\textbf{i})=1\;$ if $latex \;n\equiv 0\;mod\;4$

$latex \displaystyle S_{n}(\textbf{i})=1+\textbf{i}\;$ if $latex \;n\equiv 1\;mod\;4$

$latex \displaystyle S_{n}(\textbf{i})=\textbf{i}\;$ if $latex \;n\equiv 2\;mod\;4$

$latex \displaystyle S_{n}(\textbf{i})=0\;$ if $latex \;n\equiv 3\;mod\;4$

If we take a look at the real part of the complex number $latex S_{n}(\textbf{i})$:

$latex \displaystyle Re\bigg(\sum _{k=0}^{n} \textbf{i}^k\bigg)=\{1,1,0,0,1,1,0,0,...\}$

Then we had just found the sequence

A133872 from OEIS, and then we can construct another expressions for this sequence, and also for the problem series:

$latex \displaystyle A133872(n)=Re\bigg(\sum _{k=0}^{n} \textbf{i}^k\bigg)$

$latex \displaystyle A133872(n)=\frac{1}{2}\bigg(\sum _{k=0}^{n} \textbf{i}^k + \sum _{k=0}^{n} \textbf{i}^{-k}\bigg)$

$latex \displaystyle A133872(n)=\frac{1}{2}+\frac{1}{2} \text{cos}\left(\frac{n \pi }{2}\right)+\frac{1}{2} \text{sin}\left(\frac{n \pi }{2}\right)$

Then, if we expand to trigonometrical functions $latex S_{n}( \textbf{i} )$:

$latex \displaystyle S_{n}( \textbf{i} ) =\left(\frac{1}{2}+\frac{1}{2} \text{cos}\left(\frac{n \pi }{2}\right)+\frac{1}{2} \text{sin}\left(\frac{n \pi }{2}\right)\right) + \textbf{i} \left( \frac{1}{2}-\frac{1}{2} \text{cos}\left(\frac{n \pi }{2}\right)+\frac{1}{2} \text{sin}\left(\frac{n \pi }{2}\right)\right)$

And finally using the information inside OEIS:

$latex \displaystyle S_{n}( \textbf{i} )= \text{mod}\left(\bigg\lfloor\frac{n+2}{2}\bigg\rfloor,2\right)+ \textbf{i}\cdot \text{mod}\left(\bigg\lfloor\frac{n+1}{2}\bigg\rfloor,2\right)\cdot \textbf{i}$

**References:**[1]-A133872-Period 4: repeat 1,1,0,0. The On-Line Encyclopedia of Integer Sequences!