On the Combinatorics of Palindromes and Antipalindromes
aa r X i v : . [ c s . F L ] M a r On the Combinatorics of Palindromes andAntipalindromes
Chuan Guo , Jeffrey Shallit , and Arseny M. Shur University of Waterloo, Ontario, Canada { c3guo,shallit } @uwaterloo.ca Ural Federal University, Ekaterinburg, Russia [email protected]
Abstract.
We prove a number of results on the structure and enumera-tion of palindromes and antipalindromes. In particular, we study conju-gates of palindromes, palindromic pairs, rich words, and the counterpartsof these notions for antipalindromes.
Combinatorial and algorithmic studies of palindromes can be traced back to the1970’s, when they were considered as a promising tool to construct a “hard”context-free language, which cannot be recognized by a linear-time randomaccess machine. Nevertheless, palindrome-based languages were proved to belinear-time recognizable [5, 9, 10]. Recent topics of interest in the study of palin-dromes include, for example, rich words (containing the maximum possible num-ber of distinct palindromes; see [1, 2, 6]) and palstars (products of even-lengthpalindromes; see [9, 14, 15]). Also, there is a popular modification of the notionof palindrome, where the reversal of a word coincides not with the word itself,but with the image of the word under a certain involution of the alphabet; see,e.g., [7, 13]. In the binary case, there is a unique such modification, called an antipalindrome .In this paper, we aim to fill certain gaps in the knowledge on combinatoricsof palindromes and antipalindromes. The four subsequent sections are mostlyindependent. In Section 2, we study the distribution of palindromes among con-jugacy classes and enumerate conjugates of palindromes. Section 3 is devotedto the words which are products of two palindromes; we prove some character-izations of this class of words and show that the number of k -ary words thatare products of two odd-length palindromes is exactly k times the number of k -ary words of the same length that are products of two even-length palindromes.In Section 4, we analyze the growth function for the language of binary richwords. We give the first nontrivial lower bound, of order C √ n for a constant C ,and provide some empirical evidence that this growth function does indeed havesubexponential growth. Finally, in Section 5 we focus on antipalindromes. Weshow that antipalindromes share many common properties with palindromes,with a notable exception: the notion of a rich word becomes trivial. efinitions and notation. We study finite words over finite alphabets, using thearray notation w = w [1 ..n ] when appropriate. The notions of prefixes, suffixes,factors, periods and (integer) powers are as usual. We write | w | for the lengthof w and ε for the empty word. For two words v and w of length n , their perfect shuffle v X w is the word v [1] w [1] v [2] w [2] · · · v [ n ] w [ n ]. Thus, for example, clip X aloe = calliope . Given a word w , let w R denote its reversal (e.g.,( stressed ) R = desserts ). A word w is a palindrome if w = w R . A word is primitive if it is not an integer power of a shorter word. Two words u and v are conjugates if u = xy and v = yx for some words x and y . Conjugacy is anequivalence relation. The following lemma is folklore. Lemma 1.
Let u = z i for a primitive word z . Then the conjugacy class of u contains exactly | z | words. We use two basic properties of periodic words due to Lyndon andSch¨utzenberger [11].
Lemma 2. (i) For any nonempty words u and v , the equality uv = vu holds ifand only if u = z i and v = z j for some word z and positive integers i, j .(ii) For any nonempty words u , v , and w , the equality uw = wv holds if and onlyif u = xy , v = yx , w = ( xy ) i x for some words x = ε and y , and nonnegativeinteger i . For a language L over an alphabet Σ , its growth function (also called com-binatorial complexity or census function) is defined to be C L ( n ) = | L ∩ Σ n | .Below, we list some basic properties of palindromes. Proposition 1.
For all integers m, n ≥ , the word x m is a palindrome if andonly if x n is a palindrome. Proposition 2.
For all nonempty palindromes u, v , the word uv is a palindromeif and only if both u, v are powers of some palindrome z .Proof. Suppose uv is a palindrome. Then uv = ( uv ) R = v R u R = vu . ByLemma 2 (i), u = z i , v = z j for integers i, j ≥
1. By Proposition 1, we have that z is a palindrome. Conversely, if u = z i and v = z j , we have uv = z i + j , which isa palindrome by Proposition 1. ⊓⊔ Proposition 3.
The word x is an even-length palindrome iff there exists a word y such that x = y X y R . Here we study the distribution of palindromes in conjugacy classes and countconjugates of palindromes.
Theorem 1.
A conjugacy class contains at most two palindromes. A conjugacyclass has two palindromes if and only if it contains a word of the form ( xx R ) i ,where xx R is a primitive word and i ≥ . emma 3. Suppose u = u R and uu R = z i for a primitive word z . Then i is oddand z = xx R for some x .Proof. If i is even, then uu R = ( z i/ ) . Hence, u = u R , contradicting the condi-tions of the lemma. So i is odd and then | z | is even. Let z = xx ′ , where | x | = | x ′ | .We see that x is a prefix of u and x ′ is a suffix of u R . Hence, x ′ = x R , as re-quired. ⊓⊔ Proof (of Theorem 1).
Let us prove that for any conjugacy class with two distinctpalindromes, say uv and vu , there exists a word x and a number i such that xx R is primitive, uv = ( xx R ) i , and vu = ( x R x ) i . We use induction on n = | uv | . Thebase case is trivial, because such conjugacy classes do not exist for, say, n = 1.For the inductive step, assume | u | ≤ | v | without loss of generality. If | u | = | v | ,then v = u R . By Lemma 3 we get uv = ( xx R ) i , vu = ( x R x ) i for a primitiveword xx R and i ≥ | u | < | v | . Then v begins and ends with u R . Applying Lemma 2 (ii),we obtain u R = ( st ) i s , where s = ε and i ≥ v = ( st ) i +1 s .Looking at the central factor of the palindromes uv = ( s R t R ) i s R · st · s ( ts ) i , (1) vu = ( st ) i s · ts · s R ( t R s R ) i , (2)we see that st and ts are also palindromes. If t = ε , then s is a palindrome,implying uv = vu , which is impossible. If st = ts , then by Lemma 2 (i) both s and t are powers of some z . By Proposition 1, s , t , and z are palindromes, andthen again uv = vu . Therefore, we obtain st = ts . So we can apply the inductivehypothesis to these two palindromes, getting st = ( xx R ) j , ts = ( x R x ) j for aprimitive word xx R . Then we can write v = ( xx R ) j ( i +1) s = s ( x R x ) j ( i +1) . (3)Since all conjugates of the word xx R are distinct words by Lemma 1, x ’s andtheir reversals occur in the same positions in both representations (3). Then s = ( xx R ) k x for some k , 0 ≤ k < j . Then we can easily compute t , s R , and t R toget uv = ( xx R ) j ( i +1) , vu = ( x R x ) j ( i +1) . Thus, we have finished the inductivestep.Note that a conjugacy class of a palindrome ( xx R ) i , where xx R is primitive,clearly contains a different palindrome ( x R x ) i . To finish the proof of the theoremit remains to show that such a class contains no other palindromes. Indeed,consider the class of w = ( xx R ) i . It consists of i th powers of conjugates of xx R (see Lemma 1). Let u and v be such that uv = xx R and ( vu ) i is a palindrome.Then vu is a palindrome by Proposition 1. If | u | 6 = | v | , say, | u | < | v | , then weapply the above argument to uv and vu , getting uv = ( yy R ) k for some y and k . But this is impossible, because uv = xx R is primitive. Hence, | u | = | v | , andthus vu = x R x . Thus, the class of w contains exactly two palindromes. ⊓⊔ Corollary 1.
A conjugacy class of a word w = z m , where z is primitive and m ≥ , contains(i) 0 or 1 palindrome, if | z | is odd;(ii) 0 or 2 palindromes, if | z | is even. et n = p i · · · p i k k , where p , . . . , p k are primes. Recall that the M¨obius func-tion µ ( n ) equals ( − k if i = · · · = i k = 1 (i.e., if n is square-free ) and 0otherwise. The following result apparently first appeared in [12]. Lemma 4.
The number ρ ( k, n ) of k -ary words of length n that are both (i)primitive and (ii) a palindrome satisfies the following formula ρ ( k, n ) = X d | n µ ( d ) k ⌊ (( n/d )+1) / ⌋ . (4)We use (4) and Corollary 1 to count the conjugates of palindromes. Theorem 2.
The number of conjugates of k -ary palindromes of length n is c ( k, n ) = X d | n f ( d ) · ρ ( k, d ) , where f ( d ) = ( d, if d is odd ; d/ , if d is even . (5) Proof. If n is odd, it suffices to count the number of palindromes and multiply itby the number of distinct conjugates given in Lemma 1. Instead of non-primitivepalindromes, we count their primitive roots, which are palindromes by Proposi-tion 1. Thus we have c ( k, n ) = X d | n d · ρ ( k, d ) , which is equivalent to (5) because d takes only odd values. If n is even, someclasses contain two palindromes. Let w = z i , where z is primitive. If | z | is odd,then the class of w contains 0 or 1 palindrome, while if | z | is even, the class of w contains 0 or 2 palindromes. In the latter case, we must divide the result ofcounting the conjugates of palindromes by 2. This gives precisely (5). ⊓⊔ In this section we consider palindromic pairs, which are words factorizable intotwo palindromes. First we give a few easy characterizations of palindromic pairs,and then prove Theorem 4 on the number of “even” and “odd” palindromic pairs.Let P be the set of palindromes over the alphabet Σ . Palindromic pairs areexactly the elements of P . Recall that L /L = { x ∈ Σ ∗ | ∃ y ∈ L : xy ∈ L } . Proposition 4. P / P = P .Proof. P / P ⊆ P : Suppose x ∈ P / P . Then there exists a palindrome y such that xy is a palindrome. If either x or y is empty, the result is clearly true. Otherwise xy = ( xy ) R = y R x R = yx R . Then by Lemma 2 (ii) there exist u ∈ Σ + , v ∈ Σ ∗ and an integer e ≥ x = uv , x R = vu , and y = ( uv ) i u . From x R = vu we get x = u R v R . But x = uv , so u = u R and v = v R . So u, v ∈ P and then x ∈ P . P ⊆ P / P : If x = uv with u, v palindromes, then uvu is a palindrome. Thus,taking y = u , we have xy ∈ P and y ∈ P . Hence x ∈ P / P . ⊓⊔ all a word x credible if it is a conjugate of its reverse x R , like the Englishword referee . Proposition 5.
The word x is in P if and only if it is credible.Proof. Suppose x ∈ P , that is, that x = uv where u, v are palindromes. Then x R = v R u R = vu , so x is a conjugate of x R .Otherwise, assume x is a conjugate of x R . Then there exist u, v such that x = uv and x R = vu . But x R = v R u R , so v = v R and u = u R , and x is theproduct of two palindromes. ⊓⊔ Remark 1.
The growth function for P was studied by Kemp [8], who computeda precise formula and described its asymptotics. For the binary alphabet, seesequence A007055 in the On-Line Encyclopedia of Integer Sequences [18].A factorization of a palindromic pair w is a pair of palindromes u, v suchthat uv = w and v = ε . The number of factorizations of a palindromic pair isdescribed in the following theorem, also due to Kemp [8]. Theorem 3.
A palindromic pair w has m factorizations if and only if w = z m for a primitive word z . A palindromic pair w is even (resp., odd) if it can be factorized into twopalindromes of even (resp., odd) length. Thus, an even-length palindromic pairis either even, or odd, or both, like the word aabaab = aa · baab = aabaa · b . (6)Note that in view of Theorem 3, the last option applies to non-primitive wordsonly. Let E ( n, k ) (resp., O ( n, k )) denote the number of even (resp., odd) k -arypalindromic pairs of length n . Theorem 4.
For all n and k we have O ( n, k ) = k · E ( n, k ) . The proof is based on several lemmas. The following lemma is a well-knowncorollary of the Fine-Wilf property [4]:
Lemma 5.
Let p be the minimal period of a word w , q be a period of w , and p, q ≤ | w | / . Then q is a multiple of p . We call an even-length word w even-primitive if it is not an integer power ofa shorter even-length word. The difference between primitive and even-primitivewords is clarified in the following lemma. Lemma 6.
An even-length non-primitive word is even-primitive iff it is thesquare of an odd-length primitive word.Proof.
Let w be an even-length non-primitive word. Then w = z m , for a primi-tive word z and an integer m >
1. Such a pair ( z, m ) is unique. Indeed, | z | is aperiod of w , | z | ≤ | w | /
2, and | z | is not a multiple of a shorter period of w dueto primitivity. Then | z | is the minimal period of w by Lemma 5. Necessity . Since w is even-primitive, | z | is odd. Then m is even, because | w | = m | z | . If m ≥
4, then w = ( z ) m/ is not even-primitive. Hence, m = 2, asdesired. Sufficiency stems from the fact that | z | is the minimal period of w . ⊓⊔ palindromic pair can have several factorizations according to Theorem 3.However, the even-primitive words have the following useful property (cf. (6)). Lemma 7.
An even-length even-primitive word has at most one factorizationinto two even-length palindromes and at most one factorization into two odd-length palindromes.Proof.
Let u , u , v , v be even-length palindromes such that u v = u v = w and | v | < | v | (recall that v = ε by the definition of factorization). Then v isa suffix of v and, as both these words are palindromes, a prefix of v as well. ByLemma 2 (ii), v = ( xy ) s x , v = ( xy ) s +1 x for some words x = λ and y , and someinteger s ≥
0; in addition, it is clear that both x and y are palindromes. Hence, u = u xy , and, since u , u , x, y are palindromes, u = yxu . Applying Lemma 2(ii) again, we finally get w = ( yx ) t for some t ≥
2. Since | yx | = | v | − | v | iseven, w is not even-primitive.The same argument works for odd-length palindromes u , u , v , v . ⊓⊔ Lemma 8.
Let z be an even-primitive word, m > be an integer. Then z m isan even (resp., odd) palindromic pair iff z is.Proof. Necessity . If z m = uv for palindromes u and v , then u = ( xy ) t x , v = y ( xy ) m − t − for some words x, y and some integer t such that xy = z and 0 ≤ t ≤ m −
1. Since u and v are palindromes, x and y are also palindromes, implyingthat z is a palindromic pair. Since | z | = | xy | is even by definition, the numbers | x | and | u | (resp., | y | and | v | ) have the same parity, whence the result. Sufficiency . If z = xy for palindromes x and y , then z m = x · y ( xy ) m − . Theword y ( xy ) m − is a palindrome and its length has the same parity as y . ⊓⊔ In what follows we suppose that the size k > E ( n ) (resp., O ( n )) for E ( n, k ) (resp., O ( n, k )). We also assume that n is even, because E ( n ) = O ( n ) = 0for odd n . Let E ′ ( n ) (resp., O ′ ( n )) be the number of even-primitive even (resp.,odd) palindromic pairs of length n . Lemma 9. If O ′ ( n ) = k · E ′ ( n ) for all n , then O ( n ) = k · E ( n ) for all n .Proof. Any word w of length n can be uniquely represented as w = z n/ d , where2 d is a divisor of n and the word z of length 2 d is even-primitive. Then byLemma 8 the number of even (resp., odd) palindromic pairs of this form is equalto the number of even (resp., odd) palindromic pairs z . The latter number isexactly E ′ (2 d ) (resp., O ′ (2 d )). Hence, O ( n ) = X d | n O ′ (2 d ) = k · X d | n E ′ (2 d ) = k · E ( n ) . ⊓⊔ Proof (of Theorem 4).
In view of Lemma 9, it suffices to prove the equality O ′ ( n ) = k · E ′ ( n ) for all even n .Let P i ( n ) be the set of all palindromic pairs w = uv such that | w | = n , | u | = i . Then the sets P e ( n ) of all even palindromic pairs and P o ( n ) of all oddpalindromic pairs of length n can be written as P e ( n ) = P ( n ) ∪ P ( n ) ∪ · · · ∪ P n − ( n ) (7a) P o ( n ) = P ( n ) ∪ P ( n ) ∪ · · · ∪ P n − ( n ) (7b)n general, the sets P i ( n ) may intersect, but Lemma 7 tells us that an even-primitive word belongs to at most one set of (7a) and at most one set (7b).Furthermore, let 2 d be a divisor of n , and consider an even palindromic pair ofthe form w = z n/ d , where z is even-primitive. Then z is an even palindromicpair by Lemma 8. By Lemma 7, z has a unique factorization into two even-length palindromes, say, z = xy . Hence, w has exactly n/ d factorizations intotwo even-length palindromes (see the proof of Lemma 8): w = x · y ( xy ) n/ d − = xyx · y ( xy ) n/ d − = ( xy ) n/ d − x · y. Thus, w belongs to exactly n/ d sets (7a). In the same way, an odd palindromicpair of the form w = z n/ d belongs to exactly n/ d sets (7b). To get the value of E ′ ( n ) (resp., O ′ ( n )), we must sum up the cardinalities of all sets (7a) (resp., (7b))and subtract the total contribution of the words that are not even-primitive.Since the number of even (resp., odd) palindromic pairs of the form w = z n/ d is the same as the number of even-primitive even (resp., odd) palindromic pairs z (of length 2 d ), we have E ′ ( n ) = n/ − X i =0 P i ( n ) − X d | n, d 1, where the letters a i and a i +1 are distinct for any i . We call eachterm a s i i a block . Consider the language I of binary words whose run-lengthencoding satisfies s i ≤ s i +2 for all i = 1 , . . . , k − 2. The language I is close to thelanguages of intermediate growth studied in [16]. Theorem 5. I ⊆ R .Proof. Let w = 0 s s s · · · a s k k ∈ I for s , . . . , s k ≥ 1. We prove the richness ofall the prefixes of w (including w itself) by induction on the length of w .The base case is trivial. Now assume that w [1 ..i ] is rich and w [ i ] = 0 (thecase w [ i ] = 1 is analysed in the same way). We add the letter w [ i +1] and searchfor the “new” palindromic suffix described in Proposition 6 (iii). If w [1 ..i ] = 0 i ,there is nothing to prove: the new suffix is 0 i +1 if w [ i +1] = 0 and 1 if w [ i +1] = 1.So let w [1 ..i ] = 0 s s · · · s ′ l , where s ′ l ≤ s l and 1 < l ≤ k .If s ′ l ≥ s l − and w [ i +1] = 0, then the new palindromic suffix is 0 s ′ l +1 ; if s ′ l > s l − and w [ i +1] = 1, then the new suffix is 10 s ′ l 1. Thus, two nontrivialcases remain. Case 1 : s ′ l < s l − ; clearly then w [ i +1] = 0. The word w [1 ..i ] ends witha palindrome 0 s ′ l , but it has more occurrences in w [1 ..i ]. Hence, it is not thelongest palindromic suffix. Then this suffix, which we denote by v , begins with0 s ′ l and ends with 1 s l − s ′ l . If v = 0 s ′ l s l − s ′ l , then 0 v is a suffix of w [1 ..i ] because s ′ l < s l − . Hence, the palindrome 0 v w [1 ..i +1], and it has no earlieroccurrences because v occurs in w [1 ..i ] only once.If v intersects more than three blocks, then v = 0 s ′ l (1 s l − s l − ) k s l − s ′ l forsome k ≥ 1. If v is preceded by 0 in w , then the suffix 0 v w [1 ..i +1] is a newpalindrome, as before. Finally, if v is preceded by 1, consider the palindrome v ′ = 0 s ′ l (1 s l − s l − ) k − s l − s ′ l . The word w [1 ..i +1] ends with 0 v ′ 0, and this isa new palindrome, because 0 v ′ occurs in w [1 ..i ] only as a suffix. (Indeed, 0 v ′ begins with 0 s ′ l +1 , and there is no large enough block of zeroes to the left of v .) Case 2 : s ′ l = s l − and w [ i +1] = 1. Since 0 s ′ l s l − s ′ l is a palindromic suffix of w [1 ..i ], the longest such suffix is v = (0 s ′ l s l − ) k s ′ l for some k ≥ 1. Clearly, 1 v isa suffix of w [1 ..n ], implying that w [1 ..i +1] ends with the new palindrome 1 v w [1 ..i +1] ends with a new palindrome. The inductive stepis finished. ⊓⊔ Theorem 6. The growth function of the language of binary rich words satisfies ln( C R ( n )) ≥ π √ · √ n − O (ln n ) . (10) roof. Let p ( n ) [ p ( n, k )] denote the number of integer partitions (resp., partitionswith exactly k parts) of n . There is a natural injection of partitions of n intowords of length n : a partition s + · · · + s k = n , where the parts are writtenin increasing order, defines the word w = 0 s s s · · · a s k k . Note that w ∈ I ,implying C I ( n ) ≥ p ( n ). By the famous Hardy-Ramanujan-Uspensky formula, p ( n ) ∼ e π √ n/ n √ n → ∞ . (11)So we already have the bound similar to (10), but with a smaller constant inthe leading term. To get the desired constant, we assume n to be even (since C I ( n ) is an increasing function, substituting the bound obtained for n = 2 m for n = 2 m +1 gives the general bound of the same order of growth). Note that anypair of partitions s + · · · + s k = t + · · · + t k = n/ s t · · · s k t k ∈ I , and this map is injective. Then we have C I ( n ) > n/ − X k =1 (cid:0) p ( n/ , k ) (cid:1) > (cid:0) max k p ( n/ , k ) (cid:1) > (cid:0) p ( n/ (cid:1) n . (12)Substituting (11) and taking logarithms, we obtain (10). ⊓⊔ Remark 2. More precise estimates of C I ( n ) cannot give better bounds for C R ( n ),because all inequalities in (12) affect only the O -term in (10). Using Proposi-tion 6 (i,ii), one can extend I , closing it under taking factors and reversals; butthe effect of such extensions is swallowed by the O -term as well.How good is this lower bound, which is roughly 37 √ n divided by a poly-nomial? It is unclear, because no good upper bound for C R ( n ) has yet beenobtained. The function C R ( n ) is submultiplicative due to Proposition 6 (i), soits growth rate lim n →∞ ( C R ( n )) /n is majorized by any value ( C R ( n )) /n , ac-cording to Fekete’s lemma [3]. Also, the ratio C R ( n ) C R ( n − gives us a clue about thegrowth of this function. Until recently, the number of known values of C R ( n ) wasquite small ( n ≤ 25 on OEIS, posted by the second author). But short rich wordsconstitute a substantial share of all short words, giving us ( C R (25)) / ≈ . C R (25) C R (24) ≈ . n = 60. From hiscalculations we get ( C R (60)) / ≈ . 605 and C R (60) C R (59) ≈ . C R ( n ).A much stronger argument is provided in Table 1 below: C R ( n ) ≤ n √ n for4 ≤ n ≤ 60, and, moreover, the function n √ n seems to grow faster. So wepropose the following conjecture, which implies that the bound of Theorem 6 isquite reasonable. Conjecture 1. One has C R ( n ) = O (cid:0) ng ( n ) (cid:1) √ n , or, equivalently, ln( C R ( n )) = O ( √ n (ln n − g ( n )), for some infinitely growing function g ( n ). able 1. Number of rich words compared to the n √ n function. n C R ( n ) n √ n Ratio4 16 16 15 32 ≈ . 55 0 . · · · 25 3 089 518 ≈ . · . ≈ . · . · · · 59 1 530 103 385 844 ≈ . · . ≈ . · . In this section, the alphabet is { , } . For a word x ∈ { , } ∗ , its negation x is obtained by changing each 0 in x to 1 and vice versa. A word x is an an-tipalindrome if x = x R . Thus, for example, is an antipalindrome; notethat all antipalindromes have even length. Let A denote the set of all antipalin-dromes. There are definite similarities between the properties of palindromes andantipalindromes. The following analogs of Propositions 1-3 are straightforward. Proposition 7. For all integers m, n ≥ , x m is an antipalindrome if and onlyif x n is an antipalindrome. Proposition 8. For all nonempty antipalindromes u, v , the word uv is an an-tipalindrome iff both u and v are powers of an antipalindrome z . Proposition 9. The word x is an antipalindrome if and only if there exists aword z such that x = z X z R . A binary word x is called an antipalstar if it is the concatenation of 1 ormore antipalindromes. A nonempty antipalstar is called prime if it is not theproduct of two or more even-length antipalindromes. An antipalstar is alwaysan antipalindrome, but the converse is false, because for any antipalindromes x, y the word xyx will be an antipalindrome. The following theorem is a counterpartof the decomposition property for palstars [9]. Theorem 7. Every antipalstar can be factored uniquely as the concatenation ofprime antipalstars.Proof. If some antipalstar has multiple factorizations into prime antipalstars,then some prime antipalindrome u has another prime antipalindrome v as aprefix. Let v be the shortest antipalindrome in such pairs. If | v | ≤ | u | / 2, then u = vzv , where z is either empty or an antipalindrome; this contradicts theprimality of u . Let | v | > | u | / u = xx R , v = yy R . Then v = xy , x R = yz for somenonempty y, z . Since v is an antipalindrome, we have v = xy R = y R x R = y R yz .Since y R y is an antipalindrome, this contradicts the minimality of v . Thus, noprime antipalindrome has another prime antipalindrome as a prefix. ⊓⊔ Next we look at the number of antipalindromic factors in a word. heorem 8. A word w of length n ≥ has at most n − distinct nonemptyfactors that are antipalindromes.Proof. For any nonempty antipalindromic factor of w , consider its leftmost oc-currence in w . We show that no two such occurrences end in the same positionin w . If they did, say x and y , with | x | < | y | , then x is a suffix of y . But then x R = x is a prefix of y R = y . So x is a prefix of y . Since | x | < | y | , we have foundan occurrence of x to the left of its leftmost occurrence, a contradiction.Since no nonempty antipalindromic factor of w ends at position 1, the numberof possible end positions of such factors is at most n − 1, whence the result. ⊓⊔ One can introduce the notion of an a-rich word as a word with maximumpossible number of antipalindromic factors. But the following theorem showsthat these words are trivial, in contrast with the rich words. Theorem 9. For all n ≥ , there are exactly two a-rich words of length n .Proof. Let us prove that any word having the factor 00 or 11 is not a-rich.Consider such a word w and the position in which its leftmost factor of the form aa ends. An antipalindrome ending with aa must begin with aa ; hence, w has noantipalindrome ending in the chosen position. From the proof of Theorem 8 weknow that an a-rich word contains nonempty antipalindromes ending at everyposition, except position 1, so w is not a-rich.Thus, only two words of each length n remain. These words are (10) k and(01) k if n = 2 k is even, and (10) k k n = 2 k + 1 is odd.To see that these words have n − w = 1010 · · · ; the other word admits the same proof. Note that w [1 .. k ] = (10) k and w [2 .. k +1] = (01) k for k ≥ n − ⊓⊔ We call a word x creaky if it is a conjugate of its reversed complement x R . Proposition 10. The word x is in A if and only if it is creaky.Proof. Suppose x ∈ A . Then x = uv where u, v are antipalindromes. So x R = v R u R = vu , a conjugate of x .For the other direction, suppose x is a conjugate of x R . Then x = uv and x R = vu . From x = uv we get x R = v R u R and then x R = v R u R . It follows that v = v R and u = u R . ⊓⊔ Proposition 11. For all integers m, n ≥ , the word x m is creaky iff x n iscreaky.Proof. It suffices to prove the result for m = 1. Suppose x is creaky. Then thereexist u, v such that x = uv and x R = vu . Then x n = ( uv ) n , which is clearly aconjugate of ( vu ) n = ( x R ) n = ( x n ) R .Suppose x n is creaky. Then there exist u, v such that x n = uv and ( x n ) R = vu . Then there exist an integer m and words x ′ , x ′′ such that u = x m x ′ , v = x ′′ x n − m − , where x ′ x ′′ = x . So vu = ( x ′′ x ′ ) n , and it follows that x nR = x ′′ x ′ , aconjugate of x . ⊓⊔ n analogy with palindromic pairs, we define factorization of a creaky word w as a pair of antipalindromes u , v , where v = ε and uv = w . The followinganalog of Theorem 3 holds. Theorem 10. A creaky word w has m factorizations if and only if w = z m fora primitive word z .Proof. A useful observation, used several times in this proof, is that if v ∈ A ,then for any word u any two of the following conditions (i) u ∈ A , (ii) u is aprefix of v , (iii) u is a suffix of v , imply the third one.First we take a creaky word with two different factorizations, w = u v = u v , and prove that it is not primitive. We can assume | u | < | u | . If u = ε ,then w ∈ A . By Proposition 8, w is a nontrivial power of an antipalindrome.Now let u = ε . We prove the following fact by induction on | w | : for someantipalindromes x and y , one has w = ( xy ) m , u = ( xy ) j x , u = ( xy ) k x , where0 ≤ j < k < m . The base case is trivial (the shortest creaky words have a uniquefactorization), so we proceed with the inductive step.Since u ∈ A , it is both a prefix and a suffix of u . By Lemma 2 (ii) we have u = ( xy ) i x , u = ( xy ) i +1 x for some words x, y and some i ≥ 0. Similarly wehave v = ( x ′ y ′ ) i ′ x ′ , v = ( x ′ y ′ ) i ′ +1 x ′ . Clearly, x, y, x ′ , y ′ ∈ A . Furthermore, thesuffix yx of u coincides with the prefix x ′ y ′ of v . So we have w = ( xy ) i + i ′ +1 xx ′ .If x ′ = y , then we are done, so assume that | x ′ | < | y | (the case | x ′ | > | y | issimilar). Since yx = x ′ y ′ are different factorizations of a creaky word which isshorter than w , we apply the inductive hypothesis to get yx = ( zt ) m , x ′ = ( zt ) j z , y = ( zt ) k z . Then we have u = ( tz ) mi + m − k − t , u = ( tz ) m ( i +1)+ m − k − t , w =( tz ) m ( i + i ′ +1)+ m − k + j . The inductive step is finished.We proved that a primitive creaky word has a unique factorization. Nowlet us take w = z m for a primitive z and let z = z ′ z ′′ be the factorization of z . Then clearly all words of the form z i z ′ = ( z ′ z ′′ ) i z ′ and z ′′ z i = z ′′ ( z ′ z ′′ ) i are antipalindromes. Thus, w has m factorizations of the form z i z ′ · z ′′ z m − i − .Conversely, suppose that w has a factorization z i ˆ z · ˜ zz m − i − . Then ˆ z, ˜ z ∈ A ,implying ˆ z = z ′ and ˜ z = z ′′ . Thus, the number of factorizations is exactly m . ⊓⊔ Using Theorem 10, it is easy to relate the growth function of A (sequenceA045655 in the OEIS [18]) to palindromic pairs. Theorem 11. C A ( n ) = E ( n, for all n ≥ .Proof. Antipalindromes can be mapped to even-length palindromes with thebijection negating the right half of a word. We can extend this idea to creakywords and even palindromic pairs. For a creaky word w = z m with z primitive,we know that z is creaky (Proposition 11) and has a unique factorization z = uv (Theorem 10). Negating the right halves of both u and v , we get an evenpalindromic pair ˆ z = ˆ u ˆ v . The even palindromic pair ˆ w = ˆ z m will be the imageof w . Theorem 3 allows one to invert this mapping and thus obtain a bijectionbetween creaky words and even palindromic pairs of a fixed length. ⊓⊔ eferences 1. Bucci, M., de Luca, A., De Luca, A.: Rich and periodic-like words. In: Proc. 13thInt. Conf. on Developments in Language Theory. DLT 2009. LNCS, vol. 5583, pp.145–155. Springer (2009)2. Droubay, X., Justin, J., Pirillo, G.: Episturmian words and some constructions ofde Luca and Rauzy. Theoret. Comput. Sci. 255, 539–553 (2001)3. Fekete, M.: ¨Uber der verteilung der wurzeln bei gewissen algebraischen gleichungenmit ganzzahligen koeffizienten. Math. Zeitschrift 17, 228–249 (1923)4. Fine, N.J., Wilf, H.S.: Uniqueness theorems for periodic functions. Proc. Amer.Math. Soc. 16, 109–114 (1965)5. Galil, Z., Seiferas, J.: A linear-time on-line recognition algorithm for “Palstar”. J.ACM 25, 102–111 (1978)6. Glen, A., Justin, J., Widmer, S., Zamboni, L.: Palindromic richness. European J.Combinatorics 30(2), 510–531 (2009)7. Kari, L., Mahalingam, K.: Watson-Crick palindromes in DNA computing. NaturalComputing 9, 297–316 (2010)8. Kemp, R.: On the number of words in the language { w ∈ Σ ∗ | w = w R } . DiscreteMath. 40, 225–234 (1982)9. Knuth, D.E., Morris, J., Pratt, V.: Fast pattern matching in strings. SIAM J.Comput. 6, 323–350 (1977)10. Kosolobov, D., Rubinchik, M., Shur, A.M.: Pal k is linear recognizable online. In:Proc. 41th Int. Conf. on Theory and Practice of Computer Science (SOFSEM2015). LNCS, vol. 8939, pp. 289–301. Springer (2015)11. Lyndon, R.C., Sch¨utzenberger, M.P.: The equation a M = b N c P in a free group.Michigan Math. J. 9, 289–298 (1962)12. Nester, M.R.: Mathematical investigations of some plant interaction designs. Ph.D.thesis, University of Queensland, Brisbane, Australia (1999)13. Pelantova, E., Starosta, S.: Almost rich words as morphic images of rich words.Internat. J. Found. Comp. Sci. 23, 1067–1083 (2012)14. Rampersad, N., Shallit, J., Wang, M.W.: Inverse star, borders, and palstars. In-form. Process. Lett. 111, 420–422 (2011)15. Richmond, L.B., Shallit, J.: Counting the palstars. Electronic J. Combinatorics21(3), in a free group.Michigan Math. J. 9, 289–298 (1962)12. Nester, M.R.: Mathematical investigations of some plant interaction designs. Ph.D.thesis, University of Queensland, Brisbane, Australia (1999)13. Pelantova, E., Starosta, S.: Almost rich words as morphic images of rich words.Internat. J. Found. Comp. Sci. 23, 1067–1083 (2012)14. Rampersad, N., Shallit, J., Wang, M.W.: Inverse star, borders, and palstars. In-form. Process. Lett. 111, 420–422 (2011)15. Richmond, L.B., Shallit, J.: Counting the palstars. Electronic J. Combinatorics21(3),