Staaarter

Generate Tribonacci Words

Generates the first N characters of the Tribonacci word, the ternary analog of the Fibonacci word, built from the fixed-point substitution 0 -> 01, 1 -> 02, 2 -> 0 starting from "0". A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-08-05
By Staaarter Team
fibonaccisequence

Overview

Introduction

Where the Fibonacci word extends the golden-ratio recurrence into a binary string, the Tribonacci word does the same for the three-term Tribonacci recurrence, using a three-symbol alphabet instead of two.

This tool applies the defining substitution repeatedly and returns the first N characters of the resulting word.

What Is Generate Tribonacci Words?

An infinite ternary string over the alphabet {0, 1, 2}, the unique fixed point of the substitution 0 -> 01, 1 -> 02, 2 -> 0 starting from the single character "0".

The first several characters are 0, 1, 0, 2, 0, 1, 0, 0, 1, 0, 2, 0, 1, matching the sequence documented on OEIS as A080843.

How Generate Tribonacci Words Works

Starting from the string "0", the tool repeatedly rewrites every character in the current string according to the rule 0 -> 01, 1 -> 02, 2 -> 0, producing a new, longer string each round.

Because each round expands the string by roughly the Tribonacci constant (about 1.839), only a modest number of rounds are needed to reach thousands of characters; the result is truncated to exactly N characters.

When To Use Generate Tribonacci Words

Use it for coursework or research touching on Rauzy fractals, ternary Sturmian-like sequences, or generalizations of the Fibonacci word to more symbols.

It's also a convenient way to get exact reference data for testing your own substitution-based string generator.

Often used alongside Generate Fibonacci Words.

Features

Advantages

  • Produces an exact prefix of the documented Tribonacci word, matching the standard Rauzy substitution definition exactly.
  • Fast even at large character counts, since the string's length grows geometrically each round.
  • Ternary output stays simple, just the digits 0, 1, and 2, easy to parse or feed into other tools.

Limitations

  • Capped at 5000 characters to keep the tool responsive.
  • Only implements the standard Tribonacci substitution starting from "0"; it doesn't support alternate seeds or substitution rules.

Examples

First 7 characters of the Tribonacci word

Input

7

Output

0102010

Reached after three rounds of the substitution: "0" -> "01" -> "0102" -> "0102010", then read off the first 7 characters.

First 4 characters of the Tribonacci word

Input

4

Output

0102

Best Practices & Notes

Best Practices

  • Compare output side by side with Fibonacci Word Generator at the same character count to see how a third symbol changes the sequence's structure.
  • If you're studying the Rauzy fractal, generate a longer prefix, the visual structure only becomes apparent with several hundred characters or more.

Developer Notes

Each substitution round maps every character of the current string through the rule 0 -> "01", 1 -> "02", 2 -> "0" and concatenates the results into a new string; the loop repeats until the string's length reaches the requested character count, then the result is sliced to that exact length, mirroring the same doubling-and-truncate approach used for the binary Fibonacci word.

Generate Tribonacci Words Use Cases

  • Studying Rauzy fractals and their associated substitution dynamics
  • Generating a ternary Sturmian-like sequence for combinatorics-on-words exercises
  • Comparing growth and structure against the binary Fibonacci word

Common Mistakes

  • Expecting a binary (0/1 only) output, the Tribonacci word uses three symbols, 0, 1, and 2, by definition.
  • Assuming the substitution rule is symmetric between all three symbols, it isn't: only "0" ever produces two characters per round, which is what drives the sequence's specific growth rate.

Tips

  • Use Fibonacci Word Generator alongside this tool to build intuition for how the binary and ternary constructions relate.
  • Track how often each of 0, 1, and 2 appears in a long prefix, their relative frequencies converge to specific values tied to the Tribonacci constant.

References

Frequently Asked Questions