REPETITIONS IN WORDS

NARAD RAMPERSAD AND JEFFREY SHALLIT

(DRAFT Version of May 10, 2012)

Contents 1. Introduction 2 1.1. Words 2 1.2. Morphisms 2 2. Avoidability 3 2.1. Squares, cubes, and k-powers 3 2.2. Fractional powers 4 2.3. Overlaps 6 2.4. Fife’s theorem 8 2.5. Power-free morphisms 12 2.6. The probabilistic method 12 3. Dejean’s theorem 14 3.1. The repetition threshold 15 3.2. Restrictionsonmorphicconstructions 17 3.3. Pansiot recoding 19 4. Avoidingrepetitionsinarithmeticprogressions 20 5. Patterns 23 6. Abelian repetitions 24 6.1. Theadjacencymatrixassociatedwithamorphism 24 6.2. Dekking’s construction 25 6.3. Abelianrepetitionsinbalancedwords 28 7. Enumeration 30 7.1. Enumeratingsquarefreewords 30 7.2. Enumerating overlap-free words 30 7.3. TheGoulden–Jacksonclustermethod 30 7.4. Apowerseriesmethodforlowerbounds 33 8. Algorithmics of patterns 39 8.1. Algorithms for automatic sequences 39 8.2. Abelian patterns 40 9. Notes 45 References 48

1 2 NARAD RAMPERSAD AND JEFFREY SHALLIT

1. Introduction The study of combinatorics on words dates back at least to the begin- ning of the 20th century and the work of Axel Thue [93, 94] on repetitions in words. The study of repetitions in words has several applications; perhaps the most famous is in the work of Novikov and Adjan [73, 74, 75, 76] in solving the Burnside problem for groups. Recently, combinatorial results regarding repetitions in words have been used to prove deep results in tran- scendental number theory. Some of these recent developments are described in the first CANT volume [4]. Here we discuss some aspects of repetitions in words, with emphasis on powers of words and their avoidability.

1.1. Words. Let Σ be a finite, nonempty set called an alphabet; the ele- ments of Σ are referred to as symbols or letters. We let Σ∗ denote the set of all finite words over the alphabet Σ. The set of all finite, non-empty words over Σ is denoted Σ+. We let ǫ denote the empty word. The length of a ∗ word w is denoted w . For a Σ and w Σ , we write w a for the number of occurrences of a|in| w. ∈ ∈ | | Let N denote the set 0, 1, 2,... . An (one-sided right) infinite word is a map from N to Σ. If w {is an infinite} word, we often write w = a a a , 0 1 2 ··· ω where each ai Σ. The set of all infinite words of Σ is denoted Σ . If y is a finite nonempty∈ word, then yω denotes the infinite word yyy . A infinite word is ultimately periodic if it can be written in the form xy···ω, where x,y are finite words with y nonempty. A two-sided or bi-infinite word is a map from Z to Σ. The set of all bi-infinite words is denoted ωΣω. A word w′ is a factor of a word w if w can be written as uw′v for some words u and v. If such a decomposition exists where u = ǫ (resp., v = ǫ), then w′ is called a prefix (resp., suffix) of w. A prefix (resp., suffix) of a word w is proper if it is not equal to w. Thus, for example, if w = concatenation, then con is a prefix, ate is a factor, and nation is a suffix. Frequently we shall deduce the existence of an infinite word with a cer- tain property from the existence of arbitrarily large finite words with the desired property. To pass from the finite to the infinite, we shall often rely (implicitly) on the following form of K¨onig’s infinity lemma. Theorem 1. Let Σ be a finite alphabet, and let A be an infinite subset of Σ∗. Then there exists an infinite word w such that every prefix of w is a prefix of at least one word in A. 1.2. Morphisms. A map h : Σ∗ ∆∗, where Σ and ∆ are alphabets, is called a morphism if h satisfies →h(xy) = h(x)h(y) for all x,y Σ∗. A morphism may be specified by providing the values h(a) for all a ∈ Σ. For ∈ REPETITIONSINWORDS 3 example, we may define a morphism h : 0, 1, 2 ∗ 0, 1, 2 ∗ by { } → { } 0 01201 → (1) 1 020121 → 2 0212021. → This domain of a morphism is easily extended to (one-sided) infinite words. A morphism h : Σ∗ Σ∗ such that h(a) = ax for some a Σ and x Σ∗ with hi(x) = ǫ for→ all i is said to be prolongable on a; we may∈ then repeatedly∈ iterate h6 to obtain the infinite fixed point hω(a)= axh(x) h2(x) h3(x) . ··· The morphism h given by (1) above is prolongable on 0, so we have the fixed point hω(0) = 01201020121021202101201020121 . ··· A morphism h is non-erasing if h(a) = ǫ for all a Σ. Otherwise it is erasing. A morphism is k-uniform if6 h(a) = k for∈ all a Σ; it is uniform if it is k-uniform for some k. For| example,| if the morphism∈ µ : 0, 1 ∗ 0, 1 ∗ is defined by { } → { } 0 01 → 1 10, → then µ is 2-uniform. This morphism is often referred to as the Thue–Morse morphism. The fixed point t = µω(0) = 0110100110010110 ··· is known as the Thue–Morse word. A generalization of morphism is the substitution. A substitution s is ∗ a map from Σ∗ to 2∆ satisfying s(xy) = s(x)s(y) for all x,y Σ∗ and s(ǫ)= ǫ . ∈ { }

2. Avoidability 2.1. Squares, cubes, and k-powers. The most basic type of repetition is the square, that is, a nonempty word of the form xx, where x Σ∗. An example of a square in English is the word murmur. We say a word∈ w is squarefree (or avoids squares) if no factor of w is a square. It is easy to see that every word of length at least four over the alphabet 0, 1 contains a square; it is therefore impossible to avoid squares in infini{te binary} words. In 1906, Thue [93] proved the following fundamental result. Theorem 2. There exists an infinite squarefree word over an alphabet of size three. 4 NARAD RAMPERSAD AND JEFFREY SHALLIT

By analogy with the definition of a square, a cube is a nonempty word of the form xxx, where x Σ∗. A word w is cubefree if no factor of w is a cube. The Thue–Morse word∈ t is cube-free, but we shall see presently that it is possible to prove something even stronger. For any positive integer k 2, a k-power is a nonempty word of the form k ≥ xx x, written for convenience as xk. Thus a 2-power is a square, and a 3-power··· is a cube. A nonempty word that is not a k-power for any k 2 is primitivez }| { . A word is k-power-free (or avoids k-powers) if none of its factors≥ are k-powers. 2.2. Fractional powers. We can extend the notion of integer powers in words to fractional powers. Let α be a real number > 1. A word y is said to be an α-power of x if y is the shortest prefix of of xω such that y α x . Similarly, y is said to be an α+-power of x if y is the shortest| prefix|≥ | of| xω such that y > α x . For example, the French word entente is both 7 | | | | √ n ′ a 3 -power of ent, and a 5 = 2.236 -power. If we can write y = x x , where n 1 is an integer and x′ is a prefix··· of x, then we say that y / x is an exponent≥ of y. The largest such exponent is called the exponent| of| |y.| Lemma 3. Let h be a uniform morphism, and let α = β (resp., β+) for a real number β 1. If w contains an α-power then so does h(w). ≥ Proof. Suppose w contains an α-power. Then there exist words s,s′ Σ+ and r, t Σ∗ such that w = rsns′t, where s′ is a nonempty prefix of s∈and n + s′ /∈s β (resp., > β). Then h(w) = h(r)h(s)nh(s′)h(t). Then h(w) contains| | |h|(s ≥)nh(s′), which is of exponent α.  ≥ We now examine how exponents behave under application of the Thue- Morse morphism µ. First, we need two lemmas. We write 0=1 and 1=0. Lemma 4. Let t,v 0, 1 ∗. Suppose there exist letters c,d 0, 1 such that cµ(t)= µ(v)d. Then∈ { c}= d and t = cn and v = cn, where ∈n {= t }= v . | | | |

Proof. By induction on n. The base case is n = 0, so t = ǫ. Hence v = ǫ and c = d. For the induction step, assume the result is true for all words of length < n; we prove it for n. If cµ(t)= µ(v)d, then by comparing prefixes we see that v = cv′ for some word v′, and by comparing suffixes we see that t = t′ d. Substituting, we get cµ(t′d) = µ(cv′) d. Hence cµ(t′) dd = c cµ(v′) d. Cancelling c on the left and d on the right, we get µ(t′) d = cµ(v′). Induction then gives c = d (and hence c = d) and t′ = cn−1 and v′ = cn−1. From this the desired result follows.  Lemma 5. Suppose y,z 0, 1 ∗ and µ(y) = zz. Then there exists x 0, 1 ∗ such that z = µ(x)∈. { } ∈ { } REPETITIONSINWORDS 5

Proof. If z is even, the result is clear, since then µ(y) 0 (mod 4), and hence y is| | even. Hence z = µ(w), where w is the prefix| of| ≡y of length y /2. Let| us| show that n = z cannot be odd. If it were, let z = au = vb, where| | a,b 0, 1 and u and v|are| words of even length. Then µ(y)= zz = vbau; hence∈ { there} exist words r, s such that u = µ(r) and v = µ(s). Hence zz = µ(s)baµ(r), and b = a. But z = aµ(r) = µ(s)b; hence by Lemma 4 we have z = a (aa)(n−1)/2. Then the last letter of z equals a and a, a contradiction.  Theorem 6. Let α = β for a real number β > 2 or α = β+ for a real number β 2. Then x is α-power-free if and only if µ(x) is α-power-free. ≥ Proof. One direction follows from Lemma 3. For the other direction we handle the case where α = β > 2. Suppose µ(w) = xyny′z, where n 2 and n + y′ / y = γ, for γ α (resp., > α). There are four cases to≥ consider, based| | on| | the parity of≥ x and y . | | | | Case 1: x is even and y is even. There are two subcases, depending on the parity| | of y′ . | | | | Case 1a: y′ is even. Then z is even. Then there exist words r,s,s′,t, with s′ a prefix| | of s, such that µ| (|r)= x, µ(s)= y, µ(s′)= y′, and µ(t)= z. Then w = rsns′t, and so w contains the γ-power sns′. Case 1b: y′ is odd. Then z is odd. Then there exist words r,s,s′,t, with s′ a prefix| | of s, and a letter| c| such that µ(r)= x, µ(s)= y, µ(s′)c = y′, and cµ(t)= z. Since y′ is odd, y is even, and y′ is a prefix of y, it follows that y′c is also a prefix| of| y. Hence| | s′c is a prefix of s. Then w contains the β-power sns′c, where s′c 2 s′ + 2 y′ + 1 y′ β = n + | | = n + | | = n + | | > n + | | γ. s 2 s y y ≥ | | | | | | | | Case 2: x is even and y is odd. Since x is even and µ(w) = xyny′z, there exists| a| word t such| that| µ(t) = yy.| From| Lemma 5 there exists v such that y = µ(v). But then y is even, a contradiction. Thus this case cannot occur. | |

Case 3: x is odd and y is even. There are two subcases, depending on the parity of| | y′ . | | | | Case 3a: y′ is even. Then z is odd. Then there exist words r,s,s′,t and | | | | letters c,d,e such that x = µ(r)c, y = cµ(s)d, y′ = dµ(s′)e, and z = eµ(t). Consideration of the factor yy shows that dc must be the image of a letter under µ, so c = d. Hence µ(w) = µ(r(cs)ncs′et) and so w = r(cs)ncs′et. Thus w contains the γ-power (cs)ncs′, and since s′ is a prefix of s, it follows that cs′ is a prefix of cs. 6 NARAD RAMPERSAD AND JEFFREY SHALLIT

Case 3b: y′ is odd. Then z is even. Then we are in the mirror image of case 2a, and| | the same proof| works.| Case 4: x is odd and y is odd. Then from length considerations we see that there| | exist words t,v| | and letters c,d such that y = cµ(t)= µ(v)d. By Lemma 4, we have d = c, t = cr, and v = cr for some r 0. Thus y = c(cc)r. Since y′ is a nonempty prefix of y and n 2, we≥ may write µ(w)= xy2ct for some word t. Since x and y are odd,≥ and y ends in c, we must have that cc is the image of a| single| letter| | under µ, a contradiction. Thus this case cannot occur.  Corollary 7. Suppose x is a binary word. Then the largest exponent of a factor of x is exactly the same as the largest exponent of a factor of µ(x) if and only if x 01, 10, 010, 101 . 6∈ { } Proof. Let a 0, 1 . One direction is easy, since ∈ { } (a) µ(a a)= a a aa contains a square, while a a has largest power 1; 3 (b) µ(a aa) contains a square, while a aa is a 2 -power. For the other direction, if x or µ(x) contains a power > 2, the result follows from Theorem 6. Hence the largest power in x and µ(x) is 2. If the largest power in x is < 2, then x 3. Since x 01, 10, 010, 101≤ this means x ǫ, 0, 1 , and the result follows.| |≤ 6∈ { } So the∈ largest { power} in x is 2. By Lemma 3 we know that µ(x) contains a power 2. From above we have µ(x) contains only powers 2. So the largest power≥ in µ(x) is 2. ≤  2.3. Overlaps. An overlap is a word of the form axaxa, where a Σ and x Σ∗. In the terminology of the previous section, an overlap can∈ also be defined∈ as a 2+-power. An example of an overlap in English is the word alfalfa. A finite or infinite word is overlap-free if it contains no factor that is an overlap. Thue [94] was the first to show the existence of infinite overlap-free binary words. Theorem 8. The Thue–Morse word t is overlap-free. Proof. The word 0 is clearly overlap-free. By Theorem 6 we know that if x is overlap-free, then µ(x) is also. Repeatedly applying µ to 0 gives longer and longer prefixes of t, each of which is overlap-free.  There is a beautiful and useful characterization of overlap-free words due to Restivo and Salemi [86]. Basically, the theorem says that, up to the edges, overlap-free words can be factorized as an image under µ of shorter overlap-free words. Theorem 9. Let x 0, 1 ∗ be overlap-free. Then there exist u,v ǫ, 0, 1, 00, 11 and an∈ overlap-free { } word y such that x = uµ(y)v. ∈ { } First, we need a lemma: REPETITIONSINWORDS 7

Lemma 10. Let a 0, 1 . Suppose a a ay is overlap-free. Then at least one of the following∈ holds: { } (a) y 3; (b) y| |≤begins with aa ; (c) y begins with aaaa.

Proof. If y begins with aa or y 3, we’re done. So assume y doesn’t begin with aa and y 4. | |≤ If y begins| with|≥ a, then a a ay begins with a a a a, which has an overlap. So y begins with a, but not aa. So it begins with a a. If y = a a az for some z with z 1, then by hypothesis a a ay = a a aa a az is overlap-free. But whatever| |≥ the first character of z is, the result has an overlap. So y = a aaz for some z. If z = az′, then a a ay = a a aa aa az′ has an overlap. So z = az′. Thus y begins with a aaa as desired.  Now we can prove the Restivo-Salemi theorem. Proof. The proof is by induction on x . For x = k 2, the result is easy, for either x = aa for some a 0, 1 ,| in| which| case| u≤= v = ǫ and y = a, or x is in ǫ, 0, 1, 00, 11 . ∈ { } Now{ assume the result} is true for x

Proof. Consider applying Theorem 9 to longer and longer prefixes of x. For each such prefix xn of length n, we get a factorization of the form unµ(yn)vn. But there are only finitely many possibilities for un, so among this infinite ′ ′ list of factorizations there must be a single u such that un = u for for ′ infinitely many n; say, for n = n1, n2,.... Let u = u . Then yn1 is a prefix of yn2 , which is a prefix of yn3 , etc., so let y be the unique infinite word such that each yni is a prefix of y. Then x = uµ(y). We now prove the claim about u being determined by a short prefix. Without loss of generality, assume that x begins with 0. The reader can now check that the following table provides the only possible decomposition of x: Prefix Decomposition 00100 00µ(10 ) 00101 0µ(00 ···) 0011 0µ(01 ··· ) 0100 0µ(10 ··· ) 0101 ǫµ(00 ···) 0110 ǫµ(01 ··· ) ··· 

2.4. Fife’s theorem. Fife’s theorem says that there is an encoding of all overlap-free words in terms of a finite automaton. In this section we give a version of this theorem. We let denote the set of (right-) infinite binary overlap-free words. O Define p0 = ǫ, p1 = 0, p2 = 00, p3 = 1, and p4 = 11, and let P = p0,p1,p2,p3,p4 . { We can now iterate} Theorem 11 to get Corollary 12. Every infinite overlap-free word x can be written uniquely in the form (2) x = p µ(p µ(p µ( ))) i1 i2 i3 ··· with ij 0, 1, 2, 3, 4 for j 1, subject to the understanding that if there exists c ∈such { that i =} 0 for j≥ c, then we also need to specify whether the j ≥ “tail” of the expansion represents µω(0) = t or µω(1) = t. Furthermore, every truncated expansion p µ(p µ(p µ( p µ(p ) ))) i1 i2 i3 ··· in−1 in ··· is a prefix of x, with the understanding that if in = 0, then we need to replace 0 with either 1 (if the “tail” represents t) or 3 (if the “tail” represents t).

Proof. The form (2) is unique, since each pi is uniquely determined by the first 5 characters of the associated word.  REPETITIONSINWORDS 9

Thus, we can associate each infinite binary overlap-free word x with the essentially unique infinite sequence of indices i := (ij )j≥0 coding elements in P , as specified by (2). If i ends in 0ω, then we need an additional element (either 1 or 3) to disambiguate between t and t as the “tail”. In our notation, we separate this additional element with a semicolon so that, for example, the word 000 ;1 represents t and 000 ;3 represents t. Other sequences··· of interest include 203000··· ; 1, which codes 001001t, the lexicographically least infinite word, and 2(31)··· ω, which codes the word having, in the i’th position, the number of 0’s in the binary expansion of i. Of course, not every possible sequence of (ij )j≥1 of indices corresponds to an infinite overlap-free word. For example, every infinite word coded by 21 represents 00µ(0µ(...)) and hence begins with 000 and has an overlap. Our··· goal is to characterize precisely, using a finite automaton, those infinite sequences corresponding to overlap-free words. We recall some basic facts about overlap-free words.

Lemma 13. Let a Σ. Then ∈ (a) x µ(x) ; (b) aµ∈(x O) ⇐⇒ a∈x O ; (c) aaµ(x∈) O ⇐⇒ a x∈ O and x begins with aa a. ∈ O ⇐⇒ ∈ O

Proof. See, for example, [5]. 

We now define 11 subsets of : O A = O B = x Σω : 1x { ∈ ∈ O} C = x Σω : 1x and x begins with 101 { ∈ ∈ O } D = x Σω : 0x { ∈ ∈ O} E = x Σω : 0x and x begins with 010 { ∈ ∈ O } F = x Σω : 0x and x begins with 11 { ∈ ∈ O } G = x Σω : 0x and x begins with 1 { ∈ ∈ O } H = x Σω : 1x and x begins with 1 { ∈ ∈ O } I = x Σω : 1x and x begins with 00 { ∈ ∈ O } J = x Σω : 1x and x begins with 0 { ∈ ∈ O } K = x Σω : 0x and x begins with 0 { ∈ ∈ O }

Next, we describe the relationships between these classes: 10 NARAD RAMPERSAD AND JEFFREY SHALLIT

Lemma 14. Let x be an infinite binary word. Then (3) x A µ(x) A ∈ ⇐⇒ ∈ (4) x B 0µ(x) A ∈ ⇐⇒ ∈ (5) x C 00µ(x) A ∈ ⇐⇒ ∈ (6) x D 1µ(x) A ∈ ⇐⇒ ∈ (7) x E 11µ(x) A ∈ ⇐⇒ ∈ (8) x D µ(x) B ∈ ⇐⇒ ∈ (9) x B 0µ(x) B ∈ ⇐⇒ ∈ (10) x E 1µ(x) B ∈ ⇐⇒ ∈ (11) x B µ(x) D ∈ ⇐⇒ ∈ (12) x D 1µ(x) D ∈ ⇐⇒ ∈ (13) x C 0µ(x) D ∈ ⇐⇒ ∈ (14) x I µ(x) E ∈ ⇐⇒ ∈ (15) x C 0µ(x) E ∈ ⇐⇒ ∈ (16) x F µ(x) C ∈ ⇐⇒ ∈ (17) x E 1µ(x) C ∈ ⇐⇒ ∈ (18) x J 0µ(x) I ∈ ⇐⇒ ∈ (19) x G 1µ(x) F ∈ ⇐⇒ ∈ (20) x K µ(x) J ∈ ⇐⇒ ∈ (21) x J µ(x) K ∈ ⇐⇒ ∈ (22) x B 0µ(x) J ∈ ⇐⇒ ∈ (23) x C 0µ(x) K ∈ ⇐⇒ ∈ (24) x H µ(x) G ∈ ⇐⇒ ∈ (25) x G µ(x) H ∈ ⇐⇒ ∈ (26) x D 1µ(x) G ∈ ⇐⇒ ∈ (27) x E 1µ(x) H ∈ ⇐⇒ ∈

Proof. Assertions (3,4,5,6,7,8,10,11,13) follow from Lemma 13. The remain- ing ones can be proved as follows: (9,12): aµ(x) B aaµ(x)= µ(a x) a x . (14,16): µ(x) ∈ E ⇐⇒ (aµ(x) and∈µ O(x) ⇐⇒ begins with∈ O a aa) (ax and x begins∈ with⇐⇒ aa). ∈ O ⇐⇒ (15,17):∈ O aµ(x) E (aaµ(x) and aµ(x) begins with a aa) (1x and x begins∈ with⇐⇒ aa a). ∈ O ⇐⇒ (18,19):∈ O aµ(x) I (aaµ(x) and aµ(x) begins with aa) (µ(ax) and x∈begins⇐⇒ with a) ∈ O(ax and x begins with a). ⇐⇒ ∈ O ⇐⇒ ∈ O REPETITIONSINWORDS 11

(20,24,21,25): µ(x) J (aµ(x) and µ(x) begins with a) (ax and x begins∈ with⇐⇒a). ∈ O ⇐⇒ (22,26):∈ O aµ(x) J (aaµ(x) and aµ(x) begins with a) µ(ax) a∈x ⇐⇒. ∈ O ⇐⇒ (23,27):∈ Oaµ ⇐⇒(x) K∈ O (aaµ(x) and aµ(x) begins with a) (ax and x begins∈ with⇐⇒aa a). ∈ O ⇐⇒ ∈ O We can now use the result of the previous lemma to create an 11- state automaton (Figure 1) that accepts all infinite sequences (ij )j≥1 over

∆ := 0, 1, 2, 3, 4 such that pi1 µ(pi2 µ(pi3 µ( ))) is overlap-free. Each state represents{ one of} the sets A,B,...,K defined··· above, and the transitions are given by Lemma 14. Of course, we also need to verify that transitions not shown correspond to the empty set of infinite words. For example, a transition out of B on the symbol 2 would correspond to the set x : 100µ(x) . But if x begins with 0, then 100µ(x) = 10001 {contains the overlap∈ O} 000 as a factor, whereas if x begins with 10, then··· 100µ(x) = 1001001 contains the overlap 1001001 as a factor, and if x begins with 11, then··· 100µ(x) = 1001010 contains 01010 as a factor. Similarly, we can verify that all other transitions··· not given in Figure 1 correspond to the empty set. This is left to the reader. From Lemma 14 and the results above, we get Theorem 15. Every infinite binary overlap-free word x is encoded by an infinite path, starting in A, through the automaton in Figure 1. Every infinite path through the automaton not ending in 0ω codes a unique infinite binary overlap-free word x. If a path i ends in 0ω and this suffix corresponds to a cycle on state A or a cycle between states B and D, then x is coded by either i; 1 or i; 3. If a path i ends in 0ω and this suffix corresponds to a cycle between states J and K, then x is coded by i; 1. If a path i ends in 0ω and this suffix corresponds to a cycle between states G and H, then x is coded by i; 3. As an application, we recover the following result [5]: Theorem 16. The lexicographically least infinite binary overlap-free word is 001001t. Proof. Let x be the lexicographically least infinite word, and let y be its code. Then y[1] must be 2, since any other choice codes a word that starts with 01 or something lexicographically greater. Once y[1] = 2 is chosen, the next two symbols must be y[2..3] = 03. Now we are in state G. We argue that the lexicographically least word that follows causes us to alternate between states G and H on 0, producing 100 . For otherwise our only choices are 30, 31, or (if we are in G) 33 as the··· next two symbols, and all of these code a word lexicographically greater than 100. Hence y = 203 0ω;1 is the code for the lexicographically least sequence, and this codes 001001t.  12 NARAD RAMPERSAD AND JEFFREY SHALLIT

0 0 K H 0 0 J G 1 3 1 3 1 3 I F 1 0 0 3 E C 0 4 2 1 A 3 3 1 B 0 D 0 1 3

Figure 1. Automaton coding infinite binary overlap-free words

2.5. Power-free morphisms. A morphism h is squarefree (resp. α-power- free) if h(w) is squarefree (resp. α-power-free) for every squarefree (resp. α- power-free) word w. We have already seen in Theorem 6 that the morphism µ is α-power-free for all α > 2. The following result of Brandenburg [18] characterizes the uniform squarefree morphisms. Theorem 17. Let h be a uniform morphism over an alphabet Σ. Then h is squarefree if and only if h(w) is squarefree for all squarefree w of length 3. Bean, Ehrenfeucht and McNulty [11] proved the following result. Theorem 18. For any alphabet Σ of size at least three, there exists a square- free morphism h : Σ∗ 0, 1, 2 ∗. Further, for any alphabet ∆ of size at least two, there exists a→ cubefree { } morphism g : ∆∗ 0, 1 ∗. → { } 2.6. The probabilistic method. Most of our previous results concerning the existence of infinite words avoiding repetitions have been explicit, in the sense that we exhibited the desired word, usually by specifying a morphism that generates it by iteration. Next we examine a probabilistic technique REPETITIONSINWORDS 13 for showing the avoidability of repetitions. One of the first results on words to use the probabilistic method is the following theorem due to Beck [12].

Theorem 19. For any real ǫ> 0, there exist an integer Nǫ and an infinite binary word w such that for every factor x of w of length n>Nǫ, all occurrences of x in w are separated by a distance at least (2 ǫ)n. − The main tool used to proved this result is a lemma from probabilistic combinatorics known as the Lov´asz local lemma. Given a set S of probability events, we can construct a dependency digraph D =(S,E), where the event X is mutually independent of the events Y : (X,Y ) E . The Lov´asz local lemma is the following: { 6∈ }

Lemma 20. Let A1, A2,...,At be events in a probability space, with a de- pendency digraph D =(S,E). Suppose there exist real numbers x1,x2,...,xt with 0 x < 1 for 1 i t such that ≤ i ≤ ≤ (28) Pr(A ) x (1 x ) i ≤ i − j (i,jY)∈E for 1 i t. Then the probability that none of the events A1, A2,...,At occur≤ is at≤ least (1 x ). − i 1≤Yi≤t Let us now apply this lemma to prove the existence of an infinite square- free word over a finite alphabet. Let Ai,r be the event that there exists a square of length 2r beginning at position i of a word of length n, i.e., that a a a = a a a . i i+1 ··· i+r−1 i+r i+r+1 ··· i+2r−1 Then the event Ai,r is mutually independent of the set of all events Aj,s when i + 2r 1 < j or i>j + 2s 1. Thus in our dependency digraph, (i, r) is connected− to (j,s) by an edge− in each direction if i + 2r 1 j and i j + 2s 1. As in the statement of the lemma, we now associate− ≥ a real ≤ − number xi,r with each event Ai,r. We then have (1 x ) = (1 x ) − j,s − j,s ((i,r),(j,s))∈E i−2s+1≤j≤i+2r−1 Y 0≤jY≤n−2s 1≤s≤n/2 (1 x )2r+2s−1. ≥ − j,s sY≥1 Note that we get this inequality by throwing away the requirement that 0 j n/2 (which adds more factors, each of which is < 1, and by extending≤ ≤ the product on s to infinity, instead of just to n/2. Now taking logs will turn this product into a sum, and we get log(1 x ) (2r + 2s + 1) log(1 x ). − j,s ≥ − j,s ((i,r)X,(j,s))∈E Xs≥1 14 NARAD RAMPERSAD AND JEFFREY SHALLIT

We now have to choose the xj,s. This is somewhat of a art, but it −s turns out that choosing xj,s = α for some α often works. We now have to estimate log(1 xj,s). Since log(1 x−)= x x2/2 x3/3 , it seems reasonable that we can bound log(1− x) from− − below− with x−···, minus a little bit more. Suppose 0 x 0 and f(z) < 0, and y>m, then we know that log(1 x) cx for x y. To apply this idea, we need to choose y such that α−s −y for≥ all s. Clearly≤ it suffices to ensure this for s = 1. With the≤ appropriate choice of c and α, we then get (2r + 2s 1) log(1 x ) (2r + 2s 1)cα−s − − j,s ≥ − Xs≥1 Xs≥1 = (2r 1)c α−s + 2c sα−s − Xs≥1 Xs≥1 (2r 1)c 2cα = − + . α 1 (α 1)2 − − Now if our events are taking place over an alphabet of cardinality k, then −r Pr(Ai,r)= k , so if (2r 1)c 2cα log Pr(Ai,r)= r log k r log α + − + , − ≤− α 1 (α 1)2 − − then Eq. (28) of the local lemma will be satisfied, and we can conclude that there is a word w of length n such that none of the events Ai,r occur, or in other words, that w is squarefree. It now suffices to take α = 6.23, c = 1.091, y = .162, and k 13. Thus we have shown that squarefree words− of all lengths exist over≥ an alphabet of cardinality 13, and hence by Lemma 1, infinite squarefree words exist over an alphabet≥ of cardinality 13. ≥ Now suppose we don’t demand that all squares be avoided, but only sufficiently large squares. Then everything in the previous analysis goes through, except that we only need to calculate Pr(Ai,r) for sufficiently large r. We can improve the result by choosing α = 4.297, c = 1.14, y = .235. − Then for r 12 and k 9, we have r log k r log α + (2r−1)c + 2cα , ≥ ≥ − ≤− α−1 (α−1)2 so there exist words that avoid all squares xx with x 12 over an alphabet of size 9. | |≥ ≥ 3. Dejean’s theorem REPETITIONSINWORDS 15

3.1. The repetition threshold. Given an alphabet Σ of k symbols, we can ask, what is the infimum of real numbers α such that we can avoid α-powers over Σ? This number is sometimes called the repetition threshold, and is denoted by RT(k). From Theorem 8 we already know that RT(2) 2. Since every word of length 4 contains a square, it follows that RT(2) =≤ 2. Similarly, from Theorem 2≥ we know that RT(3) 2, since we can avoid squares on 3 letters. Dejean proved that RT(3) = 7≤/4. She also conjectured that RT(4) = 7/5 and for k 5, RT(k) = k/(k 1). This conjecture has recently been resolved, due to≥ the combined efforts− of several researchers (see endnotes). We start with a formal definition: Definition 21. RT(k) is defined to be the infimum, over all extended reals α, of the exponent α such that there exists an infinite α-power-free word over an alphabet of size k. It is not hard to see, using the Lov´asz local lemma, that RT(k) exists. Note that, a priori, RT(k) could be (a) rational, (b) irrational, or (c) of the form α+ where α is rational. However, in all cases where RT(k) is known, case (c) holds. Theorem 22. If for all ǫ> 0 there exists an infinite word avoiding (α +ǫ)- powers, then (a) It is possible to avoid α-powers, if α is irrational. (b) It is possible to avoid α+-powers, if α is rational. To prove this theorem, we use some topology. As you may recall, a topological space T consists of a set X together with a collection of subsets of X such that S (a) and X are both in ; (b) The∅ union of any collectionS of sets in is again in ; (c) The intersection of any finite collectionS of sets in Sis again in . S S If S , it is called open; if S = X S , it is called closed. An open∈S cover of a set Y is a collection− ∈S of open sets such that O⊆S Y O∈O O. A topological space T =(X, ) is said to be compact if every open⊆ cover of X has a finite subcover. If a spaceS is compact, then so is every closedS subset of X. There is a natural topology on Σω, the space of one-sided infinite words over a finite alphabet Σ. Here the open sets are of the form LΣω, where L Σ∗ is any language of finite words. Furthermore, Σω is compact, as the following⊆ argument shows: Suppose Σω is covered by a collection of open sets A : A , and assume it has no finite subcover. { ∈ C} ω Each open set A looks like LAΣ for some language LA. If ǫ is in any LA, we can just take that A as our finite cover, a contradiction. Otherwise, 16 NARAD RAMPERSAD AND JEFFREY SHALLIT if prefixes of all words of length 1 lie in some LA’s (not necessarily the same ones), take the corresponding A’s (at most Σ of them) to be our finite cover, a contradiction. Otherwise, if prefixes of| | all of the words of length 2 lie in any LA’s (possibly different ones) take the corresponding A’s (at most Σ 2) to be our finite cover, etc., a contradiction. | |So now we know for every length ℓ there is at least one word of length ℓ such that no prefix of that word is in any LA. Consider the collection of such words, one for every length. By the infinite pigeonhole principle, infinitely many of them must begin with some letter a. Of those, infinitely many beginning with a must have some symbol b as the second symbol, etc. Construct an infinite word in this manner. It is not covered by any of the A’s. If it were, some finite prefix of it would be in some LA. But it isn’t. So every cover has a finite subcover. An alternate definition of compactness, which is not hard to see is equiv- alent to the characterization by open covers, is that if C is a collection of closed sets such that every finite intersection of sets from C is nonempty, then the intersection of all sets in C is also nonempty.

Proof. Let β be an extended real. Let Wk(β) denote the set of all infinite words over Σk = 0, 1,...,k 1 avoiding β-powers. Note that from the { − } ω definition Wk(β) is a closed set, as it is the complement LΣ , where L is the language of all finite words containing a β-power. Now suppose that W (α+ǫ) = for all ǫ. If α β, then W (α) W (β). k 6 ∅ ≤ k ⊆ k It follows that the intersection of any finite number of the Wk(α+ǫ) is equal ′ ′ to Wk(α + ǫ ), where ǫ is the smallest of the ǫ, and is therefore nonempty. It now follows that W = ǫ>0 Wk(α + ǫ) is nonempty. If α is irrational, then we claim that W = Wk(α). To see this, let w W , and suppose w contains an α-power. ThenS by definition of α-power∈ for α irrational, it must contain a p/q power for some rational p/q > α. So it contains an (α + ǫ)-power for some ǫ and hence is not in Wk(α + ǫ/2). This proves (a). + If α is irrational, then we claim that W = Wk(α ). To see this, let w W , and suppose w contains some α+-power. Then again, by definition of ∈α+-power, it contains an (α + ǫ)-power for some ǫ and hence is not in Wk(α + ǫ/2). This proves (b).  Theorem 23. RT(3) > 7/4 and RT(4) > 7/5. Proof. By computer search.  Theorem 24. RT(4) = (7/4)+. Proof. Consider the following morphism: h(0) = 0120212012102120210 h(1) = 1201020120210201021 h(2) = 2012101201021012102 REPETITIONSINWORDS 17

We claim that h isa(7/4)+-avoiding morphism, in that it preserves words with this property. By iterating h on 0, we obtain an infinite word with the desired property. Let us now prove that h avoids (7/4)+-powers. Assume that x is the shortest word without (7/4)+-powers such that h(x) contains a (7/4)+ ′ ′ 3 ′ power, that is, a word of the form uu with u > 4 u and u a prefix of u. When we speak of a block we will mean the| image,| | under| h, of a single letter. There are three cases to consider. Case 1: x < 4. We can simply enumerate all such words x avoiding (7/4)+ powers and| | check that h(x) also has no (7/4)+-powers. Case 2: x 4. Since x is the shortest such word, we can assume that u begins within| | ≥ h(a), where a is the first letter of x and u′ ends within h(b) where b is the last letter of x; otherwise we could find a shorter x. Thus uu′ 40 and hence u′ 18. | |≥ | |≥ Case 2a: 19 ∤ u . Since u′ 18, either the first 7 letters or the last 7 letters of a block| | lie entirely| | within ≥ u′, say at a position j letters from the start of u′. Now look at the 7 letters that occur j letters from the start of u. Since 19 ∤ u , these 7 letters must straddle two blocks in u. But a short computation| shows| that neither the first 7 letters nor the last 7 letters of any block can straddle the boundary between two blocks. Case 2b: 19 u . Now the first letter of any block uniquely determines the block, and the| | same| is true of the last letter of any block. Thus the (7/4)+ power uu′ leads to at least a (7/4)+ power within x, a contradiction. 

3.2. Restrictions on morphic constructions. The proof of Theorem 24 was accomplished by the exhibition of a (7/4)+-avoiding morphism. On might then suppose that Dejean’s Conjecture could be established for each alphabet size by producing morphisms of this type. We shall now see that that for alphabets of size larger than three, this is not possible. First, for each integer k 2, define the quantity ≥ 7/4, if k = 3; αk = 7/5, if k = 4;  k , if k = 3, 4. k−1 6 + Dejean’s Conjecture is that RT( k) = αk. We first show that if αk -free morphisms exist over a k-letter alphabet, they must be uniform. + Theorem 25. Let k 3 and let h : Σk Σk be an αk morphism. Then h is uniform. ≥ → Proof. Without loss of generality suppose that h(1) = max h(a) : a Σ and h(2) = min h(a) : a Σ . Suppose| further| that{| h|is not∈ k} | | {| | ∈ k} 18 NARAD RAMPERSAD AND JEFFREY SHALLIT uniform, so that h(1) > h(2) . If k = 3, then 1232123 is (7/4)+-free but h(1232123) is a (7|/4)+|-power.| If| k = 4, then 12342132431234 is (7/5)+-free but h(12342132431234) is a (7/5)+-power. If k > 4, then 12 (k 1)1 is (k/(k 1))+-free but h(12 (k 1)1) is a (k/(k 1))+-power.··· −  − ··· − − + The next result gives a further restriction on αk -free morphisms. Theorem 26. Let k 2 and let h : Σ Σ be an α+ morphism. Then ≥ k → k k the first letters of the words in h(Σk) are distinct. Similarly, the last letters of the words in h(Σk) are also distinct. Proof. Suppose to the contrary, and without loss of generality, that h(1) = au and h(2) = av for some letter a and words u,v. If k = 2, then 112 is overlap-free, but h(112) = auauav contains the overlap auaua. If k > 2, then define the word 1231231, if k = 3; wk = 123421324312341, if k = 4; k23 (k 1)k1, if k > 4; ··· − and write w = x2zx1, where x2zx / x2z = α . Note that w is α+- k  | | | | k k k free. By Theorem 25, the morphism h is uniform. It follows that h(wk) = +  h(x)avh(z)h(x)au contains the αk -power h(x)avh(z)h(x)a. We can now show that Dejean’s argument does not generalize to alpha- bets of size larger than 3. In the statement of the following theorem, the term growing morphism refers to a morphism h such that h(a) = ǫ for all a Σ and h(a) > 1 for at least one letter a Σ. 6 ∈ | | ∈ Theorem 27. Let k 4. There exists no growing α+-free morphism from ≥ k Σk to Σk. Proof. Suppose there exists such a morphism h. Without loss of generality, we may assume that there exists a Σ such that h(a) = 12u for some word ∈ k u. By Theorem 26, the k words in h(Σk) all end differently, so there exists b Σ such that h(b) = v2 for some word v. We first show that a = b. ∈ k 6 Again, by Theorem 26, there exists c Σk, c = a, such that h(c) = 2w for some word w. If a = b, then h(ac) =∈v22w contains6 the square 22, so we must have a = b. Now h(ba) = v212u contains the 3/2-power 212. This is a contradiction,6 since for k 4 we have α < 3/2.  ≥ k This result shows that we cannot hope to prove Dejean’s Conjecture + by producing αk -free morphisms. This does not completely rule out the + possibility of generating αk -free words with a morphism. It could be the + case that there exist morphisms h that are not αk -free but still have an + infinite αk -free fixed point. However, the previous result is strong evidence that a new idea is needed in order to attack Dejean’s Conjecture for larger alphabets. This new idea was provided by Pansiot. REPETITIONSINWORDS 19

3.3. Pansiot recoding. Dejean conjectured that RT(k)=(k/(k 1))+. We now show that RT(k) (k/(k 1))+. For the remainder of this− chapter we assume that we are working≥ over− the alphabet Σ = 1, 2,...,k . k { } Proposition 28. (a) Every word w over a k-letter alphabet of length k + 2 contains a k/(k 1) power; (b) Every≥ word x over a k-letter− alphabet avoiding (k/(k 1))+-powers has the property that every factor of length k 1 consists− of k 1 different symbols. − − Proof. (a) Let w be of length k+2. Then w contains at least 3 factors of length k. If any one of≥ these factors contains some symbol of the alphabet at least twice, then w contains a power k/(k 1), and we’re done. Otherwise, up to a permutation of the≥ symbols,− we can assume w = 123 k12. But then w contains a (k + 2)/k-power, and (k + 2)/k k/···(k 1) for k 2. (b) Suppose x does≥ not have− the stated≥ property. Then there is a factor of length k 1 containing some symbol twice, and hence containing a power (−k 1)/(k 2). But (k 1)/(k 2) k/(k 1) for k 3. ≥ − − − − ≥ − ≥ 

This result suggests the following. Suppose a word w over a k-letter alphabet avoids (k/(k 1))+ powers, and suppose y is a factor of length k 1. Then the letter− following y is either − the first letter of y; or • the unique symbol of Σ missing from y. • We can code these two choices with a 0 in the first case and a 1 in the second case. If we then know the sequence of codes and the first k 1 letters of w, we can uniquely reconstitute w. Such a coding is called Pansiot− recoding.

Example 29. Let us recode 12341532145 Σ5: the series of codes is 0101011. Given 1234 and 0101011 we can reconstitute∈ the original word. With this coding, we can also interpret a word over Σ of length k 1, k − with no symbol occurring twice, as a permutation of Σk. Namely, if w = a a a , the associated permutation is 1 2 ··· k−1 1 2 3 k 1 k , a a a ··· a − b  1 2 3 ··· k−1  where b is the unique letter in Σk a1,a2,...,ak . The going from a block of k 1 letters to the next block−{ of k 1 letters,} obtained by a “0” code, amounts− to right multiplication by the− permutation 1 2 3 k 1 k σ = , 0 2 3 4 ··· −1 k  ···  20 NARAD RAMPERSAD AND JEFFREY SHALLIT and going from one block to the next via a “1” code amounts to right multiplication by the permutation 1 2 3 k 1 k σ = . 1 2 3 4 ··· −k 1  ···  Example 30. Suppose k = 5 and the last four symbols seen were 4135. Then a code of “0” produces the next symbol 4 and a code of “1” produces the next symbol 2. The original block, 4135, corresponds to the permutation 12345 p = . 41352   The new block 1354, following a “0” code, corresponds to the permutation 12345 q = 13542   while the new block 1352, following a “1” code, corresponds to the permu- tation 12345 r = . 13524   The reader can now check that q = pσ0 and r = qσ1. For the remainder of this chapter we are interested in repetitions of ex- ponent < 2, and we write them in a special way. If w = pe with e a prefix of pe, p = ǫ, then we write w =(p,e). Here p is called the period and e the excess. Note6 that w = pe = ep′ and such a word is a pe / p ’th power. A repetition (p,e) with e < k 1 is called a short| | repetition| | , while a repetition with e k 1| | is called− a kernel repetition. A repetition of exponent ( e + |p |+ ≥k −1)/ p in a word corresponds to a kernel repetition (p,e) in the| Pansiot| | | code− for| that| word. Theorem 31. There is an infinite word over a 4-letter alphabet avoiding (7/5)+-powers. Proof. Consider the infinite word generated by the morphism h, where h(1) = 10 and h(0) = 101101. Then hω(1) codes an infinite word over 1, 2, 3, 4 avoiding (7/5)+-powers.  { } 4. Avoiding repetitions in arithmetic progressions In this section we consider the question of the existence of infinite words that avoid squares in certain subsequences indexed by arithmetic progres- sions. Of course, by the classical theorem of van der Waerden, it is not possible to avoid repetitions in all arithmetic subsequences. Theorem 32. Let the natural numbers be partitioned into finitely many dis- joint sets C1,C2,...,Ck. Then some Ci contains arbitrarily long arithmetic progressions. REPETITIONSINWORDS 21

A subsequence of w is word of the form w w , i0 i1 ··· where 0 i0 0. Suppose that w contains a (1+1/pm)-power in an arithmetic progression of difference k, where k is not a multiple of p. That is, a a a = a a a i i+k ··· i+(s−1)k i+rk i+(r+1)k ··· i+(r+s−1)k for some integers i,r,s satisfying s/r 1/pm. 2 ≥ Suppose that ai = ai+rk > q . Then by the definition of w, q divides 2 both i and i + rk and hence divides rk. If instead ai = ai+rk < q , then i mod q2 = (i + rk) mod q2, so that q2 divides rk. In either case, since p does not divide k, it must be the case that q divides r. We can therefore write r = qℓr′ for some positive integers ℓ, r′ with r′ not divisible by q. Recall that s/r 1/pm, so that ≥ s qℓr′/pm ≥ = pqℓ−1r′ pqℓ−1. ≥ It follows that the set i,i+k,...,i+(s 1)k forms a complete set of residue classes modulo pqℓ−1.{ Thus there exists− j } i,i + k,...,i +(s 1)k such that ∈ { − } j qℓ−1 (mod pqℓ−1). ≡ 22 NARAD RAMPERSAD AND JEFFREY SHALLIT

Let us write then j = apqℓ−1 + qℓ−1 = qℓ−1(ap + 1), for some non-negative integer a. We also have j + rk = qℓ−1(ap +1)+ qℓr′k = qℓ−1(ap +1+ qr′k). Furthermore, since a = a , we have j j + rk (mod q2), and hence, j j+rk ≡ ap + 1 ap +1+ qr′k (mod q2), ≡ so that qr′k 0 (mod q2). We must therefore have r′k 0 (mod q). However, p does≡ not divide k, and q does not divide r′, so this≡ congruence cannot be satisfied. This contradiction completes the proof. 

Corollary 34. There exists an infinite word over a 4-letter alphabet that contains no squares in arithmetic progressions of odd difference. Proof. This is a special case of Theorem 33, obtained by taking p = 2 and m = 0 (so that q = 2) in that theorem. We then have Σ = 1, 3, 5, 7 and, writing n = 2tn′, { }

n′ mod 4, if n is odd; an = ′ (4+(n mod 4), if n is even. It follows that w = 1535173515371735153 ··· contains no squares in arithmetic progressions of odd difference. 

The word w defined in Corollary 34 is closely related to the well-studied paperfolding word. Indeed, if one applies the map 1, 5 0, 3, 7 1 to the word w, one obtains the paperfolding word → → f = 0010011000110110001 . ··· We now show how to apply the previous construction to define non- repetitive labelings of the integer lattice. Consider a map w from N2 to A, where we write wm,n for w(m, n). We call such a w a 2-dimensional word. A word x is a line of w if there exists i1,i2, j1,j2 such that gcd(j1,j2)=1, and for t 0, ≥ xt = wi1+j1t,i2+j2t. Theorem 35. There exists a 2-dimensional word w over a 16-letter alpha- bet such that every line of w is squarefree. REPETITIONSINWORDS 23

Proof. Let u = u0u1u2 and v = v0v1v2 be any infinite words over the alphabet A = 1, 2, 3, 4···that avoid squares··· in all arithmetic progressions of odd difference.{ We define} w over the alphabet A A by × wm,n =(um,vn). Consider an arbitrary line

x = (wi1+j1t,i2+j2t)t≥0,

= (ui1+j1t,vi2+j2t)t≥0, for some i1,i2, j1,j2, with gcd(j1,j2) = 1. Without loss of generality, we may assume j1 is odd. Then the word (ui1+j1t)t≥0 is an arithmetic subsequence of odd difference of u and hence is squarefree. The line x is therefore also squarefree.  A computer search shows that there are no 2-dimensional words w over a 7-letter alphabet, such that every line of w is squarefree. It remains an open problem to determine if the alphabet size of 16 in Theorem 35 is best possible.

5. Patterns We have seen previously that a square is a word of the form xx. We now consider more general patterns. Let Σ and ∆ be alphabets: the alphabet ∆ is the pattern alphabet and its elements are variables. A pattern p is a nonempty word over ∆. A word w over Σ is an instance of p if there exists a non-erasing morphism h : ∆∗ Σ∗ such that h(p)= w. → Let x1,x2,... be variables. Define Z1 = x1 and for all n > 1 define Zn = Zn−1xnZn−1. The words Zn are called the Zimin patterns. The following result can be proved by induction on n.

Theorem 36. The Zimin patterns Zn are unavoidable. Proof. The proof is by induction on n. Let Σ be an arbitrary alphabet and let k = Σ . Clearly Z1 is unavoidable on Σ. Suppose that Zn is unavoidable on Σ. Then| | there is an integer N such that every word of length N contains N ∗ an instance of Zn. There are k such words. Now consider a word w Σ of length M = kN (N +1)+ N. Write ∈

w = x a x a x N a N x N , 0 0 1 1 ··· k −1 k −1 k where for 0 i kN , x = N and a = 1. By the pigeonhole principle ≤ ≤ | i| | i| there exists i

Next we examine the question of which patterns are avoidable over small alphabets. The following classification of the binary patterns is due to the combined work of several authors. Theorem 37. We have the following classification of binary patterns: The patterns x, xy, and xyx are unavoidable. • The patterns xx, xxy, xxyx, xyyx, xyxy, xxyxx, and xxyxy are • avoidable over a ternary alphabet but not over a binary alphabet. All other patterns not equal to the reverse or complement of the • above listed patterns are avoidable over a binary alphabet.

6. Abelian repetitions An abelian square is a word of the form xx′ with x = x′ and x′ a permutation of x. Examples in English include reappear| |and|intestines| . An abelian cube is a word of the form xx′x′′ with x = x′ = x′′ and x′ and x′′ both permutations of x. An example in English| | is deeded| | |. Similarly,| we can speak about abelian k-th powers for any integer k 2. In 1961, Erd˝os [44] posed the problem of the existence≥ of an infinite word over a finite alphabet that avoids abelian squares. Evdokimov [45] gave an example over a 25-letter alphabet, and this was improved to 5 letters by Pleasants [81]. Finally, Keranen [63] gave an example over a 4-letter alphabet. Theorem 38. Abelian squares cannot be avoided over an alphabet of size 3. Abelian cubes cannot be avoided over an alphabet of size 2. 6.1. The adjacency matrix associated with a morphism. Given a ∗ ∗ morphism ϕ : Σ Σ for some finite set Σ = a1,a2,...,ad , we define the adjacency matrix→ M = M(ϕ) as follows: { }

M =(mi,j )1≤i,j≤d where m is the number of occurrences of a in ϕ(a ), i.e., m = ϕ(a ) . i,j i j i,j | j |ai Example 39. Consider the morphism ϕ defined by ϕ : a ab → b cc → c bb. → Then a b c a 1 0 0 M(ϕ)= b 1 0 2 c  0 2 0    REPETITIONSINWORDS 25

∗ d T Let us also define the map ψ : Σ Z by ψ(w)=[ w a1 , w a2 ,..., w ad ] . The matrix M(ϕ) is useful because→ of the following proposition.| | | | | | Proposition 40. ψ(ϕ(w)) = M(ϕ)ψ(w).

Proof. Clearly we have

ϕ(w) = ϕ(a ) w . | |ai | j |ai | |aj 1≤Xj≤d From this, the desired equation easily follows. 

Now an easy induction gives M(ϕ)n = M(ϕn), and hence Corollary 41. ψ(ϕn(w))=(M(ϕ))nψ(w).

Hence we find Corollary 42.

ϕn(w) = 1 1 1 1 (M(ϕ))nψ(w). | | ··· 6.2. Dekking’s construction. In this section we explore a construction due to Dekking [39] that gives optimal results for abelian-power-free words over alphabets of size 2 and 3. We start with some definitions about morphisms and groups. Let ϕ : Σ∗ Σ∗ be a morphism. If w = ϕ(a) is the image of a single letter a Σ, we call→ it a block. If ϕ(a)= vv′, v′ = ǫ, then we call v a left subblock and∈ v′ its corresponding right subblock. 6 Let G be a finite abelian group (written additively). We say that a subset A G is progression-free of order n if for all a A, a,a + g,a + 2g,...a + (n⊆ 1)g A implies that g = 0. ∈ − ∈ Example 43. Let G = Z/(7), the integers modulo 7, and let A = 0, 1, 2, 4 . Then A is progression-free of order 4. For example, for each a {A, the fol-} lowing table shows that for each g = 0 there exists i, 0 i ∈3, such that a + ig A. 6 ≤ ≤ 6∈ a g i a + ig a g i a + ig 0 1 3 3 1 1 2 3 0 2 3 6 1 2 1 3 0 3 1 3 1 3 3 3 0 4 3 5 1 4 1 5 0 5 1 5 1 5 1 6 0 6 1 6 1 6 2 6 26 NARAD RAMPERSAD AND JEFFREY SHALLIT

a g i a + ig a g i a + ig 2 1 1 3 4 1 1 5 2 2 2 6 4 2 1 6 2 3 1 5 4 3 2 3 2 4 1 6 4 4 2 5 2 5 2 5 4 5 3 5 2 6 3 6 4 6 1 3

Let f : Σ∗ G be a morphism, so that f(ǫ) = 0, the identity element of G, and f(a→a a ) = f(a ). We call f ϕ-injective if for any 1 2 ··· i 1≤j≤i j collection v ,v ,...,v of left subblocks and v′ ,v′ ,...,v′ the corresponding 1 2 n P 1 2 n right subblocks, the equality f(v1)= f(v2)= = f(vn) implies that either v = v = = v or v′ = v′ = = v′ . ··· 1 2 ··· n 1 2 ··· n

Lemma 44. Let n be a positive integer, let ϕ : Σ∗ Σ∗ be a morphism, let G be a finite abelian group, and let f : Σ∗ G be→ a morphism such that → (a) The adjacency matrix of ϕ has nonzero determinant; (b) f(ϕ(a))=0 for all a Σ; (c) the set A = g G∈ : g = f(v), v a left subblock of ϕ is progression-free{ of∈ order n + 1; } (d) f is ϕ-injective.

ω If ϕ is prolongable on a, and ϕ (a) avoids abelian n’th powers x1x2 xn where x max ϕ(a) , then ϕω(a) is abelian n-th-power-free. ··· | i|≤ a∈Σ | |

Proof. Let x = ϕω(a). By the hypothesis, x avoids “short” abelian n’th powers, that is, factors of the form x1x2 xn where each xi is a permuta- tion of x and x max ϕ(a) . ··· 1 | i|≤ a∈Σ | | Suppose B1B2 Bn is an abelian n’th-power occurring in x, with B1 = B = = B ···, and each B a permutation of B , and B is minimal.| | | 2| ··· | n| i 1 | i| Since we have ruled out short powers, we must have Bi > maxa∈Σ ϕ(a) . Consider the factorization of x into blocks, each an image| | of a letter| under| ϕ. Then each Bi starts inside some block ϕ(a); let vi be the corresponding ′ ′ left subblock and vi the corresponding right subblock, so that ϕ(a)= vivi, ′ and Bi occurs starting at the same position where vi starts, and Bn ends at the same position where vn+1 ends. (We take vi = ǫ if a Bi occurs starting at the same position as the beginning of a block.) By the length condition on the Bi, each Bi starts in a distinct block. See Figure 2, where this is illustrated for n = 3. REPETITIONSINWORDS 27

C1 C2 C3 x = v v′ v v′ v v′ v v′ 1 1 2 2 3 3 4 4

B1 B2 B3

Figure 2. An abelian cube and the corresponding blocks

Since each Bi is a permutation of every other Bi, it follows that each Bi contains exactly the same number of every letter, and so (29) f(B )= f(B )= = f(B ). 1 2 ··· n On the other hand, from condition (b) of the Lemma, we know that f(ϕ(a)) = ′ 0 for every a Σ. Writing Bi = viyivi+1 for some yi that is the image of ∈ ′ ′ a word under ϕ, we get f(Bi) = f(vi)+ f(vi+1). Since f(vivi) = 0, we get f(B ) = f(v )+ f(v ). From Eq. (29) we get that the f(v ) form i − i i+1 i an (n + 1)-term arithmetic progression with difference f(Bi). But then by hypothesis (c), we get f(v1)= f(v2)= = f(vn+1). Hence by hypothesis (d), it follows that either v = v = ···= v or v′ = v′ = = v′ . 1 2 ··· n+1 1 2 ··· n+1 In the former case, we can “slide” the abelian n’th power to the left by v1 symbols and still get an abelian n’th power; in the latter case we can slide| | ′ it to the right by v1 symbols and still get an abelian n’th power. Now our abelian n’th power| | is aligned at both ends with blocks of ϕ, so there is an abelian n’th power C C C where each C is composed of blocks; 1 2 ··· n i again see Figure 2. Let Di be such that Ci = ϕ(Di). Since x = ϕ(x), it follows that D1D2 Dn occurs in x. Now ψ(Ci) = Mψ(Di), where M is the matrix of ϕ···. Since M is invertible, there is only one possi- bility for ψ(D ). Since ψ(C ) = ψ(C ) = = ψ(C ), it follows that i 1 2 ··· n ψ(D1) = ψ(D2) = = ψ(Dn). Hence D1 Dn is a shorter abelian n’th power, contradicting··· the minimality of B B··· B .  1 2 ··· n Corollary 45. There is a sequence on two symbols that avoids abelian 4th powers. Proof. Let Σ = 0, 1 and define ϕ(0) = 011, ϕ(1) = 0001. We can check { } ω that there are no abelian 4th powers x1x2x3x4 in ϕ (0) for x1 4 by enumerating all subwords of length 16. | | ≤ 1 3 ≤ The matrix of ϕ is . which has determinant 5. Choose G = 2 1 −   Z/(5) and define f by f(0) = 1, f(1) = 2. Then f(ϕ(a)) = 0 for a 0, 1 . Furthermore A = 0, 1, 2, 3 , which is progression free of order 5. ∈ { } Thus ϕω(0) is abelian{ 4th-power-free.}  Corollary 46. There is a sequence on 3 symbols that avoids abelian cubes. 28 NARAD RAMPERSAD AND JEFFREY SHALLIT

Proof. Let Σ = 0, 1, 2 and define ϕ by ϕ(0) = 0012, ϕ(1) = 112, and { } 2 0 1 ϕ(2) = 022. Then the matrix of ϕ is 1 2 0 which has determinant  1 1 2  7. Let G = Z/(7), and define f(0) = 1, f(1) = 2, and f(2) = 3. Then f(ϕ(a)) = 0 for each a Σ. Then A = 0, 1, 2, 4 which is progression-free of order 4, as we saw in∈ Example 43. { }  6.3. Abelian repetitions in balanced words. Next we show that any word that avoid abelian k-powers is “unbalanced”. We say that a word w is M-balanced if for every pair of factors u,v of w with u = v , we have u v M for all letters a. | | | | || |a −| |a |≤ Theorem 47. Let w be an infinite word. If w is M-balanced for some M, then for every k 2, the word w contains an abelian k-power. ≥ The proof is an application of van der Waerden’s theorem. We first need a lemma. Lemma 48. Let M and r be positive integers. There exist positive integers α1,...,αr and N such that whenever r c α 0 (mod N) i i ≡ i=1 X for integers c with c M, then c = = c = 0. i | i|≤ 1 ··· r Proof. The α are defined inductively: Set α = 1 and for i 1, choose i 1 ≥ αi+1 to be any integer satisfying i

αi+1 >M αj. j=1 X r Now choose N to be any integer satisfying N >M j=1 αj . Suppose that r P c α 0 (mod N) i i ≡ i=1 X for some c satisfying c M. Then i | i|≤ r r r

ciαi ci αi M αi < N, ≤ | | ≤ i=1 i=1 i=1 X X X which implies that r ciαi = 0. i=1 X To show that the ci are necessarily zero, suppose to the contrary that some c is non-zero and let t be the largest index such that c = 0. We cannot i t 6 REPETITIONSINWORDS 29 have t = 1, for otherwise we should have c1 = c1α1 = 0, so let us assume that t> 1 and observe that t−1 t−1 t−1

ctαt = ciαi ci αi M αi <αt ctαt , | | − ≤ | | ≤ ≤| | i=1 i=1 i=1 X X X which gives us our desired contradiction and completes the proof. 

We now give the proof of Theorem 47.

Proof of Theorem 47. Let w = w1w2 be an infinite word over an alpha- bet of size r and suppose further that···w is M-balanced for some positive integer M. Let α1,...,αr and N be as in Lemma 48. By recoding the alpha- bet of w, we may suppose without loss of generality that w is a word over the alphabet α ,...,α . For any word x = x x over this alphabet, { 1 r} 1 ··· n we define the function f(x) := x1 + + xn. We now define a map τ : 1, 2,...··· 0, 1,...,N 1 by τ(n) = f(w[1..n]). By Theorem 32, for every{ positive} → integer{ k, there− exists} positive integers n0 and d such that (30) τ(n )= τ(n + d)= = τ(n + kd). 0 0 ··· 0 For j = 1,...,k, define w(j) = w[n +(j 1)d..n + jd]. We claim that 0 − 0 w(1) w(k) is an abelian k-power. We first note that (30) implies that ··· f(w(j)) 0 (mod N) for each j = 1,...,k. ≡ Next, for i = 1,...,r, let a(j) = w(j) . Since i | |αi r (j) (j) f(w )= ai αi i=1 X for j = 1,...,k, we must have r a(j)α 0 (mod N), i i ≡ i=1 X and in particular, r r a(j)α a(1)α (mod N), i i ≡ i i i=1 i=1 X X which we may rearrange to obtain r (a(j) a(1))α 0 (mod N). i − i i ≡ i=1 X Since w is M-balanced, we have a(j) a(1) M, and so by Lemma 48 we | i − i |≤ must have a(j) a(1) = 0, or in other words, a(j) = a(1) for all j = 1,...,k. i − i i i It follows that w(1) w(k) is an abelian k-power, as claimed.  ··· 30 NARAD RAMPERSAD AND JEFFREY SHALLIT

7. Enumeration 7.1. Enumerating squarefree words. Here we examine the question: How many squarefree words of length n do we have over a 3-letter alphabet? We do not have a precise characterization of the squarefree words, so the best we can hope for are some good asymptotic upper and lower bounds. To obtain a lower bound, consider the substitution h defined by 0 210201202120102012, 210201021202102012 → { } 1 021012010201210120, 021012102010210120 → { } 2 102120121012021201, 102120210121021201 → { } The set h(w) consists entirely of squarefree words if w is squarefree. This shows that there are at least 2n/17 1.0416n ternary squarefree words of length n. The best bounds currently≈ known are due to Shur [92]: Theorem 49. There number of squarefree words of length n over a 3-letter alphabet grows like ρn, where ρ [1.3017579, 1.3017619]. ∈ 7.2. Enumerating overlap-free words. Unlike the squarefree ternary words, the overlap-free binary words have a well understood structure, thanks to Theorem 9. This makes it much easier for us to count the number of overlap-free binary words. Let x = x0 be a nonempty overlap-free binary word. Then by Theorem 9 we can write x = u µ(x )v with u , v 2. If x 1, we can repeat 0 1 1 1 | 1| | 1| ≤ | 1| ≥ the process, writing x1 = u2µ(x2)v2. Continuing in this fashion, we obtain the decomposition xi−1 = uiµ(xi)vi for i = 1, 2,... until xt+1 = 0 for some t. Then | | x = u µ(u ) µt−1(u )µt(x )µt−1(v ) µ(v )v . 0 1 2 ··· t t t ··· 2 1 Then from the inequalities 1 xt 4 and 2 xi xi−1 2 xi + 4, 1 ≤|t |≤ t+3 | |≤| |≤ | | ≤ i t, an easy induction gives 2 x 2 4. Thus t log2 x

Theorem 50. There are O(nlog2 25) = O(n4.644) binary words of length n that are overlap-free. 7.3. The Goulden–Jackson cluster method. Let S be a set of words to be avoided over an alphabet Σ of size k. We say that S is reduced if S satisfies the following property: if x is a word in S, then no other word in S is a factor of x. For example, the set 001, 111, 1101 is reduced, but the { } REPETITIONSINWORDS 31 set 001, 111, 1001 is not reduced, since 001 is a factor of 1001. Clearly, if x,y{ S and x is a} factor of y, then S is avoided by exactly the same set of words∈ as avoids S y . We therefore only consider reduced sets S. \ { } Let S be a reduced set of words. For n 0, let an denote the number of ≥ n words of length n over Σ that avoid S and let A(x) := n≥0 anx be the corresponding generating function. A marked word is a word w over Σ where we haveP distinguished (i.e., “marked”) some number of occurrences of factors of w that are in the set S. We will indicate these marked factors by underlining. For example, if S := 00, 010 and w = 0101010100, then { } w := 0101010100 is one possible way of marking w. We will use w to denote a particular marked version of w. We do not require that all occurrences in w of words in S necessarily be marked, so in general there are many different ways to mark a given word w. For any given marking w of a word w, define the weight of w, denoted m(w), by m(w):=( 1)t, where t is the number of factors that are marked in w. Suppose that in− total there are r occurrences of words of S as factors r of w. Then for t = 0,...,r, there are t possible marked versions w of w containing t marked factors. The sum of the weights of all marked versions  of w is therefore equal to r r ( 1)t = (1 1)r, − t − t=0 X   which is 1 when r is 0 (i.e., when w avoids S) and 0 when r> 0 (i.e., when w contains a word in S as a factor). This may perhaps seem somewhat mysterious, but it is nothing more than the principle of Inclusion/Exclusion. Summing weights over all marked words of length n, we thus obtain

(32) m(w)= an, |wX|=n which is the number of words of length n avoiding S. We define a cluster to be a marked word w such that every position of w is marked in w and w cannot be written as the concatenation of two smaller marked words. For example, 01010 is a cluster, but 010 010 is not a cluster, since it is the concatenation of two copies of the marked word 010. We can use clusters to enumerate marked words. Let M denote the set of all marked words and let T denote the set of all clusters. Let C(x) be 32 NARAD RAMPERSAD AND JEFFREY SHALLIT the weighted cluster generating function for S defined by

|v| n (33) C(x) := m(v)x = cnx . vX∈T nX≥0 Consider a marked word w of length n. We have two cases. Case 1: The last position of w is unmarked. In this case we write w = w′a for some marked word w′ and some unmarked letter a. Moreover, we have m(w)= m(w′). Case 2: The marked word w ends with a cluster. In this case we write w = u v, where u is a marked word of length n j and v is a cluster of length j. Moreover, we have m(w)= m(u)m(v). − Since any marked word can be uniquely written as a concatenation of clusters and unmarked letters, it follows that for n 1, (34) ≥

m(w)= k m(w′)+  m(u)  m(v) . ′ j wX∈M wX∈M X  uX∈M   vX∈T  |w|=n |w′|=n−1 |u|=n−j  |v|=j      Applying (32) and (33), we rewrite (34) as   

an = kan−1 + an−j cj, j X i.e., a ka a c = 0. n − n−1 − n−j j j X Recall that A(x) := a xn. Since for n 1, n≥0 n ≥ [xn]A(x)(1 Pkx C(x)) = a ka a c = 0, − − n − n−1 − n−j j j X and [x0]A(x) = 1, we must have A(x)(1 kx C(x)) = 1, so that − − 1 A(x)= . 1 kx C(x) − − We summarize our discussion as follows. Theorem 51. Let S be a reduced set of words over a k-letter alphabet and let C(x) be the weighted cluster generating function for S. The generating function A(x) for the number of words of length n over a k-letter alphabet that avoid S is 1 A(x) := . 1 kx C(x) − − In practice, to be able to apply Theorem 51 one must be able to calculate the generating function C(x). For simple sets S this can be done by hand, as REPETITIONSINWORDS 33 illustrated in the example below; for more complicated sets S one generally resorts to computer calculations. Example 52. Let S := 00, 010 and let C(x) := c xn be the { } n≥0 n weighted cluster generating function for S. Consider a cluster v of length n. If n 4, we have either P ≥ v = 0 0 ··· v′ where v′ is a cluster of length n 1,| or{z } − v = 01 0 ··· v′ where v′ is a cluster of length n 2.| In either{z } case, v has precisely one more marked factor than v′, so that m−(v)= m(v′). It follows that for n 4, − ≥ (35) c = c c . n − n−1 − n−2 We check that there is one cluster of length 2 (00, which has weight 1) and 2 clusters of length 3 (010, which has weight 1, and 000, which has− weight 2 − ( 1) = 1). This gives the initial values c2 = 1 and c3 = 1+1 = 0. From− these initial values and the recurrence (35)− one derives − x2 x3 C(x)= − − . 1+ x + x2 The generating function for the binary words avoiding S is thus 1 A(x) = 1 2x −x2−x3 − − 1+x+x2 1+ x + x2 = 1 x x3 − − = 1+2x + 3x2 + 4x3 + 6x4 + 9x5 + 13x6 + ··· Indeed one verifies, for instance, that the following 6 words are exactly the binary words of length 4 that avoid 00 and 010: 0110 0111 1011 1101 1110 1111. 7.4. A power series method for lower bounds. The following theorem gives a method to bound from below the number of words of length n over an m-letter alphabet that avoid a given set of words S. Unlike the Goulden– Jackson cluster method, this method does not give an exact enumeration; however, here the set S of words to be avoided may now be infinite. Theorem 53. Let S be a set of words over an m-letter alphabet, each word of length at least 2. Suppose that for each i 2, the set S contains at most ≥ 34 NARAD RAMPERSAD AND JEFFREY SHALLIT ci words of length i. If the power series expansion of pow −1 G(x) := 1 mx + c xi  − i  Xi≥2 has non-negative coefficients, then there are least[xn]G(x) words of length n over an m-letter alphabet that avoid S.

i i Proof. For two power series f(x) = i≥0 aix and g(x) = i≥0 bix , we write f g to mean that a b for all i 0. Let F (x) := a xi, ≥ i ≥ i P ≥ P i≥0 i where ai is the number of words of length i over an m-letter alphabet that i P avoid S. Let G(x)= i≥0 bix be the power series expansion of G defined above. We wish to show F G. P ≥k For k 1, there are m ak words w of length k over an m-letter alphabet that≥ contain a word− in S as a factor. On the other hand, for any such w either (a) w = w′a, where a is a single letter and w′ is a word of length k 1 containing a word in S as a factor; or (b) w = xy, where x is a word of length− k j that avoids S and y S is a word of length j. There are at most (mk−−1 a )m words w of the∈ form (a), and there are at most − k−1 j ak−jcj words w of the form (b). We thus have the inequality P mk a (mk−1 a )m + a c . − k ≤ − k−1 k−j j j X Rearranging, we have (36) a a m + a c 0, k − k−1 k−j j ≥ j X for k 1. Consider≥ the function

H(x) := F (x) 1 mx + c xj  − j  Xj≥2   = a xi 1 mx + c xj .  i   − j  Xi≥0 Xj≥2     Observe that for k 1, we have [xk]H(x) = a a m + a c . By ≥ k − k−1 j k−j j (36), we have [xk]H(x) 0 for k 1. Since [x0]H(x) = 1, the inequality P H 1 holds, and in particular,≥ H≥ 1 has non-negative coefficients. We conclude≥ that F = HG =(H 1)G +− G G, as required.  − ≥ We now apply Theorem 53 to prove the following result concerning the number of words of length n over an m-letter alphabet that avoid instances of a pattern p. REPETITIONSINWORDS 35

Theorem 54. Let k 2 and m 4 be integers with (k,m) = (2, 4). Let p be a pattern containing≥ k distinct≥ variables, each occurring at6 least twice in p. Then for n 0, there are at least λn words of length n over an m-letter alphabet that avoid≥ the pattern p, where

1 −1 λ = λ(k,m) := m 1+ . (m 2)k  −  To prove the theorem we need some lemmas.

Lemma 55. Let k 1 be a integer and let p be a pattern over the set of variables ∆ = x ,...,x≥ . Suppose that for 1 i k, the variable x { 1 k} ≤ ≤ i occurs ai 1 times in p. Let m 2 be an integer and let Σ be an m-letter alphabet.≥ Then for n 1, the number≥ of words of length n over Σ that are instances of the pattern≥ p is at most [xn]C(x), where

C(x) := mi1+···+ik xa1i1+···+akik . ··· iX1≥1 iXk≥1

Proof. For n 1, let tn denote the number of words of length n over Σ that are instances≥ of the pattern p. We wish to show that for n 1, the n ≥ inequality tn [x ]C(x) holds. Given any k-tuple of non-empty words (W ,...,W ) we≤ obtain a word of length a W + + a W matching p 1 k 1| 1| ··· k| k| by substituting Wi for each occurrence of xi in p. Furthermore, all words matching p can be obtained by such a substitution. It follows that

n a1|W1|+···+ak|Wk| tnx x ≤ + ··· + nX≥1 WX1∈Σ WXk∈Σ = xa1|W1| xak|Wk| + ··· + WX1∈Σ WXk∈Σ = mi1 xa1i1 mik xakik ··· iX1≥1 iXk≥1 = mi1+···+ik xa1i1+···+akik , ··· iX1≥1 iXk≥1 so that t [xn]C(x), as required.  n ≤ In what follows, let k 2 and m 4 be integers with (k,m) = (2, 4). Also let ≥ ≥ 6 1 −1 λ = λ(k,m) := m 1+ . (m 2)k  −  Lemma 56. We have λ m 1/2. ≥ − 36 NARAD RAMPERSAD AND JEFFREY SHALLIT

Proof. We have 1 −1 λ = m 1+ (m 2)k  − 

m ( 1)i(m 2)−ki ≤  − −  Xi≥0 m 1 1/(m 2)k .  ≥ − − When k 3,  ≥ m 1 1/(m 2)k m 1 1/(m 2)3 − − ≥ − − = m m/(m 2)3  − −  m 4/23 (since m 4) ≥ − ≥ m 1/2. ≥ − When k = 2 and m = 5 we have λ = m 1/2, so suppose k = 2 and m 6. Then − ≥ m 1 1/(m 2)k = m 1 1/(m 2)2 − − − − = m m/(m 2)2  − −  m 6/42 (since m 6) ≥ − ≥ m 1/2. ≥ − 

Lemma 57. Let a1,...,ak be integers, each at least 2. Let C(x) := mi1+···+ik xa1i1+···+akik , ··· iX1≥1 iXk≥1 and let B(x) := b xi = (1 mx + C(x))−1. i − Xi≥0 Then b λb for all n 0. n ≥ n−1 ≥ Proof. The proof is by induction on n. When n = 0, we have b0 = 1 and b1 = m. Since m>λ, the inequality b1 λb0 holds, as required. Suppose ≥ −1 that for all j < n, we have bj λbj−1. Since B = (1 mx + C) , we have B(1 mx + C)=1. Hence [x≥n]B(1 mx + C)=0 for− n 1. However, − − ≥

B(1 mx+C)= b xi 1 mx + mi1+···+ik xa1i1+···+akik , −  i   − ···  Xi≥0 iX1≥1 iXk≥1 so     [xn]B(1 mx+C)= b b m+ mi1+···+ik b = 0. − n− n−1 ··· n−(a1i1+···+akik) iX1≥1 iXk≥1 REPETITIONSINWORDS 37

Rearranging, we obtain b = λb +(m λ)b mi1+···+ik b . n n−1 − n−1 − ··· n−(a1i1+···+akik) iX1≥1 iXk≥1 To show b λb it therefore suffices to show n ≥ n−1 (37) (m λ)b mi1+···+ik b 0. − n−1 − ··· n−(a1i1+···+akik) ≥ iX1≥1 iXk≥1 i−1 Since bj λbj−1 for all j < n, we have bn−i bn−1/λ for 1 i n. Hence ≥ ≤ ≤ ≤ mi1+···+ik b ··· n−(a1i1+···+akik) iX1≥1 iXk≥1 λbn−1 mi1+···+ik ≤ ··· λa1i1+···+akik iX1≥1 iXk≥1 mi1+···+ik = λbn−1 ··· λa1i1+···+akik iX1≥1 iXk≥1 mi1 mik = λbn−1 . λa1i1 ··· λakik iX1≥1 iXk≥1 Since a 2 for 1 i k, we have i ≥ ≤ ≤ mi1 mik λbn−1 λa1i1 ··· λakik iX1≥1 iXk≥1 mi1 mik λbn−1 ≤ λ2i1 ··· λ2ik iX1≥1 iXk≥1 k mi = λb . n−1  λ2i  Xi≥1 By Lemma 56, we have λ m 1/2, whence m/λ2 m/(m 1/2)2 < 1. Thus ≥ − ≤ − k mi m/λ2 k m k λb = λb = λb . n−1  λ2i  n−1 1 m/λ2 n−1 λ2 m Xi≥1  −   −  We have thus shown m k mi1+···+ik b λb . ··· n−(a1i1+···+akik) ≤ n−1 λ2 m iX1≥1 iXk≥1  −  In order to show that (37) holds, it suffices to show that m k (38) m λ λ . − ≥ λ2 m  −  38 NARAD RAMPERSAD AND JEFFREY SHALLIT

Again, by Lemma 56, we have λ m 1/2, whence ≥ − m k m k λ λ λ2 m ≤ (m 1/2)2 m  −   − −  m k = λ m2 2m + 1/4  −  m k λ ≤ m2 2m  −  (39) = λ/(m 2)k. − On the other hand, 1 −1 λ = m 1+ , (m 2)k  −  whence 1 λ 1+ = m, (m 2)k  −  and so (40) λ/(m 2)k = m λ. − − Applying (39) and (40) establishes (38) and hence (37), completing the proof.  We are now ready to prove Theorem 54. Proof of Theorem 54. Let Σ be an m-letter alphabet and let S be the set of all words of length at least 2 over Σ that are instances of the pattern p. By Lemma 55, the number of words of length n in S is at most [xn]C(x), where C(x) := mi1+···+ik xa1i1+···+akik . ··· iX1≥1 iXk≥1 Define B(x) := b xi = (1 mx + C(x))−1. i − Xi≥0 By Lemma 57, we have b λb for all n 0. In particular, the n ≥ n−1 ≥ coefficients of B are non-negative. By Theorem 53, there are at least bn n n words of length n over Σ that avoid S. Since bn λ , there are at least λ words of length n that avoid the pattern p. ≥  From Theorems 37 and 54 we have, a fortiori Corollary 58. Let p be a pattern in which every variable occurs at least twice. There is an infinite word over a 4-letter alphabet that avoids p. It is easy to show that any pattern with k variables and length at least 2k contains a factor x where every variable that occurs in x occurs at least twice in x. We therefore have REPETITIONSINWORDS 39

Corollary 59. All patterns with k variables and length at least 2k are avoid- able over a 4-letter alphabet.

8. Algorithmics of patterns

8.1. Algorithms for automatic sequences. A sequence (an)n≥0 over a finite alphabet ∆ is said to be k-automatic for some integer k 2 if, roughly speaking, there exists an automaton that, on input n in base≥ k, reaches a state with the output an. This class of sequences, also called k-recognizable in the literature, has been studied extensively in the literature [8] and has several different char- acterizations, the most famous being images of fixed points of k-uniform morphisms. The archetypal example of a k-automatic sequence is the Thue-Morse sequence t =(t ) = 0110100110010110 , n n≥0 ··· where tn is the sum (modulo 2) of the bits in the base-2 expansion of n [7]. See Figure 3. As noted in Section 1.2, it can also be obtained as the fixed point of the morphism µ where 0 01 and 1 10. → → 0 0 1

0 1

1

Figure 3. Automaton generating the Thue-Morse sequence

Given a k-automatic sequence, one might reasonably inquire as to whether the sequence is ultimately periodic. More precisely, we would like to know if the problem Given a k-automatic sequence, is it ultimately periodic? is decidable (i.e., recursively solvable). This problem was solved by Honkala [58], who gave a rather complicated decision procedure. This problem, as well as many similar problems, can be solved by rec- ognizing that a statement of the desired property can be expressed in the logical theory N, +,V , where V (n) is the largest power of k dividing n. h ki k For example, for a k-automatic sequence w = a0a1a2 , the property of being ultimately periodic is equivalent to the assertion th···at (41) p 1,N 0 j N a = a . ∃ ≥ ≥ ∀ ≥ j+p j 40 NARAD RAMPERSAD AND JEFFREY SHALLIT

Using the techniques in [6, 26], given an automaton M generating the ′ sequence (ai)i≥0, we can construct another automaton M with the property that it accepts all pairs (p,N), expressed in base k, such that (41) holds. From M ′ we can easily decide if the sequence is ultimately periodic. Here are a few more of the problems that, using this technique, have recursive solutions for automatic sequences x and y. given a rational number p/q, determining if x has infinitely many • distinct p/q powers. computing the critical exponent. The critical exponent is the supre- • mum, over all finite factors f of x, of the exponent of f. given a rational number p/q, determining if the universal critical • exponent = p/q (resp., p/q). The universal critical exponent is the infimum, over all≤ positions i 0 of the supremum of the exponents of all factors f of x beginning≥ at position i. determining whether x is a shift of y • given an automatic sequence x, a rational number ρ, and an integer • m 1, determining whether x is (ρ, m)-repetitive [61]: that is, whether≥ all sufficiently long prefixes of x have a suffix of the form vρ, where v m and σ ρ. To see,| this|≤ note that ≥x is (ρ, m)-repetitive if and only if N 1 i N j,ℓ with 0 j < i, 1 l

.2p(n) .. 22 , where the number of 2’s equals the number of quantifiers in the logical formula, p is a polynomial, and n the number of states in the DFA defining the automatic sequence), in many cases it can be implemented and runs in reasonable time for sequences of interest. For example, [6] used the method to reprove, purely mechanically, that the Thue-Morse sequence is overlap- free. More recently the method has been used to resolve a conjecture on the lengths of unbordered factors in the Thue-Morse word [57].

8.2. Abelian patterns. Under some circumstances it is possible to decide if the fixed point of a morphism avoids an abelian k-power. The method of Dekking presented in Section 6.2 applies to a certain class of morphisms. We now describe another approach to this problem. In particular, we show REPETITIONSINWORDS 41

Theorem 60. Let µ be a morphism on Σ= 1, 2,...,m and let M be the adjacency matrix of µ. Suppose that { } µ(1) = 1x, for some x Σ+, ∈ µ(a) > 1, for all a Σ, | | ∈ M −1 < 1 | | and M is non-singular. It is decidable whether µω(1) is abelian k-power free. Here, M denotes the norm on Rm×m induced by the Euclidean norm on Rm: i.e.,| | Mv M = sup | | | | v∈Rm v v6=0 | | where v is the usual Euclidean length of the vector v. Let |k |be a positive integer. A k-template is a (2k)-tuple

t =[a1,a2,...ak+1,d1,d2,...,dk−1] m where the ai ǫ, 1, 2,...,m and the di Z . We say that a word w realizes the k-template∈ { t if a non-empty} factor∈ u of w has the form u = a X a X a a X a 1 1 2 2 3 ··· k k k+1 where ψ(Xi+1) ψ(Xi)= di, i = 1, 2,...,k 1. We call u an instance of t (note that a word− u may be an instance of more− than one template). The particular k-template

Tk =[ǫ,ǫ,...,ǫ, −→0 , −→0 ,..., −→0] will be of interest. The word u is an instance of Tk if and only if u has the form u = X X X 1 2 ··· k where ψ(Xi+1)= ψ(Xi), i = 1, 2,...,k 1; in other words, if and only if u is an Abelian k-power. − Let t1 =[a1,a2,...,ak+1,d1,d2,...,dk−1] and t2 =[A1, A2,...,Ak+1,D1,D2,...,Dk−1] be k-templates. We say that t2 is a parent of t1 if ′ ′′ ′ ′′ µ(Ai)= aiaiai for some words ai,ai while (42) ψ(a′′ a′ ) ψ(a′′a′ )+ MD = d , 1 i k. i+1 i+2 − i i+1 i i ≤ ≤ Lemma 61. (Parent Lemma) Suppose that w Σ∗ realizes t . Then µ(w) ∈ 2 realizes t1. 42 NARAD RAMPERSAD AND JEFFREY SHALLIT

Proof. Let w contain the factor

u = A Y A Y A Y A 1 1 2 2 ··· k k k+1

′ ′′ where ψ(Yi+1) ψ(Yi) = Di. For each i, write µ(Ai) = aiaiai and let ′′ ′ − Xi = ai µ(Yi)ai+1. Then

µ(u)= a′ a X a X X a X a a′′ 1 1 1 2 2 ··· k−1 k k k+1 k+1 and for each i,

ψ(X ) ψ(X )= ψ(a′′ µ(Y )a′ ) ψ(a′′µ(Y )a′ ) i+1 − i i+1 i+1 i+2 − i i i+1 = ψ(a′′ a′ ) ψ(a′′a′ )+ ψ(µ(Y )) ψ(µ(Y )) i+1 i+2 − i i+1 i+1 − i = ψ(a′′ a′ ) ψ(a′′a′ )+ ψ(Y ) ψ(Y ) i+1 i+2 − i i+1 i+1 − i = ψ(a′′ a′ ) ψ(a′′a′ )+ MD i+1 i+2 − i i+1 i  = di, by (42) and µ(w) contains the instance a X a X X a of t .  1 1 2 2 ··· k k+1 1

Observe that given a k-template t1, we may calculate all of its parents. Indeed, the set of candidates for the Ai in a parent, and hence for the ′ ′′ ai,ai is finite, and may be searched exhaustively. Since M is non-singular, ′ ′′ a choice of values for ai,ai , together with given values di, determines the m Di by (42). However, not all computed values for Di may be in Z ; some k-templates may have no parents. Let ancestor be the transitive closure of the parent relation.

Lemma 62. The template Tk has finitely many ancestors.

Proof. Rewriting (42), we obtain

D = M −1 d + ψ(a′′a′ ) ψ(a′′ a′ ) . i i i i+1 − i+1 i+2  ′ ′′ Since the ai,ai are factors of words of µ(Σ), there are finitely many possi- ′′ ′ ′′ ′ bilities for c = ψ(ai ai+1) ψ(ai+1ai+2). Let C be the (finite) set of possible values for c. − The Di vectors in any ancestor of k-template Tk will have the form

D = M −qc + M q−1c + + M −1c + c , c C,j = 0,...,q. i q q−1 ··· 1 0 j ∈ REPETITIONSINWORDS 43

Let c∗ = max c : c C and let r = c∗/(1 M −1 ). We have {| | ∈ } −| |

D = M −qc + M q−1c + + M −1c + c | i| | q q−1 ··· 1 0| M −qc + M q−1c + + M −1c + c ≤| q| | q−1| ··· | 1| | 0| (triangle inequality) M −q c + M q−1 c + + M −1 c + c ≤| || q| | || q−1| ··· | || 1| | 0| (property of the induced norm) M −1 q c + M −1 q−1 c + + M −1 c + c ≤| | | q| | | | q−1| ··· | || 1| | 0| (submultiplicativity) M −1 qc∗ + M −1 q−1c∗ + + M −1 c∗ + c∗ ≤| | | | ··· | | ∞ c∗ M −1 i (since M −1 < 1) ≤ | | | | i=0 X c∗ = 1 M −1 −| | = r.

m Thus, the Di lie within a ball of radius r in R . It follows that there are m only finitely many Di’s in Z . Since there are finitely many choices for the Ai ǫ, 1, 2,...,m and the Di in any ancestor, it follows that Tk has only finitely∈ { many ancestors.} 

Let N = max µ(a) . a∈Σ | |

Lemma 63. (Inverse Parent Lemma) Suppose that u is a factor of µω(1) which is an instance of t1, and u >N +k 1+(k 1)(N 2+mk∆). Then ω | | − − − for some parent t2 of t1, µ (1) contains a factor v which is an instance of t , and such that v < u . 2 | | | |

Proof. Suppose that in k-template t we have max d = ∆. Let u be an 1 ⌊ i | i|⌋ instance of t1,

u = a X a X a a X a 1 1 2 2 3 ··· k k k+1 where ψ(X ) ψ(X )= d , i = 1, 2,...k 1. i+1 − i i − 44 NARAD RAMPERSAD AND JEFFREY SHALLIT

If i>j, we have

m X X = ( X X ) | i|−| j | | i|n −| j |n n=1 X m i−j = ( X X ) | j+q|n −| j+q−1|n n=1 q=1 X X m i−j = ψ(X )(n) ψ(X )(n) j+q − j+q−1 n=1 q=1 X X   m i−j ∆ ≤ n=1 q=1 X X mk∆. ≤ This can be argued with the opposite inequality, showing in total that X X mk∆. || i|−| j || ≤ If for some i we have Xi N 2, then for 1 j k we have Xj N 2+ mk∆. The greatest| | ≤ possible− length of u would≤ ≤ then be | | ≤ − k+1 X + a + X N 2+ k +1+(k 2)(N 2+ mk∆). | i| | j | | j |≤ − − − j=1 X Xj6=i If u >N +k 1+(k 2)(N 2+mk∆) then for each i we have Xi >N 2 and| | we can then− parse− u as − | | − u = a X a X a a X a 1 1 2 2 3 ··· k k k+1 = a a′′µ(Y )a′ a a′′µ(Y )a′ a′′µ(Y )a′ a 1 1 1 2 2 2 2 3 ··· k k k+1 k+1 ω ′ ′′ where v = A1Y1 AkYkAk+1 is a factor of µ (1), µ(Ai)= aiaiai for each ′′ ··· ′ i and Xi = ai µ(Yi)ai+1. It follows that the parent t2 of t1 is realized by a factor of µω(1); moreover, the instance v of t satisfies v < u /2.  2 | | | | The algorithm that completes the proof of Theorem 60 proceeds as fol- lows. Calculate the set T of ancestors of Tk. By Lemma 62 this set is finite. The word µω(1) contains an Abelian k-power if and only if an instance of one of these ancestors is a factor of µω(1). For each t = [a ,a ,...,a ,d ,d ,...,d ] T , let D = d ,d ,...,d . Let 1 2 k+1 1 2 k−1 ∈ t { 1 2 k−1} D = t∈T Dt, and let ∆ = maxd∈D d . As per Lemma 63, the short- est instance∪ (if any) in µω(1) of⌊ a template| |⌋ of T has length at most N + k 2+(k 2)(N 2+ mk∆). We therefore generate all the factors of µω(1)− of this− length,− and test whether any contains an instance of one of these ancestors. REPETITIONSINWORDS 45

9. Notes Notes for Section 1.2. The Thue–Morse word is named after Thue [93] and Morse [69], who rediscovered it in the 1920’s. However, the Thue– Morse word occurs implicitly in a much earlier communication of Prouhet [82] to the French Academy of Sciences in 1851. Prouhet actually gave a construction of a wider family of words known as the Prouhet words. For a survey concerning properties of the Thue–Morse word see Allouche and Shallit [7]. Notes for Section 2.2. For slightly weaker versions of Corollary 7, see Brandenburg [18] and Shur [91]. An important notion concerning fractional powers is that of the critical exponent of a infinite word w: that is, the supremum of all real numbers α such that w contains an α power. The definitive study is Krieger’s Ph.D.’s thesis [64]. Thue [94] showed that the critical exponent of the Thue–Morse word is 2. Mignosi and Pirillo [66] showed that the critical exponent of the Fibonacci word is 2 + ϕ, where ϕ is the golden ratio. Damanik and Lenz [36] gave a formula for the critical exponent of general Sturmian words. Notes for Section 2.3. Aberkane, Linek, and Mor [3] characterized the set of all rational numbers α such that the Thue–Morse word contains an α-power. Saari [89] proved that a 5/3-power begins at every position of the Thue–Morse word, and the constant 5/3 is optimal. Using results of Mignosi, Restivo, and Sciortino [67], along with the work of de Luca and Mione [65], one can describe the set of minimal forbidden subwords of t. Dekking [38] showed that any infinite overlap-free binary word contains arbitrarily large squares. Allouche, Currie, and Shallit [5] determined the lexicographically least overlap-free word. Brown, Rampersad, Shallit, and Vasiga [19] proved that modifying any finite number of bits of the Thue–Morse word results in a word containing an overlap. Notes for Section 2.4. Earl Fife [46, 47] showed that the set of all in- finite binary overlap-free words can be concisely represented using a finite automaton. His proof was later simplified by Berstel [15]. The approach presented here based on Restivo-Salemi factorization theorem [86] is due to Shallit [90]. Rampersad, Shallit, and Shur [84] applied the same method to 7 obtain an automaton encoding the 3 -power-free words. Thue [94] (see also Gottschalk and Hedlund [49]) characterized the bi- infinite overlap-free words. Shur [91] generalized this result. Notes for Section 2.6. For more on the Lov´asz Local Lemma, see the book by Alon and Spencer [10]. Beck [12] gave one of the earliest applica- tions of the local lemma to combinatorics on words. Currie [27] applied it 46 NARAD RAMPERSAD AND JEFFREY SHALLIT to avoiding fractional powers. Grytczuk [52] applied it to the avoidance of repetitions in arithmetic progressions. Alon, Grytczuk, Haluszczak, and Ri- ordan [9] applied it to nonrepetitive colourings of graphs. Krieger, Ochem, Rampersad, and Shallit [77] made use of it to study the avoidance of “ap- proximate” squares. Pegden [79] used a “one-sided” variant of the local lemma to proved results on “game” versions of nonrepetitive colourings. In 2010, Moser and Tardos [70] produced an “algorithmic version” of the local lemma. This approach inspired several new results in combinatorics on words by Grytczuk, Kozik, Micek, and Witkowski [54, 55, 56]. Notes for Section 3.1. The notion of repetition threshold was first for- mulated by Brandenburg [18]; however, there are some problems with his definition. We have attempted to provide a more precise treatment here. The proof of Dejean’s Conjecture consists of the following works: Dejean [37], Pansiot [78], Moulin Ollagnier [71], Mohammad-Noori & Currie [68], Carpi [23], Rao [85], and Currie & Rampersad [29, 30, 31]. Notes for Section 3.2. The material in the section is from Brandenburg [18]. Notes for Section 3.3. The Pansiot encoding is due to Pansiot [78]. Notes for Section 4. The original paper of van der Waerden is hard to find; for a proof of the theorem the reader may consult the classic textbook of Graham, Rothschild, and Spencer [51]. The problem of avoiding repetitions in arithmetic progressions seems to have first been studied by Carpi [21] and subsequently by Currie and Simpson [33] and Grytczuk, Kozik, and Witkowski [52, 56]. Downarowicz [40] studied a related problem. Theorem 33 is due to Carpi [21]. Kao, Rampersad, Shallit, and Silva [60] proved that there exists an infi- nite word over a binary alphabet that contains no squares xx with x 3 in any arithmetic progression of odd difference. This improves upon a| result|≥ of Entringer, Jackson, and Schatz [43]. Theorem 35 is due to Carpi [21]. Dumitrescu and Radoiˇci´c[41] proved that every 2-dimensional word over a 2-letter alphabet must contain a line containing a cube. Grytczuk [53] presented the problem of determining the Thue threshold of N2, namely, the smallest integer t such that there exists an integer k 2 and a 2-dimensional word w over a t-letter alphabet such that every line≥ of w is k-power-free. Carpi’s result showed that t 16. It is possible to show that there is a 2-dimensional word over a 4-letter≤ alphabet such that every line is 3+-power-free, so t 4. ≤ Notes for Section 5. Bean, Ehrenfeucht, and McNulty [11] and Zimin [95] independently developed the study of patterns. Zimin [95] gave an algorithm to determine if a given pattern is avoidable over some finite alphabet. It remains an open problem to determine if there is an algorithm which decides, REPETITIONSINWORDS 47 given a pattern p and a natural number k, whether p is avoidable on a k- letter alphabet. A pattern p is scrambled if all variables occur at least twice in p, and for each pair of distinct variables x,y, the pattern p contains occurrences of both xy and yx. Bean, Ehrenfeucht, and McNulty [11] proved that there is an infinite word over a 20-letter alphabet that simultaneously avoids all scrambled patterns. Petrov [80] later improved this to a 4-letter alphabet. The classification of the binary patterns avoidable on the binary alpha- bet is due to several authors and was completed by Cassaigne [24] and independently by Vaniˇcek (see [48]).

Notes for Section 6.2. Currie and Linek [28] and Currie and Visentin [34, 35] proved results on avoidability in the abelian sense of more general patterns.

Notes for Section 6.3. Theorem 47 is due to Richomme, Saari, and Zam- boni [87].

Notes for Section 7.1. Brandenburg [18] established that there are ex- ponentially many ternary squarefree words of length n and binary cubefree words of length n. His bounds were subsequently improved by several au- thors. The substitution h given in this section was found by Ekhad and Zeilberger [42]. Shur [92] has calculated growth rates for β-power-free words over k-letter alphabets for several values of β and k.

Notes for Section 7.2. The method presented here for estimating the number of binary overlap-free words is due to Restivo and Salemi [86]. A more refined approach was given by [25, 22]. The current best bounds are due to Jungers, Protasov, and Blondel [59]. The same method was subsequently applied to enumerate the words avoiding α-powers with 2 < α 7/3 [17]. Karhum¨aki and Shallit [62] established that the exponent 7/3≤ is a “threshold” for polynomial vs. exponential growth over the binary alphabet.

Notes for Section 7.3. For the Goulden–Jackson cluster method see [50]. Noonan and Zeilberger [72] and Berstel [16] also give expositions of the cluster method.

Notes for Section 7.4. The material in this section is based on Bell and Goh [14]. Rampersad [83] derived some additional results using the same method. Theorem 53 is a special case of a result originally presented by Golod (see Rowen [88, Lemma 6.2.7]) in an algebraic setting. We have reformulated the theorem and proof using combinatorial terminology more congenial for the applications considered here. Bell [13] applied Theorem 53 to give enumerative results concerning the avoidability of finite sets of words. Theorem 54 is due to Bell and Goh [14]. The avoidability of the patterns 48 NARAD RAMPERSAD AND JEFFREY SHALLIT treated in Corollaries 58 and 59 was originally established by Bean, Ehren- feucht, and McNulty [11]. The significance of Corollaries 58 and 59 is that they establish the avoidability of these patterns over a 4-letter alphabet.

Notes for Section 8.1. The material in this section is based on Allouche, Rampersad, and Shallit [6] and Charlier, Rampersad, and Shallit [26]. The method described here is very similar to techniques previously developed by B¨uchi, Bruy`ere, Michaux, Villemaire, and others (see [20]), involving formal logic.

Notes for Section 8.2. The material in this section is based on Currie and Rampersad [32], which attempts to present a more systematic treatment of the somewhat ad hoc arguments of Aberkane, Currie, and Rampersad [2] and Aberkane and Currie [1].

References

[1] A. Aberkane and J. Currie. A cyclic binary morphism avoiding abelian fourth powers. Theoret. Comput. Sci. 410 (2009), 44–52. [2] A. Aberkane, J. Currie, and N. Rampersad. The number of ternary words avoiding abelian cubes grows exponentially. J. Integer Sequences 7 (2004), Article 04.2.7. Available at http://www.cs.uwaterloo.ca/journals/JIS/VOL7/Currie/currie18. html. [3] A. Aberkane, V. Linek, and S. J. Mor. On the powers in the Thue–Morse word. Australasian J. Combinat. 35 (2006), 41–49. [4] B. Adamczewski and Y. Bugeaud. Transcendence and Diophantine approximation. In V. Berth´eand M. Rigo, editors, Combinatorics, Automata, and Number Theory, Vol. 135 of Encyclopedia of Mathematics and its Applications. Cambridge University Press, 2010. [5] J.-P. Allouche, J. D. Currie, and J. Shallit. Extremal infinite overlap- free binary words. Electronic J. Combinatorics 5 (1998), #R27 (electronic), http://www.combinatorics.org/Volume_5/Abstracts/v5i1r27.html [6] J.-P. Allouche, N. Rampersad, and J. Shallit. Periodicity, repetitions, and orbits of an automatic sequence. Theoret. Comput. Sci. 410 (2009), 2795–2803. [7] J.-P. Allouche and J. O. Shallit. The ubiquitous Prouhet-Thue-Morse sequence. In C. Ding, T. Helleseth, and H. Niederreiter, editors, Sequences and Their Applica- tions, Proceedings of SETA ’98, pp. 1–16. Springer-Verlag, 1999. [8] J.-P. Allouche and J. Shallit. Automatic Sequences: Theory, Applications, General- izations. Cambridge University Press, 2003. [9] N. Alon, J. Grytczuk, M. Haluszczak, and O. Riordan. Nonrepetitive colorings of graphs. Random Structures and Algorithms 21 (2002), 336–346. [10] N. Alon and J. Spencer. The Probabilistic Method. Wiley, 2000. [11] D. A. Bean, G. Ehrenfeucht, and G. McNulty. Avoidable patterns in strings of symbols. Pacific J. Math. 85 (1979), 261–294. [12] J. Beck. An application of Lov´asz local lemma: there exists an infinite 01-sequence containing no near identical intervals. In A. Hajnal et al., editors, Finite and Infinite Sets, Vol. I, II (Eger, 1981), Vol. 37 of Colloq. Math. Soc. J´anos Bolyai, pp. 103– 107. North-Holland, 1984. [13] J. P. Bell. Unavoidable and almost unavoidable sets of words. Internat. J. Algebra Comput. 15 (2005), 717–724. REPETITIONSINWORDS 49

[14] J. P. Bell and T. L. Goh. Exponential lower bounds for the number of words of uniform length avoiding a pattern. Inform. Comput. 205 (2007), 1295–130. [15] J. Berstel. A rewriting of Fife’s theorem about overlap-free words. In J. Karhum¨aki, H. Maurer, and G. Rozenberg, editors, Results and Trends in Theoretical Computer Science, Vol. 812 of Lecture Notes in Computer Science, pp. 19–29. Springer-Verlag, 1994. [16] J. Berstel. Growth of repetition-free words—a review. Theoret. Comput. Sci. 340 (2005), 280–290. [17] V. D. Blondel, J. Cassaigne, and R. M. Jungers. On the number of α-power-free binary words for 2 < α ≤ 7/3. Theoret. Comput. Sci. 410 (2009), 2823–2833. [18] F.-J. Brandenburg. Uniformly growing k-th power-free homomorphisms. Theoret. Comput. Sci. 23 (1983), 69–82. [19] S. Brown, N. Rampersad, J. Shallit, and T. Vasiga. Squares and overlaps in the Thue–Morse sequence and some variants. RAIRO Inform. Th´eor. App. 40 (2006), 473–484. [20] V. Bruy`ere, G. Hansel, C. Michaux, and R. Villemaire. Logic and p-recognizable sets of integers. Bull. Belgian Math. Soc. 1 (1994), 191–238. Corrigendum, Bull. Belg. Math. Soc. 1 (1994), 577. [21] A. Carpi. Multidimensional unrepetitive configurations. Theoret. Comput. Sci. 56 (1988), 233–241. [22] A. Carpi. Overlap-free words and finite automata. Theoret. Comput. Sci. 115 (1993), 243–260. [23] A. Carpi. On Dejean’s conjecture over large alphabets. Theoret. Comput. Sci. 385 (2007), 137–151. [24] J. Cassaigne. Unavoidable binary patterns. Acta Informatica 30 (1993), 385–395. [25] J. Cassaigne. Counting overlap-free binary words. In P. Enjalbert, A. Finkel, and K. W. Wagner, editors, STACS 93, Proc. 10th Symp. Theoretical Aspects of Comp. Sci., Vol. 665 of Lecture Notes in Computer Science, pp. 216–225. Springer-Verlag, 1993. [26] E. Charlier, N. Rampersad, and J. Shallit. Enumeration and decidable properties of automatic sequences. Preprint, available at http://arxiv.org/abs/1102.3698, 2011. [27] J. Currie. Pattern avoidance: themes and variations. Theoret. Comput. Sci. 339 (2005), 7–18. [28] J. Currie and V. Linek. Avoiding patterns in the abelian sense. Canadian J. Math. 53 (2001), 696–714. [29] J. D. Currie and N. Rampersad. Dejean’s conjecture holds for n ≥ 27. RAIRO Inform. Th´eor. App. 43 (2009), 775–778. [30] J. D. Currie and N. Rampersad. Dejean’s conjecture holds for n ≥ 30. Theoret. Comput. Sci. 410 (2009), 2885–2888. [31] J. D. Currie and N. Rampersad. A proof of Dejean’s conjecture. Math. Comp. 80 (2011), 1063–1070. [32] J. Currie and N. Rampersad. Fixed points avoiding Abelian k-powers. J. Combin. Theory. Ser. A 119 (2012), 942–948. [33] J. Currie and J. Simpson. Non-repetitive tilings. Electronic J. Combinatorics 9 (2002), #R28. [34] J. Currie and T. Visentin. On abelian 2-avoidable binary patterns. Acta Informatica 43 (2007), 521–533. [35] J. Currie and T. Visentin. Long binary patterns are abelian 2-avoidable. Theoret. Comput. Sci. 409 (2008), 432–437. [36] D. Damanik and D. Lenz. The index of Sturmian sequences. European J. Combina- torics 23 (2002), 23–29. 50 NARAD RAMPERSAD AND JEFFREY SHALLIT

[37] F. Dejean. Sur un th´eor`eme de Thue. J. Combin. Theory. Ser. A 13 (1972), 90–99. [38] F. M. Dekking. On repetitions of blocks in binary sequences. J. Combin. Theory. Ser. A 20 (1976), 292–299. [39] F. M. Dekking. Strongly non-repetitive sequences and progression-free sets. J. Com- bin. Theory. Ser. A 27 (1979), 181–185. [40] T. Downarowicz. Reading along arithmetic progressions. Colloq. Math. 80 (1999), 293–296. [41] A. Dumitrescu and R. Radoiˇci´c.On a coloring problem for the integer grid. In Towards a theory of geometric graphs, Vol. 342 of Contemp. Math., pp. 67–74. Amer. Math. Soc., 2004. [42] S. B. Ekhad and D. Zeilberger. There are more than 2(n/17) n-letter ternary square-free words. J. Integer Sequences 1 (1998), 98.1.9 (electronic), http://www.research.att.com/~njas/sequences/JIS/zeil.html [43] R. C. Entringer, D. E. Jackson, and J. A. Schatz. On nonrepetitive sequences. J. Combin. Theory. Ser. A 16 (1974), 159–164. [44] P. Erd˝os. Some unsolved problems. Magyar Tud. Akad. Mat. Kutat´oInt. K¨ozl. 6 (1961), 221–254. [45] A. A. Evdokimov. Strongly asymmetric sequences generated by a finite number of symbols. Dokl. Akad. Nauk SSSR 179 (1968), 1268–1271. In Russian. English translation in Soviet Math. Dokl. 9 (1968), 536–539. [46] E. D. Fife. Binary sequences which contain no BBb. Trans. Amer. Math. Soc. 261 (1980), 115–136. [47] E. D. Fife. Irreducible binary sequences. In L. J. Cummings, editor, Combinatorics on Words: Progress and Perspectives, pp. 91–100. Academic Press, 1983. [48] P. Goralcik and T. Vanicek. Binary patterns in binary words. Internat. J. Algebra Comput. 1 (1991), 387–391. [49] W. H. Gottschalk and G. A. Hedlund. A characterization of the Morse minimal set. Proc. Amer. Math. Soc. 15 (1964), 70–74. [50] I. Goulden and D. Jackson. Combinatorial Enumeration. Dover, 2004. [51] R. Graham, B. Rothschild, and J. Spencer. Ramsey Theory. Wiley, second edition edition, 1990. [52] J. Grytczuk. Thue-like sequences and rainbow arithmetic progressions. Elec- tronic J. Combinatorics 9 (2002), #R44. Available electronically at http://www. combinatorics.org/Volume_9/Abstracts/v9i1r44.html. [53] J. Grytczuk. Nonrepetitive graph coloring. In Graph theory in Paris, Trends in Mathematics, pp. 209–218. Birkh¨auser, Basel, 2006. [54] J. Grytczuk, J. Kozik, and P. Micek. Nonrepetitive games. Manuscript available electronically at http://arxiv.org/abs/1103.3810. [55] J. Grytczuk, J. Kozik, and P. Micek. A new approach to nonrepetitive sequences. To appear in Random Struct. Alg. [56] J. Grytczuk, J. Kozik, and M. Witkowski. Nonrepetitive sequences on arithmetic progressions. Electronic J. Combinatorics 18 (2011), #P209. Available electronically at http://www.combinatorics.org/Volume_18/PDF/v18i1p209.pdf. [57] D. Henshall and J. Shallit. Automatic theorem-proving in combinatorics on words. Available at http://arxiv.org/abs/1203.3758, 2012. [58] J. Honkala. A decision method for the recognizability of sets defined by number systems. RAIRO Inform. Th´eor. App. 20 (1986), 395–403. [59] R. Jungers, V. Protasov, and V. Blondel. Overlap-free words and spectra of matrices. Theoret. Comput. Sci. 410 (2009), 3670–3684. [60] J.-Y. Kao, N. Rampersad, J. Shallit, and M. Silva. Words avoiding repetitions in arithmetic progressions. Theoret. Comput. Sci. 391 (2008), 126–137. REPETITIONSINWORDS 51

[61] J. Karhum¨aki, A. Lepist¨o, and W. Plandowski. Locally periodic versus globally periodic infinite words. J. Combin. Theory. Ser. A 100 (2002), 250–264. [62] J. Karhum¨aki and J. Shallit. Polynomial versus exponential growth in repetition-free binary words. J. Combin. Theory. Ser. A 105 (2004), 335–347. [63] V. Ker¨anen. Abelian squares are avoidable on 4 letters. In W. Kuich, editor, Proc. 19th Int’l Conf. on Automata, Languages, and Programming (ICALP), Vol. 623 of Lecture Notes in Computer Science, pp. 41–52. Springer-Verlag, 1992. [64] D. Krieger. Critical Exponents and Stabilizers of Infinite Words. PhD thesis, Uni- versity of Waterloo, 2008. [65] A. de Luca and L. Mione. On bispecial factors of the Thue–Morse word. Inform. Process. Lett. 49 (1994), 179–183. [66] F. Mignosi and G. Pirillo. Repetitions in the Fibonacci infinite word. RAIRO Inform. Th´eor. App. 26 (1992), 199–204. [67] F. Mignosi, A. Restivo, and M. Sciortino. Words and forbidden factors. Theoret. Comput. Sci. 273 (2002), 99–117. [68] M. Mohammad-Noori and J. D. Currie. Dejean’s conjecture and sturmian words. European J. Combinatorics 28 (2007), 876–890. [69] M. Morse. Recurrent geodesics on a surface of negative curvature. Trans. Amer. Math. Soc. 22 (1921), 84–100. [70] R. Moser and G. Tardos. A constructive proof of the general Lov´asz local lemma. J. Assoc. Comput. Mach. 57 (2010), Article 11. [71] J. Moulin-Ollagnier. Proof of Dejean’s conjecture for alphabets with 5, 6, 7, 8, 9, 10 and 11 letters. Theoret. Comput. Sci. 95 (1992), 187–205. [72] J. Noonan and D. Zeilberger. The Goulden-Jackson cluster method: extensions, applications and implementations. J. Diff. Equations. Appl. 5 (1999), 355–377. [73] P. S. Novikov. On periodic groups. Dokl. Akad. Nauk SSSR 127 (1959), 749–752. [74] P. S. Novikov and S. I. Adjan. Infinite periodic groups, I. Izv. Akad. Nauk SSSR Ser. Mat. 32 (1968), 212–244. [75] P. S. Novikov and S. I. Adjan. Infinite periodic groups, II. Izv. Akad. Nauk SSSR Ser. Mat. 32 (1968), 251–524. [76] P. S. Novikov and S. I. Adjan. Infinite periodic groups, III. Izv. Akad. Nauk SSSR Ser. Mat. 32 (1968), 709–731. [77] P. Ochem, N. Rampersad, and J. Shallit. Avoiding approximate squares. Internat. J. Found. Comp. Sci. 19 (2008), 633–648. [78] J.-J. Pansiot. A propos d’une conjecture de F. Dejean sur les r´ep´etitions dans les mots. Disc. Appl. Math. 7 (1984), 297–311. [79] W. Pegden. Highly nonrepetitive sequences: winning strategies from the local lemma. Random Structures and Algorithms 38 (2011), 140–161. [80] A. N. Petrov. A sequence that avoids every complete word. Mat. Zametki 44 (1988), 517–522. Translation in Math. Notes 44 (1988), 764–767. [81] P. A. B. Pleasants. Non-repetitive sequences. Proc. Cambridge Phil. Soc. 68 (1970), 267–274. [82] E. Prouhet. M´emoire sur quelques relations entre les puissances des nombres. C. R. Acad. Sci. Paris 33 (1851), 225. [83] N. Rampersad. Further applications of a power series method for pattern avoid- ance. Electronic J. Combinatorics 18 (2011), P134. Available at http://www. combinatorics.org/Volume_18/Abstracts/v18i1p134.html. 7 [84] N. Rampersad, J. Shallit, and A. Shur. Fife’s theorem for 3 -powers. In preparation, 2011. [85] M. Rao. Last cases of Dejean’s conjecture. Theoret. Comput. Sci. 412 (2010), 3010– 3018. 52 NARAD RAMPERSAD AND JEFFREY SHALLIT

[86] A. Restivo and S. Salemi. Overlap free words on two symbols. In M. Nivat and D. Perrin, editors, Automata on Infinite Words, Vol. 192 of Lecture Notes in Com- puter Science, pp. 198–206. Springer-Verlag, 1985. [87] G. Richomme, K. Saari, and L. Zamboni. Abelian complexity in minimal subshifts. J. London Math. Soc. 83 (2011), 79–95. [88] L. Rowen. Ring Theory, Vol. II. Academic Press, Boston, 1988. [89] K. Saari. Everywhere α-repetitive sequences and Sturmian words. In V. Diekert, M. Volkov, and A. Voronkov, editors, CSR 2007, Vol. 4649 of Lecture Notes in Computer Science, pp. 362–372. Springer-Verlag, 2007. [90] J. Shallit. Fife’s theorem revisited. Available from http://arxiv.org/abs/1102.3932, 2011. [91] A. M. Shur. The structure of the set of cube-free Z-words in a two-letter alphabet (Russian). Izv. Ross. Akad. Nauk Ser. Mat. 64 (2000), 201–224. English translation in Izv. Math. 64 (2000), 847–871. [92] A. Shur. Numerical values of the growth rates of power-free languages. Available electronically at http://arxiv.org/pdf/1009.4415.pdf. [93] A. Thue. Uber¨ unendliche Zeichenreihen. Norske vid. Selsk. Skr. Mat. Nat. Kl. 7 (1906), 1–22. Reprinted in Selected Mathematical Papers of Axel Thue, T. Nagell, editor, Universitetsforlaget, Oslo, 1977, pp. 139–158. [94] A. Thue. Uber¨ die gegenseitige Lage gleicher Teile gewisser Zeichenreihen. Norske vid. Selsk. Skr. Mat. Nat. Kl. 1 (1912), 1–67. Reprinted in Selected Mathematical Papers of Axel Thue, T. Nagell, editor, Universitetsforlaget, Oslo, 1977, pp. 413–478. [95] A. I. Zimin. Blocking sets of terms. Mat. Sbornik 119 (1982), 363–375, 447. In Russian. English translation in Math. USSR Sbornik, 47 (1984), 353–364.

Department of Mathematics and Statistics, University of Winnipeg, 515 Portage Ave., Winnipeg, MB R3B 2E9, Canada E-mail address, N. Rampersad: [email protected]

School of Computer Science, University of Waterloo, Waterloo, ON N2L 3G1, Canada E-mail address, J. Shallit: [email protected]