# Rudin–Shapiro sequence

In mathematics, the Rudin–Shapiro sequence, also known as the Golay–Rudin–Shapiro sequence, is an infinite 2-automatic sequence named after Marcel Golay, Harold S. Shapiro, and Walter Rudin, who investigated its properties.

## Definition

Each term of the Rudin–Shapiro sequence is either $1$ or $-1$. If the binary expansion of $n$ is given by
    $n=\sum _{k\geq 0}\epsilon _{k}(n)2^{k},$
then let
    $u_{n}=\sum _{k\geq 0}\epsilon _{k}(n)\epsilon _{k+1}(n).$
(So $u_{n}$ is the number of times the block 11 appears in the binary expansion of $n$.)
The Rudin–Shapiro sequence $(r_{n})_{n\geq 0}$ is then defined by
    $r_{n}=(-1)^{u_{n}}.$
Thus $r_{n}=1$ if $u_{n}$ is even and $r_{n}=-1$ if $u_{n}$ is odd.
The sequence $u_{n}$ is known as the complete Rudin–Shapiro sequence, and starting at $n=0$, its first few terms are:
    0, 0, 0, 1, 0, 0, 1, 2, 0, 0, 0, 1, 1, 1, 2, 3, ... (sequence A014081 in the OEIS)
and the corresponding terms $r_{n}$ of the Rudin–Shapiro sequence are:
    +1, +1, +1, −1, +1, +1, −1, +1, +1, +1, +1, −1, −1, −1, +1, −1, ... (sequence A020985 in the OEIS)
For example, $u_{6}=1$ and $r_{6}=-1$ because the binary representation of 6 is 110, which contains one occurrence of 11; whereas $u_{7}=2$ and $r_{7}=1$ because the binary representation of 7 is 111, which contains two (overlapping) occurrences of 11.

## Historical motivation

The Rudin–Shapiro sequence was introduced independently by Golay, Rudin, and Shapiro. The following is a description of Rudin's motivation. In Fourier analysis, one is often concerned with the $L^{2}$ norm of a measurable function $f\colon [0,2\pi )\to [0,2\pi )$. This norm is defined by
    $||f||_{2}=\left({\frac {1}{2\pi }}\int _{0}^{2\pi }|f(t)|^{2}\,\mathrm {d} t\right)^{1/2}.$
One can prove that for any sequence $(a_{n})_{n\geq 0}$ with each $a_{n}$ in $\{1,-1\}$,
    $\sup _{x\in \mathbb {R} }\left|\sum _{0\leq n<N}a_{n}e^{inx}\right|\geq \left|\left|\sum _{0\leq n<N}a_{n}e^{inx}\right|\right|_{2}={\sqrt {N}}.$
Moreover, for almost every sequence $(a_{n})_{n\geq 0}$ with each $a_{n}$ is in $\{-1,1\}$,
    $\sup _{x\in \mathbb {R} }\left|\sum _{0\leq n<N}a_{n}e^{inx}\right|=O({\sqrt {N\log N}}).$
However, the Rudin–Shapiro sequence $(r_{n})_{n\geq 0}$ satisfies a tighter bound: there exists a constant $C>0$ such that
    $\sup _{x\in \mathbb {R} }\left|\sum _{0\leq n<N}r_{n}e^{inx}\right|\leq C{\sqrt {N}}.$
It is conjectured that one can take $C={\sqrt {6}}$, but while it is known that $C\geq {\sqrt {6}}$, the best published upper bound is currently $C\leq (2+{\sqrt {2}}){\sqrt {3/5}}$. Let $P_{n}$ be the n-th Shapiro polynomial. Then, when $N=2^{n}-1$, the above inequality gives a bound on $\sup _{x\in \mathbb {R} }|P_{n}(e^{ix})|$. More recently, bounds have also been given for the magnitude of the coefficients of $|P_{n}(z)|^{2}$ where $|z|=1$.
Shapiro arrived at the sequence because the polynomials
    $P_{n}(z)=\sum _{i=0}^{2^{n}-1}r_{i}z^{i}$
where $(r_{i})_{i\geq 0}$ is the Rudin–Shapiro sequence, have absolute value bounded on the complex unit circle by $2^{\frac {n+1}{2}}$. This is discussed in more detail in the article on Shapiro polynomials. Golay's motivation was similar, although he was concerned with applications to spectroscopy and published in an optics journal.

## Properties

The Rudin–Shapiro sequence can be generated by a 4-state automaton accepting binary representations of non-negative integers as input. The sequence is therefore 2-automatic, so by Cobham's little theorem there exists a 2-uniform morphism $\varphi$ with fixed point $w$ and a coding $\tau$ such that $r=\tau (w)$, where $r$ is the Rudin–Shapiro sequence. However, the Rudin–Shapiro sequence cannot be expressed as the fixed point of some uniform morphism alone.
There is a recursive definition
    ${\begin{cases}r_{2n}&=r_{n}\\r_{2n+1}&=(-1)^{n}r_{n}\end{cases}}$
The values of the terms r$_n$ and u$_n$ in the Rudin–Shapiro sequence can be found recursively as follows. If n = m·2$^k$ where m is odd then
    $u_{n}={\begin{cases}u_{(m-1)/4}&{\text{if }}m\equiv 1{\pmod {4}}\\u_{(m-1)/2}+1&{\text{if }}m\equiv 3{\pmod {4}}\end{cases}}$
    $r_{n}={\begin{cases}r_{(m-1)/4}&{\text{if }}m\equiv 1{\pmod {4}}\\-r_{(m-1)/2}&{\text{if }}m\equiv 3{\pmod {4}}\end{cases}}$
Thus u$_{108}$ = u$_{13}$ + 1 = u$_3$ + 1 = u$_1$ + 2 = u$_0$ + 2 = 2, which can be verified by observing that the binary representation of 108, which is 1101100, contains two sub-strings 11. And so r$_{108}$ = (−1)$^2$ = +1.
A 2-uniform morphism $\varphi$ that requires a coding $\tau$ to generate the Rudin-Shapiro sequence is the following:${\begin{aligned}\varphi :a&\to ab\\b&\to ac\\c&\to db\\d&\to dc\end{aligned}}$ ${\begin{aligned}\tau :a&\to 1\\b&\to 1\\c&\to -1\\d&\to -1\end{aligned}}$
The Rudin–Shapiro word +1 +1 +1 −1 +1 +1 −1 +1 +1 +1 +1 −1 −1 −1 +1 −1 ..., which is created by concatenating the terms of the Rudin–Shapiro sequence, is a fixed point of the morphism or string substitution rules
    +1 +1 → +1 +1 +1 −1
    +1 −1 → +1 +1 −1 +1
    −1 +1 → −1 −1 +1 −1
    −1 −1 → −1 −1 −1 +1
as follows:
    +1 +1 → +1 +1 +1 −1 → +1 +1 +1 −1 +1 +1 −1 +1 → +1 +1 +1 −1 +1 +1 −1 +1 +1 +1 +1 −1 −1 −1 +1 −1 ...
It can be seen from the morphism rules that the Rudin–Shapiro string contains at most four consecutive +1s and at most four consecutive −1s.
The sequence of partial sums of the Rudin–Shapiro sequence, defined by
    $s_{n}=\sum _{k=0}^{n}r_{k}\,,$
with values
    1, 2, 3, 2, 3, 4, 3, 4, 5, 6, 7, 6, 5, 4, 5, 4, ... (sequence A020986 in the OEIS)
can be shown to satisfy the inequality
    ${\sqrt {{\frac {3}{5}}n}}<s_{n}<{\sqrt {6n}}{\text{ for }}n\geq 1\,.$
Let $(s_{n})_{n\geq 0}$ denote the Rudin–Shapiro sequence on $\{0,1\}$, in which case $s_{n}$ is the number, modulo 2, of occurrences (possibly overlapping) of the block $11$ in the base-2 expansion of $n$. Then the generating function
    $S(X)=\sum _{n\geq 0}s_{n}X^{n}$
satisfies
    $(1+X)^{5}S(X)^{2}+(1+X)^{4}S(X)+X^{3}=0,$
making it algebraic as a formal power series over $\mathbb {F} _{2}(X)$. The algebraicity of $S(X)$ over $\mathbb {F} _{2}(X)$ follows from the 2-automaticity of $(s_{n})_{n\geq 0}$ by Christol's theorem.
The Rudin–Shapiro sequence along squares $(r_{n^{2}})_{n\geq 0}$ is normal.
The complete Rudin–Shapiro sequence satisfies the following uniform distribution result. If $x\in \mathbb {R} \setminus \mathbb {Z}$, then there exists $\alpha =\alpha (x)\in (0,1)$ such that
    $\sum _{n<N}\exp(2\pi ixu_{n})=O(N^{\alpha })$
which implies that $(xu_{n})_{n\geq 0}$ is uniformly distributed modulo $1$ for all irrationals $x$.

## Relationship with one-dimensional Ising model

Let the binary expansion of n be given by
    $n=\sum _{k\geq 0}\epsilon _{k}(n)2^{k}$
where $\epsilon _{k}(n)\in \{0,1\}$. Recall that the complete Rudin–Shapiro sequence is defined by
    $u(n)=\sum _{k\geq 0}\epsilon _{k}(n)\epsilon _{k+1}(n).$
Let
    ${\tilde {\epsilon }}_{k}(n)={\begin{cases}\epsilon _{k}(n)&{\text{if }}k\leq N-1,\\\epsilon _{0}(n)&{\text{if }}k=N.\end{cases}}$
Then let
    $u(n,N)=\sum _{0\leq k<N}{\tilde {\epsilon }}_{k}(n){\tilde {\epsilon }}_{k+1}(n).$
Finally, let
    $S(N,x)=\sum _{0\leq n<2^{N}}\exp(2\pi ixu(n,N)).$
Recall that the partition function of the one-dimensional Ising model can be defined as follows. Fix $N\geq 1$ representing the number of sites, and fix constants $J>0$ and $H>0$ representing the coupling constant and external field strength, respectively. Choose a sequence of weights $\eta =(\eta _{0},\dots ,\eta _{N-1})$ with each $\eta _{i}\in \{-1,1\}$. For any sequence of spins $\sigma =(\sigma _{0},\dots ,\sigma _{N-1})$ with each $\sigma _{i}\in \{-1,1\}$, define its Hamiltonian by
    $H_{\eta }(\sigma )=-J\sum _{0\leq k<N}\eta _{k}\sigma _{k}\sigma _{k+1}-H\sum _{0\leq k<N}\sigma _{k}.$
Let $T$ be a constant representing the temperature, which is allowed to be an arbitrary non-zero complex number, and set $\beta =1/(kT)$ where $k$ is the Boltzmann constant. The partition function is defined by
    $Z_{N}(\eta ,J,H,\beta )=\sum _{\sigma \in \{-1,1\}^{N}}\exp(-\beta H_{\eta }(\sigma )).$
Then we have
    $S(N,x)=\exp \left({\frac {\pi iNx}{2}}\right)Z_{N}\left(1,{\frac {1}{2}},-1,\pi ix\right)$
where the weight sequence $\eta =(\eta _{0},\dots ,\eta _{N-1})$ satisfies $\eta _{i}=1$ for all $i$.