P. Dömösi, Sz. Iván (Eds.): Automata and Formal Languages. AFL 2011, Debrecen, Hungary, August 17–22, 2011. Proceedings, pages 93 – 107
On Operations Preserving Primitivity of Partial Words with One Hole∗ F. Blanchet-Sadri1 1
2
Sarah Nelson2
Amelia Tebbe3
Department of Computer Science, University of North Carolina P.O. Box 26170, Greensboro, NC 27402–6170, USA
[email protected]
Department of Mathematics, Bryn Mawr College, Park Science Building 101 North Merion Avenue, Bryn Mawr, PA 19010–2899, USA 3
Department of Mathematics University of Illinois at Urbana-Champaign 1409 W. Green Street, Urbana, IL 61801, USA
Abstract The notion of a primitive word, one that is not a power of another word, is useful in many areas including coding theory, combinatorics on words, formal language theory, and text algorithms. The proportion of such words turns out to be very high. We investigate operations that preserve the primitivity of partial words with one hole, or words that have an undefined position. As a result, all primitive binary partial words with one hole of length up to 11 can be generated.
1 Introduction The fundamental concept of primitive words plays an important role in several research areas related to codes [2], combinatorics on words [7, 12], formal languages [10, 14], and text algorithms [8]; a word is primitive if it cannot be written as a power of another word. Since the proportion of words that are primitive is very high, it is expected that various operations do preserve primitivity. Some ∗
This material is based upon work supported by the National Science Foundation under Grant No. DMS–0754154. The Department of Defense is gratefully acknowledged.
93
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
have been investigated such as substituting a letter for another one [11,15], inserting or deleting letters [15], applying morphisms [13, 15], and taking prefixes [15]. In [9], Dassow et al. consider the word ww′ , where w is a given primitive word and w′ is a modified copy of w or a modified mirror image of w so that the edit distance of w and w′ is very small (at most 2) or very large (almost the length of w), and study whether ww′ is primitive. As a result of their study, which is motivated in particular by dynamical systems, all primitive binary words of length at most 11 can be generated as well as a large number with length up to 20. Motivated by a practical problem on gene comparison, Berstel and Boasson introduced the notion of partial words, which are sequences that may have some holes, or undefined positions, that match every letter of the alphabet [1]. (Full) words are just partial words without holes. Primitive partial words were introduced in [3]; a partial word is primitive if it is not contained in a non-trivial power of a full word, that is, if there is no way of filling in the holes with letters of the alphabet that produces a word that is not primitive. Testing whether or not a partial word is primitive can be done in linear time in the length of the word [5]. Moreover in [6], the problem of counting primitive partial words with h holes of length n over a k-letter alphabet was initiated based on a constructive method related to the well-known periodicity result of Fine and Wilf. In this paper, we investigate operations that preserve primitivity of partial words with one hole. Here, if we begin with a partial word w, having some properties, we can produce primitive partial words which have w as a prefix. Generally, we make various changes to w to create w′ ; the concatenation ww′ ends up being primitive. Using our operations, which extend those of Dassow et al., we can generate all primitive binary partial words with one hole of length up to and including 11, as well as a large number of primitive binary partial words with one hole of length from 12 to 21. Since this is an extended abstract, most of the proofs are omitted due to page restriction.
2
Preliminaries
A partial word of length n over an alphabet A can be defined by a function u : {0, . . . , n − 1} → A⋄ , where A⋄ = A ∪ {⋄}. For 0 ≤ i < n, if u(i) ∈ A, then i ∈ D(u); if u(i) = ⋄, then i ∈ H(u). We treat the ⋄’s, called holes, like wild cards that match any letter of A. A (full) word is a partial word without holes. The set of all words over A (resp., of length n) is denoted by A∗ (resp., An ). For any partial word u, |u| denotes its length. A partial word v is a factor of the partial word u if there exist x, y such that u = xvy. The empty word is denoted by ε. If x = ε, then v is a prefix of u; if y = ε, v is a suffix of u. The notation u[i..j) (resp., u[i..j]) refers to the factor u(i) · · · u(j − 1) (resp., u(i) · · · u(j)). We write rev(u) for the reversal of the partial word u. 94
On Operations Preserving Primitivity of Partial Words with One Hole
If u and v are two partial words of equal length, then u is contained in v, denoted u ⊂ v, if u(i) = v(i) for all i ∈ D(u); u and v are compatible, denoted u ↑ v, if there exists a partial word w such that u ⊂ w and v ⊂ w. A partial word u is primitive if there is no v such that u ⊂ v p with p ≥ 2. The following lemmas are useful throughout the paper. Lemma 1. Let w be a partial word. If, for all words u such that w ⊂ u, u is primitive, then w is primitive. Lemma 2. Let w, w′ be partial words. If, for all words u, u′ such that w ⊂ u and w′ ⊂ u′ , uu′ is primitive, then ww′ is primitive. Lemma 3. [ [4], p. 188] Let u, v be non-empty words, let y, z be partial words, and let w be a partial word with one hole satisfying |w| ≥ |u| + |v|. If wy ⊂ up and wz ⊂ v q (resp., yw ⊂ up and zw ⊂ v q ), for some integers p, q, then there exists a word x of length not greater than gcd(|u| , |v|) such that u = xk and v = xl for some integers k, l. Lemma 4. [ [4], p. 189] Let u, v be partial words. If there exists a primitive word x such that uv ⊂ xp for some positive integer p, then a primitive word y exists such that vu ⊂ y p . Moreover, if uv is primitive, then so is vu.
3 Generating Primitive Words of Even Length In this section, we examine operations which produce primitive partial words of even length. First, we deal with operations on the first, middle, and/or last letter. Theorems 9 and 18 of [9] investigate the primitivity of ww′ , where w′ is defined by a substitution operation on the first, middle, and last letter of w. We extend them to partial words using a similar proof. Theorem 1. Let n ≥ 5 be odd, let w = a0 a1 · · · an−1 be a primitive partial word of length n, and let h : A → A be a mapping such that h(a) 6= a for all a ∈ A. ′ Set i = n−1 2 , w1 = a1 · · · ai−1 and w2 = ai+1 · · · an−2 . Then ww is primitive if one of the following statements holds: 1. 0, . . . , i, n − 1 ∈ D(w) and w′ = h(a0 )w1 h(ai )w2 h(an−1 ); 2. 0, i, . . . , n − 1 ∈ D(w) and w′ = h(a0 )w1 h(ai )w2 h(an−1 ); 3. 0, i, . . . , n − 1 ∈ D(w) and w′ = h(an−1 )rev(w2 )h(ai )rev(w1 )h(a0 ); 4. 0, . . . , i, n − 1 ∈ D(w) and w′ = h(an−1 )rev(w2 )h(ai )rev(w1 )h(a0 ); 5. 0, . . . , i, n − 1 ∈ D(w) and w′ = h(a0 )w1 h(ai )w2 an−1 ; 95
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
6. 0, i, . . . , n − 1 ∈ D(w) and w′ = h(a0 )w1 h(ai )w2 an−1 ; 7. 0, . . . , i, n − 1 ∈ D(w) and w′ = a0 w1 h(ai )w2 h(an−1 ); 8. 0, i, . . . , n − 1 ∈ D(w) and w′ = a0 w1 h(ai )w2 h(an−1 ). We now construct w′ by changing the first and last letters of a partial word with one hole, w, and by substituting a letter for the hole in w. Theorem 2. Let n ≥ 4, let w = a0 a1 · · · an−1 be a partial word of length n with one hole at position i, where 0 < i < n − 1, and h : A → A be a mapping such that h(a) 6= a for all a ∈ A. Then ww′ is primitive if w′ = h(a0 )a1 · · · ai−1 bai+1 · · · an−2 h(an−1 ), for some b ∈ A. Proof. Suppose there exist a word v and an integer p ≥ 2 such that ww′ ⊂ v p . If p p p is even, then w ⊂ v 2 and w′ ⊂ v 2 ; but w 6↑ w′ , a contradiction. So p is odd, and set p = 2m + 1 for some m ≥ 1. The length of v is even, so let v = v1 v2 where |v1 | = |v2 |. We have w ⊂ v m v1 and w′ ⊂ v2 v m . Since a0 is the first letter of v and an−1 is the last letter of w, a0 is the first letter of v1 and an−1 is the last letter of v1 . Likewise, h(a0 ) is the first letter of v2 and h(an−1 ) is the last letter of v2 . Set v1 = a0 v1′ an−1 and v2 = h(a0 )v2′ h(an−1 ). First, suppose |v1 | = |v2 | = 1, so a0 = an−1 and h(a0 ) = h(an−1 ). By substitution, w ⊂ (a0 h(a0 ))m a0 and w′ ⊂ h(a0 )(a0 h(a0 ))m . Since |w| ≥ 4, w ⊂ (a0 h(a0 ))m−1 a0 h(a0 )a0 and w′ ⊂ h(a0 )a0 h(a0 )(a0 h(a0 ))m−1 . If i = 1, the third letter of w is a0 and the third letter of w′ is h(a0 ), but a0 6= h(a0 ). If i ≥ 2, the second letter of w is h(a0 ) and the second letter of w′ is a0 , but a0 6= h(a0 ). Now, suppose |v1 | = |v2 | ≥ 2. We have w ⊂ (a0 v1′ an−1 h(a0 )v2′ h(an−1 ))m a0 v1′ an−1 w′ ⊂ h(a0 )v2′ h(an−1 )(a0 v1′ an−1 h(a0 )v2′ h(an−1 ))m Assume |v1 | ≤ i < n − 1 (that is, the hole is not in the prefix of length |v1 | of w). Since |a0 v1′ an−1 | = |h(a0 )v2′ h(an−1 )|, the last letter of each segment coincide. So an−1 = h(an−1 ), a contradiction. Finally, assume 0 ≤ i < |v1 | (that is, the hole is in the prefix of length |v1 | of w but not in the suffix of length |v1 | of w). Since |a0 v1′ an−1 | = |h(a0 )v2′ h(an−1 )|, the first letter of each segment coincide. So a0 = h(a0 ), a contradiction. Theorem 3 does reversal and substitution on a word w of odd length with one hole to create w′ . After reversing w, we replace the hole with a letter and substitute for the middle letter to build a primitive word, ww′ . 96
On Operations Preserving Primitivity of Partial Words with One Hole
Theorem 3. Let n ≥ 5 be odd, let w = a0 a1 · · · an−1 be a partial word of length n with one hole at position j, and let h : A → A be a mapping such that ′ h(a) 6= a for all a ∈ A. Set i = n−1 2 . Then ww is primitive if one of the following statements holds, where b ∈ A: 1. 0 < j < i and w′ = an−1 · · · ai+1 h(ai )ai−1 · · · aj+1 baj−1 · · · a0 ; 2. i < j < n − 1 and w′ = an−1 · · · aj+1 baj−1 · · · ai+1 h(ai )ai−1 · · · a0 ; 3. 0 < j < i and w′ = an−1 · · · ai+1 h(ai )ai−1 · · · aj+1 ⋄aj−1 · · · a0 ; 4. i < j < n − 1 and w′ = an−1 · · · aj+1 ⋄aj−1 · · · ai+1 h(ai )ai−1 · · · a0 . Proof. For Statement 1, suppose there exist a word v and integer p ≥ 2 such that ww′ ⊂ v p . If p is even, then w ⊂ v p/2 and w′ ⊂ v p/2 . However, since h(ai ) 6= ai , it follows that w 6↑ w′ , a contradiction. Thus, p is odd and p ≥ 3, and |v| is even. Let p = 2m + 1 for some m ≥ 1, and set v = v1 v2 , where |v1 | = |v2 |. We have w ⊂ v m v1 = (v1 v2 )m v1 and w′ ⊂ v2 v m = v2 (v1 v2 )m . Since i is the middle position of w and |w| = (2m + 1)|v1 | is odd, it follows that |v1 | is odd and i = m|v1 | + |v12|−1 . In other words, i is the middle position of some v1 or some v2 . If i corresponds to the middle position in some v1 with respect to w, then it corresponds to the middle position in some v2 with respect to w′ , and vice versa. Because w(i) = ai 6= h(ai ) = w′ (i), the letters in the middle positions of v1 and v2 are distinct. Since w ⊂ (v1 v2 )m v1 and j < i, the suffix of length |v1 | of w is v1 . Also, since m ≥ 1, i < n − |v1 |. Because w′ ⊂ v2 (v1 v2 )m , the prefix of length |v2 | of w′ is v2 , and so v1 = rev(v2 ). However, we have a contradiction since the middle positions of v1 and v2 have different letters. Second, we deal with operations involving the first two and last two letters of a word w with one hole. Theorem 4. Let n ≥ 6, let w = a0 a1 · · · an−1 be a partial word of length n with one hole at position i, 0 < i < n − 1, and let h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a for all a ∈ A. Then ww′ is primitive if one of the following statements holds for some b ∈ A: 1. w′ = h(a0 a1 )a2 · · · ai−1 bai+1 · · · an−3 h(an−2 an−1 ); 2. w′ = h(a0 a1 )a2 · · · ai−1 bai+1 · · · an−1 ; 3. w′ = a0 · · · ai−1 bai+1 · · · an−3 h(an−2 an−1 ); 4. w′ = a0 a1 h(a2 · · · ai−1 bai+1 · · · an−3 )an−2 an−1 . 97
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
Theorem 5. Let n ≥ 3, let w be a primitive partial word of length n with one hole at position 1. If w′ = w[2..n), then ww′ is primitive. Proof. Set w = a0 ⋄a2 · · · an−1 , and suppose there exist v and p ≥ 2 such that ww′ ⊂ v p . Note that w being primitive implies |v| ≥ 2 and ww′ = a0 ⋄w′ w′ . Consider the case where w(0) = a0 6= an−1 = w(n − 1) (the other case is similar). If |v| = 2, then v = a0 an−1 because the last letter of w′ is equal to the last letter of w. Moreover, if |w| is even, then w is contained in a non-trivial power ′ of v which contradicts w being primitive, while if |w| is odd then w ⊂ v p a0 for some p′ , which contradicts w(0) 6= w(n − 1). Thus, |v| ≥ 3. Suppose p is even, in other words, p = 2m, for some m ≥ 1. Since ww′ ⊂ v 2m , w[0..n − 1) = a0 ⋄a2 · · · an−2 ⊂ v m and an−1 w′ ⊂ v m . It follows that a0 = an−1 , a contradiction. Thus, p is odd, or p = 2m + 1 for some m ≥ 1. Since the first letter of ww′ is a0 and the last letter of ww′ is an−1 , set v = a0 v1 v2 an−1 , where |v1 | = |v2 | + 2, w ⊂ (a0 v1 v2 an−1 )m a0 v1 and w′ = v2 an−1 (a0 v1 v2 an−1 )m . Since m ≥ 1, the suffix of length |v1 | of w is full, and it follows that the last letter of v1 is an−1 . Setting v1 = v1′ an−1 , for some v1′ , w ⊂ (a0 v1′ an−1 v2 an−1 )m a0 v1′ an−1 and w′ = v2 an−1 (a0 v1′ an−1 v2 an−1 )m . Since w′ = w[2..n) and |v1′ an−1 | = |an−1 v2 an−1 |, we get v1′ an−1 = an−1 v2 an−1 . We find w ⊂ a0 an−1 v2 an−1 v2 an−1 (a0 an−1 v2 an−1 v2 an−1 )m−1 a0 an−1 v2 an−1 w′ = v2 an−1 (a0 an−1 v2 an−1 v2 an−1 )m−1 a0 an−1 v2 an−1 v2 an−1 Since w′ = w[2..n), w′ [|v2 an−1 |..n − 2 − |v2 an−1 |) = w[2 + |v2 an−1 |..n − |v2 an−1 |) and (a0 an−1 (v2 an−1 )2 )m−1 a0 an−1 v2 an−1 = v2 an−1 (a0 an−1 (v2 an−1 )2 )m−1 a0 an−1 Now, v2 an−1 a0 an−1 = a0 an−1 v2 an−1 , and so there exists a word z such that v2 an−1 and a0 an−1 are powers of z. By substitution, w is contained in a power of z, which contradicts the fact that w is primitive. Third, we deal with operations including a morphism on most letters. Theorem 6. Let n ≥ 4, let w = a0 a1 · · · an−1 be a word of length n with one hole at position i, where a0 , an−1 are distinct letters of A, and h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a for all a ∈ A. Then ww′ is primitive if one of the following statements holds, where b ∈ A: 1. w′ = a0 h(a1 · · · ai−1 bai+1 · · · an−2 )an−1 ; 2. h(h(a)) = a, for all a ∈ A, w′ = an−1 h(an−2 · · · ai+1 bai−1 · · · a1 )a0 . 98
On Operations Preserving Primitivity of Partial Words with One Hole
Proof. For Statement 1, suppose a word v and integer p ≥ 2 exist such that p p ww′ ⊂ v p . If p is even, then w ⊂ v 2 and w′ ⊂ v 2 . But w 6↑ w′ , a contradiction. So suppose p is odd, and set p = 2m + 1 for some m ≥ 1. The length of v being even, let v1 , v2 be two words such that v = v1 v2 , |v1 | = |v2 |, w ⊂ v m v1 and w′ ⊂ v2 v m . Since a0 is the first letter of w and an−1 is the last letter of w, a0 is the first letter of v1 and an−1 is the last letter of v1 . Likewise a0 is the first letter of v2 and an−1 is the last letter of v2 . Suppose |v1 | = 1, so a0 = an−1 , a contradiction. So suppose |v1 | ≥ 2, and set v1 = a0 v1′ an−1 , v2 = a0 v2′ an−1 , for some v1′ , v2′ . We get w ⊂ (a0 v1′ an−1 a0 v2′ an−1 )m a0 v1′ an−1 w′ ⊂ a0 v2′ an−1 (a0 v1′ an−1 a0 v2′ an−1 )m Assume |v1 | ≤ i < n − 1. Since |a0 v1′ | = |a0 v2′ | = l for some l ∈ [1..n − 1), the letter in position l of w and the letter in position l of w′ are both an−1 . But since 1 ≤ l < n − 1, al 6= h(al ), a contradiction. A similar argument holds when 0 < i < |v1 |. Theorems 23 and 24 of [9] explore the primitivity of ww′ , where w′ is built by applying a morphism on w excluding only the first or last letter, then reversing this sequence. We extend them to one-hole words. Theorem 7. Let n ≥ 2, let w = a0 · · · an−1 be a primitive partial word of length n with one hole at position i, 0 < i < n − 1, and let h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a for all a ∈ A. If w′ = an−1 h(an−2 · · · ai+1 bai−1 · · · a0 ) or w′ = h(an−1 · · · ai+1 bai−1 · · · a1 )a0 , where b ∈ A, then ww′ is primitive. Fourth, we deal with powers of two. The results are different from any of our previous results; instead of changing specific letters of w to create w′ , we instead change a certain number of letters of w. To prove Theorem 9, the following useful result involves the Hamming distance, d(w, w′ ), between two words w and w′ , or the number of positions i such that w(i) 6= w′ (i). It extends Theorems 7 and 19 of [9] in terms of full words, using a similar proof, which shows that w being primitive is not a necessary condition. Theorem 8. Let w, w′ be words of length n. 1. If d(w, w′ ) is a power of 2, then ww′ is primitive; 2. If n − d(w, w′ ) is a power of 2, then ww′ is primitive. We extend Theorem 8 to partial words. 99
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
Theorem 9. Let w be a partial word with one hole of length n. 1. If w′ is a full word of length n such that there is exactly one defined position i of w such that w(i) 6= w′ (i), then ww′ is primitive; 2. If n = 2q , for some q ≥ 0, and w′ is a full word of length n such that, for every i ∈ D(w), w(i) 6= w′ (i), then ww′ is primitive. Proof. For Statement 2, let w be a word with one hole at position j such that |w| = n is a power of 2. Let w′ be a full word of length n such that, for every defined position i of w, w(i) 6= w′ (i). Consider a word u such that w ⊂ u. If u(j) 6= w′ (j), then d(u, w′ ) = n, which is a power of 2, so by Theorem 8 uw′ is primitive. If u(j) = w′ (j), then d(u, w′ ) = n − 1. Now, |u| − d(u, w′ ) = n − (n − 1) = 1, which is a power of 2, so by Theorem 8 uw′ is primitive. Thus, for all words u such that w ⊂ u, uw′ is primitive and the result follows by Lemma 1.
4
Generating Primitive Words of Odd Length
In this section, we examine operations which produce primitive partial words of odd length. First, we deal with an operation involving one letter. The primitivity of ww′ , where w′ is defined by a single insertion operation of one letter on w, is studied in Theorem 13 of [9]. We can expand on it with the following theorem and similar proof. Here, we consider w with one hole. When forming w′ , we replace the hole in w with any letter a ∈ A and insert a letter b ∈ A. Theorem 10. 1. Let u1 , u2 , v be non-empty words, and let w = u1 ⋄u2 v be primitive. If w′ = u1 au2 bv, for some a, b ∈ A, then ww′ is primitive; 2. Let u, v1 , v2 be non-empty words, and let w = uv1 ⋄v2 be primitive. If w′ = ubv1 av2 , for some a, b ∈ A, then ww′ is primitive. Corollary 1. 1. Let u1 , u2 , v be non-empty words, and let be u1 ⋄u2 v primitive. Then u1 ⋄u2 vu1 ⋄u2 av, for any a ∈ A, is primitive; 2. Let u, v1 , v2 be non-empty words, and let uv1 ⋄v2 be primitive. Then uv1 ⋄v2 uav1 ⋄v2 , for any a ∈ A, is primitive. The primitivity of ww′ , where w′ is defined by a deletion of one letter of w, is studied in Theorem 11 of [9]. We extend it to partial words by deleting a letter of w and replacing the hole in w with a letter to create w′ . Theorem 11. 1. If w = u1 ⋄u2 av is a primitive word with one hole, a ∈ A, ′ then ww = u1 ⋄u2 avu1 bu2 v, for any b ∈ A, is primitive; 100
On Operations Preserving Primitivity of Partial Words with One Hole
2. If w = uav1 ⋄v2 is a primitive partial word with one hole, with a ∈ A, then ww′ = uav1 ⋄v2 uv1 bv2 , for any b ∈ A, is primitive. Corollary 2. 1. If u1 ⋄u2 av is a primitive partial word with one hole, with a ∈ A, then u1 ⋄u2 avu1 ⋄u2 v is primitive; 2. If uav1 ⋄v2 is a primitive partial word with one hole, with a ∈ A, then uav1 ⋄v2 uv1 ⋄v2 is primitive. The following theorem also enables us to construct a primitive word, ww′ . We concatenate a partial word with one hole w, and a full word w′ created by the same sequence of letters as w but without the hole. Theorem 12. Let n ≥ 3, let w = a0 · · · an−1 be a partial word of length n with one hole at position i such that w 6⊂ an for any a ∈ A. If w′ = a0 a1 · · · ai−1 ai+1 · · · an−1 , then ww′ is primitive. Second, we deal with operations involving two positions. Theorem 12 of [9] is concerned with the primitivity of ww′ , when w′ is defined by a single deletion operation of one letter of w and a single substitution operation of one letter of w. We prove a similar statement when w has one hole. Theorem 13. Let n ≥ 2, w = a0 a1 · · · an−1 be a word of length n with one hole at position i, and h : A → A be a mapping such that h(a) 6= a for all a ∈ A. Then ww′ is primitive if one of the following statements holds: 1. i < j and w′ = a0 · · · ai−1 ai+1 · · · aj−1 h(aj )aj+1 · · · an−1 ; 2. j < i and w′ = a0 · · · aj−1 h(aj )aj+1 · · · ai−1 ai+1 · · · an−1 . The primitivity of ww′ , where w′ is defined by a single deletion operation of the first letter of w and a single substitution operation of one letter of w, then reversing the remaining sequence of letters is studied in Theorem 17 of [9]. We extend it to two positions i, j (the case where i < j) instead of only one position j (the case where i = j). Theorem 14. Let w = a0 a1 · · · an−1 be a primitive word of length n, w′ = an−1 · · · aj+1 h(aj )aj−1 · · · ai+1 h(ai )ai−1 · · · a1 , 1 ≤ i < j < n, and h : A → A be a mapping such that h(a) 6= a for all a ∈ A. Then ww′ is primitive. Proof. Suppose there exist a word v and integer p ≥ 2 such that ww′ = v p . Since |ww′ | = 2n − 1 is odd, both |v| and p are odd, and p ≥ 3. Since w is primitive, |v| ≥ 3. Let p = 2m + 1 and |v| = 2q + 1, where m, q ≥ 1. It is convenient to refer to v p as v1 v2 · · · vp where v = v1 = · · · = vp , that is, vl 101
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
is the lth v block. The first letter of v is the first one of ww′ , so for each l, we ′ and have v = vl = a0 vl′ vl′′ , with |vl′ | = |vl′′ | = q. Note that w = v m a0 vm+1 m ′ ′ ′′ w = vm+1 v . Set l = l mod 2q + 1, 0 ≤ l < n. The case when neither ai nor aj falls in vm+1 is easy to see, so let us prove the remaining cases. First, suppose aj falls in vm+1 and p = 3 (or m = 1), and so aj = v2 (j ′ ). ′ If j = 0, then aj = v2 (0) = a0 and h(aj ) = v3 (0) = a0 , which contradicts the fact that h(aj ) 6= aj . Thus, j ′ ≥ 1 and aj must fall in v2′ . Note that v2′′ = rev(v2′ ) and we have v2′ (j ′ ) = aj , so v2′′ (q − 1 − j ′ ) = h(aj ). We see that |v1′ [j ′ + 1..q)v1′′ a0 v2′ | = |v2′′ a0 v3′ v3′′ [0..q − 1 − j ′ )|, and v1′ (j ′ ) corresponds to v3′′ (q − 1 − j ′ ). If i 6= j ′ , we get a contradiction because v1′ (j ′ ) = v2 (j ′ ) = aj 6= h(aj ) = v2′′ (q − 1− j ′ ) = v3′′ (q − 1− j ′ ). Thus, i = j ′ . Now, |v1′′ [q − j ′ ..q)a0 v2′ | = |v2′′ a0 v3′ [0..j ′ )|. Since ai falls in v1′ and aj falls in v2′ , v1′′ (q − 1 − j ′ ) = v3′ (j ′ ). This again gives a contradiction since v1′′ (q − 1 − j ′ ) = v2′′ (q − 1 − j ′ ) = h(aj ), v3′ (j ′ ) = v2 (j ′ ) = aj and h(aj ) 6= aj . Now, suppose aj falls in vm+1 and p ≥ 5. Some vl in w exists such that neither ai nor aj falls in it. Set w = x1 vl x2 an−1 , w′ = x3 vx4 , where |x1 | = |x4 | and |x2 | = |x3 |. If v = a0 v ′ v ′′ , with |v ′ | = |v ′′ |, we get ww′ = x1 a0 v ′ v ′′ x2 an−1 x3 a0 v ′ v ′′ x4 . Since |x2 an−1 | = |x3 a0 | and neither ai nor aj falls in vl , it follows that v ′′ = rev(v ′ ). So, v = a0 v ′ rev(v ′ ). As we have just ′′ ′ shown, vm+1 = rev(vm+1 ). By a similar argument to that above, aj 6= vm+1 (0), ′ ′ ′′ and thus aj falls in vm+1 . But this implies vm+1 6= rev(vm+1 ). Corollary 3. Let w = a0 a1 · · · an−1 be a primitive partial word of length n with one hole at position i, 1 ≤ i < n, let w′ = an−1 · · · aj+1 h(aj )aj−1 · · · a1 , 1 ≤ j < n and j 6= i, and let h : A → A be a mapping such that h(a) 6= a for all a ∈ A. Then ww′ is primitive. Third, we deal with operations including a morphism on most letters. Theorem 15. Let n ≥ 4, let w = a0 a1 · · · an−1 be a partial word of length n with one hole at position i, 0 ≤ i < n, and let h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a and h(h(a)) = a for all a ∈ A. If w′ = h(a0 · · · ai−1 ai+1 · · · an−1 ), then ww′ is primitive. Proof. Suppose there exist a word v and integer p ≥ 2 such that ww′ ⊂ v p . Since |ww′ | is odd, |v| and p are odd. Let p = 2m+1 for some m ≥ 1, and set v = v1 v2 where |v1 | = |v2 | + 1. So w ⊂ (v1 v2 )m v1 and w′ ⊂ v2 (v1 v2 )m . Let v1 = v1′ a for some a ∈ A, so |v1′ | = |v2 |, and w ⊂ (v1′ av2 )m v1′ a and w′ ⊂ v2 (v1′ av2 )m . If |v1′ | ≤ i < n (that is, the hole is not in the prefix of length |v1′ | of w), then h(v1′ ) = v2 . Similarly, if 0 ≤ i < |v1′ |, then h(v2 ) = v1′ or v2 = h(v1′ ). In either case, v2 = h(v1′ ), and so w ⊂ (v1′ ah(v1′ ))m v1′ a and w′ ⊂ h(v1′ )(v1′ ah(v1′ ))m . If 102
On Operations Preserving Primitivity of Partial Words with One Hole
|v1′ | = 0, then w ⊂ an and w′ ⊂ an−1 ; but h(a) 6= a, a contradiction. Thus |v1′ | ≥ 1. First, suppose |v1 v2 | ≤ i < n. So h(v1′ ah(v1′ )) = h(v1′ )v1′ a or h(v1′ )h(a)v1′ = h(v1′ )v1′ a. Thus h(a)v1′ = v1′ a, and h(a) = a, a contradiction. Now, suppose 0 ≤ i < |v1 v2 |. So h(v1′ a) = ah(v1′ ), or v2 h(a) = av2 , and h(a) = a. Theorem 16 defines w′ by deleting the hole from w and then performing a morphism on the remaining sequence excluding only the last letter. Theorem 16. Let n ≥ 6, let w = a0 a1 · · · an−1 be a partial word of length n with one hole at position i, 0 ≤ i < n, and let h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a and h(h(a)) = a for all a ∈ A. Suppose that w 6⊂ an for any a ∈ A. 1. If w′ = h(a0 · · · ai−1 ai+1 · · · an−2 )an−1 and the first two defined letters are distinct, then ww′ is primitive; 2. If w′ = a0 h(a1 · · · ai−1 ai+1 · · · an−1 ) and the last two defined letters are distinct, then ww′ is primitive. We now define w′ by substituting a letter for the hole in a word with one hole, w, then perform a morphism on the sequence remaining after we substitute a letter for the hole. We then insert a letter at the end of w′ . Theorem 17. Let n ≥ 5, w = a0 a1 · · · an−1 be a word of length n with one hole at position i, i = 0 or i = 1, and h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a and h(h(a)) = a, for all a ∈ A. If w′ = h(a0 a1 · · · ai−1 aai+1 · · · an−1 )b for some a, b ∈ A, then ww′ is primitive. w′
The following theorem considers a partial word with one hole w and creates through operations of reversal, deletion, insertion, and morphism.
Theorem 18. Let n ≥ 4, w = a0 a1 · · · an−1 be a partial word of length n with one hole at position i = n − 3, n − 2, or n − 1, and h : A → A be a mapping such that h(a) 6= a and h(h(a)) = a for all a ∈ A. If i = n − 1 (resp., i = n − 2, i = n − 3), let w′ = h(an−2 an−3 · · · a0 ) (resp., w′ = ah(an−3 an−4 · · · a0 ), w′ = h(an−2 )ah(an−4 an−5 · · · a0 )), for any a ∈ A. Then ww′ is primitive. Proof. Suppose that ww′ ⊂ v p for some v and p ≥ 2. Since |ww′ | is odd, |v| and p are odd, and let p = 2m + 1. Since |w| ≥ 4, w(0) = a0 ∈ A. By the construction of w′ , w′ (n − 2) 6= w(0), and thus v must contain at least two distinct letters, so |v| ≥ 2. Moreover, since |v| is odd, |v| ≥ 3. Set v = v1 v2 , with |v1 | = |v2 | + 1, so w ⊂ (v1 v2 )m v1 and w′ = v2 (v1 v2 )m . 103
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
First, suppose |v| = 3, p = 3, so ww′ ⊂ vvv = a0 bh(a0 )a0 bh(a0 )a0 bh(a0 ), for some b ∈ A, and w ⊂ a0 bh(a0 )a0 b, w′ = h(a0 )a0 bh(a0 ). By definition of h, w(1) 6= w′ (2), a contradiction. Now, suppose |v| ≥ 5. Note that |v1 | ≥ 3. Since w ⊂ (v1 v2 )m v1 , the first |v| positions of w are defined. Furthermore, since w′ = v2 (v1 v2 )m , we have h(rev(v1 v2 )) = v1 v2 . Let v1 = v1′ b for some b ∈ A. Note that |v1′ | = |v2 |, and h(rev(v2 ))h(b)h(rev(v1′ )) = v1′ bv2 . However, this implies that h(b) = b, a contradiction. Finally, suppose p ≥ 5. Since m ≥ 2, the first |v| positions of w are defined, and we again have a contradiction by a similar argument to the case when |v| ≥ 5. Fourth, we deal with operations with a morphism on half the letters. Theorem 19. Let n ≥ 2, let w = w1 w2 ⋄ where w1 and w2 are full words of length n, and let h : A∗ → A∗ be a length preserving morphism such that h(a) 6= a and h(h(a)) = a for all a ∈ A. Set w1 = a0 a1 · · · an−1 . If w′ = h(w1 )w2 a0 h(a0 ) or w′ = w1 h(w2 )h(a0 )a0 , then ww′ is primitive. Proof. For w′ = h(w1 )w2 a0 h(a0 ), let v and p ≥ 2 be such that ww′ ⊂ v p . Since |ww′ | is odd, |v| and p are odd. Let v = v1 v2 such that |v1 | = |v2 | − 1, and p = 2m + 1. So w1 w2 ⋄ ⊂ (v1 v2 )m v1 and h(w1 )w2 a0 h(a0 ) ⊂ v2 (v1 v2 )m , and v2 = v2′ h(a0 ) where |v2′ | = |v1 |. By substitution, w1 w2 ⋄ ⊂ (v1 v2′ h(a0 ))m v1 , h(w1 )w2 a0 h(a0 ) ⊂ v2′ h(a0 )(v1 v2′ h(a0 ))m . If |v1 | = 0, then w1 w2 ⋄ ⊂ (h(a0 ))m , so h(a0 ) = w1 (0), a contradiction. Thus |v1 | ≥ 1. Note that v1 b, where b = v2′ (0), is a prefix of w1 , and v2′ h(a0 ) is a prefix of h(w1 ). So v1 b = h(h(v1 b)) = h(v2′ h(a0 )), and thus b = h(h(a0 )) = a0 , implying that a0 = v2′ (0). But h(a0 ) = h(w1 )(0), and h(a0 ) 6= a0 . The following is concerned with |w| odd and w′ defined by reversing ⋄w and applying a morphism on the first half excluding the middle letter. Theorem 20. Let n ≥ 3 be odd, w = a0 a1 · · · an−1 a full word of length n, h : A∗ → A∗ a length preserving morphism such that h(a) 6= a for all a ∈ A. Set ′ ′ i = n−1 2 . If w = h(an−1 · · · ai+1 )ai · · · a0 ⋄, then ww is primitive. Fifth, we deal with concatenating a square. Theorem 21. Let m be a non-negative integer, let w be a partial word with one hole of length n = 4m + 3, and let w′ be a full word of length n + 1. If w 6⊂ an , for any a ∈ A, and w[0..2] 6↑ w′ [0..2], then ww′ w′ is primitive. Proof. Suppose there exist a word v and integer p ≥ 2 such that ww′ w′ ⊂ v p . Since |ww′ w′ | = (4m + 3) + 2(4m + 4) = 12m + 11 is odd, |v| and p are odd. Let p = 2q + 1 for some q ≥ 1, and let v = v1 v2 where |v1 | = |v2 | − 1. Since 104
On Operations Preserving Primitivity of Partial Words with One Hole
|w′ | is even, set w′ = w1′ w2′ such that |w1′ | = |w2′ |, and so ww1′ ⊂ (v1 v2 )q v1 and w2′ w′ ⊂ v2 (v1 v2 )q . Let v2 = v2′ a for some a ∈ A, so |v2′ | = |v1 |, ww1′ ⊂ (v1 v2′ a)q v1 and w2′ w1′ w2′ ⊂ v2′ a(v1 v2′ a)q . Looking at the latter, since |w2′ | = |w1′ |, |v2′ a(v1 v2′ a)q | is divisible by 3. If |v1 | = 0, then ww1′ ⊂ aq implies that w ⊂ an , a contradiction. So |v1 | ≥ 1, and we consider the case where q mod 3 = 2 (the others are similar). Suppose q mod 3 = 2, so q = 3t + 2 for some t ≥ 0, thus |v2′ a(v1 v2′ a)q | = (6t + 5)|v1 | + (3t + 3) is divisible by 3 only if |v1 | is. So let v1 = v1′ v1′′ v1′′′ and v2′ = v2′′ v2′′′ v2′′′′ such that |v1′ | = |v1′′ | = |v1′′′ | = |v2′′ | = |v2′′′ | = |v2′′′′ |. We get ww1′ ⊂ (v1′ v1′′ v1′′′ v2′′ v2′′′ v2′′′′ a)q−1 v1′ v1′′ v1′′′ v2′′ v2′′′ v2′′′′ av1′ v1′′ v1′′′ and w2′ w1′ w2′ ⊂ v2′′ v2′′′ v2′′′′ av1′ v1′′ v1′′′ v2′′ v2′′′ v2′′′′ a(v1′ v1′′ v1′′′ v2′′ v2′′′ v2′′′′ a)q−1 . Since |w1′ | = |w2′ |, w1′ w1′ w2′ w2′
⊂ v2′′′ v2′′′′ av1′ v1′′ v1′′′ (v2′′ v2′′′ v2′′′′ av1′ v1′′ v1′′′ )t ⊂ v1′′′ v2′′ v2′′′ v2′′′′ av1′ (v1′′ v1′′′ v2′′ v2′′′ v2′′′′ av1′ )t ⊂ v2′′ v2′′′ v2′′′′ av1′ v1′′ (v1′′′ v2′′ v2′′′ v2′′′′ av1′ v1′′ )t ⊂ v1′′ v1′′′ v2′′ v2′′′ v2′′′′ a(v1′′′ v2′′ v2′′′ v2′′′′ av1′ v1′′ )t
Since w1′ and w2′ are both full words, v2′′′ v2′′′′ av1′ v1′′ v1′′′ = v1′′′ v2′′ v2′′′ v2′′′′ av1′ and v2′′ v2′′′ v2′′′′ av1′ v1′′ = v1′′ v1′′′ v2′′ v2′′′ v2′′′′ a. From the former, v2′′′ = v1′′′ = v1′ . Similarly from the latter, v2′′ = v1′′ , and so v1′ v1′′ v1′′′ = v1′′′ v2′′ v2′′′ . Since |v1 | ≥ 1 is divisible by 3, we have |v1 | ≥ 3. Thus |v1′ | ≥ 1. We obtain w[0..2] ⊂ v1′ v1′′ v1′′′ and w′ [0..2] = w1′ [0..2] = v1′′′ v2′′ v2′′′ = v1′ v1′′ v1′′′ , and so w[0..2] ↑ w′ [0..2].
5 Conclusion In addition to exploring operations which produce primitive partial words of even or odd length exclusively, we include operations which yield primitive words of any length. The following generalizes Theorem 27 of [9]. Theorem 22. 1. Let n ≥ 2, w be a primitive partial word of length n, and a, b ∈ A be distinct. Then wan , wan−1 and wabn−2 are primitive; 2. Let n ≥ 4 be even, w be a primitive partial word of length n, and a, b ∈ A (n−2) (n−2) be distinct. Then w(ab) 2 a and w(ab) 2 b are primitive. Furthermore, if a ∈ A and w is a partial word of length n such that w 6⊂ an , then wan and wan−1 are primitive.
A World Wide Web server interface has been established at www.uncg.edu/cmp/research/primitive3 105
F. Blanchet-Sadri, Sarah Nelson and Amelia Tebbe
for automated use of a program that when given as input a binary partial word with one hole, outputs the primitive partial words that can be generated using our operations. When we perform the operations of our results along with Lemma 4 and the fact that if a partial word is primitive, then so is its reversal, we can generate all the primitive binary partial words with one hole of length n, 1 ≤ n ≤ 11, as well as many of the ones in the range 12 ≤ n ≤ 21. The table below gives the number G1,2 (n) of primitive binary partial words with one hole of length n generated with our results, the number P1,2 (n) of primitive binary partial words with one hole of length n, as well as their ratio. n 12 13 14 15 16 17 18 19 20 21
G1,2 (n) 16320 50310 78372 209520 174432 762212 721800 2563328 1315320 7599354
P1,2 (n) 23664 53222 112868 245190 520192 1114078 2349072 4980698 10465040 22017282
Ratio 0.690 0.945 0.694 0.855 0.335 0.684 0.307 0.515 0.126 0.345
References [1] J. Berstel and L. Boasson. Partial words and a theorem of Fine and Wilf. Theoretical Computer Science, 218:135–141, 1999. [2] J. Berstel and D. Perrin. Theory of Codes. Academic Press, 1985. [3] F. Blanchet-Sadri. Primitive partial words. Discrete Applied Mathematics, 148(3):195–213, 2005. [4] F. Blanchet-Sadri. Algorithmic Combinatorics on Partial Words. Chapman & Hall/CRC Press, Boca Raton, FL, 2008. [5] F. Blanchet-Sadri and A. R. Anavekar. Testing primitivity on partial words. Discrete Applied Mathematics, 155(3):279–287, 2007. [6] F. Blanchet-Sadri and M. Cucuringu. Counting primitive partial words. Journal of Automata, Languages and Combinatorics. To appear. [7] C. Choffrut and J. Karhumäki. Combinatorics of Words. In G. Rozenberg and A. Salomaa, editors, Handbook of Formal Languages, volume 1, pages 329–438. Springer-Verlag, Berlin, 1997. [8] M. Crochemore and W. Rytter. Jewels of Stringology: Text Algorithms. World Scientific, Singapore, 2002.
106
On Operations Preserving Primitivity of Partial Words with One Hole
[9] J. Dassow, G. M. Martín, and F. J. Vico. Some operations preserving primitivity of words. Theoretical Computer Science, 410:2910–2919, 2009. [10] P. Dömösi, S. Horváth, and M. Ito. Context-Free Languages and Primitive Words. World Scientific, 2011. To appear. [11] L. Kari and G. Thierrin. Word insertions and primitivity. Utilitas Mathematica, 53:49–61, 1998. [12] M. Lothaire. Algebraic Combinatorics on Words. Cambridge University Press, Cambridge, 2002. [13] V. Mitrana. Primitive morphisms. Information Processing Letters, 64:277–281, 1997. [14] H. Petersen. On the language of primitive words. Theoretical Computer Science, 161:141– 156, 1996. [15] G. P˘aun, N. Santean, G. Thierrin, and S. Yu. On the robustness of primitive words. Discrete Applied Mathematics, 117:239–252, 2002.
107