Improved Bounds on the Maximum Number of Distinct Squares in Circular Words
Abstract
We investigate the asymptotic growth of function , which maps to the maximum number of distinct squares in a circular word of length (that is, the maximum number of distinct squares of length at most in a word of length ). We improve upon the lower bound of established by Amit and Gawrychowski [SPIRE 2017] and the straightforward upper bound of , which follows from the recent result of Brlek and Li [Comb. Theory, 2025] stating that there are fewer than squares in standard (i.e., non-circular) words of length . (Previously, Amit and Gawrychowski gave an upper bound of using a weaker upper bound on squares in standard words.) Specifically, we show that and that, for infinitely many , .
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, repetitionsFunding:
Jakub Radoszewski: Supported by the Polish National Science Center, grant no. 2022/46/E/ST6/00463.Copyright and License:
Tomasz Waleń, and Wiktor Zuba; licensed under Creative Commons License CC-BY 4.0
2012 ACM Subject Classification:
Mathematics of computing Combinatorics on wordsEditors:
Philip Bille and Nicola PrezzaSeries and Publisher:
Leibniz International Proceedings in Informatics, Schloss Dagstuhl – Leibniz-Zentrum für Informatik
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 for a word . Here, we focus on square fragments of circular words. That is, for a standard word , we study the square fragments that occur in any rotation of or, equivalently, the square fragments of that are of length at most .
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 be the maximum number of distinct squares in a (standard) word of length . Fraenkel and Simpson [7] proved that and conjectured that . The resolution of this conjecture took more than two decades. Milestone results include the upper bound of due to Ilie [9], the upper bound of due to Deza, Franek, and Thierry [5], and the upper bound of due to Thierry [18]. Finally, Brlek and Li [3] confirmed the Fraenkel-Simpson conjecture using a graph-theoretic approach, establishing that .
Let denote the maximum number of distinct squares in a circular word of length . The growth of was first studied by Amit and Gawrychowski [1] who showed an upper bound of and a lower bound of (for infinitely many ). Note that this work was published when the best known upper bound for standard squares was . Further, observe that the number of squares of length at most in a word is at most . The result of Brlek and Li [3] thus implies that .
Our results.
Discussion.
As we remark at the end of Section 4, the proof of the upper bound of Amit and Gawrychowski could be modified to yield an upper bound of by incorporating the upper bound of for standard squares. However, the resulting argument remains technically involved. We establish a stronger upper bound of and also a (still stronger) upper bound of which is considerably simpler.
2 Preliminaries
A word is a sequence of length of letters from some alphabet. For any two integers , and denote the fragment if and the empty word otherwise. A fragment is called a prefix of . A prefix of is called a proper prefix of if its length is smaller than . A fragment is called a suffix of .
We say that integer is a period of a word if for all . We denote the smallest period of by . We say that is periodic if ; otherwise is called non-periodic.
Lemma 1 (Periodicity Lemma [6]).
If a word has periods and such that , then is also a period of .
A word is called primitive if the equality for a positive integer implies that . Primitive words satisfy the following synchronization property that follows from the periodicity lemma: a primitive word occurs in only as a prefix and as a suffix.
For a word , for any integer , we call a rotation of .
For a word , we denote by the set of squares of length at most that occur . Thus, the set of squares of a circular word equals , where .
Fibonacci words are defined by the recurrence
The number of distinct squares in the (standard) word is equal to ; see [8]. As a warm-up, we show an exact bound on the number of squares in circular Fibonacci words.
Fact 2.
If , .
Proof.
Every square in is a square of a rotation of some shorter Fibonacci word; see [10, Theorem 2.3]. The same holds for since is a prefix of the infinite Fibonacci word for , and for it can be easily verified.
For , we have as expected. Assume . The set does not contain and (because ). Let us show by induction that for all , each rotation of occurs in . Correctness in the base cases of can be easily checked. Assume that and the property holds for . By the hypothesis, contains all rotations of for . Since , is a prefix of , so all these squares are also in . Moreover, has a suffix and a prefix (since ). Hence, has a fragment , so each rotation of occurs in .
In total, we obtain squares. All these squares are different because each Fibonacci word is primitive.
Example 3.
We have
For , we have
and
In particular, has distinct squares, while the circular contains distinct squares in total.
3 Lower Bound
We use Fibonacci words as building blocks. For any word of length at least two, let be the word obtained from by deleting its two last letters. Let denote the word with the last two letter exchanged, that is, .
Example 4.
and .
The following (folklore) property of Fibonacci words follows by a straightforward inductive argument.
Observation 5.
For , we have and .
The next observation follows directly from the synchronization property of primitive words; see Figure 1.
Observation 6 (Squares in periodic fragments).
-
(a)
If is a proper prefix of a primitive word , then contains distinct squares of length .
-
(b)
contains at least words that are rotations of words in 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 and , the words , and are primitive.
Proof.
For any , words and are standard Sturmian words for . Since every standard Sturmian word is primitive (cf. [15]), it follows that all words of the form and are primitive. Moreover, since any rotation of a primitive word is primitive, the word is primitive as its rotation is primitive.
The construction.
We define an infinite family of words. For any , let
Note that is parametrized by both and (eventually, we will set ), and let . For convenience, we express bounds on the lengths of fragments and the number of square fragments in terms of
Note that we have
| (1) |
Squares in and .
We show that the words are almost cubes (except the last two letters); see Figure 2 for an illustration.
Lemma 8.
For all , we have that . Further, contains at least distinct squares which are rotations of .
Proof.
We have
By Observation 5,
Hence, is a prefix of . Now, is primitive due to Observation 7 and the second part of the statement follows by a direct application of Observation 6.
Lemma 9.
If and , contains more than distinct squares that are rotations of and .
Proof.
We denote and . We show that both and occur in ; see Figure 3. Then we obtain the statement using Observation 7 and Observation 6.
We first show that occurs in . The word
has a fragment equal to , which in turn has a fragment equal to . Thus, contains more than distinct squares which are rotations of .
Next, we show that occurs in . The word
contains a fragment equal to
which itself has a fragment equal to
which is equal to , since . Now, observe that is a prefix of this fragment. Thus contains distinct squares which are rotations of .
Since and have different lengths, all considered square fragments are distinct and this concludes the proof.
Lemma 10.
If then contains at least distinct squares which are rotations of for .
Proof.
The word contains the fragment ; see Figure 4. For each it contains the fragment
which contains the fragment .
By Observations 6 and 7, each such fragment, , contains distinct squares that are rotations of .
Summing over all , we obtain at least distinct squares of the claimed form.
The fact that occurs in and Observations 6 and 7 imply the following:
Lemma 11.
contains at least distinct squares that are rotations of the words in .
We are now ready to prove the main result of this section.
Theorem 12.
There are infinitely many integers for which .
Proof.
Let us set . Then and . From Equation 1, the length of is and hence .
By Lemmas 8, 9, 10, and 11, the word contains at least squares (of length at most ). They are all distinct. Indeed, the squares from Lemmas 8, 9, and 10 are rotations of , for different , so they have different lengths for different . The squares from Lemma 11 are of the form for , and we have .
Therefore, the circular word contains
distinct squares, as required.
4 Upper Bound
Let us fix a word of length . We denote . Our aim is to show that .
High-level idea of the proof.
If there exists a fragment (a -window) of of (small) length that contains no starting position of a long square, then it is easy to show that there are at most distinct squares in the circular word . If no such fragment exists, we call -dense. Hence, we reduce the problem to showing that primitive -dense words do not exist – a simple upper bound of can be shown for non-primitive words. We view a square as a “transporter” which shifts long fragments of by positions (from the first copy of to the second one). By choosing a long non-periodic fragment (called a sample) , we consider only those distances that correspond to the distances between occurrences of the sample in which start in the first copy of . The number of these occurrences is very small (bounded by a constant). Then, using samples, we show that if is primitive, then is not -dense.
Observation 13.
If is a rotation of , then .
Lemma 14.
If is a rotation of that is not primitive, then .
Proof.
Suppose for some integer . Then . Consequently, due to [3], we have . Since , it follows that .
Corollary 15.
If contains a square of length exactly , then .
By the above corollary, we may henceforth assume that is primitive and does not contain any square of length .
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 , each of which is a square, such that .
Definition 17.
Let be a word of length . A square fragment starting at position in is called a -square fragment with respect to an interval if
| (2) |
Observe that if is the last occurrence in of a square , then is a -square with respect to the interval .
Definition 18.
A word is called -dense if, for every length- fragment of , there exists a -square fragment with respect to . (See Figure 5.)
We first consider the easy case when is not -dense.
Lemma 19 (Upper bound for words that are not -dense).
If is not -dense, where , then .
Proof.
By Corollary 15, if contains a square fragment of length exactly , . Henceforth we assume that does not have such a fragment. Since is not -dense, by the definition, there exists an interval in such that no -square fragment exists with respect to . That is, for every square fragment starting at some position , . Equivalently, the longest square starting at any position has length at most . After a rotation (cf. Observation 13), we may assume that , so that . Now, let us consider the suffix of of length . Every square fragment of occurs entirely within . Therefore, all distinct squares appear in a fragment of length . The combination of this fact and the result of [3] implies that .
Our aim is to show that no -dense words exist when is primitive and is sufficiently small.
The next lemma states that each fragment of of length has a copy to its right at a well-specified distance . See Figure 6 for an illustration.
Lemma 20 (Transporting Lemma).
Assume is -dense with positive integer . Let be a fragment of length at most that occurs at some position in . Then, also occurs in at position for some .
Proof.
Since is -dense, there exists a position in where a -square fragment occurs in . By the definition of a -square, its total length satisfies . It follows that the half-length satisfies .
By Equation 2, the square ends at a position , so the first half of the square ends at a position . Therefore the fragment is completely contained within . The second half of also contains a copy of shifted by a distance . Therefore, also occurs at position .
We use the following fact from [1], whose proof relies on the periodicity lemma.
Fact 21 ([1, Lemma 4]).
Let be a word and let and be letters. If both and are periodic, then they have the same period.
Corollary 22.
If is primitive and , then contains a non-periodic fragment of length . We refer to this as an -sample.
Proof.
Simple Upper Bound
First we give a simple and intuitive proof for .
Lemma 23.
If is primitive and , then is not -dense.
Proof.
We prove this by contradiction. Assume that is -dense. Let be a -sample that is non-periodic (as guaranteed by Corollary 22). After a suitable rotation of , we can assume that occurs at positions and . Due to Lemma 20, also occurs at position , where ; see Figure 7. Consequently, occurs at distinct positions and that are at distance at most . Hence, is periodic, a contradiction.
Stronger Upper Bound
Next, we strengthen the upper bound using a more refined argument.
Lemma 24.
If is primitive, with , then is not -dense.
Proof.
We prove this by contradiction. Assume that is -dense for . Let be a non-periodic sample of length , (as guaranteed by Corollary 22, since for ). Let denote the set of starting positions of in .
After a suitable rotation of , we may assume that positions and belong to . Let , with and define for .
For each occurrence at position , let be the shift distance given by the Transporting-Lemma (Lemma 20). This lemma applies since , and it ensures that .
Then, there exists some such that . We denote , we define .
Claim 25.
For each , and .
Proof.
Let and . The sum of two consecutive shift distances . Hence, , and there is no occurrence of in between and ; otherwise, would be periodic. Therefore, . Moreover,
Claim 26.
For each , .
Proof.
Each shift from the Transporting-Lemma lies in (as ), while each lies in interval by Claim 25.
Since , each shift spans exactly three intervals. Hence, .
The interval bounds from Claim 25 imply that . But then, by Claim 26, , contradicting Claim 25. This completes the proof.
By Lemmas 14, 19, and 24, we obtain the upper bound , after a trivial verification of the cases when .
Theorem 27.
.
Remark 28.
If we used the sample size as in [1], we would obtain a weaker upper bound of .
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 . However, we show that for this approach no longer works.
We say that a square kills a position in if is a -square fragment with respect to the interval .
Observation 29.
-
(a)
A square such that starting at position in kills all positions contained modulo in the interval .
-
(b)
For a periodic fragment with starting at position in , all positions contained modulo in the interval
(3) are killed by the squares of length that are induced by ; see Figure 8.
Fact 30.
There exist arbitrarily long primitive words that are -dense for .
Proof.
Let us take of length and Using Equation 3, it is easy to see that each position of is killed by one of the following three periodic fragments:
-
The fragment occurring at position 0 kills positions in the interval
-
The fragment occurring at position kills positions in the interval
The union of the intervals , , , and covers all positions in . This implies that every position is killed by a suitable -square fragment. Hence, is -dense.
6 Final Remarks
We have shown that , where the lower bound holds for infinitely many . We conjecture that the lower bound is tight, that is, that .
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 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.
