# Is there a formula for the pattern $1,1,1,0,1,0,1,0,1,0\ldots$? Or a mathematical principle?

Starting from $n= 0$:

$1,1,1,0,1,0,1,0,1,0\ldots$

The $0,1,0,1$ pattern keeps on going. Is there a formula for this?

• In the framework of automata and formal languages, it is a regular language. Therefore you can express it as a regular expression. BTW I am not sure, it is what you are asking for. Jun 22, 2017 at 7:26
• The generating function is $\dfrac{1}{1-x^2}+x$ i.e. $\dfrac{1+x-x^3}{1-x^2}$ Jun 22, 2017 at 7:27
• These are the bits of the binary expansion of $0.\overline{1}_2 + 0.01_2 = \frac{2}{3} + \frac{1}{4} = \frac{11}{12}$. Jun 22, 2017 at 16:14

$$\frac{1099}{9900} = 0.111010101\dots$$

• If we interpret $0, 1$ as bits rather than digits, the result is even nicer $0.11\overline{10}_2 = \frac{11}{12}$. Jun 22, 2017 at 16:15
• To generalize this, if $n_1$ is a $d_1$-digit natural number and $n_2$ is a $d_2$-digit natural number, then $\dfrac{1}{10^{d_1}} \left( n_1 + \dfrac {n_2} {10^{d_2} - 1} \right) = 0.n_1\overline{n_2}$. Jun 23, 2017 at 20:45

You could define it this way: $$n_k=\begin{cases}1, &\text{ if }k=0,1\\ \frac{1}{2}\left((-1)^k+1)\right),&\text{ if }k\ge 2\end{cases}.$$ Or if you want a completely closed formula, you could use $$n_k=\frac{1}{2}\left(1-\frac{1}{2}\big(1-(-1)^{k!}\big)\right)\big((-1)^k+1\big)+\frac{1}{2}\big(1-(-1)^{k!}\big).$$

I actually figured out a better formula. Try $$n_k=\frac{1}{2}\left(1+(-1)^k\right)+\left(1-\frac{1}{2}\left(1+(-1)^{k\cdot k!}\right)\right).$$ Note that the first term describes the sequence $1 , 0, 1, 0, \dots$ while the second term describes the sequence $0,1,0,0,0,0,\dots$. So, adding gives $1,1,1,0,1,0,1,0,\dots$.

• A much simpler formula is $1 - \frac{1}{2}\left((-1)^{nn!} - (-1)^{n}\right)$.
– orlp
Jul 3, 2017 at 3:08
• @orlp. That's the second formula I gave. Jul 4, 2017 at 0:41

Try this one:

\begin{align} f(n)&= 1-\operatorname{sgn}(n-1)\cdot(n\bmod2) \end{align}

Edit

Here

The function $f$ works as follows:

for all even $n\ge0$ we have $(n\bmod2)=0$, hence $f(n)=1-\operatorname{sgn}(n-1)\cdot0=1$;

for $n=1$ the term $\operatorname{sgn}(n-1)=0$, hence $f(n)=1-0\cdot(n\bmod2)=1$;

and for all odd $n>1$, $f(n)=1-\operatorname{sgn}(n-1)\cdot(n\bmod2)=1-1\cdot1=0$.

Edit2

More exotic function that produces the same output as $f$ for $x=0,1,2,\dots$:

\begin{align} g(x)&= 1+\sin \left( \tfrac\pi2\,\cos(\tfrac\pi2\,x) -\arctan(x-1) -\tfrac12\,\arcsin\left({\tfrac{2\,(x-1)}{{x}^{2}-2\,x+2}}\right) \right) . \end{align}

orlp's answer, ${1099\over9900} =0.111010101…$, uses decimal arithmetic to produce the desired sequence (as digits of a number). A similar result, but using base 2, is as follows:

$$0.111010101…_2 = {1\over4}+0.101010101…_2= {1\over4}+ {1\over2}\sum\limits_{j=0}^\infty({1\over4})^j ={1\over4}+ {1\over2}\times {4\over3}= {11\over12}$$

That is, the binary representation of base-10 fraction ${11\over12}$ is $0.111010101…_2$.

The Online Encyclopedia of Integer Sequences has a few interesting results, including http://oeis.org/A266591:

"Middle column of the "Rule 37" elementary cellular automaton starting with a single ON (black) cell."

The formula of the sequence is $$a_n=\begin{cases} 0, &\text{ if }n \text{ is odd and }n \neq 1 \\ 1,&\text{ if }n \text{ is even or } n=1 \end{cases}.$$ That's all. There is no simpler formula. You could replace "$\text{if }n \text{ is even or } n=1$" by "$\text{otherwise}$", if you prefer that notation. Trying to write this without a case split makes things unnecessary complicated. Interpreting the sequence as digits of a number, as some answers do, only makes sense if you know that the sequence actually represents digits of a number. The pattern is simply too basic to have a deeper meaning.