Thue–Morse sequence
In mathematics, the Thue–Morse or Prouhet–Thue–Morse sequence is the binary sequence that can be obtained by starting with 0 and successively appending the Boolean complement of the sequence obtained thus far. It is sometimes called the fair share sequence because of its applications to fair division or parity sequence. The first few steps of this procedure yield the strings 0, 01, 0110, 01101001, 0110100110010110, and so on, which are the prefixes of the Thue–Morse sequence. The full sequence begins:
The sequence is named after Axel Thue, Marston Morse and Eugène Prouhet.
Definition
There are several equivalent ways of defining the Thue–Morse sequence.Direct definition
To compute the nth element tn, write the number n in binary. If the number of ones in this binary expansion is odd then tn = 1, if even then tn = 0. That is, tn is the even parity bit for n. John H. Conway et al. deemed numbers n satisfying tn = 1 to be odious numbers, and numbers for which tn = 0 to be evil numbers.Fast sequence generation
This method leads to a fast method for computing the Thue–Morse sequence: start with, and then, for each n, find the highest-order bit in the binary representation of n that is different from the same bit in the representation of. If this bit is at an even index, tn differs from, and otherwise it is the same as.In Python:
from typing import Iterator
def generate_sequence -> Iterator:
"""Thue–Morse sequence."""
value: int = 1
for n in range:
# Note: assumes that.bit_length gives 1
x: int =.bit_length + 1
if x & 1 0:
# Bit index is even, so toggle value
value = 1 - value
yield value
The resulting algorithm takes constant time to generate each sequence element, using only a logarithmic number of bits of memory.
Recurrence relation
The Thue–Morse sequence is the sequence tn satisfying the recurrence relationfor all non-negative integers n.
L-system
The Thue–Morse sequence is a morphic word: it is the output of the following Lindenmayer system:| Variables | 0, 1 |
| Constants | None |
| Start | 0 |
| Rules | , |
Characterization using bitwise negation
The Thue–Morse sequence in the form given above, as a sequence of bits, can be defined recursively using the operation of bitwise negation.So, the first element is 0.
Then once the first 2n elements have been specified, forming a string s, then the next 2n elements must form the bitwise negation of s.
Now we have defined the first 2n+1 elements, and we recurse.
Spelling out the first few steps in detail:
- We start with 0.
- The bitwise negation of 0 is 1.
- Combining these, the first 2 elements are 01.
- The bitwise negation of 01 is 10.
- Combining these, the first 4 elements are 0110.
- The bitwise negation of 0110 is 1001.
- Combining these, the first 8 elements are 01101001.
- And so on.
- T0 = 0.
- T1 = 01.
- T2 = 0110.
- T3 = 01101001.
- T4 = 0110100110010110.
- T5 = 01101001100101101001011001101001.
- T6 = 0110100110010110100101100110100110010110011010010110100110010110.
- And so on.
def thue_morse_bits -> int:
"""Return an int containing the first 2**n bits of the Thue–Morse sequence, low-order bit 1st."""
bits = 0
for i in range:
bits |= <<
return bits
Which can then be converted to a string as follows:
n = 7
Infinite product
The sequence can also be defined by:where tj is the jth element if we start at j = 0.
Properties
The Thue–Morse sequence contains many squares: instances of the string, where denotes the string,,, or, where for some and is the bitwise negation of. For instance, if, then. The square appears in starting at the 16th bit. Since all squares in are obtained by repeating one of these 4 strings, they all have length or for some. contains no cubes: instances of. There are also no overlapping squares: instances of or. The critical exponent of is 2.The Thue–Morse sequence is a uniformly recurrent word: given any finite string X in the sequence, there is some length nX such that X appears in every block of length nX. Notably, the Thue–Morse sequence is uniformly recurrent without being either periodic or eventually periodic.
The sequence T2n is a palindrome for any n. Furthermore, let qn be a word obtained by counting the ones between consecutive zeros in T2n. For instance, q1 = 2 and q2 = 2102012. Since Tn does not contain overlapping squares, the words qn are palindromic squarefree words.
The Thue–Morse morphism μ is defined on alphabet by the substitution map μ = 01, μ = 10: every 0 in a sequence is replaced with 01 and every 1 with 10. If T is the Thue–Morse sequence, then μ is also T. Thus, T is a fixed point of μ. The morphism μ is a prolongable morphism on the free monoid ∗ with T as fixed point: T is essentially the only fixed point of μ; the only other fixed point is the bitwise negation of T, which is simply the Thue–Morse sequence on instead of on. This property may be generalized to the concept of an automatic sequence.
The generating series of T over the binary field is the formal power series
This power series is algebraic over the field of rational functions, satisfying the equation
In the Thue-Morse sequence, the symbols 0 and 1 can be replaced with the variables and to obtain a generalized Thue-Morse sequence. If and are distinct positive integers, then the resulting sequence can be taken to be the terms of a simple continued fraction. The resulting Thue-Morse continued fraction,
is transcendental.
In combinatorial game theory
The set of evil numbers forms a subspace of the nonnegative integers under nim-addition. For the game of Kayles, evil nim-values occur for few positions in the game, with all remaining positions having odious nim-values.The Prouhet–Tarry–Escott problem
The Prouhet–Tarry–Escott problem can be defined as: given a positive integer N and a non-negative integer k, partition the set S = into two disjoint subsets S0 and S1 that have equal sums of powers up to k, that is:This has a solution if N is a multiple of 2k+1, given by:
- S0 consists of the integers n in S for which tn = 0,
- S1 consists of the integers n in S for which tn = 1.
The condition requiring that N be a multiple of 2k+1 is not strictly necessary: there are some further cases for which a solution exists. However, it guarantees a stronger property: if the condition is satisfied, then the set of kth powers of any set of N numbers in arithmetic progression can be partitioned into two sets with equal sums. This follows directly from the expansion given by the binomial theorem applied to the binomial representing the nth element of an arithmetic progression.
For generalizations of the Thue–Morse sequence and the Prouhet–Tarry–Escott problem to partitions into more than two parts, see Bolker, Offner, Richman and Zara, "The Prouhet–Tarry–Escott problem and generalized Thue–Morse sequences".
Fractals and turtle graphics
Using turtle graphics, a curve can be generated if an automaton is programmed with a sequence. Using the Thue–Morse sequence, the rules- If t = 0, move ahead by one unit,
- If t = 1, rotate by an angle of π/3 radians
It is also possible to draw the curve precisely using the following instructions:
- If t = 0, rotate by an angle of π radians,
- If t = 1, move ahead by one unit, then rotate by an angle of π/3 radians.
Equitable sequencing
Lionel Levine and Katherine E. Stange, in their discussion of how to fairly apportion a shared meal such as an Ethiopian dinner, proposed the Thue–Morse sequence as a way to reduce the advantage of moving first. They suggested that “it would be interesting to quantify the intuition that the Thue–Morse order tends to produce a fair outcome.”
Robert Richman addressed this problem, but he too did not identify the Thue–Morse sequence as such at the time of publication. He presented the sequences Tn as step functions on the interval and described their relationship to the Walsh and Rademacher functions. He showed that the nth derivative can be expressed in terms of Tn. As a consequence, the step function arising from Tn is orthogonal to polynomials of order n − 1. A consequence of this result is that a resource whose value is expressed as a monotonically decreasing continuous function is most fairly allocated using a sequence that converges to Thue–Morse as the function becomes flatter. An example showed how to pour cups of coffee of equal strength from a carafe with a nonlinear concentration gradient, prompting a whimsical article in the popular press.
Joshua Cooper and Aaron Dutle showed why the Thue–Morse order provides a fair outcome for discrete events. They considered the fairest way to stage a Galois duel, in which each of the shooters has equally poor shooting skills. Cooper and Dutle postulated that each dueler would demand a chance to fire as soon as the other's a priori probability of winning exceeded their own. They proved that, as the duelers’ hitting probability approaches zero, the firing sequence converges to the Thue–Morse sequence. In so doing, they demonstrated that the Thue–Morse order produces a fair outcome not only for sequences Tn of length 2n, but for sequences of any length.
Thus the mathematics supports using the Thue–Morse sequence instead of alternating turns when the goal is fairness but earlier turns differ monotonically from later turns in some meaningful quality, whether that quality varies continuously or discretely.
Sports competitions form an important class of equitable sequencing problems, because strict alternation often gives an unfair advantage to one team. Ignacio Palacios-Huerta proposed changing the sequential order to Thue–Morse to improve the ex post fairness of various tournament competitions, such as the kicking sequence of a penalty shoot-out in soccer. He did a set of field experiments with pro players and found that the team kicking first won 60% of games using ABAB, 54% using ABBA, and 51% using full Thue–Morse. As a result, ABBA is undergoing extensive trials in FIFA and English Federation professional soccer. An ABBA serving pattern has also been found to improve the fairness of tennis tie-breaks. In competitive rowing, T2 is the only arrangement of port- and starboard-rowing crew members that eliminates transverse forces on a four-membered coxless racing boat, while T3 is one of only four rigs to avoid wiggle on an eight-membered boat.
Fairness is especially important in player drafts. Many professional sports leagues attempt to achieve competitive parity by giving earlier selections in each round to weaker teams. By contrast, fantasy football leagues have no pre-existing imbalance to correct, so they often use a “snake” draft. Ian Allan argued that a “third-round reversal” would be even more fair. Richman suggested that the fairest way for “captain A” and “captain B” to choose sides for a pick-up game of basketball mirrors T3: captain A has the first, fourth, sixth, and seventh choices, while captain B has the second, third, fifth, and eighth choices.