Stern's Diatomic Sequence Calculator
Sequence
- Write n in binary: 100 = 110 0100, and walk the digits with Dijkstra's pair method, tracking (fusc(k), fusc(k + 1)) for the prefix k built so far.
- The recurrence behind the walk: fusc(2k) = fusc(k) and fusc(2k + 1) = fusc(k) + fusc(k + 1), starting from fusc(0) = 0 and fusc(1) = 1.
- The walk ends at fusc(100) = 7 and fusc(101) = 19.
- Consecutive terms give the Calkin-Wilf fraction fusc(n) / fusc(n + 1) = 7/19, the nth positive rational in the Calkin-Wilf enumeration.
This calculator computes terms of Stern's diatomic sequence, also called the fusc sequence, which starts 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1 for n = 0 to 16. Enter an index and it returns the matching term using the recurrence fusc(2k) = fusc(k) and fusc(2k + 1) = fusc(k) + fusc(k + 1), starting from fusc(0) = 0 and fusc(1) = 1. For example, fusc(100) = 7, fusc(101) = 19, and fusc(1000) = 11. The same values appear in the Calkin-Wilf enumeration of the positive rationals, where consecutive terms give fractions such as the 11th, fusc(11) / fusc(12) = 5/2.
The method behind the answer is Dijkstra's pair method: walk the binary digits of the index, carrying a pair of consecutive fusc values and updating them one digit at a time. For fusc(100), the walk follows the binary digits of 100 (110 0100). Because it needs only one step per binary digit, large indices stay cheap, which is why fusc(1000) is easy to reach. This binary walk is the accepted standard for this kind of calculation. On this page you will find the formula, step-by-step workings, worked examples and sources so you can check every result yourself.
Worked examples
fusc(100)
(100)
| fusc(n) — the nth Stern diatomic term | 7 |
| fusc(n + 1) | 19 |
| Calkin-Wilf fraction fusc(n) / fusc(n + 1) | 7/19 |
| sum of fusc(0) through fusc(100) | 773 |
fusc(11) and the Calkin-Wilf fraction
(11)
| fusc(n) — the nth Stern diatomic term | 5 |
| fusc(n + 1) | 2 |
| Calkin-Wilf fraction fusc(n) / fusc(n + 1) | 5/2 |
| sum of fusc(0) through fusc(11) | 26 |
fusc(1000)
(1000)
| fusc(n) — the nth Stern diatomic term | 11 |
| fusc(n + 1) | 39 |
| Calkin-Wilf fraction fusc(n) / fusc(n + 1) | 11/39 |
| sum of fusc(0) through fusc(1,000) | 29,017 |
What is Stern's diatomic sequence?
Stern's diatomic sequence, also called fusc, is a sequence of whole numbers defined by a simple rule that splits each index into even and odd cases. For an even index 2k, the value equals the value at k: fusc(2k) = fusc(k). For an odd index 2k + 1, the value is the sum of the values at the two neighboring indices k and k + 1: fusc(2k + 1) = fusc(k) + fusc(k + 1). The sequence is anchored by fusc(0) = 0 and fusc(1) = 1, and every later term follows from these two starting values.
Written out from n = 0 to n = 16, the sequence reads 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1. You can check the recurrence against these terms directly. Take n = 6, which is 2 × 3, so fusc(6) = fusc(3) = 2. Take n = 7, which is 2 × 3 + 1, so fusc(7) = fusc(3) + fusc(4) = 2 + 1 = 3. Both match the list. The sequence is named after the 19th-century mathematician Moritz Stern.
The values stay small even at large indices, and computing them does not require building the sequence term by term. fusc(1000) = 11, for example. Large indices are cheap because a binary walk needs only one step per binary digit. To see the method in action, fusc(100) = 7 and fusc(101) = 19, computed by walking the binary digits of 100 (110 0100) with Dijkstra's pair method. Because 100 in binary has seven digits, the walk takes only a handful of steps rather than one hundred.
The sequence also has a striking link to fractions. Consecutive terms form the Calkin-Wilf enumeration of the positive rationals, in which each positive rational number appears exactly once. The 11th fraction in that enumeration is fusc(11) / fusc(12) = 5/2. That pairing of neighboring terms is what makes the sequence useful beyond pure number theory, and it is one reason a Stern's diatomic sequence calculator is handy: it lets you jump straight to a term or a fraction without listing everything before it.
How the calculator finds fusc(n)
The calculator does not build the sequence term by term up to n. Instead it uses a method commonly credited to Edsger Dijkstra: a walk along the binary digits of n that carries just two consecutive values, fusc(k) and fusc(k + 1), at every step. The walk rests on the recurrence itself: fusc(2k) = fusc(k) and fusc(2k + 1) = fusc(k) + fusc(k + 1), with fusc(0) = 0 and fusc(1) = 1. Because each rule reads a term only in terms of smaller indices, the binary digits of n tell you exactly which rule to apply, left to right.
Start with the pair (fusc(0), fusc(1)) = (0, 1) and read the binary digits of n from the most significant one onward. A 0 bit means the index doubles, so the new pair is (fusc(k), fusc(k) + fusc(k + 1)): the first value stays and the second becomes the sum. A 1 bit means the index doubles and adds one, so the new pair is (fusc(k) + fusc(k + 1), fusc(k + 1)): the sum moves to the front and the second value stays. Either way, one bit costs one addition and the pair stays consecutive, so the first entry is always fusc of the index read so far.
Take n = 100, whose binary form is 1100100. Begin at (0, 1). The leading 1 gives (0 + 1, 1) = (1, 1). The next 1 gives (1 + 1, 1) = (2, 1). The 0 gives (2, 2 + 1) = (2, 3). The next 0 gives (2, 2 + 3) = (2, 5). The 1 gives (2 + 5, 5) = (7, 5). The next 0 gives (7, 7 + 5) = (7, 12). The final 0 gives (7, 7 + 12) = (7, 19). The first entry is 7, so fusc(100) = 7, and the second entry confirms fusc(101) = 19. That is how the Stern's diatomic sequence calculator finds fusc(n) without listing every earlier term.
The same walk explains why large indices are cheap. fusc(1000) = 11, and the work is proportional to the number of binary digits of the index, not to the index itself. Each digit is handled by a single addition, so even indices with hundreds of bits are reached in a few hundred steps. The pair carried along the way is also the reason consecutive terms matter: the Calkin-Wilf enumeration of the positive rationals is built from them, and the 11th fraction in that list is fusc(11) / fusc(12) = 5/2.
- 0 bit: (a, b) becomes (a, a + b).
- 1 bit: (a, b) becomes (a + b, b).
- Start from (fusc(0), fusc(1)) = (0, 1) and read the binary digits of n from the most significant one.
- For n = 100 (1100100), the pairs run (0, 1), (1, 1), (2, 1), (2, 3), (2, 5), (7, 5), (7, 12), (7, 19), giving fusc(100) = 7 and fusc(101) = 19.
The Calkin-Wilf connection
Stern's diatomic sequence, often written fusc(n), is more than a string of small integers. Its consecutive terms encode a complete list of the positive fractions. The rule is simple: take two neighboring terms, fusc(n) and fusc(n + 1), and form the fraction fusc(n) / fusc(n + 1). As n runs through the nonnegative integers, these fractions run through every positive rational number exactly once. This ordering is called the Calkin-Wilf enumeration, and it is the most striking reason the sequence appears in number theory and combinatorics.
The sequence begins 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1 for n = 0 to 16. Reading neighboring pairs gives the first fractions in the enumeration. The pair fusc(1) / fusc(2) = 1/1 comes first, followed by fusc(2) / fusc(3) = 1/2, fusc(3) / fusc(4) = 2/1, and so on. Every fraction is in lowest terms automatically, and no positive rational is skipped or repeated.
A worked example makes the connection concrete. The 11th fraction is fusc(11) / fusc(12) = 5/2. From the listed terms, fusc(11) = 5 and fusc(12) = 2, so the fraction is 5/2. The same pairing rule that produces this fraction is what defines the Calkin-Wilf enumeration: each index n gives one fraction, and each positive rational appears at exactly one index.
The recurrence behind the sequence explains why these fractions are so orderly. It is fusc(2k) = fusc(k) and fusc(2k + 1) = fusc(k) + fusc(k + 1), starting from fusc(0) = 0 and fusc(1) = 1. Because the rule splits by parity, values can be computed by walking the binary digits of an index with Dijkstra's pair method. For example, fusc(100) = 7 and fusc(101) = 19, obtained by walking the binary digits of 100 (110 0100). The same approach gives fusc(1000) = 11, and large indices are cheap because the binary walk needs only one step per binary digit.
| n | fusc(n) / fusc(n + 1) |
|---|---|
| 1 | 1/1 |
| 2 | 1/2 |
| 3 | 2/1 |
| 4 | 1/3 |
| 5 | 3/2 |
| 6 | 2/3 |
| 7 | 3/1 |
| 8 | 1/4 |
| 9 | 4/3 |
| 10 | 3/5 |
| 11 | 5/2 |
Properties worth knowing
Stern's diatomic sequence, usually written fusc(n), has a handful of structural features that make it far more than a curiosity. The first is a coprimality rule: any two consecutive terms are coprime. You can see it in the opening run, 0, 1, 1, 2, 1, 3, 2, 3, 1, 4, 3, 5, 2, 5, 3, 4, 1 for n = 0 to 16. Check neighbors such as 3 and 5, or 5 and 2, and no common factor appears. This follows directly from the recurrence fusc(2k) = fusc(k) and fusc(2k + 1) = fusc(k) + fusc(k + 1), starting from fusc(0) = 0 and fusc(1) = 1: each new term is built by adding or copying earlier neighbors, so a shared divisor could never survive the construction. The coprimality is what makes the next property possible.
That property is the link to the Calkin-Wilf tree. Consecutive terms form the Calkin-Wilf enumeration of the positive rationals, where each fraction is fusc(n) / fusc(n + 1). Because consecutive terms are coprime, every such fraction is already in lowest terms, so no reduction is needed. The 11th fraction, for example, is fusc(11) / fusc(12) = 5/2. Reading the sequence as a list of numerator-denominator pairs therefore walks through the positive rationals one at a time, each appearing exactly once. This is one of the cleanest places where Stern's diatomic sequence connects to a classical enumeration of the rationals, and it is a useful sanity check on any computed values.
A third property concerns how large the terms get. The maximum on each dyadic block grows like the Fibonacci numbers. A dyadic block is a run of indices between one power of two and the next, and the peak value inside each block follows the same growth pattern as the Fibonacci sequence. This gives a quick intuition for the sequence's overall shape: it stays small for long stretches, then reaches new heights at predictable points. It also explains why the values you meet at large indices can be surprisingly modest.
The binary-digit view ties these ideas together. Large indices are cheap to evaluate because the binary walk needs only one step per binary digit. To compute fusc(100), you walk the binary digits of 100 (110 0100) with Dijkstra's pair method and get fusc(100) = 7 and fusc(101) = 19. Push further and fusc(1000) = 11. Even at four-digit indices the answer stays small, which is exactly what the Fibonacci-style block maxima would lead you to expect.
- Consecutive terms are always coprime, so fusc(n) / fusc(n + 1) is automatically in lowest terms.
- The pairs fusc(n), fusc(n + 1) generate the Calkin-Wilf tree; the 11th fraction is fusc(11) / fusc(12) = 5/2.
- The maximum on each dyadic block grows like the Fibonacci numbers.
- Large indices are cheap: the binary walk needs one step per binary digit, giving fusc(100) = 7, fusc(101) = 19, and fusc(1000) = 11.
FAQs
What is fusc(100)?
fusc(100) = 7. The binary walk over 110 0100 produces this value, and the same walk gives fusc(101) = 19. These two results show how nearby inputs can produce quite different outputs, since fusc(100) and fusc(101) differ by 12 even though the numbers themselves are adjacent.
How is Stern's diatomic sequence defined?
Stern's diatomic sequence uses the starting values fusc(0) = 0 and fusc(1) = 1. For larger inputs, the rules are fusc(2k) = fusc(k) and fusc(2k + 1) = fusc(k) + fusc(k + 1). These two recurrences let you compute any term from smaller terms, with even inputs copying a value and odd inputs adding two values.
What is the Calkin-Wilf fraction at position 11?
The Calkin-Wilf fraction at position 11 is fusc(11) / fusc(12) = 5/2. This ratio comes directly from two consecutive fusc values, with 5 in the numerator and 2 in the denominator. Because consecutive fusc values are always coprime, the fraction is already in lowest terms.
Are consecutive fusc values always coprime?
Yes. fusc(n) and fusc(n + 1) are coprime for every n, so they share no common factor greater than 1. This is why their ratio is always in lowest terms. That property is what makes the Calkin-Wilf fractions, built from consecutive fusc values, appear in reduced form at every position.
What is fusc(1000)?
fusc(1000) = 11. Even though 1000 is a large input, its fusc value is small, which illustrates how the sequence grows unevenly rather than steadily. The value comes from applying the defining rules repeatedly, and the binary walk over 1000 produces 11 as the final result.
What do the first twelve fusc values add up to?
The first twelve fusc values, fusc(0) through fusc(11), sum to 26. This total counts the terms starting at fusc(0) = 0 and running through fusc(11) = 5. Summing a short run of terms like this is a quick way to check that a calculator is applying the sequence rules correctly.