Recassim Succession¶
Let’s consider an infinite mathematical succession defined for a given \(a_0 \geq 0\) by the following recursive rules:
\[\begin{split}a_i=
\begin{cases}
a_0, &\mbox{if } i = 0
\\
a_{i-1} - i, &\mbox{if } t = (a_{i-1}-i) \mbox{ is such that } t>0 \mbox{ and } t \mbox{ does no belong to the succession so far.}
\\
a_{i-1} + i, &\mbox{otherwise}
\end{cases}\end{split}\]
for all \(i \geq 0\). For instance, given \(a_0 = 0\) the initial terms of the succession are: $$ 0,1,3,6,2,7,13,20,12,21,11,⋯ $$
Observe that, on the one hand the 3rd term is 6 since the 2nd term is 3 and 3-3 is not >0 therefore \(t_3 = 3+3 = 6\). On the other hand, \(t_4 = 2\) since \(t_3−4 = 2\).
The next image graphically shows the first 100 terms for \(a_0 = 0\):
Please implement the following Python function in the recassim module (recassim.py file):
- : recassim(a0, n):
such that
For example,
>>> recassim(0, 1)
1
>>> recassim(0, 7)
5
>>> recassim(0, 20)
7
Doctests are available at the recassim.test file.