# Formula for periodic sequence with increasing period

The first values of the sequence are: $\lt1, 0, 1, 1, 0, 0, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0\gt$

Taking out the first two values the following subsequence is obtained: $\lt1, 1, 0, 0, -1, -1, -1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0\gt$

Which has the following pattern: $m$ 1's followed by $m$ 0's, followed by $(m + 1)$ -1's and $(m + 1)$ 0's, followed by $(m + 2)$ 1's and $(m + 2)$ 0's .... and so on.

If someone can find the general term of the sequence it would be great, or even defining it recursively would help a lot.

I've read these questions about periodic functions. However, they are about sequences with fixed period: Formula for a periodic sequence of 1s and -1s with period 5 and Defining a Perplexing Two-Dimensional Sequence Explicitly

This looks like a rounded form of a $\sin$ function, except that the period of oscillation is increasing. So instead of $\sin (n)$ the function needs to be $\sin(f(n))$.

I needed some names for the sequence so I have named the sequence $A_n$ after you. We have $A_1=1$, $A_2=1$, $A_3=0$, $A_4=0$, $A_5=-1$, etc.

I started by looking at the points where the sequence changes from $0$ to $1$. Because this happens between terms of the sequence, I gave these points fractional values of $n$. They occur at $A_{0.5}$, $A_{10.5}$, $A_{28.5}$, $A_{54.5}$, etc.

I called the identified values of $n$ the "critical values" and labelled them $\hat n$ where $\hat n_1=0.5$, $\hat n_2=10.5$, $\hat n_3=28.5$, $\hat n_4=54.5$, etc.

It was easy to see find a formula for the generalised critical value $\hat n_p=4p^2-2p-1.5$

This can be rearranged as $4p^2-2p-1.5-\hat n_p=0$, which has positive roots :

$$p=\frac{2+\sqrt{4-4 \times 4 \times (-1.5-\hat n_p)}}{8}$$

$$p=\frac{2+\sqrt{28+16\hat n_p}}{8}$$

$$p=\frac{1+\sqrt{7+4\hat n_p}}{4}$$

You will recall that the critical points were where the value of the sequence changed from $0$ to $1$. In terms of rounding, the boundary between $0$ and $1$ is at $\frac 12$.

The $\sin(f(n))$ function passes through the value $\frac 12$ on its journey from $0$ to $1$ for $f(n) = \frac \pi 6$, $f(n) = \frac {13\pi} 6$, $f(n) = \frac {25\pi} 6$, or more generally $f(\hat n_p) = \frac {(12p-11)\pi} 6$.

We can substitute our expression $p=\frac{1+\sqrt{7+4\hat n_p}}{4}$ to get:

$$f(\hat n_p) = \frac {\left(12 \frac{1+\sqrt{7+4\hat n_p}}{4} -11 \right)\pi} 6$$

$$f(\hat n_p) = \frac {\left(3 +3\sqrt{7+4\hat n_p} -11 \right)\pi} 6$$

So $$f(\hat n_p) = \frac {\left(3\sqrt{7+4\hat n_p} -8 \right)\pi} 6$$

We want a relationship that is true at all values of $n$, not just at the $\hat n_p$,

so $$f(n) = \frac {\left(3\sqrt{7+4n} -8 \right)\pi} 6$$

and the whole thing is $$\sin \left(\frac {\left(3\sqrt{7+4n} -8 \right)\pi} 6 \right)$$

Round the values to the nearest whole number and you will have your sequence.

On more careful inspection by Augusto, it turned out that my answer was not quite right, so I started again:

This time I started by looking at the points where the sequence changes from $1$ to $0$ or from $-1$ to $0$. They occur at $A_{2.5}$, $A_{7.5}$, $A_{14.5}$, $A_{23.5}$, etc.

Once again I called the identified values of $n$ the "critical values" and labelled them $\hat n$ where $\hat n_1=2.5$, $\hat n_2=7.5$, $\hat n_3=14.5$, $\hat n_4=23.5$, etc.

It was easy to see find a formula for the generalised critical value $\hat n_p=p^2-2p-0.5$

This can be rearranged as $p^2-2p-0.5-\hat n_p=0$, which has positive roots :

$$p=\frac{2+\sqrt{4-4 \times 1 \times (-0.5-\hat n_p)}}{2}$$

$$p=\frac{2+\sqrt{6+4\hat n_p}}{2}$$

$$p=1+\sqrt{\frac 32 +\hat n_p}$$

Now the critical points are where the value of the sequence changed from $1$ to $0$. In terms of rounding, the boundary between $1$ and $0$ is at $\frac 12$ and the boundary between $-1$ and $0$ is at $-\frac 12$.

The $\sin(f(n))$ function passes through the values $\frac 12$ and $-\frac 12$ for $f(n) = \frac {5 \pi} 6$, $f(n) = \frac {11\pi} 6$, $f(n) = \frac {17\pi} 6$, or more generally $f(\hat n_p) = \frac {(6p-1)\pi} 6$.

We can substitute our expression $p=1+\sqrt{\frac 32 +\hat n_p}$ to get:

$$f(\hat n_p) = \frac {\left(6 \left (1+\sqrt{\frac 32 +\hat n_p} \right) -1 \right)\pi} 6$$

$$f(\hat n_p) = \frac {\left(6 +\sqrt{54 +36 \hat n_p} -1 \right)\pi} 6$$

$$f(\hat n_p) = \frac {\left(5 +\sqrt{53 +36 \hat n_p} \right)\pi} 6$$

so $$f(n) = \frac {\left(5 +\sqrt{53 +36 n} \right)\pi} 6$$

and the whole thing is $$\sin \left(\frac {\left(5 +\sqrt{53 +36 n} \right)\pi} 6\right)$$

Try that!

I tried it myself - still not quite right!

• Thanks for the clue Tomi, I'm working on the 'f(kn)' part, looks pretty hard. Nov 13, 2015 at 13:19
• Great work! I am learning a lot with your solution! however, it is not the same sequence, your formula generates the following: Nov 21, 2015 at 22:24
• Great work! I am learning a lot with your solution! however, your formula generates a different sequence <0, 1, 1, 0, 0, -1, -1, -1, -1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1> Nov 21, 2015 at 22:33
• I am thinking about using your solution to get a formula for the sequence only with 1's and 0's and another only with -1's and 0's, then the resulting sequence would be the addition of both. Nov 21, 2015 at 22:38