Thue-Morse Sequence Calculator
Sequences
- The Thue-Morse sequence t(n) is the parity of the number of 1 bits in the binary form of n: even parity gives 0, odd parity gives 1.
- The number 13 has 3 ones in binary, which is odd, so t(13) = 1.
- The same sequence arises by starting with 0 and repeatedly appending the flipped copy of everything written so far, doubling the block every round.
- Thue showed in 1912 that the sequence is overlap-free - no block ever repeats three times in a row with the same period - which is why it turns up in chess drawing rules and fair-division protocols.
The Thue-Morse sequence is built from a single bit of information about each number: whether its binary form contains an even or odd number of 1s. Even parity gives 0, odd parity gives 1. From that austere rule comes one of the most studied sequences in mathematics - cube-free, overlap-free, and perfectly balanced at every power-of-two scale.
This Thue-Morse sequence calculator evaluates t(n) directly from the bit count, and can also list the first n terms starting from t(0). The first 16 terms are 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 - with exactly 8 zeros and 8 ones.
Axel Thue introduced the sequence in 1912 in his work on repetitions in words, and Marston Morse rediscovered it in dynamics. Its fairness properties - it never favours either symbol in any prefix-doubling - have made it the standard tool for fair division protocols and a recurring answer to 'how do we alternate without bias?'
Worked examples
t(13)
(Value at n · 13)
| Thue-Morse value t(13) | 1 |
| number of 1 bits in 13 | 3 |
| parity of the bit count | odd |
| the next value t(14) | 1 |
t(100)
(Value at n · 100)
| Thue-Morse value t(100) | 1 |
| number of 1 bits in 100 | 3 |
| parity of the bit count | odd |
| the next value t(101) | 0 |
First 16 terms
(First n terms · 16)
| first 16 Thue-Morse terms (from t(0)) | 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 |
| zeros among the terms | 8 |
| ones among the terms | 8 |
| first term t(0) | 0 |
Parity of the binary digit sum
Write n in binary and count the 1s - the population count, or popcount. t(n) = 0 if the count is even, 1 if it is odd. The number 13 is 1101 in binary, with 3 ones - odd - so t(13) = 1. The number 100 is 1100100, also with 3 ones, so t(100) = 1 as well. Two unrelated numbers, same answer, because only the parity matters.
The calculator reports the bit count and its parity alongside the value, so each answer is auditable at a glance: for t(100) you see 3 one-bits, odd, value 1, and the next value t(101) = 0 because 101 has 4 one-bits.
- t(n) = parity of the number of 1 bits in n
- t(13) = 1 (3 one-bits, odd)
- t(100) = 1 (3 one-bits, odd); t(101) = 0
The doubling construction
The same sequence arises constructively: start with 0, and repeatedly append the bitwise flip of everything written so far. The blocks grow 0; 0, 1; 0, 1, 1, 0; 0, 1, 1, 0, 1, 0, 0, 1 - doubling every round. This view explains the perfect balance: the second half of every block is the flipped first half, so any block whose length is a power of two contains exactly as many ones as zeros.
The first 16 terms illustrate it: 8 zeros and 8 ones, and the second 8 terms are the first 8 flipped. The calculator's list mode starts at t(0) = 0, matching this construction.
- Append the flipped copy, doubling each round
- Every power-of-two block is exactly balanced
- First 16 terms: 8 zeros and 8 ones
Overlap-free
Thue's 1912 theorem: the sequence contains no overlap - no block of the form x y x y x with x a single symbol, equivalently no pattern where a word repeats three times in a row with the same period. This is a strong non-repetition property; Thue built the sequence precisely to show that infinite overlap-free words on two letters exist, settling a question in combinatorics on words.
The property has a famous recreational shadow: in chess, the Thue-Morse pattern has been proposed as a drawing-avoidance scheme, since a game whose position sequence followed it could never repeat a position three times in the same rhythm. Tournament rules never adopted it, but the example remains the standard illustration of what overlap-free means.
It is worth being precise about what 'overlap' forbids. An overlap is a word of the form a x a x a where a is a single letter and x is any block: the pattern begins with two full copies of a block and a third copy started. Ordinary periodic sequences are full of overlaps - an alternating sequence contains 01010, an overlap on the block 01. The Thue-Morse sequence contains doubles, like the 1, 1 pairs visible in its first 16 terms, but the third repetition that would complete an overlap never arrives, at any position, at any scale.
- No block repeats three times with the same period
- Thue, 1912: infinite overlap-free binary words exist
- Proposed (never adopted) for chess draw avoidance
Fair division and picking sequences
Because the sequence is balanced at every scale, it is the canonical fair-picking order: two players alternately claiming items in Thue-Morse order (first player takes turns 0, 3, 4, 6, ... by the 0/1 pattern) cancel out each other's advantage far better than simple alternation when item values decline smoothly. The same idea appears in sports drafts and in penalty-shootout order research.
The sequence also defines the Prouhet-Thue-Morse constant and connects to the Prouhet-Tarry-Escott problem: splitting the numbers 0..15 by their t-values gives two sets with equal sums of like powers up to the third power - a direct consequence of the parity definition.
- Fair-picking and draft orders
- Prouhet-Tarry-Escott equal power sums
- OEIS A010060
Worked example: t(13) and t(100) by hand
13 in binary is 1101: three 1 bits. Three is odd, so t(13) = 1. Its successor 14 is 1110, also three 1 bits, so t(14) = 1 as well - consecutive values need not alternate, and indeed the sequence contains doubles (1, 1 and 0, 0) but never triples. 100 in binary is 1100100: again three 1 bits, so t(100) = 1, while 101 = 1100101 has four, giving t(101) = 0.
These four evaluations show the whole method: there is nothing to iterate and nothing to approximate. The calculator's reported bit count and parity are the entire computation, displayed so the answer can be re-derived in seconds.
- 13 = 1101 (3 ones) -> t = 1
- 100 = 1100100 (3 ones) -> t = 1
- 101 = 1100101 (4 ones) -> t = 0
- Doubles occur; triples never do
Thue-Morse beyond mathematics
The sequence keeps escaping into applications because 'balanced at every scale' is a broadly useful property. In audio and signal processing, Thue-Morse patterns distribute energy evenly; in computer science the sequence generates the parity bits of the ruler function family and appears in the analysis of the Tower of Hanoi; in music it has been used as a compositional scaffold precisely because it sounds patterned without ever quite repeating.
The common thread is the overlap-free theorem of 1912: a structure that cannot fall into a threefold rhythmic repetition, built from the simplest possible rule. Few sequences repay their definition as generously.
- Signal patterns with even energy distribution
- Compositional scaffolds without threefold repetition
- One parity rule, many fields
Reading the calculator's output
Value mode shows four things: the value t(n), the number of 1 bits in n, the parity of that count, and the next value t(n + 1). The middle two are the audit trail - they are the definition, applied in the open. For n = 100 the display reads: 3 one-bits, odd, t(100) = 1, t(101) = 0. Anyone can re-derive the answer from the bit count alone, which is the right standard for a sequence defined by a one-line rule.
List mode shows the first n terms from t(0) with the zero and one counts. Those counts encode the balance theorem: at n = 16 they read 8 and 8, and they would read exactly equal at 32, 64 and every higher power of two, while at intermediate lengths they differ by small amounts that the doubling construction keeps tightly leashed. Watching the counts as n grows is the fastest way to build intuition for what 'balanced at every scale' means.
- Bit count and parity are the audit trail
- Counts are exactly equal at powers of two
- First 16 terms: 8 zeros, 8 ones
Using the calculator
Value mode gives t(n) with the bit count, its parity, and t(n + 1) - everything needed to verify the answer from the definition. List mode prints the first n terms from t(0) with the zero and one counts. Values up to n = 500 are supported; the parity computation is a single popcount, so results are instant and exact.
A useful experiment: list the first 16 terms and check the second half against the first - flipped, exactly. Then check t(13) and t(100) by counting one-bits yourself; both have 3, and both answer 1.
- Value mode: value, bit count, parity, next value
- List mode from t(0), with zero/one counts
- Exact single-popcount evaluation
FAQs
How is the Thue-Morse sequence defined?
t(n) is the parity of the number of 1 bits in the binary form of n: an even count gives 0 and an odd count gives 1.
What is t(100)?
1 - the number 100 has 3 ones in binary, an odd count. The next value, t(101), is 0.
What are the first Thue-Morse terms?
From t(0): 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0 - exactly 8 zeros and 8 ones in the first 16.
What does overlap-free mean?
No block of the sequence ever repeats three times in a row with the same period. Thue proved the sequence has this property in 1912.
How else can the sequence be built?
Start with 0 and repeatedly append the flipped copy of everything written so far, doubling the block each round.
Why is Thue-Morse used for fair division?
It is balanced at every power-of-two scale, so picking items in Thue-Morse order cancels first-mover advantage much better than plain alternation.