Free Moser-de Bruijn sequence generator. Calculate numbers as sums of distinct powers of 4. Perfect for math education, number theory, and research.
Moser-de Bruijn sequences contain numbers that can be written as sums of distinct powers of 4
The Moser-de Bruijn sequence is a fascinating mathematical sequence consisting of numbers that can be expressed as sums of distinct powers of 4. Named after mathematicians Leo Moser and Nicolaas Govert de Bruijn, this sequence begins: 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85...
Our free online Moser-de Bruijn sequence generator allows you to instantly calculate any number of terms, making it perfect for mathematical exploration, education, and research.
Each number in the sequence has a unique property: when written in base 4, it contains only the digits 0 and 1. Equivalently, each term can be represented as a sum where each power of 4 (4⁰, 4¹, 4², 4³, etc.) appears at most once. This generator allows you to explore this intriguing sequence by generating as many terms as you wish, providing an interactive tool for mathematical exploration and education.
The sequence appears in various areas of mathematics, including additive number theory, combinatorics, and the study of sum-free sets. It's closely related to the binary number system but uses base 4 instead of base 2.
The generator performs all calculations locally in your browser using JavaScript, making it fast and requiring no external resources or internet connection.
The generator performs the following checks on user input:
If invalid input is detected, a clear error message will be displayed, and generation will not proceed until the input is corrected.
The Moser-de Bruijn sequence can be defined in several equivalent ways:
Definition 1 (Additive Form): A number n belongs to the Moser-de Bruijn sequence if and only if it can be written as: where S is a finite set of non-negative integers (each power of 4 appears at most once).
Definition 2 (Base-4 Representation): A number n is in the Moser-de Bruijn sequence if and only if its base-4 representation contains only the digits 0 and 1.
Definition 3 (Binary Correspondence): The n-th term of the sequence (0-indexed) is: where are the binary digits of n. In other words, replace each bit in the binary representation of n with the corresponding power of 4.
Examples:
The generator uses an efficient algorithm based on the binary correspondence method:
Algorithm Steps:
Example Calculation for the 6th term (index 5):
Alternative Check Method: To verify if a specific number N is in the sequence:
The generator performs these calculations using standard JavaScript arithmetic with bitwise operations for efficiency.
The Moser-de Bruijn sequence generator has various applications in mathematics education and research:
Number Theory Education: Helps students understand additive number systems, bases, and how different number representations relate to each other.
Combinatorics Research: Useful for exploring sum-free sets and additive bases in mathematical research.
Algorithm Study: Provides a practical example of efficient sequence generation using bit manipulation and number theory.
Pattern Recognition: Allows visualization of patterns in integer sequences and their relationships to binary and quaternary (base-4) systems.
Mathematical Exploration: Enables investigation of properties such as density, gaps between terms, and asymptotic behavior of the sequence.
Computer Science Education: Demonstrates the connection between binary operations and mathematical sequences, useful for teaching bitwise operations.
Recreational Mathematics: Provides an engaging way to explore mathematical curiosities and number properties.
While the Moser-de Bruijn sequence has unique properties, there are related mathematical sequences worth exploring:
Powers of 2 Sequence (A000079): Numbers that are pure powers of 2: 1, 2, 4, 8, 16, 32... The simplest additive base sequence.
Sums of Distinct Powers of 2: All non-negative integers can be expressed this way (binary representation), giving the sequence: 0, 1, 2, 3, 4, 5, 6, 7...
Powers of 3 Sequence (A000244): Numbers that are pure powers of 3: 1, 3, 9, 27, 81...
Sums of Distinct Powers of 3: Similar concept but using base-3, giving sequence A005836.
Fibbinary Numbers (A003714): Numbers whose binary representation contains no consecutive 1's, related to Fibonacci numbers.
Stanley Sequence: Numbers with no 1's in base 3 representation, analogous to Moser-de Bruijn in base 3.
OEIS Sequences: The Online Encyclopedia of Integer Sequences (OEIS) contains thousands of related sequences worth exploring.
The Moser-de Bruijn sequence is named after Leo Moser (1921-1970), an Austrian-Canadian mathematician, and Nicolaas Govert de Bruijn (1918-2012), a Dutch mathematician. The sequence was first studied in depth in the 1960s as part of research into additive number theory and sum-free sets.
De Bruijn made significant contributions to combinatorics, graph theory, and computer science, including the famous de Bruijn sequences used in coding theory. Moser was known for his work in number theory, combinatorics, and geometry, including contributions to the Erdős–Moser equation.
The sequence emerged from investigations into which sets of non-negative integers have the property that every non-negative integer can be uniquely represented as a sum of distinct elements from the set. The powers of 4 form such a set, and the Moser-de Bruijn sequence consists of all possible sums from this set.
In the broader context of mathematics, this sequence is part of the study of additive bases—sets of integers that can represent other integers through sums. The question of which bases allow unique representations and which properties these representations have continues to be an active area of research in additive number theory.
The sequence appears as A000695 in the Online Encyclopedia of Integer Sequences (OEIS), where it has been studied for its connections to binary representation, quaternary systems, and various combinatorial properties. Modern applications include computer science algorithms, particularly those involving bit manipulation and efficient representation of sparse data.
Here are code examples to generate the Moser-de Bruijn sequence in different programming languages:
1def moser_de_bruijn(n):
2 """Generate the first n terms of the Moser-de Bruijn sequence."""
3 sequence = []
4 for i in range(n):
5 term = 0
6 power = 1
7 temp = i
8 while temp > 0:
9 if temp & 1: # Check if least significant bit is 1
10 term += power
11 power *= 4
12 temp >>= 1 # Right shift to check next bit
13 sequence.append(term)
14 return sequence
15
16# Example usage:
17terms = moser_de_bruijn(20)
18print("First 20 terms of Moser-de Bruijn sequence:")
19print(terms)
20# Output: [0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85, 256, 257, 260, 261]
21
22def is_moser_de_bruijn(num):
23 """Check if a number is in the Moser-de Bruijn sequence."""
24 while num > 0:
25 digit = num % 4
26 if digit > 1:
27 return False
28 num //= 4
29 return True
30
31# Check if 21 is in the sequence
32print(f"Is 21 in the sequence? {is_moser_de_bruijn(21)}") # True
33print(f"Is 22 in the sequence? {is_moser_de_bruijn(22)}") # False
34
1function moserDeBruijn(n) {
2 const sequence = [];
3 for (let i = 0; i < n; i++) {
4 let term = 0;
5 let power = 1;
6 let temp = i;
7 while (temp > 0) {
8 if (temp & 1) { // Check if least significant bit is 1
9 term += power;
10 }
11 power *= 4;
12 temp >>= 1; // Right shift to check next bit
13 }
14 sequence.push(term);
15 }
16 return sequence;
17}
18
19// Example usage:
20const terms = moserDeBruijn(20);
21console.log("First 20 terms of Moser-de Bruijn sequence:");
22console.log(terms);
23// Output: [0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84, 85, 256, 257, 260, 261]
24
25function isMoserDeBruijn(num) {
26 while (num > 0) {
27 const digit = num % 4;
28 if (digit > 1) {
29 return false;
30 }
31 num = Math.floor(num / 4);
32 }
33 return true;
34}
35
36// Check specific numbers
37console.log(`Is 21 in the sequence? ${isMoserDeBruijn(21)}`); // true
38console.log(`Is 22 in the sequence? ${isMoserDeBruijn(22)}`); // false
39
1import java.util.ArrayList;
2import java.util.List;
3
4public class MoserDeBruijnGenerator {
5
6 public static List<Integer> generateSequence(int n) {
7 List<Integer> sequence = new ArrayList<>();
8 for (int i = 0; i < n; i++) {
9 int term = 0;
10 int power = 1;
11 int temp = i;
12 while (temp > 0) {
13 if ((temp & 1) == 1) { // Check if least significant bit is 1
14 term += power;
15 }
16 power *= 4;
17 temp >>= 1; // Right shift to check next bit
18 }
19 sequence.add(term);
20 }
21 return sequence;
22 }
23
24 public static boolean isMoserDeBruijn(int num) {
25 while (num > 0) {
26 int digit = num % 4;
27 if (digit > 1) {
28 return false;
29 }
30 num /= 4;
31 }
32 return true;
33 }
34
35 public static void main(String[] args) {
36 List<Integer> terms = generateSequence(20);
37 System.out.println("First 20 terms of Moser-de Bruijn sequence:");
38 System.out.println(terms);
39
40 System.out.println("Is 21 in the sequence? " + isMoserDeBruijn(21)); // true
41 System.out.println("Is 22 in the sequence? " + isMoserDeBruijn(22)); // false
42 }
43}
44
1#include <iostream>
2#include <vector>
3
4std::vector<int> moserDeBruijn(int n) {
5 std::vector<int> sequence;
6 for (int i = 0; i < n; i++) {
7 int term = 0;
8 int power = 1;
9 int temp = i;
10 while (temp > 0) {
11 if (temp & 1) { // Check if least significant bit is 1
12 term += power;
13 }
14 power *= 4;
15 temp >>= 1; // Right shift to check next bit
16 }
17 sequence.push_back(term);
18 }
19 return sequence;
20}
21
22bool isMoserDeBruijn(int num) {
23 while (num > 0) {
24 int digit = num % 4;
25 if (digit > 1) {
26 return false;
27 }
28 num /= 4;
29 }
30 return true;
31}
32
33int main() {
34 std::vector<int> terms = moserDeBruijn(20);
35 std::cout << "First 20 terms of Moser-de Bruijn sequence:" << std::endl;
36 for (int term : terms) {
37 std::cout << term << " ";
38 }
39 std::cout << std::endl;
40
41 std::cout << "Is 21 in the sequence? " << (isMoserDeBruijn(21) ? "true" : "false") << std::endl;
42 std::cout << "Is 22 in the sequence? " << (isMoserDeBruijn(22) ? "true" : "false") << std::endl;
43
44 return 0;
45}
46
These examples demonstrate efficient algorithms for generating the Moser-de Bruijn sequence and checking membership. The key insight is using bitwise operations to convert the binary representation of indices into sums of powers of 4.
Here are the first 32 terms of the Moser-de Bruijn sequence with their decomposition into powers of 4:
Index | Term | Decomposition | Base-4 |
---|---|---|---|
0 | 0 | 0 | 0 |
1 | 1 | 4⁰ | 1 |
2 | 4 | 4¹ | 10 |
3 | 5 | 4¹ + 4⁰ | 11 |
4 | 16 | 4² | 100 |
5 | 17 | 4² + 4⁰ | 101 |
6 | 20 | 4² + 4¹ | 110 |
7 | 21 | 4² + 4¹ + 4⁰ | 111 |
8 | 64 | 4³ | 1000 |
9 | 65 | 4³ + 4⁰ | 1001 |
10 | 68 | 4³ + 4¹ | 1010 |
11 | 69 | 4³ + 4¹ + 4⁰ | 1011 |
12 | 80 | 4³ + 4² | 1100 |
13 | 81 | 4³ + 4² + 4⁰ | 1101 |
14 | 84 | 4³ + 4² + 4¹ | 1110 |
15 | 85 | 4³ + 4² + 4¹ + 4⁰ | 1111 |
16 | 256 | 4⁴ | 10000 |
17 | 257 | 4⁴ + 4⁰ | 10001 |
18 | 260 | 4⁴ + 4¹ | 10010 |
19 | 261 | 4⁴ + 4¹ + 4⁰ | 10011 |
20 | 272 | 4⁴ + 4² | 10100 |
21 | 273 | 4⁴ + 4² + 4⁰ | 10101 |
22 | 276 | 4⁴ + 4² + 4¹ | 10110 |
23 | 277 | 4⁴ + 4² + 4¹ + 4⁰ | 10111 |
24 | 320 | 4⁴ + 4³ | 11000 |
25 | 321 | 4⁴ + 4³ + 4⁰ | 11001 |
26 | 324 | 4⁴ + 4³ + 4¹ | 11010 |
27 | 325 | 4⁴ + 4³ + 4¹ + 4⁰ | 11011 |
28 | 336 | 4⁴ + 4³ + 4² | 11100 |
29 | 337 | 4⁴ + 4³ + 4² + 4⁰ | 11101 |
30 | 340 | 4⁴ + 4³ + 4² + 4¹ | 11110 |
31 | 341 | 4⁴ + 4³ + 4² + 4¹ + 4⁰ | 11111 |
Detailed Example for Term 21:
Notice that the base-4 representation contains only 0s and 1s, confirming that 21 is in the Moser-de Bruijn sequence.
Growth Pattern: The sequence grows exponentially. The n-th term is approximately proportional to 4^(log₂(n)). The density of the sequence among all non-negative integers decreases as numbers get larger, but infinitely many terms exist.
"Moser-de Bruijn Sequence." OEIS Foundation Inc., The On-Line Encyclopedia of Integer Sequences, A000695, https://oeis.org/A000695. Accessed 2024.
"Additive Base." Wikipedia, Wikimedia Foundation, https://en.wikipedia.org/wiki/Additive_base. Accessed 2024.
De Bruijn, N. G. "On Bases for the Set of Integers." Publicationes Mathematicae Debrecen, vol. 1, 1950, pp. 232-242.
Moser, Leo. "An Application of Generating Series." Mathematics Magazine, vol. 35, no. 1, 1962, pp. 37-38.
"Sum-free Set." Wikipedia, Wikimedia Foundation, https://en.wikipedia.org/wiki/Sum-free_set. Accessed 2024.
Stolarsky, Kenneth B. "Power and Exponential Sums of Digital Sums Related to Binomial Coefficient Parity." SIAM Journal on Applied Mathematics, vol. 32, no. 4, 1977, pp. 717-730.
Allouche, Jean-Paul, and Jeffrey Shallit. "Automatic Sequences: Theory, Applications, Generalizations." Cambridge University Press, 2003.
The Moser-de Bruijn sequence is used in number theory research, combinatorics, algorithm study, computer science education (especially for teaching bitwise operations), and mathematical exploration of additive bases and sum-free sets.
To generate the Moser-de Bruijn sequence, convert each index n to binary, then replace each bit position with the corresponding power of 4. For example, index 5 (binary: 101) becomes 4² + 4⁰ = 17.
Each number in the Moser-de Bruijn sequence has a unique property: when written in base-4, it contains only the digits 0 and 1. This means every term can be expressed as a sum of distinct powers of 4, with each power appearing at most once.
Convert the number to base-4 representation. If all digits are either 0 or 1, the number is in the Moser-de Bruijn sequence. If any digit is 2 or 3, it's not in the sequence.
The n-th term M(n) is calculated by: M(n) = Σ(b_i × 4^i), where b_i are the binary digits of n. Essentially, replace each 1 in the binary representation of n with the corresponding power of 4.
Yes, the Moser-de Bruijn sequence is infinite. It continues indefinitely with infinitely many terms, though the density of sequence members decreases as numbers get larger.
Binary sequences use powers of 2, while the Moser-de Bruijn sequence uses powers of 4. Both represent numbers as sums of distinct powers, but Moser-de Bruijn creates a sparser sequence since it skips many integers.
The sequence is named after Leo Moser (1921-1970), an Austrian-Canadian mathematician, and Nicolaas Govert de Bruijn (1918-2012), a Dutch mathematician who studied it in depth during the 1960s.
Use our free online Moser-de Bruijn sequence generator to explore this fascinating mathematical sequence. Generate any number of terms instantly, perfect for students, educators, researchers, and math enthusiasts. No installation or registration required—start calculating powers of 4 sequences right in your browser.
Discover more tools that might be useful for your workflow