Baum-Sweet Sequence Generator
Generate the Baum-Sweet sequence b(n) for any range. Analyzes binary representations for odd-length zero blocks with visual breakdown.
About
The Baum-Sweet sequence, introduced by L. E. Baum and M. M. Sweet in 1976, is a binary-valued sequence indexed by non-negative integers. For each n, the term b(n) equals 1 if and only if the binary expansion of n contains no block of consecutive zeros whose length is odd. Otherwise b(n) = 0. The sequence begins 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1 (OEIS A086747). It arises in the study of algebraic power series over finite fields and connects number theory to formal language theory. Misidentifying zero-block parity leads to incorrect classification of algebraic irrationals over F2. This generator computes exact values and exposes the binary structure so you can verify each term against its zero-run decomposition.
Formulas
The Baum-Sweet sequence is defined by inspecting the binary representation of each non-negative integer for contiguous runs of zeros.
Where bin(n) denotes the binary string of n without leading zeros. A maximal block is a contiguous substring of 0s not extendable left or right. The algorithm scans this string with a regular expression matching pattern 0+ to extract all zero runs, then checks the length parity of each.
Equivalently, b(n) = 1 if and only if n can be written as n = kโi=0 ai โ 4ci where each ai โ {1, 2, 3} and ci are distinct non-negative integers. This base-4 characterization proves no digit equals 0 in the base-4 representation.
Where: b(n) = the Baum-Sweet term at index n; bin(n) = binary representation of n; ai = base-4 digits of n.
Reference Data
| n | Binary | Zero Runs | b(n) |
|---|---|---|---|
| 0 | 0 | - | 1 |
| 1 | 1 | none | 1 |
| 2 | 10 | 1 (odd) | 0 |
| 3 | 11 | none | 1 |
| 4 | 100 | 2 (even) | 1 |
| 5 | 101 | 1 (odd) | 0 |
| 6 | 110 | 1 (odd) | 0 |
| 7 | 111 | none | 1 |
| 8 | 1000 | 3 (odd) | 0 |
| 9 | 1001 | 2 (even) | 1 |
| 10 | 1010 | 1, 1 (odd) | 0 |
| 11 | 1011 | 1 (odd) | 0 |
| 12 | 1100 | 2 (even) | 1 |
| 13 | 1101 | 1 (odd) | 0 |
| 14 | 1110 | 1 (odd) | 0 |
| 15 | 1111 | none | 1 |
| 16 | 10000 | 4 (even) | 1 |
| 17 | 10001 | 3 (odd) | 0 |
| 18 | 10010 | 2, 1 (odd) | 0 |
| 19 | 10011 | 2 (even) | 1 |
| 20 | 10100 | 1, 2 (odd) | 0 |
| 21 | 10101 | 1, 1 (odd) | 0 |
| 22 | 10110 | 1, 1 (odd) | 0 |
| 23 | 10111 | 1 (odd) | 0 |
| 24 | 11000 | 3 (odd) | 0 |
| 25 | 11001 | 2 (even) | 1 |
| 26 | 11010 | 1, 1 (odd) | 0 |
| 27 | 11011 | 1 (odd) | 0 |
| 28 | 11100 | 2 (even) | 1 |
| 29 | 11101 | 1 (odd) | 0 |
| 30 | 11110 | 1 (odd) | 0 |
| 31 | 11111 | none | 1 |