Moser-de Bruijn Sequence Generator
Generate terms of the Moser-de Bruijn sequence, numbers whose base-4 representation contains only digits 0 and 2.
Moser-de Bruijn Sequence Generator
The Moser-de Bruijn sequence is the sequence of non-negative integers whose base-4 (quaternary) representation uses only the digits 0 and 2. These numbers have no 1s or 3s in base 4 — every quaternary digit is either 0 or 2. This elegant constraint produces a sparse, self-similar sequence with deep connections to the Stern-Brocot tree, the sum-of-digits function, and fractal geometry. This tool generates as many terms as you need.
Definition
A non-negative integer $n$ belongs to the Moser-de Bruijn sequence if and only if its base-4 representation contains only the digits 0 and 2 (OEIS: A000695). Equivalently, in binary, no two consecutive bits are both 1 — i.e., $n$ and $2n$ share no bits.
The sequence begins: 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85, ...
Generating the Terms
The $k$-th term ($k$ starting at 0) can be computed directly from the binary expansion of $k$: replace each bit 0 with the base-4 digit 0, and each bit 1 with the base-4 digit 2. This gives:
- $k = 0 = 0_2 \Rightarrow a(0) = 0$
- $k = 1 = 1_2 \Rightarrow a(1) = 2_4 = 2$... Wait, $2_4 = 2 \cdot 4^0 = 2$? No — but the displayed sequence starts 0,1,4,...
Actually the OEIS convention lists numbers whose digits in base 4 are only 0s and 1s for A000695 starting 0, 1, 4, 5, ... These are multiples of 1, where each base-4 digit is 0 or 1, written as $\sum_{i} d_i \cdot 4^i$ with $d_i \in \{0,1\}$. Our tool uses this standard OEIS convention.
Mathematical Properties
- Self-similarity: The set $S$ of Moser-de Bruijn numbers satisfies $S = \{4n : n \in S\} \cup \{4n+1 : n \in S\}$, making it a self-similar fractal set.
- Additive complement: Every non-negative integer $n$ can be uniquely written as $n = a + 4b$ where $a \in S$ and $b \in S$. This shows $S$ is a basis of order 2 for $\mathbb{N}$ in a sense.
- Digit sum: The element $a(k)$ equals the sum $\sum_i b_i \cdot 4^i$ where $k = \sum_i b_i \cdot 2^i$ is the binary expansion of $k$.
- Density: The sequence has asymptotic density 0 — the count of terms up to $N$ grows as $O(\sqrt{N})$.
- Growth rate: The $k$-th term satisfies $a(k) \sim k^{\log_2 4} / C = k^2 / C$ for a constant $C$, since each binary digit of $k$ doubles the range expansion by a factor of 4.
Connection to the Stern-Brocot Tree
The Moser-de Bruijn sequence is intimately related to the Stern-Brocot tree and Stern's diatomic sequence. Numbers in the sequence correspond to paths down the Stern-Brocot tree that always go in the same direction (either always left or always right at each level), producing a self-similar fractal structure in the tree.
How to Use This Tool
- Enter the number of terms to generate (up to 5,000).
- Set the start term index to generate from that position in the sequence.
- Choose a separator to format the output.
- Enable Show Base-4 Representation to see why each number qualifies.
- Enable Index Labels to display the position of each term.
Frequently Asked Questions
What is the Moser-de Bruijn sequence?
The Moser-de Bruijn sequence (OEIS A000695) is the sequence of non-negative integers whose base-4 (quaternary) representation uses only the digits 0 and 1. It starts: 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, ... These are numbers of the form $\sum_{i} b_i \cdot 4^i$ where each $b_i \in \{0,1\}$.
How do I check if a number is in the Moser-de Bruijn sequence?
Convert the number to base 4. If every digit is 0 or 1 (equivalently 0 or 2 depending on convention), it is in the sequence. Alternatively: write the number in binary and check that no two consecutive bits are both 1. For example, 5 = 101₂ has no adjacent 1-bits, so it is in the sequence. But 3 = 11₂ has two adjacent 1-bits, so it is not.
What is the growth rate of the Moser-de Bruijn sequence?
The $k$-th term (starting from $k=0$) grows quadratically: $a(k) \approx k^2$ in the sense that the number of terms up to $N$ is approximately $\sqrt{N}$. More precisely, the $k$-th term is obtained by taking the binary digits of $k$ and expanding each into a base-4 digit, giving a result that is $O(k^2)$.
Why is the sequence called Moser-de Bruijn?
The sequence is named after Leo Moser and Nicolaas Govert de Bruijn, who studied its properties in the context of additive number theory. They investigated which sets of integers can additively cover all natural numbers, and this sequence appeared as a minimal such basis component.
What is the connection to the no-adjacent-ones property in binary?
A number $n$ is in the Moser-de Bruijn sequence if and only if its binary representation has no two adjacent 1-bits. This is because the base-4 digits 0 and 1 correspond exactly to the patterns "00" and "01" in binary (reading two bits at a time), ensuring no two adjacent 1s appear in the full binary expansion.
Is this sequence related to the Fibonacci sequence?
Indirectly. The count of $n$-bit binary strings with no two adjacent 1s equals the $(n+2)$-th Fibonacci number. So the number of $n$-bit Moser-de Bruijn terms is a Fibonacci number. However, the Moser-de Bruijn terms themselves are not Fibonacci numbers in general.
Related tools
Your recent visits