Staaarter

Generate Baum-Sweet Sequence

Generates the first N terms of the Baum-Sweet sequence, a 0/1 automatic sequence defined by whether each index's binary representation contains a block of consecutive zeros of odd length. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
sequencesnumber-theory

Overview

Introduction

The Baum-Sweet sequence is a 0/1 sequence defined purely by the pattern of zero-runs in each index's binary representation, making it another well-known example of a 2-automatic sequence.

This tool generates as many terms as you need directly from that binary-digit rule, so every value can be checked by hand against its index's binary form.

What Is Generate Baum-Sweet Sequence?

It's a sequence over {0, 1} where term(n) is 1 exactly when n's binary representation has no block of consecutive 0 digits with odd length, and 0 otherwise. Index 0 is a special case, defined as 1 by convention rather than derived from its binary form "0".

Named for Leonard Baum and George Sweet, who introduced it in the 1970s while studying automatic sequences and continued fractions over finite fields.

How Generate Baum-Sweet Sequence Works

For each index n starting at 0, the tool converts n to a binary string and splits it on its "1" digits, which leaves behind the runs of "0" digits that sat between (or before/after) the ones.

It checks whether any of those zero-runs has an odd length. If at least one does, the term is 0; if none do (including the case of no zero-runs at all, like "111"), the term is 1.

n = 0 bypasses this check entirely and is always recorded as 1, matching the sequence's standard convention.

When To Use Generate Baum-Sweet Sequence

Use it to generate reference terms for verifying an automatic-sequence implementation, or to explore how a simple binary-pattern rule produces a sequence with self-similar structure.

It's also useful teaching material for automata theory courses, since the rule is simple enough to trace by hand for small n but still produces a genuinely non-trivial sequence.

Features

Advantages

  • Computes every term directly from its index's binary digits, with no recursive state to accumulate errors across a long run.
  • Handles up to 10,000 terms in one pass.

Limitations

  • Term count is capped at 10,000 to keep the browser responsive.
  • Only the standard 0-indexed convention (with n = 0 fixed at 1) is offered.

Examples

First 9 terms

Input

9

Output

1, 1, 0, 1, 1, 0, 0, 1, 0

n = 0 is 1 by convention. n = 1 ("1") has no zero runs, so 1. n = 2 ("10") has a length-1 zero run (odd), so 0. n = 3 ("11") has no zero runs, so 1. n = 4 ("100") has a length-2 zero run (even), so 1. n = 5 ("101") has a length-1 zero run (odd), so 0. n = 6 ("110") has a length-1 zero run (odd), so 0. n = 7 ("111") has no zero runs, so 1. n = 8 ("1000") has a length-3 zero run (odd), so 0.

Best Practices & Notes

Best Practices

  • When cross-checking against another source, confirm it also treats n = 0 as a special-cased 1 rather than deriving it from an empty or "0" binary string.

Developer Notes

The implementation calls `n.toString(2).split("1").filter(run => run.length > 0)` to isolate the zero-runs between (and around) the set bits, then checks `.some(run => run.length % 2 === 1)`. This is equivalent to, but simpler to verify than, the standard recursive definition b(0)=1, b(2n+1)=b(n), b(4n)=b(n), b(4n+2)=0; both were cross-checked against each other while building this tool to confirm they agree for the first several dozen terms.

Generate Baum-Sweet Sequence Use Cases

  • Generating reference values to validate a Baum-Sweet implementation in another language
  • Automata theory coursework exploring 2-automatic sequences
  • Exploring self-similar binary-digit patterns for a combinatorics-on-words demo

Common Mistakes

  • Deriving term(0) from the binary string "0" (which would suggest a single odd-length zero run and thus 0); the sequence special-cases n = 0 to 1 by convention instead.

Tips

  • Cross-check small term counts (like the first 9) against OEIS A086747 before trusting a larger run.

References

Frequently Asked Questions