A new approach to the $2$-regularity of the $\ell$-abelian complexity of $2$-automatic sequences

We prove that a sequence satisfying a certain symmetry property is $2$-regular in the sense of Allouche and Shallit, i.e., the $\mathbb{Z}$-module generated by its $2$-kernel is finitely generated. We apply this theorem to develop a general approach for studying the $\ell$-abelian complexity of $2$-automatic sequences. In particular, we prove that the period-doubling word and the Thue--Morse word have $2$-abelian complexity sequences that are $2$-regular. Along the way, we also prove that the $2$-block codings of these two words have $1$-abelian complexity sequences that are $2$-regular.


Introduction
This paper is about some structural properties of integer sequences that occur naturally in combinatorics on words. Since the fundamental work of Cobham [8], the so-called automatic sequences have been extensively studied. We refer the reader to [3] for basic definitions and properties. These infinite words over a finite alphabet can be obtained by iterating a prolongable morphism of constant length to get an infinite word (and then, an extra letter-to-letter morphism, also called coding, may be applied). As a fundamental example, the Thue-Morse word t = σ ω (0) = 0110100110010110 · · · is a fixed point of the morphism σ over the free monoid {0, 1} * defined by σ(0) = 01, σ(1) = 10. Similarly, the period-doubling word p = ψ ω (0) = 01000101010001000100 · · · is a fixed point of the morphism ψ over {0, 1} * defined by ψ(0) = 01, ψ(1) = 00. We will discuss again these two examples of 2-automatic sequences.
Since an infinite word is just a sequence over N taking values in a finite alphabet, we use the terms 'infinite word' and 'sequence' interchangeably.
Let k ≥ 2 be an integer. One characterization of k-automatic sequences is that their k-kernels are finite; see [9] or [3, Section 6.6].
Definition 1. The k-kernel of a sequence s = s(n) n≥0 is the set K k (s) = {s(k i n + j) n≥0 : i ≥ 0 and 0 ≤ j < k i }.
For instance, the 2-kernel K 2 (t) of the Thue-Morse word contains exactly two elements, namely t and σ ω (1).
A natural generalization of automatic sequences to sequences on an infinite alphabet is given by the notion of k-regular sequences. We will restrict ourselves to sequences taking integer values only.
Definition 2. Let k ≥ 2 be an integer. A sequence s = s(n) n≥0 ∈ Z N is k-regular if K k (s) is a finitely-generated Z-module, i.e., there exist a finite number of sequences t 1 (n) n≥0 , . . . , t ℓ (n) n≥0 such that every sequence in the k-kernel K k (s) is a Z-linear combination of the t r 's. Otherwise stated, for all i ≥ 0 and for all j ∈ {0, . . . , k i − 1}, there exist integers c 1 , . . . , c ℓ such that ∀n ≥ 0, s(k i n + j) = ℓ r=1 c r t r (n).
There are many natural examples of k-regular sequences [1,2]. There is a convenient matrix representation for k-regular sequences which leads to an efficient algorithm for computing the values of such a sequence (and many related quantities). See also [4,Chapter 5] for connections with rational series. In particular, a sequence taking finitely many values is k-regular if and only if it is k-automatic. The k-regularity of a sequence provides us with structural information about how the different terms are related to each other.
A classical measure of complexity of an infinite word x is its factor complexity P (∞) x : N → N which maps n to the number of distinct factors of length n occurring in x. It is well known that a k-automatic sequence x has a k-regular factor complexity function and the sequence (P (∞) x (n + 1) − P (∞) x (n)) n≥0 is k-automatic. See [6,7] for a proof and relevant extensions. As an example, again for the Thue-Morse word, we have P (∞) t (2n + 1) = 2P (∞) t (n + 1) and P for all n ≥ 2. See also [10] where a formula was obtained for the factor complexity of fixed points of some uniform morphisms.
Recently there has been a renewal of interest in abelian notions arising in combinatorics on words (e.g., avoiding abelian or ℓ-abelian patterns, abelian bordered words, etc.). For instance, two finite words u and v are abelian equivalent if one is obtained by permuting the letters of the other one, i.e., the two words share the same Parikh vector, Ψ(u) = Ψ(v). Since the Thue-Morse word is an infinite concatenation of factors 01 and 10, this word is abelian periodic of period 2. The abelian complexity of an infinite word x is a function P (1) x : N → N which maps n to the number of distinct factors of length n occurring in x, counted up to abelian equivalence. Madill and Rampersad [15] provided the first example of regularity in this setting: the abelian complexity of the paper-folding word (which is another typical example of an automatic sequence) is unbounded and 2-regular.
Let ℓ ≥ 1 be an integer. Based on [12] the notions of abelian equivalence and thus abelian complexity were recently extended to ℓ-abelian equivalence and ℓ-abelian complexity [13].
Definition 3. Let u, v be two finite words. We let |u| v denote the number of occurrences of the factor v in u. Two finite words x and y are ℓ-abelian equivalent if |x| v = |y| v for all words v of length |v| ≤ ℓ.
As an example, the words 011010011 and 001101101 are 2-abelian equivalent but not 3-abelian equivalent (the factor 010 occurs in the first word but not in the second one). Hence one can define the function P (ℓ) x : N → N which maps n to the number of distinct factors of length n occurring in the infinite word x, counted up to ℓ-abelian equivalence. That is, we count ℓ-abelian equivalence classes partitioning the set of factors Fac x (n) of length n occurring in x. In particular, for any infinite word x, we have for all n ≥ 0 P (1) x (n) ≤ · · · ≤ P (ℓ) x (n) ≤ P (ℓ+1) x (n) ≤ · · · ≤ P (∞) x (n).
In this paper, we show that both the period-doubling word and the Thue-Morse word have 2-abelian complexity sequences which are 2-regular. The computations and arguments leading to these results permit us to exhibit some similarities between the two cases and a quite general scheme that we hope can be used again to prove additional regularity results. Indeed, one conjectures that any k-automatic sequence has an ℓ-abelian complexity function that is k-regular.
We mention some other papers containing related work. In [14], the authors studied the asymptotic behavior of P (ℓ) t (n) and also derived some recurrence relations 1 showing that the abelian complexity P (1) p (n) n≥0 of the period-doubling word p is 2-regular. In [5], the abelian complexity of the fixed point v of the non-uniform morphism 0 → 012, 1 → 02, 2 → 1 is studied and the authors obtain results similar to those discussed in this paper. Even though the authors of [5] are not directly interested in the k-regularity of 1 It seems that there is some subtle error in the relation for P (1) p (4n + 2) proposed in [14,Lemma 6]. Correct relations are given by [5,Proposition 2] and could also be obtained by Theorem 4 and Proposition 47. P (1) v (n) n≥0 , they derive recurrence relations. From these relations, following the approach described in this paper, one can possibly prove some regularity result. In particular, the result of replacing in v all 2's by 0's leads back to the period-doubling word. Hence, Blanchet-Sadri et al. also proved some other relations about the abelian complexity of p.
The second and last authors of this paper conjectured the 2-regularity of the sequence P (2) t (n) n≥0 (and proved some recurrence relations for this sequence) [17]. Recently, after hearing a talk given by the last author during the Representing Streams II meeting in January 2014, Greinecker proved the recurrence relations needed to prove the 2-regularity of this sequence [11]. Hopefully, the two approaches are complementary: in this paper, we prove 2-regularity without exhibiting the explicit recurrence relations.
Let us now describe the content and organization of this paper. In Section 2 we prove Theorem 4, which establishes the 2-regularity of a large family of sequences satisfying a recurrence relation with a parameter c and 2 ℓ 0 initial conditions. The form of the recurrence implies that sequences in this family exhibit a reflection symmetry in the values taken over each interval [2 ℓ , 2 ℓ+1 ) for ℓ ≥ ℓ 0 . For the special case of the Thue-Morse word, a similar property is shown in [11]. Computer experiments suggest that many 2-abelian complexity functions satisfy such a reflection property.
Theorem 4. Let ℓ 0 ≥ 0 and c ∈ Z. Suppose s(n) n≥0 is a sequence such that, for all ℓ ≥ ℓ 0 and for all r such that 0 ≤ r ≤ 2 ℓ − 1, we have (1) The recurrence satisfied by s(n) in Theorem 4 reads words from left to right, i.e., starting with the most significant digit. Our proof of this theorem will express sequences in the 2-kernel of s(n) n≥0 as in Definition 2, starting with the least significant digit.
From Equation (1) one can get some information about the asymptotic behavior of the sequence s(n) n≥0 . We have s(n) = O(log n), and moreover for ℓ ≥ ⌊ ℓ 0 −1 2 ⌋. At the same time, there are many subsequences of s(n) n≥0 which are constant; for example, s(2 ℓ ) = c for ℓ ≥ ℓ 0 .

Example 5.
As an illustration of the reflection property described in Theorem 4, we consider the abelian complexity of the 2-block coding of the period-doubling word p.  In Section 3, we collect some general results and definitions about words and k-regular sequences (in particular stability properties of the set of k-regular sequences under sum and product) that are needed in the other parts of this paper.
In Section 4, we study the abelian complexity of the 2-block coding x = block(p, 2) of the period-doubling word p. In particular, we consider the difference ∆ 0 (n) between the maximal and minimal numbers of 0's occurring in factors of length n in block(p, 2). We prove that the sequences ∆ 0 (n) n≥0 and P (1) x (n) n≥0 are 2-regular. In Section 5, we study the 2-abelian complexity of p. We show that the 2-regularity of ∆ 0 (n) n≥0 and P (1) x (n) n≥0 implies the 2-regularity of P (2) p (n). Sections 6 and 7 share some similarities with Sections 4 and 5. The reader will see that the strategy used to prove the 2-regularity of P (2) p (n) can also be applied to the Thue-Morse word. Nevertheless, some differences do not permit us to treat the two cases within a completely unified framework.
In Section 6, we study the abelian complexity of the 2-block coding y = block(t, 2) of the Thue-Morse word t. We define ∆ 12 (n) to be the difference between the maximal total and minimal total numbers of 1's and 2's occurring in factors of length n in block(t, 2). It turns out that ∆ 12 (n) + 1 = P (1) p (n) and our results can thus be related to [5] and [14]. We prove that ∆ 12 (n) n≥0 and P (1) y (n) n≥0 are 2-regular. In Section 7, we show that the 2-regularity of P (2) t (n) follows from the 2-regularity of ∆ 12 (n) n≥0 and P (1) y (n) n≥0 . Finally, in Section 8 we suggest a direction for future work.
Proposition 6. For all n ≥ 0 we have In particular, A(n) n≥0 is 2-regular.
Proof. This proof is typical of many of the proofs throughout the paper. We work by induction on n. The case n = 0 can be checked easily using the first few values of the sequence A(n) n≥0 . Therefore, let n ≥ 1 and assume that the recurrence holds for all values less than n. Write n = 2 ℓ + r with ℓ ≥ 0 and 0 ≤ r ≤ 2 ℓ − 1.
The equations for A(8n + 3), A(8n + 5) and A(8n + 7) are handled similarly. Now we prove Theorem 4. We show that for general ℓ 0 ≥ 0, a sequence s(n) n≥0 satisfying the recurrence can be written in terms of A(n) n≥0 .
We prove the identity by induction on n. Recall that for all ℓ ≥ ℓ 0 and for all r such that 0 ≤ r ≤ 2 ℓ − 1, we have Equation (1), i.e., For n = 0, one uses A(1) = 1 and A(3) = 2 to verify that all eight cases of the identity hold. Inductively, let n ≥ 1, and assume the identity is true for all n ′ < n. Write n = 2 ℓ +r with ℓ ≥ 0 and 0 ≤ r ≤ 2 ℓ − 1.
Example 7. In Section 4, we will use Theorem 4 with ℓ 0 = 2 to conclude that ∆ 0 (n) n≥0 and P (1) x (n) n≥0 are 2-regular for the period-doubling word. For ℓ 0 = 2 the value of s(16n + i) is In Section 6, we will use Theorem 4 with ℓ 0 = 1 to conclude that ∆ 12 (n) n≥0 is 2-regular for the Thue-Morse word.

About regular sequences and words
We will often make use of the following composition theorem for a function F defined piecewise on several k-automatic sets.
Proof. It is a direct consequence of [1, Theorem 2.5]: if s(n) n≥0 and t(n) n≥0 are k-regular, then (s(n) + t(n)) n≥0 and (s(n)t(n)) n≥0 are both k-regular sequences. Recall that kautomatic sequences are special cases of k-regular sequences.
Note that if, for each n, there is exactly one i such that P i (n) = 1, then we can write This is the setting in which we will apply Lemma 8. We will also make use of the following classical results. Lemma 11. Let k ≥ 2 be an integer. Let s(n) n≥0 be a sequence. The sequence s(n) n≥0 is k-regular if and only if s(n + 1) n≥0 is k-regular.
Proof. It is a direct consequence of two results stated in [1], namely Theorem 2.6 and its following remark.
Let us now give some definitions about combinatorics on words.
Definition 12. If a word w starts with the letter a, then a −1 w denotes the word obtained from w by deleting its first letter. Similarly, if a word w ends with the letter a, then wa −1 denotes the word obtained from w by deleting its last letter. As usual, we let |w| denote the length of the finite word w. If a is a letter, we let |w| a denote the number of occurrences of a in w. If w = w 0 · · · w ℓ−1 , then we let w R = w ℓ−1 · · · w 0 denote the reversal of w. Our convention is that we index letters in an infinite word beginning with 0.
Since we are interested in ℓ-abelian complexity, it is natural to consider the following operation that permits us to compare factors of length ℓ occurring in an infinite word. Indeed, if two finite words are ℓ-abelian equivalent, then their ℓ-block codings are abelian equivalent (but the converse does not hold).

Abelian complexity of block(p, 2)
We let x denote block(p, 2) = 12001212120012001200121212001212 · · · , the 2-block coding of p, introduced in Example 16. We consider in this section the abelian complexity of x and then, in Section 5, we compare P (1) x (n) with P (2) p (n). Definition 18. We will make use of functions related to the number of 0's in the factors of x of a given length. Let n ∈ N. We let max 0 (n) (resp. min 0 (n)) denote the maximum (resp. minimum) number of 0's in a factor of x of length n. Let ∆ 0 (n) = max 0 (n)−min 0 (n) be the difference between these two values.
Each of the ∆ 0 (n) + 1 integers in the interval [min 0 (n), max 0 (n)] is attained as the number of 0's in some factor of x of length n, since when we slide a window of length n along x from a factor with min 0 (n) zeros to a factor with max 0 (n) zeros, the number of 0's changes by at most 1 per step.
Proof. Suppose a factor w = w 1 · · · w 2n of x of even length 2n has an odd number n 0 of zeros. Since φ(0) = φ(1) = 12 and φ(2) = 00, the factor w starts or ends with 0. Without loss of generality, assume it starts with w 1 = 0. Then its last letter must be w 2n = 1. The words 0w 1 · · · w 2n−1 and w 2 · · · w 2n 2 are two factors of length 2n with respectively n 0 + 1 and n 0 − 1 zeros. Hence, these two factors have even numbers of zeros which are respectively greater than and less than n 0 . The conclusion follows.
We give two related proofs of the 2-regularity of the sequence P (1) x (n) n≥0 . The first uses the following proposition, which we prove in Section 4.1, together with the fact that ∆ 0 (n) n≥0 is 2-regular and the two sequences (∆ 0 (n) mod 2) n≥0 and (min 0 (n) mod 2) n≥0 are 2-automatic (see Section 4.2, Corollary 26). Then the 2-regularity of the sequence P (1) x (n) n≥0 will follow from Lemma 8.
Proposition 20. For n ∈ N, In the second proof, we prove in Section 4.3 the following theorem, which allows us to apply our general result expressed by Theorem 4.

Proof of Proposition 20
First we mention some properties of factors of the word x. Proof. It is easy to check that these five words are factors. To prove that they are the only ones, it is enough to check that for any element u in {00, 01, 12, 20, 21} the three factors of length 2 of φ(u) are in {00, 01, 12, 20, 21}.
Lemma 23. If w is a factor of x then |w| 1 − |w| 2 ≤ 1. In particular, the letters 1 and 2 alternate in the sequence obtained from x after erasing the 0's.
Proof. Let w be a factor of x. There are two cases to consider.
If w can be de-substituted (that is, If w cannot be de-substituted, then either w has even length and occurs at an odd index in x, or w has odd length. If w has odd length, then deleting either the first or last letter results in a word that can be de-substituted, so |w| 1 − |w| 2 ≤ 1. If w has even length and occurs at an odd index, then its first letter is 0 or 2 and its last letter is 0 or 1; deleting the first and last letters results in a word that can be de-substituted, so Finally, observe that if for all factors of a word u, the numbers of two letters x and y differ by at most 1, then x and y alternate in u. Lemma 24. Let τ be the morphism defined by τ : 0 → 0, 1 → 2, 2 → 1. If w is a factor of x, then τ (w) R is also a factor of x.
Proof. We first prove by induction that for every factor of the form 2u1 of x.
One checks that this is true for 21 and 2001. If 2u1 is a factor not equal to 21 nor 2001, then u must contain a 2 and we can write 2u1 = 2u ′ 12u ′′ 1 where 2u ′ 1 and 2u ′′ 1 are factors of x. By the induction hypothesis we have We now prove the lemma by induction on the length of w. One can check by hand that the lemma is true for w of length at most 15. Assume the lemma is true for every factor of length at most n ≥ 15, and let w be a factor of length n + 1. Then w is a factor of φ(v) for some factor v of x with n+1 2 ≤ |v| ≤ n+3 2 . Since all factors of length 4 contain a 1 and a 2, there exists a factor u such that v is a factor of 2u1 and |2u1| ≤ n+3 2 + 6. In particular, w is a factor of φ(2u1) and τ (w) R is a factor of τ (φ(2u1)) R . To obtain the conclusion, we just need to show that τ (φ(2u1)) R is a factor of x.
As by Lemma 22, a 2 is always preceded by a 1 in x, the word 12u is a factor of x and it has length |12u| ≤ n+3 2 + 6 ≤ n. By induction hypothesis, τ (12u) R is a factor of x. Hence φ(τ (12u) R ) is also a factor. Finally, using the previous result, τ (φ(2u1)) R = φ(τ (12u) R ) is a factor of x.
We can now express P (1) x in terms of ∆ 0 .
Proof of Proposition 20. Let w be a factor of x of length |w| = n.
There are ∆ 0 (n)+1 possible values for the number of 0's in a factor of length n. Since each value occurs for some factor, we have where c(n) depends only on the parities of ∆ 0 (n) and n − min 0 (n); computing four explicit values allows one to determine the values of c(n) and obtain the equation claimed for P (1) x (n).
In this section, we prove the following result.
Proposition 25. Let ℓ ≥ 2 and r such that 0 ≤ r < 2 ℓ . We have Moreover, Before giving the proof, we prove a corollary. The 2-regularity of P (1) x (n) n≥0 follows from Proposition 20 and Corollary 26.
Corollary 26. The following statements are true.
Proof. The first assertion is a direct consequence of Proposition 25 and Theorem 4. Note that one can obtain explicit relations satisfied by ∆ 0 (n) n≥0 from Example 7. The second assertion follows from Lemma 10.
For the last assertion, for i ∈ {0, . . . , 31} we prove that, modulo 2, By Lemma 19, we already know that min 0 (2n) ≡ ∆ 0 (2n) ≡ 0 (mod 2) for any n ∈ N. Hence the relations above are true for i even. We prove the other relations by induction on n. They are true for n = 0. Let n > 0 and assume the relations are satisfied for all n ′ such that 0 ≤ n ′ < n. We can write n = 2 ℓ + r with ℓ ≥ 0 and 0 ≤ r < 2 ℓ . Let i ∈ {1, . . . , 31} be odd.
for some j ∈ {0, . . . , 7} according to the relations. A similar reasoning holds for the ∆ 0 relations.
For the remaining cases, i, j ∈ {3, 13, 19, 29}. As min 0 and ∆ 0 satisfy the same recurrence relations, by the induction hypothesis, there exists k ∈ {1, 3, 5, 7} such that Observe that the value of 8 − k is the value given in the relation for i. This concludes the proof of the min 0 relations. A similar argument works for the ∆ 0 relations.
We break the proof of Proposition 25 into three parts, covered by Lemmas 27, 29 and 31. We first deal with powers of 2.
Since Parikh vectors of factors of length 2 ℓ can take exactly four values, the conclusion is immediate.
The result is true for ℓ ∈ {1, 2}. Let ℓ > 2 and assume the result holds for ℓ − 1. Let w be a factor of length 2 ℓ .
If w cannot be de-substituted, then w occurs at an odd index in x and w is of the form for some factor v of length 2 ℓ−1 . If w is of one of the first two forms, then Ψ(w) = Ψ(φ(v)) and Ψ(w) = P ℓ or Ψ(w) = P ℓ + (−2, 1, 1) (as in the previous case).
To show Lemmas 29 and 31, we first prove the following technical result.
Proof. For the first assertion, assume that |u| 2 = max 2 (n) and suppose that |φ(u)| 0 < max 0 (2n). Note that |φ(u)| 0 = 2|u| 2 by definition of φ. Let v be a factor of length 2n such that |v| 0 = max 0 (2n), which is even by Lemma 19. In addition, we can assume that v starts with 00. Indeed, if it is not the case, then either v starts with 01 and ends with 0, or v is of the form t00s where t does not contain any zero. In the first case, we can consider the word 0v0 −1 that starts with 00 and has max 0 (2n) zeros. In the second case, we can consider the word 00sw for some w with |w| = |t|. This factor has also max 0 (2n) zeros. Therefore v can be de-substituted. So v = φ(z) and |z| 2 = 1 2 |v| 0 > |u| 2 , which is a contradiction.
For the other direction, assume |φ(u)| 0 = max 0 (2n) and suppose |u| 2 does not maximize the number of 2's. Then there exists a factor v of length n such that |v| 2 = max 2 (n). Hence, which is a contradiction. Similar arguments hold for the second assertion.
Lemma 31 will follow directly from the following lemma.
Observe that u maximizes the number of 2's as |u| and |u| 0 = min 0 (2 ℓ ) are even. In addition, we can assume that v also maximizes the number of 2's. Indeed, if v is of even length, |v| 0 = min 0 (2 ℓ−1 + r/2) implies |v| 2 is maximal. If v is of odd length and v does not maximize the number of 2's, then it ends with 1. Thus, v is followed by a 2. In particular, v occurs at an even index in x. So is u and u12 or u00 is a factor of x. If u12 is a factor, then consider, instead of u, u ′ = z −1 u1 where z denotes the first letter of u. In that case, the prefix of length 2 ℓ−1 + r/2 of u ′ is z −1 v2. It still minimizes the number of 0's and now maximizes the number of 2's. Assume now that u00 is a factor. Observe that x is the fixed point of φ. So it is also the fixed point of φ 2 . Therefore, x is a concatenation of blocks of length 4 of the form φ 2 (0) = φ 2 (1) = 1200 and φ 2 (2) = 1212. Since u00 is a factor of x, the only extension of this factor is 12u00 as |u| = 2 ℓ ≡ 0 (mod 4). Consider then u ′ = 2u2 −1 .
For the construction of the factors, one can construct them using the factors φ(u) and φ(u ′ ) given for r − 1 and r + 1 in the previous construction. We consider the same two cases as before.
A similar construction yields a factor of length 2 ℓ+1 minimizing the number of 0's such that the prefix of length 2 ℓ + r also minimizes the number of 0's.
The previous lemma permits us to reformulate some relations between the two sequences max 0 (n) n≥0 and min 0 (n) n≥0 .
Since similar relations hold when exchanging min 0 and max 0 , the conclusion follows.
The proof of Proposition 25 about the reflection relation satisfied by ∆ 0 (n) and the recurrence relation of min 0 (n) is now immediate.
One can prove the following result in a manner similar to the proof of Theorem 4. There may be simpler recurrences, but these relations exhibit the same symmetry as in Theorem 4.
The relationship between these sequences and P (2) p and P (1) x is stated in the following result.
Proposition 34. Let n ≥ 1 be an integer. Then We require several preliminary results.
Proposition 35. Let u and v be factors of p of length n. Let u ′ and v ′ be the 2-block codings of u and v. The factors u and v are 2-abelian equivalent if and only if u ′ and v ′ are abelian equivalent and either u ′ and v ′ both start with 2 or none of them start with 2.
Proof. By Lemma 15, u and v are 2-abelian equivalent if and only if they start with the same letter and have the same number of factors 00, 01 and 10. The number of 00 (respectively 01 and 10) in u is exactly the number of 0 (resp. 1 and 2) in u ′ . Moreover, u starts with 0 (resp. by 1) if and only if u ′ starts with 0 or 1 (resp. by 2). Therefore, u and v are 2-abelian equivalent if and only if u ′ and v ′ are abelian equivalent and both start with 2 or none of them start with 2.
To compute P p , we will use the abelian complexity of x = block(p, 2), P x , and study when an abelian equivalence class of x splits into two 2-abelian equivalence classes of p, or in other words, study when two abelian equivalent factors of x can start, respectively, with 2 and with 0 or 1. If the class does not split, we say that it leads to only one class.
Lemma 36. Let X be an abelian equivalence class of factors of length n of x. If the number of 1's in an element of X differs from the number of 2's, then X leads to only one 2-abelian equivalence class of p.
Proof. It is enough to prove that if an element of X starts with 2, all the other elements of X start with 2. If u starts with 2, then all the elements of X have more 2's than 1's. But any factor with more 2's than 1's starts with a 2.
Corollary 37. If n is odd, P  Proof. Let X be an abelian equivalence class of factors of odd length n. If no element of X starts with a 2, X leads to only one 2-abelian equivalence class of factors of p. So assume that there is a factor u in X starting with 2. Since n is odd, we can write u = 2φ(u ′ ). Then the number of 0's in u is even and there is a different number of 2's than 1's. By Lemma 36, X again leads to a unique 2-abelian equivalence class of p.
Corollary 38. Let X be an abelian equivalence class of factors of x of even length n with an odd number of zeros. Then X leads to only one 2-abelian equivalence class of p.
Proof. Factors in X have an odd number of 1's and 2's counted together, so the number of 1's and the number of 2's are different and we can apply Lemma 36.
Thus, an abelian equivalence class X of factors of length n of x can possibly lead to two 2-abelian equivalence classes of factors of length n + 1 of p only if n is even and if there are an even number of zeros in X . In most cases X will indeed lead to two different equivalence classes. The exceptions are identified by the following lemma.
Lemma 39. Let n be a positive even integer and n 0 such that min 0 (n) ≤ n 0 ≤ max 0 (n). Let X be an abelian equivalence class of factors of x of length n with exactly n 0 zeros.
• We have n 0 = max 0 (n) and MJ 0 (n) = 1 if and only if every factor u in X can be written as u = 00u ′ 00.
• We have n 0 = min 0 (n) and mj 0 (n) = 1 if and only if every factor u in X is preceded and followed only by 00.
Proof. We start by proving the first part of the lemma. Assume that all the elements of X have the form 00u ′ 00. In particular, n 0 is even. If n 0 = max 0 (n), it means that there is a factor v of length n with n 0 + 1 zeros. Indeed, sliding a window of length n from a word of X to a factor with max 0 (n) zeros gives factors with all possibilities between n 0 and max 0 (n) for the number of zeros. Since |v| 0 is odd and n is even, we must have v = 0φ(v ′ )1 or v = 2φ(v ′ )0. But then 0 −1 v2 or 1v0 −1 is an element of X not of the form 00u ′ 00, a contradiction. Hence n 0 = max 0 (n). If MJ 0 (n) = 0, then max 0 (n − 1) = n 0 and there is a factor v of odd length n − 1 with even number n 0 of 0's. We must have v = 2φ(v ′ ) or v = φ(v ′ )1 but then 1v or v2 is an element of X not of the form 00u ′ 00, a contradiction and MJ 0 (n) = 1.
For the other direction, assume that n 0 = max 0 (n) and MJ 0 (n) = 1. In particular, max 0 (n − 1) = n 0 − 1. Assume there exists a factor u of X not of the form u = 00u ′ 00. Since u has even length and even number of 0's, we must have u = 01u ′ 20 or u has its first or last letter y not equal to 0. In the first case, v = 001u ′ has length n − 1 and n 0 zeros, a contradiction. In the second case, removing the letter y leads also to a factor of length n − 1 with n 0 zeros.
The second part of the lemma is similar. Assume first that all the elements of X are preceded and followed by 00. In particular, n 0 is even. If n 0 = min 0 (n), there is a factor v of length n with n 0 − 1 zeros. Since |v| 0 is odd but n is even, we must have v = 0φ(v ′ )1 or v = 2φ(v ′ )0 but then 0v1 −1 or 2 −1 v0 is an element of X that starts or ends with 00 and so is preceded or followed by 12, a contradiction. Hence we have n 0 = min 0 (n). If mj 0 (n) = 0, then min 0 (n + 1) = n 0 and there is a factor v of odd length n + 1 with even number n 0 of 0's. We must have v = 2φ(v ′ ) or v = φ(v ′ )1 but then φ(v ′ ) is an element of X without a 00 preceding or following it.
For the other direction, assume that n 0 = min 0 (n) and mj 0 (n) = 1. In particular min 0 (n + 1) = n 0 + 1. If there exists a factor u of X such that 1u, 2u, u1 or u2 is a factor, then min 0 (n + 1) ≤ n 0 , a contradiction. Hence all the factors u of X can only be extended by 0u0. Finally, note that u ∈ X cannot occur in x at odd index. In other words, any u ∈ X can be de-substituted. Indeed, if it is not the case, then u is of the form 0φ(u ′ )0, 0φ(u ′ )1, 2φ(u ′ )0 or 2φ(u ′ )1. If u is of the first form, then φ(u ′ )001 is a factor of length n + 1 with only n 0 zeros, which is a contradiction. Otherwise, u is of one of the last three forms. Then either u2 or 1u is a factor of x, which is not possible. So the only extension of u as a factor of x is 00u00.
Lemma 40. Let n be a positive even integer and n 0 even such that min 0 (n) ≤ n 0 ≤ max 0 (n). Let X be an abelian equivalence class of factors of x of length n with n 0 zeros. The class X leads to only one 2-abelian equivalence class of p if and only if n 0 = min 0 (n) and mj 0 (n) = 1 or n 0 = max 0 (n) and MJ 0 (n) = 1. Otherwise, X splits into two classes.
Hence let n ≥ 4 even. If n 0 = min 0 (n) and mj 0 (n) = 1, then by Lemma 39, all the elements of X are preceded by 00. In particular, they all start with 1 and X leads to only one 2-abelian equivalence class. Similarly, if n 0 = max 0 (n) and MJ 0 (n) = 1, then by Lemma 39, all the elements of X start with 0 and we have only one class.
Assume now that X leads to only one class. If an element u of X starts with 2, we have u = 2φ(u ′ )1 since n and n 0 are even. Then 1u1 −1 is an element of X starting with 1 and X splits into two classes. Hence every element u of X starts with 0 or 1. Assume there exists a factor u in X that starts with a 1. Then u = 12φ(u ′ ) and u cannot be followed by a 1 since otherwise 1 −1 u1 would be an element of X starting with 2. Hence u is always followed by 00 and so ends with 12. Similarly, it can only be preceded by 00. Hence all the factors in X starting with a 1 are preceded and followed by 00. In particular, if a factor in X starts with 1 and occurs in x at index i, then the two factors starting at indices i − 1 and i + 1 in x have n 0 + 1 zeros. Assume now there exists a factor u in X starting with a 0. Then, u can be de-substituted. Otherwise, as n and n 0 are even, u is of the form 0φ(u ′ )0 where φ(u ′ ) ends with 12. Thus 2φ(u ′ )2 −1 is an element of X starting with 2, which is a contradiction. Hence u starts with 00. If u ends with 12, then again, 2u2 −1 is an element of X starting with 2. Hence u = 00φ(u ′ )00 and all elements of X starting with 0 start and end with 00. In particular, if a factor in X starts with 0 and occurs in x at index i, then the two factors starting at indices i − 1 and i + 1 in x have n 0 − 1 zeros.
If no elements of X start with 1 or no elements start with 0, we are done by Lemma 39. Otherwise, since one can show that x is uniformly recurrent 3 , we can assume that there exist a factor u ∈ X that starts with 0 and occurs at index i in x, and a factor v ∈ X that starts with 1 and occurs at index i + ℓ in x, such that any factor w s of length n occurring at index i + s in x does not belong to X for 0 < s < ℓ. Then w 1 has n 0 − 1 zeros whereas w ℓ−1 has n 0 + 1 zeros. But there is no factor w s with n 0 zeros. This is a contradiction since the number of 0's changes by at most one between two factors of the same length starting at consecutive indexes.
Proof of Proposition 34. The case n odd is given by Corollary 37. Assume now that n is even. Then by Lemma 19, min 0 (n) and max 0 (n) are even, and therefore ∆ 0 (n) is even as well. Let X be an abelian equivalence class of factors of x of length n. Let n 0 be the number of 0's in the elements of X . There are exactly ∆ 0 (n) 2 odd values of n 0 and ∆ 0 (n) 2 + 1 even values. By Corollary 38, if n 0 is odd, X leads to one 2-abelian equivalence class of p. By Lemma 40, X splits into two classes except for n 0 = min 0 (n) if mj 0 (n) = 1 and for n 0 = max 0 (n) if MJ 0 (n) = 1. Hence there are in total ∆ 0 (n) 2 + 1 − MJ 0 (n) − mj 0 (n) cases where X leads to two 2-abelian equivalence classes of p instead of one and this is exactly the difference between P (2) p (n + 1) and P (1) x (n).

Abelian complexity of block(t, 2)
In this section, we turn our attention to the Thue-Morse word t. Let y denote block(t, 2) = 132120132012132120121320 · · · , the 2-block coding of t introduced in Example 17. Recall that y is a fixed point of the morphism ν defined by ν : 0 → 12, 1 → 13, 2 → 20, 3 → 21. The approach here is similar to that of the period-doubling word: we consider in this section the abelian complexity of y, and then we compare P For the Thue-Morse word, the appropriate statistic for factors of y is the total number of 1's and 2's (or, equivalently, the total number of 0's and 3's). We will show in Lemma 45 that the letters 1 and 2 alternate in y. Therefore, for n ∈ N we set max 12 (n) := max{|u| 1 + |u| 2 : u is a factor of y with |u| = n}, min 12 (n) := min{|u| 1 + |u| 2 : u is a factor of y with |u| = n}, ∆ 12 (n) := max 12 (n) − min 12 (n).
Remark 42. Note that g(y) is exactly the period-doubling word p, where g is the coding defined by g(0) = 1, g(1) = 0, g(2) = 0 and g(3) = 1. In particular, ∆ 12 (n) + 1 is the abelian complexity function of the period-doubling word. This function was also studied in [5,14]. Here we obtain relations of the same type as the relations in Theorem 4.
The fact that P (1) y (n) n≥0 is 2-regular will follow from the next statement.
Proposition 43. Let n ∈ N. We have To be able to apply the composition result given by Lemma 8 to the expression of P (1) y derived in Proposition 43, we have therefore to prove that • the sequence ∆ 12 (n) n≥0 is 2-regular and • the predicates occurring in (3) are 2-automatic. Section 6.1 is dedicated to the proof of Proposition 43. In Section 6.2, we give a proof of the two previous items. In particular, we show that ∆ 12 (n) n≥0 satisfies a reflection symmetry. This permits us to express recurrence relations for P (1) y at the end of Section 6.2.

Proof of Proposition 43
We first need three technical lemmas about factors of y = block(t, 2). Proof. It is easy to check that these six words are factors. To prove that they are the only ones, it is enough to check that for any element u in {01, 12, 13, 20, 21, 32} the three factors of length 2 of ν(u) are still in {01, 12, 13, 20, 21, 32}.
The following lemma has already been observed in [14,Lemma 10].
Proof. First note that if for all factors of a word u, the numbers of two letters x and y differ by at most 1, then x and y alternate in u. Furthermore, if the first or the last occurrence of one of these letters is x, then |u| x ≥ |u| y . If both the first and the last occurrences are x, then |u| x = |u| y + 1.
We prove the result by induction on the length ℓ of the factor. The result is true for factors of length ℓ = 1. Let w be a factor of length ℓ > 1 and assume the result holds for factors of length smaller than ℓ. If w can be de-substituted as w = ν(w ′ ), we have Using the induction hypothesis, we have If w cannot be de-substituted and has odd length, we have for some factor w ′ with |w ′ | < ℓ. Assume that w = 1 −1 ν(w ′ ). Then as before |w| 0 −|w| 3 = |w ′ | 1 − |w ′ | 2 ≤ 1. For the numbers of 1 and 2, w ′ starts with 0 or 1. Since by Lemma 44 a 0 is always followed by a 1, w ′ starts either with 01 or with 1. In both cases, since 1 and 2 alternate, we have |w ′ | 1 ≥ |w ′ | 2 and thus The same reasoning can be done for w = 2 −1 ν(w ′ ). If w = ν(w ′ )1, then we clearly have |w| 0 − |w| 3 ≤ 1 using the result on ν(w ′ ). By Lemma 44, the factor ν(w ′ ) must end either with 0 or 2. So w ′ ends with 0 or 2 as well. Since a 0 is always preceded by a 2, we necessarily have |w ′ | 2 ≥ |w ′ | 1 and The same reasoning applies to w = ν(w ′ )2.
If w cannot be de-substituted and has even length, then we have for some factor w ′ with |w ′ | < ℓ. If the same letter is removed and added to ν(w ′ ), then the result is clearly true. Otherwise, assume that w = 1 −1 ν(w ′ )2 (the same reasoning holds for the last case). It is clear that |w| 0 − |w| 3 ≤ 1 using the result on ν(w ′ ). For the numbers of 1 and 2, as before, w ′ starts with 01 or 1 and ends with 13 or 1. Hence we have |w ′ | 1 = |w ′ | 2 + 1 and then Lemma 46. Let τ, τ ′ be the morphisms respectively defined by τ : and τ ′ : If w is a factor of y, then τ ′ (w) R , τ (w) R and τ ′ (τ (w)) are also factors of y.
We now prove the lemma (for τ and τ ′ together) by induction on the length of w. One can check by hand that the lemma is true for w of length at most 4. Assume the lemma is true for any factor of length at most n ≥ 4, and let w be a factor of length n + 1. There exist some factors s, t and v such that swt = ν(v), 0 ≤ |t| ≤ 1 and 1 ≤ |s| ≤ 2. Then we have |v| ≤ n+4 2 ≤ n. By the induction hypothesis, τ (v) R is a factor of y. Hence ν(τ (v) R ) is also a factor of y. Using the previous result, τ ′ (ν(v)) R = a −1 ν(τ (v) R )b for some letters a and b. But we also have τ ′ (ν(v)) R = τ ′ (t) R τ ′ (w) R τ ′ (s) R and since s has at least one letter, τ ′ (w) R is a factor of ν(τ (v) R ). Hence it is a factor of y. We do the same proof for τ (w) R .
We are now ready to prove the relationship between P (1) y (n) and ∆ 12 (n).
Proposition 47. Let ℓ ≥ 1 and r such that 0 ≤ r < 2 ℓ . We have Moreover, Note that those latter relations have a form similar to (but slightly different from) the assumptions of Theorem 4. Before giving the proof, we prove a corollary. The 2-regularity of P (1) y (n) n≥0 follows from Proposition 43 and Corollary 48. Corollary 48. The following statements are true.
Proof. The first assertion is a direct consequence of Proposition 47 and Theorem 4. The second assertion follows from Lemma 10.
To prove the last assertion, we prove by induction that, modulo 2, The relations are true for n = 0. Let n > 0 and assume they are true for n ′ < n. We can write n = 2 ℓ + r with ℓ ≥ 0 and 0 ≤ r < 2 ℓ . Let i ∈ {0, . . . , 15}. We consider two cases.
A similar reasoning works for the ∆ 12 relations.
Proposition 47 is a direct consequence of Lemmas 49, 52 and 54 given in this section.
To prove the second assertion of the lemma, observe that min 12 (2 ℓ ) = A ℓ if ℓ is odd and min 12 (2 ℓ ) = B ℓ if ℓ is even. Furthermore, A ℓ is always odd whereas B ℓ is always even.
In order to prove Lemmas 52 and 54, we first need some technical results.
The second part of the lemma is similar.
Proof. Let u be a factor of even length n + 1 minimizing the number of 1's and 2's. Then either u starts with 1 or 2, or ends with 1 or 2. Indeed, if u can be de-substituted, then it starts with 1 or 2. Otherwise, its last letter is the beginning of an image of ν and thus is 1 or 2. Removing this letter, we get a word of length n with min 12 (n + 1) − 1 ones and twos. Since the function min 12 increases by 0 or 1 from n to n + 1, we have min 12 (n) = min 12 (n + 1) − 1.
For the second equality, consider a factor u of even length n − 1 with max 12 (n − 1) ones and twos. There exist two letters a and b such that aub is a factor. Then, as before, since aub has even length, a or b must be a 1 or a 2. Then au or ub is a factor of length n with max 12 (n − 1) + 1 ones and twos and we conclude as before.
Proof. We prove the two results together by induction on ℓ. One checks the case ℓ = 1. Let ℓ > 1 and assume the result is true for ℓ − 1. Let r such that 0 ≤ r ≤ 2 ℓ−1 .
For the min 12 equality, a similar argument holds (using the previous result for r + 1).
Moreover, there is a factor of length 2 ℓ+1 maximizing (resp. minimizing) the number of 1's and 2's such that the prefix of length 2 ℓ + r also maximizes (resp. minimizes) the number of 1's and 2's.
For the construction of the factors, one can construct them using the factor ν(u) maximizing the number of 1's and 2's given for r − 1 and the factor ν(u ′ ) minimizing the number of 1's and 2's given for r + 1 in the previous construction. Since r is odd, the letter between the prefix ν(v) of length 2 ℓ + r − 1 and 2 ℓ + r of ν(u) is 1 or 2. Since the prefix of length 2 ℓ + r − 1 of ν(u) maximizes the number of 1's and 2's, so does the prefix of length 2 ℓ + r of ν(u). For min 12 , consider ν(u ′ ). There exist letters a and b such that w = a −1 ν(u ′ )b is still a factor. We must have a, b ∈ {1, 2}. Then the prefix of length 2 ℓ + r of w minimizes the number of 1's and 2's.
The previous lemma permits us to reformulate some relations between the two sequences max 12 (n) n≥0 and min 12 (n) n≥0 .
Similar relations hold when changing max 12 to min 12 .
The proof of Proposition 47 about the reflection relation satisfied by ∆ 12 (n) and the recurrence relation of min 12 (n) is now immediate.
Using Propositions 43 and 47, we can express recurrence relations for P (1) y as we did for the proof of Theorem 21.
For n even, we have if ∆ 12 (n) is odd.
As in Section 5, we study when an abelian equivalence class of y = block(t, 2) splits into two 2-abelian equivalence classes of t. We have similar propositions. Let X be an abelian equivalence class of factors of y of length n. For a letter a, let n a denote the number of a's in each element of X and let n 12 = n 1 + n 2 , n 03 = n 0 + n 3 .
Lemma 58. If n 12 is odd, then X leads to a unique 2-abelian equivalence class of t.
Proof. Assume that n 1 > n 2 (the other case is similar). Then a word of X cannot start with 2 since the letters 1 and 2 alternate in y by Lemma 45. It cannot start with 3 neither since n 1 > n 2 and a 3 is always followed by 2 by Lemma 44. Hence it starts with 0 or 1. Thus X leads to a unique 2-abelian equivalence class.
Lemma 59. If n and n 12 are even, then X splits into two 2-abelian equivalence classes of t.
Proof. If n and n 12 are even, then n 03 is also even and thus n 1 = n 2 and n 0 = n 3 . Let u be an element of X . Then u ′ = τ ′ (τ (u)) is also an element of X . Moreover, the first letter of u is in {0, 1} if and only if the first letter of u ′ is in {2, 3}. Hence X splits into two 2-abelian equivalence classes.
So the last and hardest case happens when n is odd and n 12 is even, i.e., when n and n 03 are odd. The MJ 03 and mj 03 functions permit us to handle this case.
• We have n 03 = max 03 (n) and MJ 03 (n) = 1 if and only if every factor in X starts and ends with a.
• We have n 03 = min 03 (n) and mj 03 (n) = 1 if and only if every factor in X is preceded and followed by b.
Proof. Assume that a = 0 and b = 3 (the other case is symmetric). We first prove the statement for the maximum. Assume that all the factors in X start and end with 0. If n 03 < max 03 (n), by continuity of the number of 0's and 3's and since y is uniformly recurrent, there exists a factor yuz such that the factor yu (resp. uz) is of length n with n 03 (resp. n 03 + 1) zeros and threes. We necessarily have z ∈ {0, 3} and u is not finishing with a letter in {0, 3}. Since yu has n 03 zeros and threes, yu or τ ′ (yu) R is an element of X that is either not finishing or not starting with 0, a contradiction. Hence we have n 03 = max 03 (n). Assume now that max 03 (n − 1) = n 03 . There exists a factor u of even length n − 1 with n 03 zeros. Without loss of generality, we can assume that u has more 0's than 3's (otherwise one can consider τ ′ (u) R by Lemma 46). Since u has even length, either u occurs at an even index in y and is always followed by 1 or 2, or u occurs at an odd index in y and is always preceded by 1 or 2. In other words, there is a factor of the form yu or uy with y ∈ {1, 2}. Then yu or uy is an element of X with the first or last letter different from 0, a contradiction. For the other direction, assume that n 03 = max 03 (n) and MJ 03 (n) = 1. Let u be a factor in X . If u = xu ′ or u = u ′ x with x = 0, then u ′ has length n − 1 and n 03 zeros and threes. Thus MJ 03 (n) = 0, a contradiction.
The second statement is proved in the same way. Assume that all the factors in X are preceded and followed by 3. If n 03 > min 03 (n), by continuity of the number of 0's and 3's and since y is uniformly recurrent, there exists a factor yuz such that the factor yu (resp. uz) is of length n with n 03 (resp. n 03 − 1) zeros and threes. We necessarily have z ∈ {1, 2}. Then as before yu or τ ′ (yu) R is and element of X that is either not always followed or not always preceded by 3, a contradiction. Hence we have n 03 = min 03 (n). Assume now that min 03 (n + 1) = n 03 . There exists a factor u of even length n + 1 with n 03 zeros. Without loss of generality, we can assume that u has more 0's than 3's (otherwise one can consider τ ′ (u) R by Lemma 46). Since u has even length, either u occurs at an even index and starts with 1 or 2 or u occurs at an odd index and ends with 1 or 2. In other words, u = yu ′ or u = u ′ y with y ∈ {1, 2} and u ′ is an element of X preceded or followed by a letter different from 3, a contradiction.
For the other direction, assume that n 03 = min 03 (n) and mj 03 (n) = 1. Let u be a factor in X . If u ′ = ux or u ′ = xu is a factor with x ∈ {1, 2}, then u ′ has length n + 1 and n 03 zeros and threes. So mj 03 (n) = 0, which is a contradiction. Observe also that it is impossible to have 0u or u0 as factors of y since |u| 0 > |u| 3 by assumption and the letters 0 and 3 alternate in y by Lemma 45. The conclusion is immediate.
Lemma 61. If n is odd and n 12 is even, then X leads to only one 2-abelian equivalence class of t if and only if n 03 = min 03 (n) and mj 03 (n) = 1, or n 03 = max 03 (n) and MJ 03 (n) = 1. Otherwise, X splits into two classes.
Proof. If n is odd and n 12 is even, then n 03 is even. Assume that n 0 > n 3 (the other case is symmetric). If n 03 = min 03 (n) and mj 03 (n) = 1 then, by Lemma 60, all the factors in X start with 0, and so X leads to only one class. If n 03 = max 03 (n) and MJ 03 (n) = 1, then all the factors in X are preceded and followed by 3. In particular, they all start with 2 and again X leads to only one class.
For the other direction, suppose that X leads to only one class. All the factors in X must start either with a letter in {0, 1} or with a letter in {2, 3}. Assume first that all the elements of X start with 0 or 1. Let u be a factor in X . If the first letter of u is 1, it must start with 120 since u has more 0's than 3's. Thus u is always preceded by 2. It cannot end with 1 (since n 1 = n 2 ). So it must end with 0 or 2. If u = 120u ′ 2, then 2120u ′ is an element of X starting with 2, which is a contradiction. If u = 120u ′ 0 then u1 is a factor of y. So 20u ′ 01 is an element of X starting with 2, a contradiction. Hence u cannot start with 1 and thus starts with 0. Observe that, if u does not end with 0, then τ (u) R is still an element of X by Lemma 46 and τ (u) R does not start with 0, a contradiction. Hence all the factors in X start and end with 0. By Lemma 60, we have n 03 = max 03 (n) and MJ 03 (n) = 1.
Assume now that all the elements of X start with 2 or 3. Since n 0 > n 3 , they all start with 2. Moreover, as n 1 = n 2 , they must end with 0 or 1. If u ∈ X ends with 0, then τ ′ (u) R ∈ X starts with 3 by Lemma 46, a contradiction. So all factors in X end with 1. Let u = 2u ′ 1 be an element of X . By Lemma 44, the only possible extensions of u as a factor of length n + 1 of y are 1u, 3u, u2 and u3. If 1u is a factor of y, then 12u ′ ∈ X starts with 1, which is a contradiction. If u2 is factor of y, then τ (u ′ 12) R ∈ X starts with 1, a contradiction. Hence all the factors in X are preceded and followed by 3 in y. By Lemma 60, this means that n 03 = min 03 (n) and mj 03 (n) = 1.
We are now ready to prove Theorem 56.
Proof of Theorem 56. The difference between P (2) t (n + 1) and P (1) y (n) is the number of abelian equivalence classes of factors of length n of y that split into two 2-abelian equivalence classes of factors of length n + 1 of t.
Indeed, consider for example the case that min 12 (n) and ∆ 12 (n) are even. First, there are ∆ 12 (n) 2 + 1 even values of n 12 . Second, since min 12 (n) is even and n is odd, we have max 03 (n) = n − min 12 (n) odd. Since ∆ 12 (n) is even, max 12 (n) is also even and min 03 (n) is odd.
As another example, consider the case that min 12 (n) and ∆ 12 (n) are odd. Then max 03 (n) is even and min 03 (n) is odd. There are ∆ 12 (n)+1 2 even values of n 12 . We cannot have n 03 = max 03 (n) (for parity reasons) and thus we never have n 03 = max 03 (n) and MJ 03 (n) = 1. But the case n 03 = min 03 (n) happens and thus we have to remove one case when mj 03 (n) = 1.
Finally, observe that to each pair (n, n 12 ), with n odd and n 12 even, correspond two abelian equivalence classes of y (see the proof of Proposition 43). Each of these classes splits into two 2-abelian equivalence classes. Hence multiplying by 2 the number of pairs (n, n 12 ), with n odd and n 12 even, gives the result claimed for n odd.

Conclusions
The two examples treated in this paper, namely the 2-abelian complexity of the perioddoubling word and the Thue-Morse word, suggest that a general framework to study the ℓ-abelian complexity of k-automatic sequences may exist. As an example, we consider the 3-block coding of the period-doubling word, z = block(p, 3) = 240125252401240124 · · · .
The abelian complexity P   Then, the next step would be to relate P