1 Introduction

Periodicity is a fundamental notion of words that has various applications. The investigation of periodicity in combinatorics on infinite words has led to several characterizations of ultimately periodic words [1, 2, 4,5,6].

In [3], the authors studied a combinatorial problem about overlaps involving suffixes of a left-infinite word \(\lambda \) and prefixes of a right-infinite word \(\rho \). We considered the “overlap gap” function \(g: {\mathbb {N}}\rightarrow {\mathbb {N}}\), defined, for each positive integer n, by \(g(n)=n-m\) where m is the maximum length of overlaps between the suffix of \(\lambda \) and the prefix of \(\rho \) of length n. We have shown that \(g({\mathbb {N}})\) is finite if and only if \(\lambda \) and \(\rho \) are ultimately periodic words of the form \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}v\) and \(\rho =w{u}^{\!\scriptscriptstyle {\,\infty }}\) for some finite words u, v and w. The above combinatorial problem about infinite words was motivated by an application to an investigation conducted by the authors on decidability properties of semidirect products of pseudovarieties of semigroups.

In the present paper, following a suggestion by Pedro Silva, we study the behavior of the function g under the asymptotic condition \(\lim \limits _{n\rightarrow \infty }g(n)/n = 0\). We prove that this asymptotic condition gives another characterization of words \(\lambda \) and \(\rho \) for which the function g has finite image. Fine and Wilf’s Theorem, one of the oldest results about periodicity, plays an important role in obtaining this characterization.

2 Preliminaries

In this section, following the terminology of Lothaire [5], we introduce the basic concepts about finite and infinite words and recall the overlap gap function(s) (left/right) associated with a pair of infinite words.

2.1 Finite and infinite words

An alphabet is a finite non-empty set A. The empty word will be denoted by \(\varepsilon \). The free semigroup generated by A is represented by \(A^+\) and \(A^*\) denotes the free monoid \(A^+\cup \{\varepsilon \}\) generated by A. The length of a word \(w \in A^*\) is denoted by |w| and \(A^n\) is the set of all words over A with length n.

A word u is called a prefix (resp. a suffix) of a word w if \(w = ux\) (resp. \(w= xu\)) for some word x. A word is called primitive if it cannot be written in the form \(u^n\) with \(n>1\). Words u and v are conjugate if \(u=w_1w_2\) and \(v=w_2w_1\) for some words \(w_1,w_2\in A^*\).

A sequence \(\lambda =(a_s)_{s}\) of elements \(a_s\) of A with \(s\in -{\mathbb {N}}\) is said to be a left-infinite word on A, also denoted \(\lambda =\cdots a_{-2}a_{-1}a_0\). The set of all left-infinite words on A is denoted by \(A^{-{\mathbb {N}}}\). Dually, a right-infinite word on A is a sequence \(\rho =(a_n)_{n}\) of letters of A indexed by \({\mathbb {N}}\), also written \(\rho = a_{0}a_{1}a_2\cdots \), and \(A^{{\mathbb {N}}}\) denotes the set of all such words. A left-infinite word \(\lambda \) (resp. a right-infinite word \(\rho \)) of the form \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w=\cdots uuuw\) (resp. \(\rho =w{u}^{\!\scriptscriptstyle {\,\infty }}=wuuu\cdots \)), with \(u\in A^+\) and \(w\in A^*\), is called ultimately periodic. The word u is said to be a root and |u| a period of \(\lambda \) (resp. of \(\rho \)). The smallest period p is named the minimal period and the roots of length p are called cyclic roots of \(\lambda \) (resp. of \(\rho \)). Observe that a root is a cyclic root if and only if it is a primitive word. Moreover, cyclic roots of the same infinite word are conjugate.

For any ultimately periodic word \(\lambda \in A^{-{\mathbb {N}}}\) (resp. \(\rho \in A^{{\mathbb {N}}}\)) there exist unique words uw of shortest length such that \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w\) (resp. \(\rho =w{u}^{\!\scriptscriptstyle {\,\infty }}\)) and this is said to be its canonical form. In this case, u is a primitive word and, if \(w\ne \varepsilon \), the first (resp. the last) letters of u and w do not coincide.

The following result is known as Fine and Wilf’s Theorem (see [5]).

Proposition 2.1

Let \(u,v\in A^+\). If two powers \(u^k\) and \(v^\ell \) of u and v have a common prefix of length at least \(|u|+|v|-\gcd (|u|,|v|)\), then u and v are powers of the same word.

2.2 The overlap gap function

Consider a left-infinite word \(\lambda \in A^{-{\mathbb {N}}}\) and a right-infinite word \(\rho \in A^{{\mathbb {N}}}\). For each non-negative integer n, denote by \(\lambda _n\) and \(\rho _n\) the suffix of \(\lambda \) and the prefix of \(\rho \) of length n, respectively, and define

$$\begin{aligned} \begin{array}{rcl} lg_{\lambda ,\rho }(n)&{} =&{}\text{ min }\{k\in {\mathbb {N}}: \lambda _n x=y \rho _n \text{ with } x,y\in A^k\},\\[1mm] rg_{\lambda ,\rho }(n)&{}=&{}\text{ min }\{k\in {\mathbb {N}}: x \lambda _n= \rho _ny \text{ with } x,y\in A^k\},\\[1mm] g_{\lambda ,\rho }(n)&{}=&{}\text{ min }\{lg_{\lambda ,\rho }(n), rg_{\lambda ,\rho }(n)\}. \end{array} \end{aligned}$$

The non-negative integers \(lg_{\lambda ,\rho }(n)\), \(rg_{\lambda ,\rho }(n)\) and \(g_{\lambda ,\rho }(n)\) are called, respectively, the left overlap gap, the right overlap gap and the overlap gap between \(\lambda _n\) and \(\rho _n\). Notice that \(lg_{\lambda ,\rho }(n)=0\) if and only if \(\lambda _n=\rho _n\) if and only if \(rg_{\lambda ,\rho }(n)=0\).

The images \(lg_{\lambda ,\rho }({\mathbb {N}}), rg_{\lambda ,\rho }({\mathbb {N}}), g_{\lambda ,\rho }({\mathbb {N}})\) of the functions \(lg_{\lambda ,\rho },rg_{\lambda ,\rho },g_{\lambda ,\rho }: {\mathbb {N}}\rightarrow {\mathbb {N}}\), will be denoted, respectively, by \(LG_{\lambda ,\rho }, RG_{\lambda ,\rho }, G_{\lambda ,\rho }\). To simplify these notations, we generally drop the subscript \(\lambda ,\rho \).

We notice the following observation proved in [3].

Lemma 2.2

Let \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\). For every \(n\in {\mathbb {N}}\),

$$\begin{aligned} lg(n+1)\in \{0,lg(n)+1\},\quad rg(n+1)\ge rg(n)-1. \end{aligned}$$

Observe that, as a consequence of the above lemma, having LG infinite is equivalent to LG being \({\mathbb {N}}\).

We now gather in the next theorem the main results of [3].

Theorem 2.3

Consider two infinite words \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\). The following conditions are equivalent:

  1. (1)

    The set \(G_{\lambda ,\rho }\) is finite;

  2. (2)

    The set \(RG_{\lambda ,\rho }\) is finite;

  3. (3)

    \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w_1\) and \(\rho =w_2{u}^{\!\scriptscriptstyle {\,\infty }}\) for some words \(u,w_1,w_2\in A^*\).

Example 2.4

Consider the left-infinite word \(\lambda ={(b^2a^2)}^{\!{\scriptscriptstyle {-\!\infty }}}cab\) and the right-infinite word \(\rho ={(ab^2a)}^{\!\scriptscriptstyle {\,\infty }}\) over the alphabet \(A=\{a,b,c\}\). The values of the functions lg, rg and g for these words are shown in the following table

n

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

\(\cdots \)

lg(n)

0

1

0

1

2

3

4

5

6

7

8

9

10

11

12

\(\cdots \)

rg(n)

0

1

0

3

3

3

5

5

4

3

6

5

4

3

6

\(\cdots \)

g(n)

0

1

0

1

2

3

4

5

4

3

6

5

4

3

6

\(\cdots \)

So, \(LG={\mathbb {N}}\), \(RG=\{0,1,3,4,5,6\}\) and \(G=\{0,1,2,3,4,5,6\}\).

3 Asymptotic characterization of overlap functions with finite image

The purpose of this paper is to give an asymptotic characterization of the pairs of words in \(A^{-{\mathbb {N}}}\times A^{{\mathbb {N}}}\) for which the overlap gap function has finite image.

3.1 Asymptotic conditions on the function lg

We begin by studying asymptotic conditions over the “left overlap gap” function lg.

For words \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\), we let

$$K_{\lambda ,\rho }=\{n\in {\mathbb {N}}: lg(n)=0\}=\{n\in {\mathbb {N}}: rg(n)=0\}.$$

Notice that \(K_{\lambda ,\rho }\) is a non-empty set since \(0\in K_{\lambda ,\rho }\). Example 2.4 above provides an instance where \(K_{\lambda ,\rho }\) is finite. The next result presents some properties of the function lg when \(K_{\lambda ,\rho }\) is finite.

Proposition 3.1

Let \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\).

  1. (a)

    The set \(K_{\lambda ,\rho }\) is finite if and only if \(\lim \limits _{n\rightarrow \infty }\frac{lg(n)}{n} = 1\).

  2. (b)

    If \(K_{\lambda ,\rho }\) is finite, then \(LG_{\lambda ,\rho }\) is infinite.

Proof

Suppose that \(K_{\lambda ,\rho }\) is finite and let m be its maximum element. Then, by Lemma 2.2, \(lg(n)=n-m\) for every integer \(n\ge m\). Hence, \(LG={\mathbb {N}}\) thus proving (b). Moreover,

$$\lim \limits _{n\rightarrow \infty }\frac{lg(n)}{n} =\lim \limits _{n\rightarrow \infty }(1-\frac{m}{n})= 1$$

thus showing the direct implication of (a).

It remains to prove the reverse implication of (a). For that, suppose that \(\lim \limits _{n\rightarrow \infty }\frac{lg(n)}{n} = 1\). Then, \(K_{\lambda ,\rho }\) is finite. Otherwise, the sequence \(\big (lg(n)/n\big )_{n\in {\mathbb {N}}}\) would be equal to 0 for an infinite number of values of n, contradicting the hypothesis that it converges to 1.

\(\square \)

We notice that the converse of condition (b) of Proposition 3.1 above does not hold as shown by Example 3.3 below.

The next result characterizes the instances in which the sequence \(\big (lg(n)/n\big )_n\) converges to 0.

Theorem 3.2

Let \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\). The following conditions are equivalent:

  1. (1)

    The set \(LG_{\lambda ,\rho }\) is finite;

  2. (2)

    \(\lim \limits _{n\rightarrow \infty }\frac{lg(n)}{n} = 0\);

  3. (3)

    \(\lambda ={v}^{\!{\scriptscriptstyle {-\!\infty }}}\) and \(\rho ={u}^{\!\scriptscriptstyle {\,\infty }}\) for conjugate words \(v,u\in A^+\).

Proof

If \(LG_{\lambda ,\rho }\) is finite, it is immediate that the sequence \(\big (lg(n)/n\big )_n\) converges to zero. Hence condition (1) implies (2). To show that (3) implies (1), suppose that \(\lambda ={v}^{\!{\scriptscriptstyle {-\!\infty }}}\) and \(\rho ={u}^{\!\scriptscriptstyle {\,\infty }}\) for conjugate words \(v,u\in A^+\). Then, as one can easily verify, \(lg(n)<|v|=|u|\) for all n. Hence \(LG_{\lambda ,\rho }\) is finite. To conclude the equivalence of conditions (1)–(3), it remains to prove that (2) implies (3). For this, assume that the limit of \(\big (lg(n)/n\big )_n\) is zero. Then

$$\begin{aligned} \forall _{\delta \in {\mathbb {R}}^+}\;\exists _{N\in {\mathbb {N}}}\;\forall _{n\ge N}\quad \frac{lg(n)}{n}<\delta . \end{aligned}$$
(3.1)

Moreover, by Proposition 3.1 (a), the set \(K_{\lambda ,\rho }\) must be infinite. Let \(0<n_0<n_1<\dots<n_i<n_{i+1}<\dots \) be the sequence of all positive integers \(n_i\) such that \(lg(n_i) = 0\). Then, for each i,

$$\begin{aligned} \lambda _{n_i}=\rho _{n_i},\quad \lambda _{n_{i+1}}=u_i\lambda _{n_i},\quad \rho _{n_{i+1}}=\rho _{n_i}v_i, \end{aligned}$$

for words \(u_i\) and \(v_i\) of length \(k_i=n_{i+1}-n_i\). Therefore, \(u_i\rho _{n_i}=u_i\lambda _{n_i}=\lambda _{n_{i+1}}=\rho _{n_{i+1}}=\rho _{n_i}v_i\).

On the other hand, by Lemma 2.2, \(lg(n_i+k_i-1)=k_i-1\). Then, from (3.1), one deduces that

$$\begin{aligned} \forall _{\delta \in {\mathbb {R}}^+}\;\exists _{i_0\in {\mathbb {N}}}\;\forall _{i\ge i_0}\quad \frac{k_i}{n_i}<\frac{1}{n_i}+\frac{\delta }{1-\delta }. \end{aligned}$$

It is now easy to deduce that \(2k_i<n_i\) for every i greater than or equal to a certain \(i_0\in {\mathbb {N}}\) (considering for instance \(\delta =1/4\) and \(n_{i_0}\ge 6\)).

For each \(i\in {\mathbb {N}}\), with \(i\ge i_0\), let \(q_i=\lfloor \frac{n_i}{k_i}\rfloor \ge 2\) be the quotient in the integer division of \(n_i\) by \(k_i\). From the equality \(u_i\rho _{n_i}=\rho _{n_i}v_i\) and from the fact that \(u_i\) and \(v_i\) are words of length \(k_i\), it follows that

$$\begin{aligned} \rho _{n_i}=u_i^{q_i}u'_i=u'_iv_i^{q_i} \end{aligned}$$

with \(u_i=u'_iu''_i\) and \(v_i=u''_iu'_i\) for words \(u'_i\) and \(u''_i\) such that \(|u'_i|<k_i\).

Claim  The word \(u_i\) is primitive (whence its conjugate \(v_i\) is also primitive).

Proof

In order to attest the claim, suppose that \(u_i=z^p\) for some word z and some integer \(p>1\). Then \(v_i=y^p\) for some conjugate y of z, say \(z=z'z''\) and \(y=z''z'\), with \(u'_i=z^sz'\) and \(u''_i=z''z^{p-s -1}\). Let \(h=|z|\). Given that \(\rho _{n_i+h}\) is a prefix and \(\lambda _{n_i+h}\) is a suffix of \(\rho _{n_{i+1}}(=\lambda _{n_{i+1}})\), we have

$$\begin{aligned} \rho _{n_i+h}=u'_iv_i^{q_i}y=z^sz'y^{pq_i+1}=z^{pq_i+1}z^sz'=zu_i^{q_i}u'_i=\lambda _ {n_i+h}. \end{aligned}$$

So \(lg(n_i+h)=0\). Now \(n_i< n_i+h <n_{i+1}\) which contradicts the definition of the sequence \((n_i)_i\). So \(u_i\) is primitive, thus proving the claim. \(\square \)

Now, on the one hand, we have

$$\begin{aligned} \rho _{n_{i+1}}=u_{i+1}^{q_{i+1}}u'_{i+1} \end{aligned}$$

and on the other

$$\begin{aligned} \rho _{n_{i+1}}=u_i^{q_i+1}u'_i. \end{aligned}$$

As \(q_i\) and \(q_{i+1}\) are greater than 1, \(|\rho _{n_{i+1}}|\ge |u_{i+1}|+|u_i|\ge |u_{i+1}|+| u_i|-\gcd (|u_{i+1}|,|u_i|)\). Therefore, one can apply Fine and Wilf’s theorem (Proposition 2.1), and deduce that \(u_i\) and \(u_{i+1}\) are powers of the same word. But, by the Claim, \(u_i\) and \(u_{i+1}\) are primitive words. It follows that \(u_i=u_{i+1}\). Symmetrically, \(v_i=v_{i+1}\). As this is valid for all \(i\ge i_0\), it follows that there are conjugate words u and v such that \(u_i=u\) and \(v_i=v\) for all \(i\ge i_0\). Therefore, from the fact that \(\rho _{n_i}(=\lambda _{n_i})\) is a prefix of \(\rho \) and a suffix of \(\lambda \),

$$\forall m\in {\mathbb {N}}\quad u^m \text{ is } \text{ a } \text{ prefix } \text{ of } \rho \text{ and } v^m \text{ is } \text{ a } \text{ suffix } \text{ of } \lambda \text{, }$$

wherefore \(\rho ={u}^{\!\scriptscriptstyle {\,\infty }}\) and \(\lambda ={v}^{\!{\scriptscriptstyle {-\!\infty }}}\). Therefore, the condition (3) is valid and the proof of the theorem is finished. \(\square \)

A given sequence \((g_k)_{k}\) of words of \(A^*\) with \(g_0\ne \varepsilon \), defines a so-called bi-ideal sequence \((f_k)_{k}\) as

$$f_0=g_0,\ f_{k+1}=f_kg_{k+1}f_k, \text{ for } k\in {\mathbb {N}}.$$

Since each word \(f_k\) is a prefix of the next term \(f_{k+1}\), the bi-ideal sequence \((f_k)_{k}\) converges to a right-infinite word

$$\begin{array}{rcl} \rho &{}=&{}f_0(g_1f_0)(g_2f_1)(g_3f_2)\cdots (g_{k+1}f_{k})\cdots \\ &{}=&{}g_0g_1g_0g_2g_0g_1g_0g_3g_0g_1g_0g_2g_0g_1g_0\cdots . \end{array}$$

Dually, each \(f_k\) is a suffix of \(f_{k+1}\), whence the bi-ideal sequence \((f_k)_{k}\) converges to a left-infinite word

$$\begin{array}{rcl} \lambda &{}=&{}\cdots (f_kg_{k+1})\cdots (f_2g_3)(f_1g_2)(f_0g_1)f_0\\ &{}=&{}\cdots g_0g_1g_0g_2g_0g_1g_0g_3g_0g_1g_0g_2g_0g_1g_0. \end{array}$$

It also follows that each \(f_k\) is simultaneously a suffix of \(\lambda \) and a prefix of \(\rho \). Therefore \(lg(n)=rg(n)=0\) for an infinite number of natural numbers n. That is \(K_{\lambda ,\rho }\) is an infinite set.

In the next example, we present a bi-ideal sequence of words which converges to words \(\lambda \) and \(\rho \) for which the sequence \(\big (\frac{lg(n)}{n}\big )_{n}\) diverges. As \(K_{\lambda ,\rho }\) is infinite this exhibits a counterexample for the converse of condition (b) of Proposition 3.1.

Example 3.3

Let \((f_k)_{k}\) be the bi-ideal sequence of words over the alphabet \(A=\{a,b\}\) defined by the sequence \((a,b,a,b,a,b,\ldots )\). That is,

$$f_0=a,\ f_{k+1}=f_kbf_k \text{ if } \text{ k } \text{ is } \text{ even },\ f_{k+1}=f_kaf_k \text{ if } \text{ k } \text{ is } \text{ odd }.$$

Notice that \(|f_k|=2^{k+1}-1\). So, the bi-ideal sequence \((f_k)_k\) defines a left-infinite word \(\lambda \in A^{-{\mathbb {N}}}\) and a right-infinite word \(\rho \in A^{{\mathbb {N}}}\) such that

$$\lambda _n= f_k= \rho _n\qquad \text{ for } n=2^{k+1}-1$$

and so \(lg(n)= rg(n)=0\) for those n. For instance

$$\lambda _{15}=aba\,a\,aba\,b\,aba\,a\,aba=\rho _{15}.$$

The values lg(n), rg(n) and g(n), for \(n\le 15\), are shown in the following table

n

0

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

\(\cdots \)

lg(n)

0

0

1

0

1

2

3

0

1

2

3

4

5

6

7

0

\(\cdots \)

rg(n)

0

0

1

0

2

2

1

0

5

4

5

4

3

2

1

0

\(\cdots \)

g(n)

0

0

1

0

1

2

1

0

1

2

3

4

3

2

1

0

\(\cdots \)

Moreover, it can be shown that,

  • The words \(\lambda \) and \(\rho \) are not ultimately periodic;

  • For \(m=2^k+2^{k-1}-1\), with \(k\ge 1\),

    $$lg(m)= rg(m)=g(m)=2^{k-1},$$

    whence LG, RG and G are infinite sets, and \(\frac{ lg(m)}{m+1}=\frac{1}{3}\). Therefore, the subsequence \(\big (\frac{lg(m)}{m}\big )_m\) of \(\big (\frac{lg(n)}{n}\big )_{n\in {\mathbb {N}}}\) converges to \(\frac{1}{3}\) and, so, \(\big (\frac{lg(n)}{n}\big )_{n\in {\mathbb {N}}}\) does not converge.

3.2 Asymptotic conditions on the function rg

In this section, we consider asymptotic conditions over the “right overlap gap” function rg.

We begin by noticing that rg does not enjoy properties analogous to those of the lg function presented in Proposition 3.1. Indeed, Example 2.4 above gives an instance in which \(K_{\lambda ,\rho }\) is finite but \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\ne 1\) and \(RG_{\lambda ,\rho }\) is finite. Moreover it may happen that \(K_{\lambda ,\rho }\) is finite and \(RG_{\lambda ,\rho }\) is infinite. This happens, for instance, when \(\lambda ={a}^{\!{\scriptscriptstyle {-\!\infty }}}\) and \(\rho ={b}^{\!\scriptscriptstyle {\,\infty }}\) since in this case \(rg(n)=n\) for every n. Also note that in this example \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 1\).

The next result characterizes the cases in which a sequence \(\big (rg(n)/n\big )_n\) converges to 0 and is the analogue of Theorem 3.2 for the function rg.

Theorem 3.4

For two given words \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\), \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\) if and only if \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w_1\) and \(\rho =w_2{u}^{\!\scriptscriptstyle {\,\infty }}\) for some words \(u,w_1,w_2\in A^*\).

Proof

Suppose that \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w_1\) and \(\rho =w_2{u}^{\!\scriptscriptstyle {\,\infty }}\) with \(u,w_1,w_2\in A^*\). Then, by Theorem 2.3, the set \(RG_{\lambda ,\rho }\) is finite. It is hence clear that \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\).

Conversely, assume that the limit of \(\big (rg(n)/n\big )_n\) is zero. Then

$$\forall _{\delta \in {\mathbb {R}}^+}\;\exists _{n_0\in {\mathbb {N}}}\;\forall _{n\ge n_0}\quad \frac{rg(n)}{n}<\delta .$$

Take, in particular, \(\delta =1/20\). So, there is an integer \(m\ge 10\) such that

$$\begin{aligned} \forall _{n\ge m}\quad rg(n)<\frac{n}{20}. \end{aligned}$$
(3.2)

Let \(n\ge m\) be an arbitrary integer. Then, by (3.2), for each \(j\in \{0,1,2,\dots ,n\}\),

$$rg(n+j)<\frac{n+j}{20}\le \frac{2n}{20}=\frac{n}{10}.$$

It follows that \(rg(n+j)< \lceil \frac{n}{10}\rceil \) for all \(j\in \{0,1,\dots ,\lceil \frac{n}{10}\rceil \}\). Therefore, by the pigeonhole principle, there are integers \(j,j'\) and \(s_n\) such that \(0\le j<j'\le \lceil \frac{n}{10}\rceil \), \(0\le s_n< \lceil \frac{n}{10}\rceil \) and \(rg(n+j) = rg(n+j') =s_n\). Let \(k=j'-j\). So, there are words \(t_n,u_n\) and \(v_n\) with \(|u_n|=|v_n|=k\), such that

$$\begin{array}{rclrcll} \lambda _{n+j}&{}=&{}t_n\lambda _{s_n},&{}\rho _{n+j}&{}=&{}\rho _{s_n}t_n,\\ \lambda _{n+j'}&{}=&{}v_nt_n\lambda _{s_n}, \qquad &{} \rho _{n+j'}&{}=&{}\rho _{s_n}t_nu_n, \end{array}$$

where \(t_nu_n=v_nt_n\). From this equality one deduces that \(t_n=xu_n^p =v_n^px\) for a positive integer p and a word x which is a proper suffix of \(u_n\) (and a proper prefix of \(v_n\)). Hence \(u_n\) and \(v_n\) are conjugate words and \(\lambda _{n+j}=xu_n^p\lambda _{s_n}\) and \(\rho _{n+j}=\rho _{s_n}v_n^px\). It follows that

$$\begin{aligned} \lambda _{n}=u'_nu_n^{q_n}\lambda _{s_n},\quad \rho _{n}=\rho _{s_n}v_n^{q_n}u'_n, \end{aligned}$$
(3.3)

with \(q_n\in \mathbb {N}\) and \(u'_n\) a proper suffix of \(u_n\) and prefix of \(v_n\). By replacing \(u_n\) and \(v_n\) by their respective primitive roots, if necessary, we may assume that \(u_n\) and \(v_n\) are primitive words. We may further assume that \(s_n\) is chosen as small as possible, meaning that either \(s_n\) is zero or the first letters of \(u_n\) and \(\lambda _{s_n}\) (resp. the last letters of \(v_n\) and \(\rho _{s_n}\)) do not coincide.

Equation (3.3) holds for any \(n\ge m\). Therefore, \(\lambda _{n}\) and \(\lambda _{n+1}\) are of the forms

$$\lambda _{n}=u'_nu_n^{q_n}\lambda _{s_n}\quad \text{ and }\quad \lambda _{n+1}=u'_{n+1}u_{n+1}^{q_{n+1}}\lambda _{s_{n+1}}.$$

On the other hand \(\lambda _{n+1}=a \lambda _n=au'_nu_n^{q_n}\lambda _{s_n}\) for some letter \(a\in A\). Now, as \(s_n,s_{n+1}< \lceil \frac{n+1}{10}\rceil \) and \(|u_n|, |u_{n+1}|\le \lceil \frac{n+1}{10}\rceil \), there is a prefix w of \(u_n^{q_n}\) such that \(|w|=|u_n|+ |u_{n+1}|\) and w is a prefix of a power of a conjugate \(\tilde{u}_{n+1}\) of \(u_{n+1}\). By Fine and Wilf’s Theorem \(u_n\) and \(\tilde{u}_{n+1}\) are powers of the same word. Since \(u_n\) and \(\tilde{u}_{n+1}\) are primitive, they are equal. Hence \(u_n\) and \(u_{n+1}\) are conjugate. Moreover, by the choice of a minimal \(s_n\) (and \(s_{n+1}\)), it follows that \(\lambda _{s_n}=\lambda _{s_{n+1}}\) and \(u_n=u_{n+1}\).

By induction on n, one deduces that \(\lambda _{s_n}=\lambda _{s_m}\) and \(u_n=u_m\) for every \(n\ge m\). Let \(w_1=\lambda _{s_m}\) and \(u=u_m\). Hence \(\lambda _{n}=u'_nu^{q_n}w_1\) for every \(n\ge m\), so that \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w_1\).

By symmetry \(\rho =z{v}^{\!\scriptscriptstyle {\,\infty }}\) for \(v=v_m\) and \(z=\rho _{s_m}\). Since \(u_m\) and \(v_m\) are conjugate words, the word v is a conjugate of u, say \(u=u''_mu'_m\) and \(v=u'_mu''_m\). Therefore \(\rho =w_2{u}^{\!\scriptscriptstyle {\,\infty }}\), with \(w_2=zu'_m\), which concludes the proof of the theorem. \(\square \)

3.3 Asymptotic conditions on the function g

We conclude our asymptotic study with the “overlap gap” function g by proving the following result.

Theorem 3.5

For words \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\), \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\) if and only if \(\lim \limits _{n\rightarrow \infty }\frac{g(n)}{n} = 0\).

Proof

The direct implication follows immediately from the fact that \(0\le g(n)\le rg(n)\) for every \(n\in {\mathbb {N}}\).

Conversely, suppose that \(\lim \limits _{n\rightarrow \infty }\frac{g(n)}{n} = 0\). Let

$$D=\{n\in {\mathbb {N}}:g(n)=rg(n) \}\quad \text{ and }\quad E=\{n\in {\mathbb {N}}:g(n)=lg(n)\}$$

and notice that \(\emptyset \ne K_{\lambda ,\rho }\subseteq D\cap E\) and \({\mathbb {N}}=D\cup E\).

If \(E\setminus D\) is a finite set, then \(g(n)=rg(n)\) for all n greater than or equal to a certain threshold and so, of course, \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\).

Suppose, otherwise, that \(E\setminus D\) is an infinite set. Then E is also infinite and, thus, \(\big (lg(n)/n\big )_n\) has a subsequence convergent to 0. Hence, condition \(\lim \limits _{n\rightarrow \infty }\frac{lg(n)}{n} = 1\) does not hold and so, by Proposition 3.1 (a), \(K_{\lambda ,\rho }\) is infinite.

Now, if \(D\setminus E\) is finite, then \(\lim \limits _{n\rightarrow \infty }\frac{lg(n)}{n} = 0\). In this case, by Theorem 3.2, \(\lambda ={v}^{\!{\scriptscriptstyle {-\!\infty }}}\) and \(\rho ={u}^{\!\scriptscriptstyle {\,\infty }}\) for conjugate words \(v,u\in A^+\). Applying Theorem 3.4, one deduces that \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\).

To complete the proof of the theorem it remains to consider the case in which \(D\setminus E\) and E are infinite sets. In this case, both sequences \(\big (rg(d)/d\big )_{d\in D}\) and \(\big (lg(e)/e\big )_{e\in E}\) converge to 0. As shown above, \(K_{\lambda ,\rho }\) is infinite, say

$$K_{\lambda ,\rho }=\{n_0,n_1,n_2,\ldots :n_i<n_{i+1} \text{ for } \text{ all } i\in {\mathbb {N}}\},$$

so that the \(n_i\) are precisely the non-negative integers whose images under lg and rg are 0. Moreover, for each i, \(lg(n_i+m)=m\) for every \(m\in \{1,2,\dots ,k_i-1\}\), where \(k_i=n_{i+1}-n_i\).

Suppose that \(2k_i<n_i\) for every i greater than or equal to a certain \(i_0\in {\mathbb {N}}\). With this hypothesis, it was proved in Theorem 3.2 that \(\lambda ={v}^{\!{\scriptscriptstyle {-\!\infty }}}\) and \(\rho ={u}^{\!\scriptscriptstyle {\,\infty }}\) for conjugate words \(v,u\in A^+\). Hence, using Theorem 3.4, one deduces that \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\).

Suppose, on the contrary, that \(2k_i\ge n_i\) for an infinite number of values of \(i\in {\mathbb {N}}\). Let i be one such value with \(n_i\ge 10\). Let \(\ell _i=\lceil \frac{n_i}{10}\rceil \) and \(j_i\in \{0,1,2,\dots ,\ell _i\}\). Then

$$\frac{lg(n_i+\ell _i+j_i)}{n_i+\ell _i+j_i}=\frac{\ell _i+j_i}{n_i+\ell _i+j_i}\ge \frac{\frac{n_i}{10}}{2n_i}=\frac{1}{20}.$$

Hence, if there would exist an infinite number of pairs \((i,j_i)\) as above such that \(g(n_i+\ell _i+j_i)=lg(n_i+\ell _i+j_i)\), then the sequence \(\big (g(n)/n\big )_n\) would not converge to 0, in contradiction with our assumptions. Therefore, one must have \(g(n_i+\ell _i+j_i)=rg(n_i+\ell _i+j_i)<\frac{n_i}{10}\) for a certain \(i_0\in {\mathbb {N}}\) and every \(i\ge i_0\) and \(j_i\in \{0,1,2,\dots ,\ell _i\}\). Now, proceeding exactly as in the proof of Theorem 3.4, we get the following equalities, analogous to (3.3),

$$\begin{aligned} \lambda _{n_i}=u'_{n_i}u_{n_i}^{q_{n_i}}\lambda _{s_{n_i}},\quad \rho _{n_i}=\rho _{s_{n_i}}v_{n_i}^{q_{n_i}}u'_{n_i}, \end{aligned}$$
(3.4)

with \(u_{n_i}\) and \(v_{n_i}\) conjugate words of length \(k_i\in \{1,2,\dots ,\ell _i\}\), \(q_{n_i}\in \mathbb {N}\) and \(u'_{n_i}\) a proper suffix of \(u_{n_i}\) and prefix of \(v_{n_i}\) and \(0\le s_{n_i}< \ell _i\). But in the current circumstances \(lg(n_i)=rg(n_i)=0\), meaning that \(\lambda _{n_i}=\rho _{n_i}\). From this, one deduces that \(\lambda _{s_{n_i}}\) and \(\rho _{s_{n_i}}\) are the empty word, which is equivalent to saying that \(s_{n_i}=0\). Hence, as in the proof of Claim 3.1 within the proof of Theorem 3.2, one can show that \(lg(n_i+k_i)=0\). But this is impossible since \(n_i< n_i+k_i <n_{i+1}\) and \(n_i\) and \(n_{i+1}\) are consecutive integers with value lg equal to 0. The contradiction comes from the assumption that \(2k_i\ge n_i\) for an infinite number of values of \(i\in {\mathbb {N}}\). So this case cannot really happen. The proof of the theorem is therefore complete. \(\square \)

Theorems 3.4 and 3.5 provide the following extension of Theorem 2.3.

Theorem 3.6

Consider two infinite words \(\lambda \in A^{-{\mathbb {N}}}\) and \(\rho \in A^{{\mathbb {N}}}\). The following conditions are equivalent:

  1. (1)

    The set \(G_{\lambda ,\rho }\) is finite;

  2. (2)

    The set \(RG_{\lambda ,\rho }\) is finite;

  3. (3)

    \(\lambda ={u}^{\!{\scriptscriptstyle {-\!\infty }}}w_1\) and \(\rho =w_2{u}^{\!\scriptscriptstyle {\,\infty }}\) for some words \(u,w_1,w_2\in A^*\);

  4. (4)

    \(\lim \limits _{n\rightarrow \infty }\frac{rg(n)}{n} = 0\);

  5. (5)

    \(\lim \limits _{n\rightarrow \infty }\frac{g(n)}{n} = 0\).