Construction Of A Rich Word Containing Given Two Factors
Josef Rukavicka
Department of Mathematics,
Faculty of Nuclear Sciences and Physical Engineering, CZECH TECHNICAL UNIVERSITY
IN PRAGUE
([email protected]).
Abstract
A finite word w with β£wβ£=n contains at most n+1 distinct palindromic factors. If the bound n+1 is attained, the word w is called rich. Let F(w) be the set of factors of the word w.
It is known that there are pairs of rich words that cannot be factors of a common rich word.
However it is an open question how to decide for a given pair of rich words u,v if there is a rich word w such that {u,v}βF(w). We present a response to this open question:
If w1β,w2β,w are rich words, m=max{β£w1ββ£,β£w2ββ£}, and {w1β,w2β}βF(w) then there exists also a rich word wΛ such that {w1β,w2β}βF(wΛ) and β£wΛβ£β€m2k(m)+2, where k(m)=(q+1)m2(4q10m)log2βm and q is the size of the alphabet. Hence it is enough to check all rich words of length equal or lower to m2k(m)+2 in order to decide if there is a rich word containing factors w1β,w2β.
1 Introduction
In the last years there have appeared several articles dealing with rich words; see, for instance, [1], [2], [3], [5]. Recall that a palindrome is a word that reads the same forwards and backwards, for example βnoonβ and βlevelβ. Rich words are those words that contain the maximal number of palindromic factors. It is known that a word of length n can contain at most n+1 palindromic factors including the empty word. The notion of a rich word has been extended also to infinite words. An infinite word is called rich if its every finite factor is rich [4], [3].
Let lps(w) and lpp(w) denote the longest palindromic suffix and the longest palindromic prefix of a word w, respectively. The authors of [1] showed the following property of rich words:
Proposition 1.1**.**
If r,t are two factors of a rich word w such that lps(r)=lps(t) and lpp(r)=lpp(t), then r=t.
Two related open questions can be found:
In [5]: Is the condition in Proposition 1.1 sufficient for joining two rich words u and v into factors of a same rich word?
In [3]: We do not know how to decide whether two rich words u and v are factors of a common rich word w.
In the current article we present a response to the question from [3] in the following form: We prove that if w1β,w2β,w are rich words, m=max{β£w1ββ£,β£w2ββ£}, and {w1β,w2β}βF(w) then there exists a rich word wΛ such that {w1β,w2β}βF(wΛ) and β£wΛβ£β€m2k(m)+2, where k(m)=(q+1)m2(4q10m)log2βm and q is the size of the alphabet. Thus it is enough to check all rich words of length equal or lower to m2k(m)+2 in order to decide if there is a rich word containing factors w1β,w2β.
We describe the basic ideas of the proof.
If w is a rich word, then let a be a letter such that lps(wa)=alpps(w)a, where lpps denotes the longest proper palindromic suffix. It is known and easy to show that wa is a rich word [5]. Thus every rich word w can be richly extended to a word wa. We will call wa a standard extension of w. If there is a letter b such that aξ =b and wb is also a rich word, then we call the longest palindromic suffix of wb a flexed palindrome; the explication of the terminology is that wb is not a standard extension of w, hence wb is βflexedβ from the standard extension.
We define a set Ξ of pairs of rich words (w,r), where r is a flexed palindrome of w, the longest palindromic prefix of w does not contain the factor r, and β£rβ£β₯β£rΛβ£ for each flexed palindrome rΛ of w. If (w,r)βΞ, w1β is the prefix of w with β£w1ββ£=β£rβ£β1 and w2β is the suffix of w with β£w2ββ£=β£rβ£β1 then we construct a rich word wΛ possessing the following properties:
The word w1β is a prefix of wΛ.
The word w2β is a suffix of wΛ.
The number of occurrences of r in wΛ is strictly smaller than the number of occurrences of r in w.
The set of flexed palindromes of wΛ is a subset of the set of flexed palindromes of w.
Iterative applying of this construction will allow us for a given rich word w with a prefix w1β and a suffix w2β to construct a rich word t containing factors w1β,w2β and having no flexed palindrome longer than m, where m=max{β£w1ββ£,β£w2ββ£}.
Another important, but simple, observation is that if w is a rich word with prefix u such that the number of flexed palindromes in w is less than k and u has exactly one occurrence in w then there is an upper bound for the length of w. We show this upper bound as a function of k and consequently we derive an upper bound for the length of t.
2 Preliminaries
Let A be a finite alphabet with q=β£Aβ£. The elements of A will be called letters.
Let Ο΅ denote the empty word.
Let Aβ be the set of all finite words over A including the empty word, let AnβAβ be the set of all words of length n, and let A+=Aββ{Ο΅}.
Let RβAβ denote the set of all rich words and let R+=Rβ©A+.
Let F(w)βAβ denote the set of all factors of wβAβ; we state explicitly that Ο΅,wβF(w).
Let F(S)=βvβSβF(v), where SβAβ.
Let Fpβ(w)βF(w) be set of all palindromic factors of wβAβ.
Let F(w,r)={uβ£uβF(w)\mboxandrξ βF(u)}βF(w), where w,rβAβ. The set F(w,r) contains factors of w avoiding the factor r.
Let Fpβ(w,r)=Fpβ(w)β©F(w,r).
Let Prf(w) and Suf(w) be the set of all prefixes and all suffixes of wβAβ respectively; we define that {Ο΅,w}βPrf(w)β©Suf(w).
Let wR denote the reversal of wβAβ; formally if w=w1βw2ββ¦wkβ then wR=wkββ¦w2βw1β, where wiββA and iβ{1,2,β¦,k}. In addition we define that Ο΅R=Ο΅.
Let lps(w) and lpp(w) denote the longest palindromic suffix and the longest palindromic prefix of wβAβ respectively. We define that lps(Ο΅)=lpp(Ο΅)=Ο΅.
Let lpps(w) and lppp(w) denote the longest proper palindromic suffix and the longest proper palindromic prefix of wβAβ respectively, where β£wβ£β₯2.
Let trim(w)=v, where v,wβAβ, x,yβA, w=xvy, and β£wβ£β₯2.
Let rtrim(w)=v, where v,wβAβ, yβA, w=vy, and β£wβ£β₯1.
Let ltrim(w)=v , where v,wβAβ, xβA, w=xv, and β£wβ£β₯1.
Example 2.1**.**
A={1,2,3,4,5}.
w=124135.
trim(w)=2413.
ltrim(w)=24135.
rtrim(w)=12413.
Let pc(w) be the palindromic closure of wβAβ; formally pc(w)=uvuR, where w=uv and v=lps(w).
Let MinLenWord(U) and MaxLenWord(U) be the shortest and the longest word from the set U respectively, where either UβPrf(w) or UβSuf(w) for some wβAβ. If U=β
then we define MinLenWord(U)=Ο΅ and MaxLenWord(U)=Ο΅.
Let lcp(w1β,w2β) be the longest common prefix of words w1β,w2ββAβ; formally lcp(w1β,w2β)=MaxLenWord(Prf(w1β)β©Prf(w2β)).
Let lcs(w1β,w2β) be the longest common suffix of words w1β,w2ββAβ; formally lcs(w1β,w2β)=MaxLenWord(Suf(w1β)β©Suf(w2β)).
Let occur(u,v) be the number of occurrences of v in u, where u,vβAβ and β£vβ£>0; formally occur(u,v)=β£{wβ£wβSuf(u)\mboxandvβPrf(w)}β£.
Recall the notion of a complete return [2]: Given a word w and factors r,uβF(w), we call the factor r a complete return to u in w if r contains exactly two occurrences of u, one as a prefix and one as a suffix.
We list some known properties of rich words that we use in our article. All of them can be found, for instance, in [2].
Proposition 2.2**.**
If w,uβR+ and uβFpβ(w) then all complete returns to u in w are palindromes.
Proposition 2.3**.**
If wβR and pβF(w) then p,pRβR.
Proposition 2.4**.**
A word w is rich if and only if every prefix pβPrf(w) has a unioccurrent palindromic suffix.
3 Standard Extensions and Flexed Palindromes
We start with a formal definition of a standard extension and a flexed palindrome introduced at the beginning of the article.
Definition 3.1**.**
Let jβ₯0 be a nonnegative integer, wβR, and β£wβ£β₯2. We define StdExt(w,j) as follows:
StdExt(w,0)=w.
StdExt(w,1)=wa* such that lps(wa)=alpps(w)a and aβA.*
StdExt(w,j)=StdExt(StdExt(w,jβ1),1), where j>1.
*Let StdExt(w)={StdExt(w,j)β£jβ₯0}. If pβStdExt(w) then we call p a standard extension of w.
Let
T(w)={lps(ub)β£ubβPrf(w)\mboxandbβA\mboxandubξ =StdExt(u,1)}. If rβT(w) then we call r a flexed palindrome of w.*
For a given rich word wβR having a flexed palindrome r we define a standard palindromic replacement of r to be the longest palindromic suffix of a standard extension of a prefix p of w such that lps(px)=r, where px is a prefix of w and xβA. The idea is that we can βreplaceβ r with the standard palindromic replacement.
Definition 3.2**.**
*Let stdPalRep(w,r)=lps(StdExt(h,1)), where w,rβR, rβT(w), hxβPrf(w), xβA, and lps(hx)=r.
We call stdPalRep(w,r) a standard palindromic replacement of r in w.*
Example 3.3**.**
A={0,1}.
w=110101100110011.
001100βT(w).
lps(1101011001100)=001100.
StdExt(110101100110,1)=1101011001101.
stdPalRep(w,001100)=lps(1101011001101)=1011001101.
We show that the length of a flexed palindrome r is less than the length of the standard palindromic replacement stdPalRep(w,r).
Lemma 3.4**.**
If ux,uyβR, x,yβA, xξ =y, and ux=StdExt(u,1) then β£lps(ux)β£>β£lps(uy)β£.
Proof.
Let yty=lps(uy). From the definition of a standard extension we have lps(ux)=xvx, where v=lpps(u) and hence tβSuf(v). Since yξ =x we have also ytβSuf(v). The lemma follows.
β
An obvious corollary is that a flexed palindrome of w is not a prefix of w.
Corollary 3.5**.**
If w,rβR and rβT(w) then rξ βPrf(w).
In [5] the standard extension has been used to prove that each rich word w can be extended βrichlyβ; this means that there is aβA such that wa is rich.
Lemma 3.6**.**
If wβR and β£wβ£β₯2 then StdExt(w)βR.
Proof.
Obviously it is enough to prove that StdExt(w,1)βR, since for every tβStdExt(w)β{w} there is a rich word tΛ such that t=StdExt(tΛ,1).
Let xpx=lps(StdExt(w,1)), where xβA. Proposition 2.4 implies that we need to prove that xpx is unioccurrent in StdExt(w,1). Realize that p is unioccurrent in w, hence xpx is unioccurrent in StdExt(w,1).
β
To simplify the proofs of the paper we introduce a function MaxStdExt(u,v) to be the longest prefix z of u such that z is also a standard extension of v:
Definition 3.7**.**
Let
MaxStdExt(u,v)=MaxLenWord({StdExt(v)β©Prf(u)}). We call MaxStdExt(u,v) a maximal standard extension of v in u.
The next lemma shows that if a rich word contains factors ypx and ypy, where p is a palindrome, p is not a prefix of w, x,y are distinct letters, and ypx βoccursβ before ypy in w then ypy is a flexed palindrome.
Lemma 3.8**.**
If w,v,pβR, vβPrf(w), pξ βPrf(w), x,yβA, xξ =y, ypxβSuf(v), ypyξ βF(v), and ypyβF(w) then ypyβT(w).
Proof.
Let vΛ be such that vΛyβPrf(w), ypyβSuf(vΛy), and occur(vΛy,ypy)=1. Let u=lps(vΛ). Because pξ βPrf(w) it follows that u=lpps(vΛ)=lps(vΛ) and thus there is zβA such that zuβSuf(vΛ). Obviously vβPrf(vΛ) and hence occur(vΛ,p)>1. Proposition 2.2 implies that occur(u,p)>1, since the complete return to p which is a suffix of vΛ must a suffix of u. It follows that ypβSuf(u) and Lemma 3.4 implies that ypyβT(w).
β
4 Removing flexed points
We define formally the set Ξ mentioned in the introduction.
An element (w,r) of the set Ξ represents a rich word w for which we are able to construct a new rich word wΛ such that wΛ does not contain the flexed palindrome r, but wΛ have certain common prefixes and suffixes with w. We define that r is one of the longest flexed palindromes of w and that r is not a factor of the longest palindromic prefix of w. In addition we require that β£rβ£>2 so that the standard extension of rtrim(r) would be defined.
Definition 4.1**.**
Let Ξ be a set defined as follows: (w,r)βΞ if
-
w,rβR* and*
2. 2.
β£rβ£>2.
3. 3.
rβT(w)* and*
4. 4.
rξ βF(lpp(w))* and*
5. 5.
β£rβ£β₯β£rΛβ£* for each rΛβT(w).*
Given (w,r)βΞ, we need to express w as a concatenation of its factors having some special properties. For this reason we define a function parse(w,r):
Definition 4.2**.**
If (w,r)βΞ then let parse(w,r)=(v,z,t), where
v,z,tβR* and*
vzt=w* and*
rβSuf(v)* and*
occur(w,r)=occur(v,r)* and*
vz=MaxStdExt(vzt,v).
Remark 4.3**.**
The prefix v is the shortest prefix of w that contains all occurrences of r. The prefix vz is the maximal standard extension of v in w, and t is such that vzt=w. It is easy to see that v,z,t exist and are uniquely determined for (w,r)βΞ.
For an element (w,r)βΞ we define a function rdcPrf(w,r) (a reduced prefix), which is a prefix of the palindromic closure of some prefix of w. In Theorem 4.12 we show that the concatenation of rdcPrf(w,r) and t is a rich word having a strictly smaller number of occurrences of r than in w, where (v,z,t)=parse(w,r).
Definition 4.4**.**
*If w,rβΞ and (v,z,t)=parse(w,r) then let
rdcPrf(w,r) be defined as follows:
It follows from Property 4 of Definition 4.1 that there is hβPrf(w) such that w=hzRlps(v)zt. Note that lps(v)ξ =v since rβT(w) and thus rξ βPrf(w), see Corollary 3.5. It is clear that rβPrf(lps(v))β©Suf(lps(v)). This implies that hzRrβPrf(w). We distinguish two cases:*
rβF(hzRrtrim(r)):
Let g be the complete return to r such that gβSuf(hzRr). Clearly rzβPrf(g) and zRrβSuf(g), since rξ βF(ltrim(r)z); recall rβSuf(v) and occur(v,r)=occur(vzt,r). Let gΛβ be such that gΛβg=hzRr.
We define rdcPrf(w,r)=gΛβrz. Note that rdcPrf(w,r)βPrf(w).
rξ βF(hzRrtrim(r)):
Let uΛ=stdPalRep(hzRr,r).
Clearly lps(hzRr)=r and uΛξ =r. Because zRrtrim(r)βSuf(hzRrtrim(r)), then obviously Uξ =β
and rξ βF(U), where U={uβ£uβPrf(pc(hzRrtrim(r)))\mboxandltrim(r)zβSuf(u)}. We define rdcPrf(w,r)=MinLenWord(U). Note that rξ βF(rdcPrf(w,r)).
We call rdcPrf(w,r) a reduced prefix of w by r.
Remark 4.5**.**
Note in Definition 4.4 in the second case where rξ βF(hzRrtrim(r)) that it may happen that rdcPrf(w,r) is not a prefix of w. However it is a prefix of a palindromic closure of hzRrtrim(r), hence the number of flexed palindromes remains the same; formally β£T(hzRrtrim(r)))β£=β£T(rdcPrf(w,r))β£. Realize that pc(t)βStdExt(t) for each tβR and β£tβ£β₯2.
To clarify the definition of the reduced prefix rdcPrf(w,r) we present below two examples representing those two cases in the definition.
Example 4.6**.**
A={1,2,3,4,5,6,7,8,9}.
w=123999322399932442399932255223993.
r=999.
v=1239993223999324423999.
z=322.
t=55223993.
lps(v)=999324423999.
h=1239993.
w=hzRlps(v)zt.
g=9993223999βSuf(hzRr)=Suf(1239993223999).
gΛβ=123.
rdcPrf(w,r)=123999322.
Example 4.7**.**
A={1,2,3,4,5,6,7,8,9}.
w=123999599932239949.
r=999.
v=1239995999.
z=32.
t=239949.
lps(v)=9995999.
h=1.
w=hzRlps(v)zt.
StdExt(hzRrtrim(r),1)=StdExt(12399,1)=123993.
uΛ=stdPalRep(123999,999)=3993.
pc(12399)=12399321.
U={1239932}.
rdcPrf(w,r)=1239932.
We know that the reduced prefix rdcPrf(w,r) may not be a prefix of w, however we show that the longest common prefix of rdcPrf(w,r) and w is longer than β£rβ£β1.
Lemma 4.8**.**
If (w,r)βΞ and u=rdcPrf(w,r) then β£lcp(u,w)β£β₯β£rβ£β1.
Proof.
In Definition 4.4 in the first case where rξ βF(hzRrtrim(r)) and uβPrf(w), it is clear that rβF(u) and thus β£uβ£β₯β£rβ£. Hence we need to verify only the second case, where rξ βF(hzRrtrim(r)). Either hzRrtrim(r)βPrf(u) or uβPrf(hzRrtrim(r)). Since ltrim(r)zRβSuf(u) the lemma follows.
β
Using the reduced prefix we can now define the word rdcWrd(w,r) (a reduced word):
Definition 4.9**.**
Let rdcWrd(w,r)=rdcPrf(w,r)t, where (v,z,t)=parse(w,r) and (w,r)βΞ. We call rdcWrd(w,r) a reduced word of w by r.
We show that the longest common suffix of the reduced word rdcWrd(w,r) and w is longer than β£rβ£β1.
Lemma 4.10**.**
If (w,r)βΞ then lcs(rdcWrd(w,r),w)β£β₯β£rβ£β1.
Proof.
Given (w,r)βΞ and (v,z,t)=parse(w,r).
From Definition 4.4 of the reduced prefix, it is obvious that ltrim(r)zβSuf(rdcPrf(w,r)) and consequently ltrim(r)ztβSuf(rdcWrd(w,r)). Recall Definition 4.2 of the function parse(w,r). Since w=vzt and rβSuf(v) it follows that ltrim(r)ztβSuf(w). This implies that ltrim(r)zt is a common suffix of w and rdcWrd(w,r). Because β£ltrim(r)β£=β£rβ£β1 the lemma follows.
β
As already mentioned the reduced prefix rdcPrf(w,r) is not necessarily a prefix of w. In such a case rdcPrf(w,r) contains palindromic factors that are not factors of the longest common prefix lcp(w,rdcPrf(w,r)). We show that none of these palindromes is a factor of w. This will be important when proving richness of the word rdcWrd(w,r).
Proposition 4.11**.**
If (w,r)βΞ, u=rdcPrf(w,r), uΛ=stdPalRep(w,r), and g=lcp(w,u), then Fpβ(u,uΛ)βFpβ(g) and uΛξ βFpβ(w).
Proof.
From the properties of the palindromic closure it is easy to see that Fpβ(pc(f),lps(f))βFpβ(f) for each fβR. It means that every palindromic factor of f that is not a factor of pc(f) contains the factor lps(f). It follows that Fpβ(u,uΛ)βFpβ(g).
We show that occur(w,uΛ)=0. Let uΛ=xtx and r=ypy, where x,yβA. Obviously xξ =y, pyβPrf(t), and ypβSuf(p). Thus xtyβF(w). Lemma 3.8 implies that uΛβF(w) if and only if uΛβT(w). In addition Lemma 3.4 implies that β£uΛβ£>β£rβ£. This is a contradiction to Property 5 of Definition 4.1. Hence uΛξ βFpβ(w). This completes the proof.
β
The main theorem of the paper states the the reduced word rdcWrd(w,r) is rich, where (w,r)βΞ. In addition the theorem asserts that the set of flexed palindromes of rdcWrd(w,r) is a subset of the set of flexed palindromes of the word w, the number of occurrences of r is strictly smaller in rdcWrd(w,r) than in w, and the longest common prefix and suffix of rdcWrd(w,r) and w are longer than β£rβ£β1.
Theorem 4.12**.**
If (w,r)βΞ then
rdcWrd(w,r)βR* and*
T(rdcWrd(w,r))βT(w)* and*
occur(rdcWrd(w,r),r)<occur(w,r)* and*
β£lcp(rdcWrd(w,r),w)β£β₯β£rβ£β1* and*
β£lcs(rdcWrd(w,r),w)β£β₯β£rβ£β1.
Proof.
Recall that rdcWrd(w,r)=ut, where (v,z,t)=parse(w,r) and u=rdcPrf(w,r).
Suppose that upβR, T(up)βT(vzp), where pβPrf(rtrim(t)). In addition suppose that if β£pβ£β₯1 then lps(up)=lps(vzp) and rξ βF(lps(vzp)). The assumptions obviously hold for p=Ο΅.
Let xβA be such that pxβPrf(t). We show that the assumptions hold also for upx.
Proposition 2.4 implies that if fβR and yβA then fyβR if and only if fy has a unioccurrent palindromic suffix. Using this property we prove the theorem. We distinguish two cases:
If lps(vzpx)βT(w) then Property 5 of Definition 4.1 implies that lps(vzpx)βSuf(ltrim(r)zpx). From Definition 4.4 we know that ltrim(r)zβSuf(u). This implies that lps(vzpx)βSuf(upx) and rξ βF(lps(vzpx)).
Proposition 4.11 implies that lps(vzpx) is unioccurrent in upx. In consequence lps(upx)=lps(vzpx) and upxβR. Because lps(vzpx)βT(w) and T(up)βT(vzp) we conclude that T(upx)βT(vzpx). We do not need to prove that lps(upx)βT(upx), although it would not be difficult.
If lps(vzpx)ξ βT(w), then β£pβ£β₯1, because vz=MaxStdExt(vzt,v). Realize that lps(vzy)βT(w), where yβA and vzyβPrf(vzt).
Hence according to our assumptions we have lps(up)=lps(vzp). Obviously lps(vzpx)=xlpps(vzp)x and rξ βlpps(vzp).
Suppose that rβF(lps(vzpx)). Then rβPrf(lps(vzpx))β©Suf(lps(vzpx)). This is a contradiction since occur(v,r)=occur(w,r), see Definition 4.2. This implies that rξ βlps(vzpx). It follows that β£lps(vzpx)β£<β£rzpxβ£ and that lps(vzpx)βSuf(upx). In consequence lps(upx)=xlpps(up)x. Thus upx is a standard extension of up. We conclude that lps(upx)=lps(vzpx), lps(upx)ξ βT(upx), T(upx)βT(vzpx), and upxβR.
So we have upxβR and T(upx)βT(vzpx) for each pxβPrf(t). The fact that occur(ut,r)<occur(w,r) follows simply from the construction of u=rdcPrf(w,r), see Definition 4.4.
Lemma 4.8 and Lemma 4.10 imply that β£lcp(rdcWrd(w,r),w)β£β₯β£rβ£β1 and
β£lcs(rdcWrd(w,r),w)β£β₯β£rβ£β1. This completes the proof.
β
Two more examples illuminate the construction of rdcWrd(w,r).
Example 4.13**.**
A={1,2,3,4,5,6,7,8}.
w=vzt=12145656547745656545656547874.
r=656.
v=12145656547745656545656.
z=547.
t=874.
lps(v)=656545656.
u=rdcPrf(w,r)=12145656547.
rdcWrd(w,r)=ut=12145656547874.
Example 4.14**.**
- A={1,2,3,4,5,6,7,8}.
- β’
w=vzt=12145656547874.
r=656.
v=12145656.
z=54.
t=7874.
lps(v)=656.
u=rdcPrf(w,r)=12145654.
rdcWrd(w,r)=ut=121456547874.
If a rich word w has a factor u, then the palindromic closure of w is rich and contains the factor uR. Hence for us when constructing a rich word containing given factors, it does not matter if w contains u or uR. We introduce the notion of a reverse-unioccurrent factor.
Definition 4.15**.**
If β£{u,uR}β©F(w)β£=1 then we say that a word u is reverse-unioccurrent in w, where w,uβR.
We introduce a function ruo(w,u,v) (a reverse unioccurrence of u,v in w) which returns a factor of w such that u,v are reverse unioccurrent. In addition we require that u or uR is a prefix and v or vR is a suffix of ruo(w,u,v).
Definition 4.16**.**
If w1β,w2β,wβR, w1ββPrf(w) and w2ββSuf(w), then let M(w,w1β,w2β)βF(w) such that tβM(w,w1β,w2β) if:
tβF(w)* and*
w1β,w2β* are reverse-unioccurrent in t and*
{w1β,w1Rβ}β©Prf(t)ξ =β
* and*
{w2β,w2Rβ}β©Suf(t)ξ =β
.
Let the set M(w,w1β,w2β) be ordered and let ruo(w,w1β,w2β) be the first element of M(w,w1β,w2β).
Remark 4.17**.**
It is not difficult to see that the function ruo(r,w1β,w2β) is well defined and the set M(w,w1β,w2β) is nonempty.
We define maximal flexed palindrome of a rich word w, which is a flexed palindrome r of w, such (w,r)βΞ and β£rβ£>n, where n is a positive integer.
Definition 4.18**.**
Let H(w,n)={rβ£(w,r)βΞ\mboxandβ£rβ£>n}, let the set H(w,n) be ordered and let maxFlxPal(w,n) be the first element of H(w,n). If H(w,n)=β
then we define maxFlxPal(w,n)=Ο΅. We call maxFlxPal(w,n) a maximal flexed palindrome of w.
Remark 4.19**.**
The name βmaximal flexed palindromeβ comes from the properties of Ξ. Recall that for a pair (w,r) to be in the set Ξ, it is necessary that r is one of the longest flexed palindromes of w.
Next we define the function elmWrd(w,w1β,w2β) (eliminated word) that constructs a rich word from w by βeliminating allβ flexed palindromes longer than m=max{β£w1ββ£,β£w2ββ£} and keeping the prefix w1β and the suffix w2β of w.
Definition 4.20**.**
If w,w1β,w2ββR, m=max{β£w1ββ£,β£w2ββ£}, w1ββPrf(w), and w2ββSuf(w), then let elmWrd(w,w1β,w2β) be the result of the following procedure:
01 INPUT: w,m,w_1,w_2;
02 res: = ruo(w,w_1,w_2);
03 r := maxFlxPal(res,m);
04 WHILE r is nonempty word
05 DO
06 res := rdcWrd(res,r);
07 res := ruo(res,w_1,w_2);
08 r := maxFlxPal(res,m);
09 END-DO;
10 RETURN res;
*
The call of the function ruo on the lines 02 and 07 guarantees that w1β,w2β are reverse-unioccurrent in the word res and that {w1β,w1Rβ}β©Prf(res)ξ =β
and {w2β,w2Rβ}β©Suf(res)ξ =β
. Realize that it is not guaranteed that w1β,w2β are reverse-unioccurrent in rdcWrd(res,r), even if w1β,w2β are reverse-unioccurrent in res.
Clearly, the facts that tΛ is reverse unioccurrent in a rich word t and tΛβPrf(t) imply that lppp(t)βPrf(tΛ). Thus if r is a flexed palindrome of t longer than the prefix tΛ, then r is not a factor of lppp(t) and hence r satisfies Property 4 of Definition 4.1. In consequence the word elmWrd(w,w1β,w2β) contains no flexed palindrome longer than m.
The call of the function rdcWrd(res,r) on the line 06 makes obviously sense, since if maxFlxPal(w,m)ξ =Ο΅ then (w,maxFlxPal(w,m))βΞ.
In addition, because β£rβ£>max{β£w1β,w2β}, Theorem 4.12 asserts that {w1β,w1Rβ}β©Prf(rdcWrd(res,r))ξ =β
and {w2β,w2Rβ}β©Prf(rdcWrd(res,r))ξ =β
; consequently {w1β,w1Rβ}β©Prf(res)ξ =β
and {w2β,w2Rβ}β©Suf(res)ξ =β
on the line 06.
Moreover Theorem 4.12 implies that the procedure finishes after a finite number of iterations, because occur(rdcWrd(w,r),r)<occur(w,r) and T(rdcWrd(w,r))βT(w). The number of iterations is bounded by the number βrβT(w)βoccur(w,r). Note that several occurrences of r may be βeliminatedβ in one iteration. Hence we proved the following lemma:
Lemma 4.21**.**
If (w,r)βΞ, w1ββPrf(w), w2ββPrf(w), m=max{β£w1ββ£,β£w2ββ£}, and t=elmWrd(w,w1β,w2β) then
tβR* and*
{w1β,w1Rβ}β©Prf(t)ξ =β
* and*
{w2β,w2Rβ}β©Suf(t)ξ =β
* and*
for each rβT(t) we have β£rβ£β€m.
5 Words with limited number of flexed points
What is the maximal length of a word u such that w is reverse-unioccurrent in u, w is a prefix of u, and u has a given maximal number of flexed palindromes? The proposition below answers this question.
Proposition 5.1**.**
If u,wβR+, wβPrf(u), β£T(u)βT(w)β£β€k, β£wβ£β€m, and w is reverse-unioccurrent in u then β£uβ£β€m2k+1.
Proof.
Let uΛ=StdExt(u,1); then obviously β£pc(uΛ)β£<2β£uΛβ£, pc(uΛ)βStdExt(u), and w is not reverse-unioccurrent in pc(uΛ), since wRβSuf(pc(uΛ)).
It follows that if v1β,v2ββPrf(uΛ) such that v1β is reverse unioccurrent in uΛ, v1ββPrf(v2β), β£T(v2β)βT(v1β)β£=1, and lps(v2β)βT(v2β) then β£ltrim(v2β)β£<2β£v1ββ£, since ltrim(v2β)βStdExt(v1β). This implies that β£v2ββ£β€2β£v1ββ£. The proposition follows.
β
Remark 5.2**.**
The proof asserts that if v1β,v2β are two prefixes of a word u such that the longest palindromic suffix of v2β is the only flexed palindrome in v2β which is not a factor of v1β, then v2β is at most twice longer than v1β on condition that v1Rβ is not a factor of ltrim(v2β). Less formally it means that the length of a word can grow at most twice before next flexed palindrome appears. Note that for k=1 we have β£uβ£β€2m, which makes sense, since the palindromic closure of a nonpalindromic word w is at most twice longer than w and w is not reverse-unioccurrent in pc(w); realize that wRβSuf(pc(w)).
In [4] the author showed an upper bound for the number of palindromic factors of given length in a rich word:
Proposition 5.3** ([4],Corollary 2.23).**
If wβR and n>0 then
[TABLE]
Proposition 5.3 implies an upper bound for the number of flexed palindromes:
Lemma 5.4**.**
If wβR, n>0, and T(w)β©Aj=β
for each j>n then
[TABLE]
Proof.
Just realize that βj=1nβ(q+1)j(4q10j)log2βjβ€(q+1)n2(4q10n)log2βn.
β
From Lemma 4.21, Lemma 5.4 and Proposition 5.1 we obtain the result of the article:
Corollary 5.5**.**
If w,w1β,w2β are rich words, w1β,w2ββF(w), m=max{β£w1ββ£,β£w2ββ£} then there exists also a rich word wΛ such that w1β,w2ββF(wΛ) and β£wΛβ£β€m2k(m)+2, where k(m)=(q+1)m2(4q10m)log2βm.
Proof.
Let tβF(pc(w)) such that w1ββPrf(t) and w2ββSuf(t). Obviously such t exists.
Consider the word g=elmWrd(t,w1β,w2β). Let k(m)=(q+1)m2(4q10m)log2βm. Lemma 5.4 and Proposition 5.1 imply that β£gβ£β₯m2k(m)+1. Lemma 4.21 implies that gβR, {w1β,w1Rβ}β©F(g)ξ =β
, and {w2β,w2Rβ}β©F(g)ξ =β
. Let wΛ=pc(g). It follows that w1β,w2ββF(wΛ).
Because β£pc(g)β£β€2β£gβ£, the corollary follows. β
Acknowledgments
The author wishes to thank to Ε tΔpΓ‘n Starosta for his useful comments. The author acknowledges support by the Czech Science
Foundation grant GAΔR 13-03538S and by the Grant Agency of the Czech Technical University in Prague, grant No. SGS14/205/OHK4/3T/14.