Abstract 1 Introduction 2 Preliminaries 3 Lower Bound 4 Upper Bound 5 Limitations of our Approach 6 Final Remarks References

Improved Bounds on the Maximum Number of Distinct Squares in Circular Words

Panagiotis Charalampopoulos ORCID King’s College London, UK    Manal Mohamed ORCID King’s College London, UK    Jakub Radoszewski ORCID University of Warsaw, Poland    Wojciech Rytter ORCID University of Warsaw, Poland    Tomasz Waleń ORCID University of Warsaw, Poland    Wiktor Zuba ORCID University of Warsaw, Poland
Abstract

We investigate the asymptotic growth of function 𝖢𝖲⁢(n), which maps n to the maximum number of distinct squares in a circular word of length n (that is, the maximum number of distinct squares of length at most n in a word w⁢w of length 2⁢n). We improve upon the lower bound of 1.25⁢n established by Amit and Gawrychowski [SPIRE 2017] and the straightforward upper bound of 2⁢n, which follows from the recent result of Brlek and Li [Comb. Theory, 2025] stating that there are fewer than n squares in standard (i.e., non-circular) words of length n. (Previously, Amit and Gawrychowski gave an upper bound of 3⁤215⁢n using a weaker upper bound on squares in standard words.) Specifically, we show that 𝖢𝖲⁢(n)≤⌈ 1.8⁢n⌉ and that, for infinitely many n, 𝖢𝖲⁢(n)≥ 1.5⁢n−𝒪⁢(n).

For the lower bound, we exploit the combinatorial structure of Fibonacci words to construct a family of square-rich circular words. For the upper bound, we exploit density properties of the starting positions of long squares, adapting an approach of Amit and Gawrychowski.

Keywords and phrases:
circular words, squares, repetitions
Funding:
Jakub Radoszewski: Supported by the Polish National Science Center, grant no. 2022/46/E/ST6/00463.
Copyright and License:
[Uncaptioned image] © Panagiotis Charalampopoulos, Manal Mohamed, Jakub Radoszewski, Wojciech Rytter,
Tomasz Waleń, and Wiktor Zuba; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Mathematics of computing → Combinatorics on words
Editors:
Philip Bille and Nicola Prezza

1 Introduction

The study of square and symmetric fragments of words is central in combinatorics and algorithms on words. A square is a word of the form u⁢u for a word u. Here, we focus on square fragments of circular words. That is, for a standard word w, we study the square fragments that occur in any rotation of w or, equivalently, the square fragments of w⁢w that are of length at most |w|.

The earliest result concerning squares in words is the construction of square-free ternary words of all lengths by Thue [19]. The analogue of this problem for circular words is more intricate. Currie [4] showed that square-free circular words over the ternary alphabet exist for all lengths except for 5, 7, 9, 10, 14, and 17 using a computer-aided proof. Shur [16] later gave a computer-free proof that also implied an exponential (in the length) lower bound on the number of such words of any fixed length.

Let 𝖲𝖰⁢(n) be the maximum number of distinct squares in a (standard) word of length n. Fraenkel and Simpson [7] proved that 𝖲𝖰⁢(n)<2⁢n and conjectured that 𝖲𝖰⁢(n)<n. The resolution of this conjecture took more than two decades. Milestone results include the upper bound of 2⁢n−log⁡n due to Ilie [9], the upper bound of 116⁢n due to Deza, Franek, and Thierry [5], and the upper bound of 1.5⁢n due to Thierry [18]. Finally, Brlek and Li [3] confirmed the Fraenkel-Simpson conjecture using a graph-theoretic approach, establishing that 𝖲𝖰⁢(n)<n.

Let 𝖢𝖲⁢(n) denote the maximum number of distinct squares in a circular word of length n. The growth of 𝖢𝖲⁢(n) was first studied by Amit and Gawrychowski [1] who showed an upper bound of 3⁤215⁢n and a lower bound of 1.25⁢n (for infinitely many n). Note that this work was published when the best known upper bound for standard squares was 𝖲𝖰⁢(n)≤116⁢n. Further, observe that the number of squares of length at most n in a word w⁢w is at most 𝖲𝖰⁢(2⁢|w|). The result of Brlek and Li [3] thus implies that 𝖢𝖲⁢(n)≤𝖲𝖰⁢(2⁢n)<2⁢n.

Our results.

Here, we improve upon both the upper bound of 2⁢n that follows from [3] and the lower bound of 1.25⁢n from [1] for 𝖢𝖲⁢(n). Specifically, we show that 𝖢𝖲⁢(n)≤⌈1.8⁢n⌉ for all n and that 𝖢𝖲⁢(n)≥1.5⁢n−𝒪⁢(n) for infinitely many n.

Our lower and upper bounds are presented in Section 3 and Section 4, respectively. Then, Section 5 discusses the limitations of our approach.

Discussion.

As we remark at the end of Section 4, the proof of the 3⁤215⁢n upper bound of Amit and Gawrychowski could be modified to yield an upper bound of ⌈137⁢n⌉ by incorporating the upper bound of n for standard squares. However, the resulting argument remains technically involved. We establish a stronger upper bound of ⌈1.8⁢n⌉ and also a (still stronger) upper bound of ⌈116⁢n⌉ which is considerably simpler.

2 Preliminaries

A word u=u⁢[0]⁢⋯⁢u⁢[n−1] is a sequence of length |u|=n of letters from some alphabet. For any two integers i,j∈[0..|u|), u⁢[i⁢..⁢j] and u[i..j+1) denote the fragment u⁢[i]⁢⋯⁢u⁢[j] if i≤j and the empty word otherwise. A fragment u⁢[0⁢..⁢j] is called a prefix of u. A prefix of u is called a proper prefix of u if its length is smaller than n. A fragment u⁢[i⁢..⁢n−1] is called a suffix of u.

We say that integer p∈[1⁢..⁢|u|] is a period of a word u if u⁢[i]=u⁢[i+p] for all i∈[0..|u|−p). We denote the smallest period of u by per⁢(u). We say that u is periodic if per⁢(u)≤12⁢|u|; otherwise u is called non-periodic.

Lemma 1 (Periodicity Lemma [6]).

If a word u has periods p and q such that p+q≤|u|+gcd⁡(p,q), then gcd⁡(p,q) is also a period of u.

A word u is called primitive if the equality u=vk for a positive integer k implies that k=1. Primitive words satisfy the following synchronization property that follows from the periodicity lemma: a primitive word u occurs in u2 only as a prefix and as a suffix.

For a word u, for any integer i∈[0..|u|), we call u[i..|u|)u[0..i) a rotation of u.

For a word w, we denote by 𝐒n⁢(w) the set of squares of length at most n that occur w. Thus, the set of squares of a circular word w equals 𝐒n⁢(w2), where n=|w|.

Fibonacci words are defined by the recurrence

F0=b,F1=a,Ft=Ft−1⁢Ft−2⁢ for ⁢t≥2.

The number of distinct squares in the (standard) word Fn is equal to 2⁢|Fn−2|−2; see [8]. As a warm-up, we show an exact bound on the number of squares in circular Fibonacci words.

Fact 2.

If n≥2, |𝐒|Fn|⁢(Fn⁢Fn)|=|Fn|−2.

Proof.

Every square in Fn is a square of a rotation of some shorter Fibonacci word; see [10, Theorem 2.3]. The same holds for Fn2 since Fn2 is a prefix of the infinite Fibonacci word for n≥3, and for n≤2 it can be easily verified.

For n=2, we have 𝐒|Fn|⁢(Fn⁢Fn)=∅ as expected. Assume n≥3. The set 𝐒|Fn|⁢(Fn2) does not contain F02=b⁢b and Fn−12 (because 2⁢|Fn−1|>|Fn|). Let us show by induction that for all k∈[1⁢..⁢n−2], each rotation of Fk2 occurs in Fn2. Correctness in the base cases of n∈{3,4} can be easily checked. Assume that n≥5 and the property holds for n−1. By the hypothesis, Fn−12 contains all rotations of Fk2 for k∈[1⁢..⁢n−3]. Since n≥4, Fn−12 is a prefix of Fn2, so all these squares are also in 𝐒|Fn|⁢(Fn2). Moreover, Fn has a suffix Fn−2 and a prefix Fn−22 (since n−2≥3). Hence, Fn2 has a fragment Fn−23, so each rotation of Fn−22 occurs in Fn2.

In total, we obtain |F1|+|F2|+⋯+|Fn−2|=|Fn|−2 squares. All these squares are different because each Fibonacci word is primitive. ◀

Example 3.

We have

F2=a⁢b,F3=a⁢b⁢a,F4=a⁢b⁢a⁢a⁢b,F5=a⁢b⁢a⁢a⁢b⁢a⁢b⁢a,F6=a⁢b⁢a⁢a⁢b⁢a⁢b⁢a⁢a⁢b⁢a⁢a⁢b.

For F6, we have

𝐒13⁢(F6)={a2,(a⁢b)2,(b⁢a)2,(a⁢b⁢a)2,(a⁢a⁢b)2,(b⁢a⁢a)2,(a⁢b⁢a⁢a⁢b)2,(b⁢a⁢a⁢b⁢a)2},

and

𝐒13⁢(F62)=𝐒n⁢(F6)∪{(a⁢a⁢b⁢a⁢b)2,(a⁢b⁢a⁢b⁢a)2,(b⁢a⁢b⁢a⁢a)2}.

In particular, F6 has 8=2⁢|F3|−2 distinct squares, while the circular F6 contains 11=|F6|−2 distinct squares in total.

3 Lower Bound

We use Fibonacci words as building blocks. For any word v of length at least two, let 𝐜𝐮𝐭(v):=v[0..|v|−2) be the word obtained from v by deleting its two last letters. Let 𝐞𝐱⁢(v) denote the word v with the last two letter exchanged, that is, 𝐞𝐱⁢(v):=𝐜𝐮𝐭⁢(v)⁢v⁢[|v|−1]⁢v⁢[|v|−2].

Example 4.

𝐜𝐮𝐭⁢(a⁢b⁢c⁢d⁢e)=a⁢b⁢c and 𝐞𝐱⁢(a⁢b⁢c⁢d)=a⁢b⁢d⁢c.

The following (folklore) property of Fibonacci words follows by a straightforward inductive argument.

Observation 5.

For t≥2, we have 𝐜𝐮𝐭⁢(Ft)=𝐜𝐮𝐭⁢(Ft−2⁢Ft−1) and 𝐞𝐱⁢(Ft)=Ft−2⁢Ft−1.

The next observation follows directly from the synchronization property of primitive words; see Figure 1.

Figure 1: Illustration of Observation 6(a). For the primitive word u=abcd and its proper prefix u′=ab, the word u2⁢u′ contains |u′|+1 distinct squares of length |u2|: (abcd)2, (bcda)2, (cdab)2.
Figure 2: The structure of 𝒲k,t for k=2 and t≥2: 𝒲k,t=A2⁢B⁢A3⁢B⁢A4⁢B, where A=Ft and B=Ft−1. We have 𝒲k,t=(A⁢A⁢B⁢A)2⁢A⁢A⁢B⁢A′, where A′=𝐞𝐱⁢(A). We have α=|Ftk|=2⁢|A| and |𝒲2,t|=3⁢α+3⁢|A⁢B|.
Observation 6 (Squares in periodic fragments).
  1. (a)

    If u′ is a proper prefix of a primitive word u, then u⁢u⁢u′ contains |u′|+1 distinct squares of length |u⁢u|.

  2. (b)

    uk contains at least ⌊k−12⌋⁢|u| words that are rotations of words in {u2⁢j∣1≤j≤12⁢k} and are pairwise distinct.

Before describing our construction, we first identify the primitive roots of the squares under consideration. These roots correspond to rotations of squares of words of the following types.

Observation 7 (Primitive words).

For any i>0 and t≥1, the words Ft−1,Fti⁢Ft−1, and Fti⁢Ft−1⁢Ft are primitive.

Proof.

For any t≥1, words Ft−1 and Ftk⁢Ft−1 are standard Sturmian words for k≥1. Since every standard Sturmian word is primitive (cf. [15]), it follows that all words of the form Ft−1 and Fti⁢Ft−1 are primitive. Moreover, since any rotation of a primitive word is primitive, the word Fti⁢Ft−1⁢Ft is primitive as its rotation Fti+1⁢Ft−1 is primitive. ◀

The construction.

We define an infinite family of words. For any k,t∈ℤ+, let

𝒲k,t:=Ftk⁢Ft−1⁢Ftk+1⁢Ft−1⁢Ftk+2⁢Ft−1.

Note that 𝒲k,t is parametrized by both k and t (eventually, we will set k:=|Ft|), and let n:=|𝒲k,t|. For convenience, we express bounds on the lengths of fragments and the number of square fragments in terms of

α:=|Ftk|=k⁢|Ft|.

Note that we have

|𝒲k,t|=(3⁢k+3)⁢|Ft|+3⁢|Ft−1|= 3⁢α+ 3⁢|Ft+1|. (1)

Squares in 𝓦𝒌,𝒕 and 𝓦𝒌,𝒕𝟐.

We show that the words 𝒲k,t are almost cubes (except the last two letters); see Figure 2 for an illustration.

Lemma 8.

For all k,t∈ℤ+, we have that 𝐜𝐮𝐭⁢(𝒲k,t)=𝐜𝐮𝐭⁢((Ftk⁢Ft−1⁢Ft)3). Further, 𝒲k,t contains at least α distinct squares which are rotations of (Ftk+1⁢Ft−1)2.

Proof.

We have

𝒲k,t=Ftk⁢Ft−1⁢Ftk+1⁢Ft−1⁢Ftk+2⁢Ft−1=(Ftk⁢Ft−1⁢Ft)⁢(Ftk⁢Ft−1⁢Ft)⁢Ftk⁢Ft⁢Ft−1.

By Observation 5,

𝐜𝐮𝐭⁢(𝒲k,t)=(Ftk⁢Ft−1⁢Ft)⁢(Ftk⁢Ft−1⁢Ft)⁢(Ftk⁢𝐜𝐮𝐭⁢(Ft−1⁢Ft))=𝐜𝐮𝐭⁢((Ftk⁢Ft−1⁢Ft)3).

Hence, 𝐜𝐮𝐭⁢((Ftk⁢Ft−1⁢Ft)3) is a prefix of 𝒲k,t. Now, Ftk⁢Ft−1⁢Ft is primitive due to Observation 7 and the second part of the statement follows by a direct application of Observation 6. ◀

Lemma 9.

If t≥2 and k>0, 𝒲k,t2 contains more than 2⁢α distinct squares that are rotations of (Ftk⁢Ft−1)2 and (Ftk+2⁢Ft−1)2.

Proof.

We denote ℛ1:=(Ftk⁢Ft−1)3 and ℛ2:=(Ftk+1⁢Ft−1⁢Ft)2⁢Ftk. We show that both ℛ1 and ℛ2 occur in 𝒲k,t2; see Figure 3. Then we obtain the statement using Observation 7 and Observation 6.

Figure 3: Illustration of Lemma 9: Structure of 𝒲k,t2 for k=3. The upper periodic fragment ℛ1=(Ftk⁢Ft−1)3 in 𝒲3,t2 does not occur in 𝒲3,t. The lower periodic fragment is ℛ2=(Ftk+1⁢Ft−1⁢Ft)2⁢Ftk. Together, these two periodic fragments contain at least 2⁢α distinct squares of length at most n.

We first show that ℛ1 occurs in 𝒲k,t2. The word

𝒲k,t2=Ftk⁢Ft−1⁢Ftk+1⁢Ft−1⁢ Ftk+2⁢Ft−1⁢Ftk⁢Ft−1⁢Ftk+1⁢Ft−1⁢Ftk+2⁢Ft−1

has a fragment equal to Ftk+2⁢Ft−1⁢Ftk⁢Ft−1⁢Ftk+1, which in turn has a fragment equal to (Ftk⁢Ft−1)⁢(Ftk⁢Ft−1)⁢Ftk⁢Ft−1=ℛ1. Thus, 𝒲k,t2 contains more than α distinct squares which are rotations of (Ftk⁢Ft−1)2.

Next, we show that ℛ2 occurs in 𝒲k,t2. The word

𝒲k,t2=Ftk⁢Ft−1⁢ Ftk+1⁢Ft−1⁢Ftk+2⁢Ft−1⁢Ftk⁢Ft−1⁢Ftk+1⁢Ft−1⁢Ftk+2⁢Ft−1

contains a fragment equal to

Ftk+1⁢Ft−1⁢Ft⁢Ftk+1⁢Ft−1⁢Ft⁢Ftk−1⁢Ft−1⁢Ftk+1

which itself has a fragment equal to

(Ftk+1⁢Ft−1⁢Ft)⁢(Ftk+1⁢Ft−1⁢Ft)⁢Ftk−1⁢Ft−1⁢Ft

which is equal to 𝐞𝐱⁢((Ftk+1⁢Ft−1⁢Ft)2⁢Ftk⁢Ft−1), since Ft−1⁢Ft=𝐞𝐱⁢(Ft⁢Ft−1). Now, observe that ℛ2=(Ftk+1⁢Ft−1⁢Ft)2⁢Ftk is a prefix of this fragment. Thus 𝒲k,t2 contains |Ftk|+1=α+1 distinct squares which are rotations of (Ftk+1⁢Ft−1⁢Ft)2.

Since Ftk⁢Ft−1 and Ftk+2⁢Ft−1 have different lengths, all considered square fragments are distinct and this concludes the proof. ◀

Lemma 10.

If k≤|Ft| then 𝒲k,t contains at least α−𝒪⁢(|Ft|) distinct squares which are rotations of (Ftj⁢Ft−1)2 for 0<j<k.

Proof.

The word 𝒲k,t contains the fragment Ftk+1⁢Ft−1⁢Ftk+2; see Figure 4. For each j≤k it contains the fragment

Ftj⁢Ft−1⁢Ftj+2= Ftj⁢Ft−1⁢Ftj⁢Ft−1⁢Ft−2⁢Ft−1⁢Ft−2=Ftj⁢Ft−1⁢Ftj⁢Ft−1⁢𝐞𝐱⁢(Ft−1⁢Ft−2)⁢Ft−2,

which contains the fragment (Ftj⁢Ft−1)2⁢𝐜𝐮𝐭⁢(Ft).

By Observations 6 and 7, each such fragment, (Ftj⁢Ft−1)2⁢𝐜𝐮𝐭⁢(Ft), contains |𝐜𝐮𝐭⁢(Ft)|+1=|Ft|−1 distinct squares that are rotations of (Ftj⁢Ft−1)2.

Summing over all 0<j<k, we obtain at least (|Ft|−1)⋅(k−1)=α−𝒪⁢(|Ft|) distinct squares of the claimed form. ◀

Figure 4: Illustration of Lemma 10. For k=4,t=4, let A=Ft=a⁢b⁢a⁢a⁢b,B=Ft−1=a⁢b⁢a, and C=𝐜𝐮𝐭⁢(Ft)=a⁢b⁢a. Then 𝒲k,t contains the fragment Ftk⁢Ft−1⁢Ftk+2, which in turn contains the fragments (Aj⁢B)2⁢C, for 1≤j≤k. Each of these fragments implies |C|+1=|Ft|−1 squares. Altogether (including the case j=0), they contain (|Ft|−1)⋅k+|Ft−1| squares, but Lemma 10 excludes the squares generated for j=0 and j=k to avoid double counting.

The fact that Ftk+2 occurs in 𝒲k,t and Observations 6 and 7 imply the following:

Lemma 11.

𝒲k,t contains at least 12⁢α distinct squares that are rotations of the words in {Ft2⁢j∣1≤j≤k+22}.

We are now ready to prove the main result of this section.

Theorem 12.

There are infinitely many integers n for which 𝖢𝖲⁢(n)≥1.5⁢n−𝒪⁢(n).

Proof.

Let us set k:=|Ft|. Then α=k2 and |Ft|=𝒪⁢(n). From Equation 1, the length of 𝒲k,t is n=3⁢α+𝒪⁢(n) and hence α=13⁢n−𝒪⁢(n).

By Lemmas 8, 9, 10, and 11, the word 𝒲k,t2 contains at least 4.5⁢α−Θ⁢(|Ft|) squares (of length at most n). They are all distinct. Indeed, the squares from Lemmas 8, 9, and 10 are rotations of (Ftj⁢Ft−1)2, for different j∈[1⁢..⁢k+2], so they have different lengths for different j. The squares from Lemma 11 are of the form (Ftj)2 for j≤k, and we have |Ftj−1⁢Ft−1|<|Ftj|<|Ftj⁢Ft−1|.

Therefore, the circular word 𝒲k,t contains

4.5⋅(13⁢n−𝒪⁢(n))= 1.5⁢n−𝒪⁢(n)

distinct squares, as required. ◀

4 Upper Bound

Let us fix a word w of length n. We denote w~=w⁢w. Our aim is to show that |𝐒n⁢(w~)|≤⌈1.8⁢n⌉.

High-level idea of the proof.

If there exists a fragment (a δ-window) of w∞ of (small) length δ that contains no starting position of a long square, then it is easy to show that there are at most 2⁢n−δ distinct squares in the circular word w. If no such fragment exists, we call w δ-dense. Hence, we reduce the problem to showing that primitive δ-dense words do not exist – a simple upper bound of 1.5⁢n can be shown for non-primitive words. We view a square u⁢u as a “transporter” which shifts long fragments of w by |u| positions (from the first copy of u to the second one). By choosing a long non-periodic fragment (called a sample) s, we consider only those distances |u| that correspond to the distances between occurrences of the sample in w⁢w which start in the first copy of w. The number of these occurrences is very small (bounded by a constant). Then, using samples, we show that if w is primitive, then w is not δ-dense.

Observation 13.

If w′ is a rotation of w, then 𝐒n⁢(w⁢w)=𝐒n⁢(w′⁢w′).

Lemma 14.

If w′ is a rotation of w that is not primitive, then |𝐒n⁢(w~)|≤1.5⁢n.

Proof.

Suppose w′=uk for some integer k≥2. Then 𝐒n⁢(w~)=𝐒n⁢(w′⁢w′)=𝐒n⁢(u⁢w′). Consequently, due to [3], we have |𝐒n⁢(w~)|=|𝐒n⁢(u⁢w′)|≤|u|+|w|=(1+1k)⁢n. Since k≥2, it follows that |𝐒n⁢(w~)|≤1.5⁢n. ◀

Corollary 15.

If w~ contains a square of length exactly n, then |𝐒n⁢(w~)|≤1.5⁢n.

By the above corollary, we may henceforth assume that w is primitive and w~ does not contain any square of length n.

▶ Remark 16.

Circular words that are themselves squares can still contain many squares. It was shown in [1] that there exists an infinite family of words wk, each of which is a square, such that 𝐒n⁢(wk⁢wk)≥1.25⁢|wk|−o⁢(|wk|).

Definition 17.

Let w be a word of length n. A square fragment u⁢u starting at position j in w∞ is called a δ-square fragment with respect to an interval [i⁢..⁢i+δ) if

i≤j<i+δ⁢and⁢n−(j−i)<|u⁢u|<n. (2)

Observe that if j<δ is the last occurrence in w⁢w of a square u⁢u, then u⁢u is a δ-square with respect to the interval I=[0..δ).

Definition 18.

A word w is called δ-dense if, for every length-δ fragment I of w∞, there exists a δ-square fragment with respect to I. (See Figure 5.)

Figure 5: Illustration of the notion of δ-density. The shown word is a prefix of w∞[i..∞). Here, u⁢u is a δ-square fragment with respect to the interval I=[i..i+δ) (shown in blue): there exists a position j in the interval I where a square u⁢u starts and satisfies |u⁢u|+(j−i)>n. The word w is δ-dense if such a square u⁢u exists for each interval [i⁢..⁢i+δ) with i∈ℤ+.

We first consider the easy case when w~ is not δ-dense.

Lemma 19 (Upper bound for words that are not δ-dense).

If w~ is not δ-dense, where 0<δ≤12⁢n, then |𝐒n⁢(w~)|≤2⁢n−δ.

Proof.

By Corollary 15, if w~ contains a square fragment of length exactly n, |𝐒n⁢(w~)|≤1.5⁢n. Henceforth we assume that w~ does not have such a fragment. Since w~ is not δ-dense, by the definition, there exists an interval I=[i..i+δ) in w∞ such that no δ-square fragment exists with respect to I. That is, for every square fragment u⁢u starting at some position j∈I, |u⁢u|<n−(j−i). Equivalently, the longest square starting at any position q∈I has length at most n−(q−i). After a rotation (cf. Observation 13), we may assume that i=0, so that I=[0..δ). Now, let us consider the suffix w~′ of w~ of length 2⁢n−δ. Every square fragment of w~ occurs entirely within w~′. Therefore, all distinct squares appear in a fragment of length 2⁢n−δ. The combination of this fact and the result of [3] implies that |𝐒n⁢(w~)|≤2⁢n−δ. ◀

Our aim is to show that no δ-dense words exist when w is primitive and δ is sufficiently small.

The next lemma states that each fragment of w~ of length 12⁢n−δ has a copy to its right at a well-specified distance d. See Figure 6 for an illustration.

Lemma 20 (Transporting Lemma).

Assume w is δ-dense with positive integer δ≤12⁢n. Let F be a fragment of length at most 12⁢n−δ that occurs at some position i≥n in w∞. Then, F also occurs in w∞ at position i+ℓ for some ℓ∈(12⁢(n−δ)⁢..⁢12⁢n).

Proof.

Since w is δ-dense, there exists a position j in (i−δ⁢..⁢i] where a δ-square fragment x=u⁢u occurs in w∞. By the definition of a δ-square, its total length satisfies n−(j−(i−δ))<|u⁢u|<n. It follows that the half-length |u| satisfies 12⁢(n−δ)<|u|<12⁢n.

By Equation 2, the square x=u⁢u ends at a position z≥i−δ+n, so the first half u of the square ends at a position z′≥i−δ+12⁢n≥i+|F|. Therefore the fragment F is completely contained within u. The second half of x also contains a copy of F shifted by a distance |u|. Therefore, F also occurs at position i+|u|. ◀

Figure 6: Illustration of the Transporting Lemma (Lemma 20). The sample is shown in blue, and the δ-length interval with respect to which the δ-square occurs is shown in red.

We use the following fact from [1], whose proof relies on the periodicity lemma.

Fact 21 ([1, Lemma 4]).

Let w be a word and let a and b be letters. If both a⁢w and w⁢b are periodic, then they have the same period.

Corollary 22.

If w is primitive and ℓ∈[1⁢..⁢n], then w~ contains a non-periodic fragment 𝐬 of length ℓ. We refer to this as an ℓ-sample.

Proof.

Let us assume that w~ does not contain a non-periodic fragment of length ℓ. Then, by Fact 21, all length-ℓ fragments of w⁢w are periodic with the same period, i.e., the whole w~ has a period at most 12⁢ℓ. By the periodicity lemma (Lemma 1), w~=w⁢w has a period p such that p≤12⁢n and p divides n. Hence, w is non-primitive. ◀

We show that, for every primitive word w, w~ is not δ-dense for a certain parameter δ≤0.5⁢n. Together with Lemmas 14 and 19, this implies that |𝐒n⁢(w~)|≤2⁢n−δ.

Simple Upper Bound

First we give a simple and intuitive proof for δ=⌊16⁢n⌋.

Lemma 23.

If w is primitive and n=|w|≥6, then w~ is not ⌊16⁢n⌋-dense.

Proof.

We prove this by contradiction. Assume that w~ is ⌊16⁢n⌋-dense. Let 𝐬 be a ⌊13⁢n⌋-sample that is non-periodic (as guaranteed by Corollary 22). After a suitable rotation of w⁢w, we can assume that 𝐬 occurs at positions 0 and n. Due to Lemma 20, 𝐬 also occurs at position i=d+d′, where d,d′∈(12⋅56⁢n⁢..⁢12⁢n); see Figure 7. Consequently, 𝐬 occurs at distinct positions n and i that are at distance at most ⌊16⁢n⌋≤|𝐬|/2. Hence, 𝐬 is periodic, a contradiction. ◀

Figure 7: Illustration of the proof of Lemma 23.

Lemmas 14, 19, and 23 imply that 𝖢𝖲⁢(n)≤2⁢n−⌊16⁢n⌋=⌈116⁢n⌉, after a trivial verification of the cases when n<6.

Stronger Upper Bound

Next, we strengthen the upper bound using a more refined argument.

Lemma 24.

If w is primitive, with n=|w|≥5, then w~ is not ⌊0.2⁢n⌋-dense.

Proof.

We prove this by contradiction. Assume that w~ is δ-dense for δ=⌊0.2⁢n⌋. Let 𝐬 be a non-periodic sample of length ℓ=⌊0.3⁢n⌋, (as guaranteed by Corollary 22, since ℓ≥1 for n≥4). Let 𝐀 denote the set of starting positions of 𝐬 in w⁢w.

After a suitable rotation of w⁢w, we may assume that positions 0 and n belong to 𝐀. Let 𝐀′=𝐀∩[0..n), 𝐀′={a0,…,a|𝐀′|−1} with a0<⋯<a|𝐀′|−1 and define ℓi=a(i+1)mod|𝐀′|−ai for i∈[0..|𝐀′|).

For each occurrence at position ai, let di be the shift distance given by the Transporting-Lemma (Lemma 20). This lemma applies since ℓ+δ≤12⁢n, and it ensures that di∈(12⋅⌈0.8⁢n⌉⁢..⁢0.5⁢n).

Then, there exists some i′∈[0..|𝐀′|) such that (ai+di)modn=ai′. We denote 𝗌𝗎𝖼𝖼⁢(i):=i′, we define 𝗌𝗎𝖼𝖼⁢(i):=𝗌𝗎𝖼𝖼⁢(imod|𝐀′|).

Claim 25.

For each i∈[0..|𝐀′|), 𝗌𝗎𝖼𝖼⁢(𝗌𝗎𝖼𝖼⁢(i))=(i−1)modn and ℓi∈(0.15⁢n⁢..⁢⌊0.2⁢n⌋).

Proof.

Let 𝗌𝗎𝖼𝖼⁢(i)=i′ and 𝗌𝗎𝖼𝖼⁢(i′)=i′′. The sum of two consecutive shift distances di+di′∈(⌈0.8⁢n⌉⁢..⁢n). Hence, ai+di+di′<ai+n, and there is no occurrence of 𝐬 in w∞ between ai+di+di′ and ai+n; otherwise, 𝐬 would be periodic. Therefore, 𝗌𝗎𝖼𝖼⁢(𝗌𝗎𝖼𝖼⁢(i))=(i−1)modn. Moreover,

ℓ(i−1)modn≤n−(⌈0.8⁢n⌉+1)<⌊0.2⁢n⌋,as claimed.

⊲

Claim 26.

For each i∈[0..|𝐀′|), 𝗌𝗎𝖼𝖼⁢(i)=(i+3)modn.

Proof.

Each shift di from the Transporting-Lemma lies in (0.4⁢n⁢..⁢0.5⁢n) (as 12⋅⌈0.8⁢n⌉≥12⋅0.8⁢n), while each ℓi lies in interval (0.15⁢n⁢..⁢⌊0.2⁢n⌋) by Claim 25.

Since 2⋅⌊0.2⁢n⌋≤0.4⁢n<di<0.5⁢n<4⋅0.15⁢n, each shift spans exactly three intervals. Hence, 𝗌𝗎𝖼𝖼⁢(i)=(i+3)modn. ⊲

The interval bounds from Claim 25 imply that |𝐀′|=6. But then, by Claim 26, 𝗌𝗎𝖼𝖼⁢(𝗌𝗎𝖼𝖼⁢(0))≠|𝐀′|−1, contradicting Claim 25. This completes the proof. ◀

By Lemmas 14, 19, and 24, we obtain the upper bound 𝖢𝖲⁢(n)≤2⁢n−⌊0.2⁢n⌋=⌈1.8⁢n⌉, after a trivial verification of the cases when n<5.

Theorem 27.

𝖢𝖲⁢(n)≤⌈1.8⁢n⌉.

▶ Remark 28.

If we used the sample size ⌊0.25⁢n⌋ as in [1], we would obtain a weaker upper bound of ⌈137⁢n⌉.

5 Limitations of our Approach

It appears that by taking larger values of δ, one could possibly strengthen Lemma 24, showing that every primitive word is not δ-dense, and thereby obtaining a stronger upper bound of 2⁢n−δ. However, we show that for δ=13⁢n+4 this approach no longer works.

We say that a square u⁢u kills a position i in w∞ if u⁢u is a δ-square fragment with respect to the interval [i⁢..⁢i+δ).

Observation 29.
  1. (a)

    A square u⁢u such that n−(δ−1)<|u⁢u|<n starting at position j in w∞ kills all positions contained modulo n in the interval [j−(δ−1)⁢..⁢j+|u⁢u|−n).

  2. (b)

    For a periodic fragment R with n−(δ−1)<2⋅per⁢(R)<n starting at position j in w∞, all positions contained modulo n in the interval

    IR=[j−(δ−1)⁢..⁢j+|R|−n−1] (3)

    are killed by the |R|−2⋅per⁢(R)+1 squares of length 2⋅per⁢(R) that are induced by R; see Figure 8.

Figure 8: Let w=a4⁢b⁢a5⁢b⁢a6⁢b (fragment shown in brown) and δ=10. The figure shows a word (w′)2 for a rotation w′ of w. The square fragments in w∞ induced by the periodic fragment R (shown in red) together kill all positions contained modulo n in the interval IR indicated by the yellow rectangle.
Fact 30.

There exist arbitrarily long primitive words w that are δ-dense for δ=13⁢|w|+4.

Proof.

Let us take 𝒲k,1=ak⁢b⁢ak+1⁢b⁢ak+2⁢b of length n=3⁢k+6 and δ=k+6=13⁢n+4. Using Equation 3, it is easy to see that each position of 𝒲k,1 is killed by one of the following three periodic fragments:

  • ■

    The fragment R1=(ak⁢b⁢a)2⁢ak occurring at position 0 kills positions in the interval

    [0−(k+5)⁢..⁢ 0+(3⁢k+4)−n−1]≡modn[2⁢k+1⁢..⁢n−3].
  • ■

    The fragment R2=(ak+1⁢b⁢a)2⁢ak−1 occurring at position k+1 kills positions in the interval

    [(k+1)−(k+5)⁢..⁢(k+1)+(3⁢k+5)−n−1]≡modn[n−4⁢..⁢n−1]∪[0⁢..⁢k−1];

    cf. Figure 8.

  • ■

    The fragment R3=(ak⁢b)2⁢ak occurring at position 2⁢k+5 kills positions in the interval

    [(2⁢k+5)−(k+5)⁢..⁢(2⁢k+5)+(3⁢k+2)−n−1]≡modn[k⁢..⁢2⁢k].

The union of the intervals [0⁢..⁢k−1], [k⁢..⁢2⁢k], [2⁢k+1⁢..⁢n−3], and [n−4⁢..⁢n−1] covers all positions in 𝒲k,1. This implies that every position is killed by a suitable δ-square fragment. Hence, 𝒲k,1 is δ-dense. ◀

6 Final Remarks

We have shown that 1.5⁢n−𝒪⁢(n)≤𝖢𝖲⁢(n)≤⌈1.8⁢n⌉, where the lower bound holds for infinitely many n. We conjecture that the lower bound is tight, that is, that 𝖢𝖲⁢(n)≤1.5⁢n.

Tight bounds related to repetitions and symmetries are usually non-trivial. This was, for instance, the case for bounds on standard squares (see [7, 9, 12, 5, 18, 3]) and powers ([11, 13, 14]), runs (the “runs theorem”; see [2] and references therein), and palindromes in circular words ([17]). For example, the abstract of [17] states: “In this paper we show, with a very complicated proof, …”).

Possibly, the elegant graph-theoretic proof of the recent upper bound for standard squares in [3] can be adapted to establish an 1.5⁢n upper bound for distinct squares in circular words.

References

  • [1] Mika Amit and Pawel Gawrychowski. Distinct squares in circular words. In String Processing and Information Retrieval - 24th International Symposium, SPIRE 2017, volume 10508 of Lecture Notes in Computer Science, pages 27–37. Springer, 2017. doi:10.1007/978-3-319-67428-5_3.
  • [2] Hideo Bannai, Tomohiro I, Shunsuke Inenaga, Yuto Nakashima, Masayuki Takeda, and Kazuya Tsuruta. The "runs" theorem. SIAM Journal on Computing, 46(5):1501–1514, 2017. doi:10.1137/15M1011032.
  • [3] Srecko Brlek and Shuo Li. On the number of squares in a finite word. Combinatorial Theory, 5(1), 2025. doi:10.5070/C65165014.
  • [4] James D. Currie. There are ternary circular square-free words of length n for n >= 18. Electronic Journal of Combinatorics, 9(1), 2002. doi:10.37236/1671.
  • [5] Antoine Deza, Frantisek Franek, and Adrien Thierry. How many double squares can a string contain? Discrete Applied Mathematics, 180:52–69, 2015. doi:10.1016/J.DAM.2014.08.016.
  • [6] Nathan J. Fine and Herbert S. Wilf. Uniqueness theorems for periodic functions. Proceedings of the American Mathematical Society, 16(1):109–114, 1965. doi:10.2307/2034009.
  • [7] Aviezri S. Fraenkel and Jamie Simpson. How many squares can a string contain? Journal of Combinatorial Theory, Series A, 82(1):112–120, 1998. doi:10.1006/JCTA.1997.2843.
  • [8] Aviezri S. Fraenkel and Jamie Simpson. The exact number of squares in Fibonacci words. Theoretical Computer Science, 218(1):95–106, 1999. doi:10.1016/S0304-3975(98)00252-7.
  • [9] Lucian Ilie. A note on the number of squares in a word. Theoretical Computer Science, 380(3):373–376, 2007. doi:10.1016/J.TCS.2007.03.025.
  • [10] Costas S. Iliopoulos, Dennis W. G. Moore, and William F. Smyth. A characterization of the squares in a Fibonacci string. Theoretical Computer Science, 172(1-2):281–291, 1997. doi:10.1016/S0304-3975(96)00141-7.
  • [11] Marcin Kubica, Jakub Radoszewski, Wojciech Rytter, and Tomasz Waleń. On the maximum number of cubic subwords in a word. European Journal of Combinatorics, 34(1):27–37, 2013. doi:10.1016/J.EJC.2012.07.012.
  • [12] Nguyen Huong Lam. On the number of squares in a string. AdvOL-Report, 2, 2013.
  • [13] Shuo Li. On the number of k-powers in a finite word. Advances in Applied Mathematics, 139:102371, 2022. doi:10.1016/J.AAM.2022.102371.
  • [14] Shuo Li, Jakub Pachocki, and Jakub Radoszewski. A note on the maximum number of k-powers in a finite word. Electronic Journal of Combinatorics, 31(3), 2024. doi:10.37236/11270.
  • [15] Gwénaël Richomme, Kalle Saari, and Luca Q. Zamboni. Standard factors of Sturmian words. RAIRO - Theoretical Informatics and Applications, 44(1):159–174, 2010. doi:10.1051/ITA/2010011.
  • [16] Arseny M. Shur. On ternary square-free circular words. Electronic Journal of Combinatorics, 17(1), 2010. doi:10.37236/412.
  • [17] Jamie Simpson. Palindromes in circular words. Theoretical Computer Science, 550:66–78, 2014. doi:10.1016/J.TCS.2014.07.012.
  • [18] Adrien Thierry. A proof that a word of length n has less than 1.5n distinct squares, 2020. arXiv:2001.02996.
  • [19] Axel Thue. Über unendliche Zeichenreihen. Norske Videnskabers Selskabs Skrifter Mat.-Nat. Kl., 7:1–22, 1906.