Keywords

1 Introduction

Palindromes are a common topic in combinatorics on words. Some examples of subtopics are palindromic richness [11] and palindrome complexity [1]. In this article, we are interested in palindromic factorizations of words. Every word can be trivially written as a product of palindromes, because every letter is a palindrome. However, studying minimal palindromic factorizations is a highly nontrivial topic that has been studied in many articles, for example by Ravsky [15]. The length of a minimal palindromic factorization of a word, that is, the smallest number n such that the word can be written as a product of n palindromes, is called the palindromic length of the word.

Frid, Puzynina and Zamboni [10] made the following conjecture about the palindromic lengths of factors of infinite words.

Conjecture 1

Every aperiodic infinite word has factors of arbitrarily high palindromic length.

They also proved the conjecture for a large class of words, including all words that are k-power-free for some k. They actually proved that all words in this class have not only factors but also prefixes of arbitrarily high palindromic length. This leads to the following stronger version of the conjecture.

Conjecture 2

Every aperiodic infinite word has prefixes of arbitrarily high palindromic length.

Let us mention here some related results, many of which have been inspired by the conjectures. The complexity of determining the palindromic length of a word is known to be \(O(n \log n)\) [8, 14]. Words of palindromic length at most two are sometimes called symmetric or palindrome pairs, and they have appeared in many articles [5, 6, 12, 13]. Variations of palindromic length called left greedy palindromic length and right greedy palindromic length were defined and studied by Bucci and Richomme [7].

In this article, we prove the equivalence of Conjectures 1 and 2. More specifically, we prove that the maximal palindromic length of factors of a word can be at most twice as large as the maximal palindromic length of prefixes of the word, and this result is at least very close to optimal. We also give other results on palindromic length. Conjecture 1 remains a very interesting open problem.

Palindromes and palindromic length can also be defined in a free group in a natural way. To avoid confusion, we talk about FG-palindromes and FG-palindromic length in the case of free groups. These concepts were studied by Bardakov, Shpilrain and Tolstykh [3]. They proved that in every nonabelian free group, there are elements with arbitrarily high FG-palindromic length. Palindromic length has been defined and studied in many other groups as well, see, for example, the paper by Bardakov and Gongopadhyay about finitely generated solvable groups [2] or the paper by Fink about wreath products [9].

Because a free monoid of words is a subset of a free group, both the ordinary palindromic length and FG-palindromic length are defined for words. However, there does not seem to be any research on the relation of these two concepts. We take the first steps in this direction, inspired by the fact that some of our results on palindromic length can be formulated by using free groups and, specifically, inverses of palindromes. We prove that the ratio of the palindromic length and the FG-palindromic length of a word can be arbitrarily large, and we study the relation of palindromic length, FG-palindromic length, conjugacy, and edit distance. Combinatorial and algorithmic analysis of FG-palindromic length seems like an interesting topic for future research.

2 Preliminaries

Throughout the article, let \(\varSigma \) be an alphabet. The set of all words over \(\varSigma \) is denoted by \(\varSigma ^*\) and it is a free monoid. The empty word is denoted by \(\varepsilon \) and the length of a word \(w \in \varSigma ^*\) by |w|.

The set of all infinite words over \(\varSigma \) is denoted by \(\varSigma ^\omega \). An infinite word w is ultimately periodic if there are words \(u, v \in \varSigma ^*\) such that \( w = u v^\omega = u v v v \cdots . \) If w is not ultimately periodic, it is aperiodic.

The set of factors of a finite or infinite word w is denoted by \(\text {Fact}(w)\) and the set of prefixes by \(\mathrm {Pref}(w)\).

If \(a_1, \dots , a_n \in \varSigma \), then the reverse of the word \(w = a_1 \cdots a_n\) is \(w^R = a_n \cdots a_1\). If \(w = w^R\), then w is a palindrome.

The palindromic length of a word w, denoted by \(|w |_{\mathrm {pal}}\), is the smallest number n such that w can be written as a product of n palindromes. Because every letter is a palindrome, \(|w |_{\mathrm {pal}} \le |w|\). The palindromic length of \(\varepsilon \) is zero, the palindromic length of every nonempty palindrome is one, and the palindromic length of every other word is at least two.

Example 3

The reverse of the word reverses is sesrever, so it is not a palindrome. It is a product of the two palindromes rever and ses, so its palindromic length is two.

The palindromic width of a language L is

$$\begin{aligned} |L |_{\mathrm {pal}} = \sup \{|u |_{\mathrm {pal}} \mid u \in L\} \end{aligned}$$

(this terminology actually comes from studying palindromicity in groups; the case of free groups is discussed below). Conjecture 1 can now be reformulated as claiming that \(|\mathrm {Fact}(w) |_{\mathrm {pal}} = \infty \) for every aperiodic infinite word w, and Conjecture 2 can be reformulated as claiming that \(|\mathrm {Pref}(w) |_{\mathrm {pal}} = \infty \) for every aperiodic infinite word w.

The free monoid \(\varSigma ^*\) can be extended to a free group. For any subset S of the free group, let \(S^*\) be the monoid generated by S, let \(S^{-1}\) be the set of inverses of elements of S, and let \(S^{\pm 1} = S \cup S^{-1}\). For example, \((\varSigma ^{\pm 1})^*\) is the whole free group, and \((\varSigma ^*)^{\pm 1}\) is the set of all words and their inverses. The term “word” always refers to an element of \(\varSigma ^*\).

Every element x of the free group \((\varSigma ^{\pm 1})^*\) can be written uniquely in a reduced form \( x = a_1 \cdots a_n, \) where \(n \ge 0\), \(a_1, \dots , a_n \in \varSigma ^{\pm 1}\), and \(a_{i - 1} a_i \ne \varepsilon \) for all \(i \in \{2, \dots , n\}\). The reverse of x is then \(x^R = a_n \cdots a_1\). This is an extension of the definition of the reverse of a word. If \(x = x^R\), then x is an FG-palindrome. A word is an FG-palindrome if and only if it is a palindrome.

Reversal is an antimorphism, that is, \((xy)^R = y^R x^R\) for all \(x, y \in (\varSigma ^{\pm 1})^*\). It follows that if \( x = a_0 \cdots a_n, \) where \(a_0, \dots , a_n \in \varSigma ^{\pm 1}\) (but not necessarily \(a_{i - 1} a_i \ne \varepsilon \) for all \(i \in \{1, \dots , n\}\)), and if \(a_i = a_{n - i}\) for all \(i \in \{0, \dots , n\}\), then x is an FG-palindrome. The converse is not true; for example, the empty word is an FG-palindrome, but it can be written as \(a a^{-1}\), which does not “look like” a palindrome.

The FG-palindromic length of an element x is the smallest number n such that x can be written as a product of n FG-palindromes. This definition is not compatible with the definition of palindromic length, because there are words whose palindromic length is larger than their FG-palindromic length.

Example 4

The palindromic length of abca is four, but it is a product of three FG-palindromes:

$$\begin{aligned} abca = aba \cdot a^{-2} \cdot aca. \end{aligned}$$

When studying palindromicity in free groups (and not in free monoids), FG-palindromes are usually called just palindromes, but in this article, the term “palindrome” always refers to a word. Similarly, FG-palindromic length is sometimes called just palindromic length, but because it is different from the usual palindromic length of words, it is important to use different terms in this article.

3 Palindromic Lengths of Factors and Prefixes

We start with an easy lemma, which was also proved in [12]. Lemmas of similar flavor can be found in [4].

Lemma 5

Let \(x, y \in \varSigma ^*\). If two of the words x, y, xy are palindromes, then the third one is a product of two palindromes.

Proof

If x and y are palindromes, then the claim is clear.

If x and xy are palindromes, then \( x y = (x y)^R = y^R x^R = y^R x, \) so y and \(y^R\) are conjugates, meaning that there are words pq such that \(y = pq\) and \(y^R = qp\). Then \( q p = y^R = (pq)^R = q^R p^R, \) so \(q = q^R\) and \(p = p^R\), and thus \(y = pq\) is a product of two palindromes.

If y and xy are palindromes, then the claim can be proved in a symmetric way. Alternatively, we can notice that \(y^R\) and \(y^R x^R\) are palindromes, so \(x^R\) is a product of two palindromes by the previous case, and therefore also x is a product of two palindromes.    \(\square \)

If x is a product of m palindromes and y is a product of n palindromes, then xy is a product of \(m + n\) palindromes, so we have the inequality \(|xy |_{\mathrm {pal}} \le |x |_{\mathrm {pal}} + |y |_{\mathrm {pal}}\). The following generalization of Lemma 5 gives two other similar “triangle inequalities” for palindromic length.

Lemma 6

Let \(x, y \in \varSigma ^*\). Then

$$\begin{aligned} |y |_{\mathrm {pal}} \le |x |_{\mathrm {pal}} + |xy |_{\mathrm {pal}} \qquad {and} \qquad |x |_{\mathrm {pal}} \le |y |_{\mathrm {pal}} + |xy |_{\mathrm {pal}}. \end{aligned}$$

Proof

We prove the first inequality by induction on |xy| (the second inequality is symmetric). The cases where \(|x| = 0\) or \(|y| = 0\) are clear. Let us assume that \(|x|, |y| > 0\) and \( |y' |_{\mathrm {pal}} \le |x' |_{\mathrm {pal}} + |x'y' |_{\mathrm {pal}} \) whenever \(|x'y'| < |xy|\). Let \(|x |_{\mathrm {pal}} = m\) and \(|xy |_{\mathrm {pal}} = n\). Let \(x = p_1 \cdots p_m\) and \(xy = q_1 \cdots q_n\), where every \(p_i\) and every \(q_i\) is a nonempty palindrome. There are two (similar) cases: \(|p_1| \le |q_1|\) and \(|p_1| > |q_1|\).

If \(|p_1| \le |q_1|\), then \(q_1 = p_1 r\) for some word r, and \(r = st\) for some palindromes st by Lemma 5. Let \(x' = p_2 \cdots p_m\). Then \(x'y = st q_2 \cdots q_n\). By the induction hypothesis,

$$\begin{aligned} |y |_{\mathrm {pal}} \le |x' |_{\mathrm {pal}} + |x'y |_{\mathrm {pal}} \le (m - 1) + (n + 1) = |x |_{\mathrm {pal}} + |xy |_{\mathrm {pal}}. \end{aligned}$$

If \(|p_1| > |q_1|\), then \(p_1 = q_1 r\) for some word r, and \(r = st\) for some palindromes st by Lemma 5. Let \(x' = st p_2 \cdots p_m\). Then \(x'y = q_2 \cdots q_n\). By the induction hypothesis,

$$\begin{aligned} |y |_{\mathrm {pal}} \le |x' |_{\mathrm {pal}} + |x'y |_{\mathrm {pal}} \le (m + 1) + (n - 1) = |x |_{\mathrm {pal}} + |xy |_{\mathrm {pal}}. \end{aligned}$$

This completes the induction.    \(\square \)

Now we are ready to prove the main result of this section and the equivalence of Conjectures 1 and 2.

Theorem 7

Let w be a finite or infinite word. Then

$$\begin{aligned} |\mathrm {Fact}(w) |_{\mathrm {pal}} \le 2 |\mathrm {Pref}(w) |_{\mathrm {pal}}. \end{aligned}$$

Proof

Let y be any factor of w. There is a word x such that xy is a prefix of w. Then \(|x |_{\mathrm {pal}}, |xy |_{\mathrm {pal}} \le |\mathrm {Pref}(w) |_{\mathrm {pal}}\), and

$$\begin{aligned} |y |_{\mathrm {pal}} \le |x |_{\mathrm {pal}} + |xy |_{\mathrm {pal}} \le 2 |\mathrm {Pref}(w) |_{\mathrm {pal}} \end{aligned}$$

by Lemma 6.    \(\square \)

Corollary 8

Conjectures 1 and 2 are equivalent.

Proof

For an aperiodic infinite word w, the condition \(|\mathrm {Pref}(w) |_{\mathrm {pal}} = \infty \) implies \(|\mathrm {Fact}(w) |_{\mathrm {pal}} = \infty \), because \(\mathrm {Pref}(w) \subseteq \mathrm {Fact}(w)\), and the condition \(|\mathrm {Fact}(w) |_{\mathrm {pal}} = \infty \) implies \(|\mathrm {Pref}(w) |_{\mathrm {pal}} = \infty \) by Theorem 7. Therefore Conjectures 1 and 2 are equivalent.    \(\square \)

The next example shows that the inequality \( |\mathrm {Fact}(w) |_{\mathrm {pal}} \le 2 |\mathrm {Pref}(w) |_{\mathrm {pal}} \) in Theorem 7 is almost optimal. We do not know whether it could be replaced by \( |\mathrm {Fact}(w) |_{\mathrm {pal}} \le 2 |\mathrm {Pref}(w) |_{\mathrm {pal}} - 1. \)

Example 9

Let \(\{a_1, \dots , a_{n - 1}, b_1, \dots , b_{n - 1}\}\) be an alphabet and let

$$\begin{aligned} A = a_1 \cdots a_{n - 1} \qquad \text { and } \qquad B = b_1 \cdots b_{n - 1}. \end{aligned}$$

It is quite easy to see that all prefixes of the infinite word

$$\begin{aligned} w = (A A^R B B^R)^\omega = ((a_1 \cdots a_{n - 1}) (a_{n - 1} \cdots a_1) (b_1 \cdots b_{n - 1}) (b_{n - 1} \cdots b_1))^\omega \end{aligned}$$

have palindromic length at most n. On the other hand, w has the factor

$$\begin{aligned} u&= A^R B B^R A A^R B \\&= (a_{n - 1} \cdots a_1) (b_1 \cdots b_{n - 1}) (b_{n - 1} \cdots b_1) (a_1 \cdots a_{n - 1}) (a_{n - 1} \cdots a_1) (b_1 \cdots b_{n - 1}), \end{aligned}$$

and we can show that u has palindromic length \(2n - 1\). To see this, let \(u = p_1 \cdots p_k\), where every \(p_i\) is a palindrome. We first note that u contains every letter exactly three times. Every letter appears an even number of times in every palindrome of even length, so every letter must appear in at least one \(p_i\) of odd length. But u does not contain a factor of the form aba for any letters ab, so it does not have palindromic factors of odd length, except the letters. Therefore, for every letter a, there exists i such that \(p_i = a\). This means that the sequence \(p_1, \dots , p_k\) contains at least \(2n - 2\) letters. It follows that \(k \ge 2n - 1\).

4 Binary Alphabet

In Example 9, we used an alphabet whose size depended on the parameter n. This raises the question of whether similar examples could be constructed using an alphabet of fixed sized, preferably a binary alphabet. It would be convenient if, for any alphabet \(\{a_1, \dots , a_n\}\), we could give a morphism \(h: \{a_1, \dots , a_n\}^* \rightarrow \{a, b\}^*\) that preserves palindromic lengths of words, and approximately preserves palindromic widths of sets of factors and prefixes. Then we could use this morphism also later to turn n-ary examples into binary ones. The first idea might be to define \(h(a_i) = a b^i a\) for all i. This morphism preserves palindromicity, but it can significantly reduce the palindromic length of a word. A better morphism is given in the next lemma.

Lemma 10

Let us define a morphism

$$\begin{aligned} h: \{a_1, \dots , a_n\}^* \rightarrow \{a, b\}^*, \ h(a_i) = a b^i a^5 b^i a. \end{aligned}$$

Let u be a finite word and w a finite or infinite word over \(\{a_1, \dots , a_n\}\). Then

$$\begin{aligned}&|h(u) |_{\mathrm {pal}} = |u |_{\mathrm {pal}}, \\&|\mathrm {Fact}(w) |_{\mathrm {pal}} \le |\mathrm {Fact}(h(w)) |_{\mathrm {pal}} \le |\mathrm {Fact}(w) |_{\mathrm {pal}} + 6, \\&|\mathrm {Pref}(w) |_{\mathrm {pal}} \le |\mathrm {Pref}(h(w)) |_{\mathrm {pal}} \le |\mathrm {Pref}(w) |_{\mathrm {pal}} + 3. \end{aligned}$$

Proof

First, we prove that \( |h(u) |_{\mathrm {pal}} \le |u |_{\mathrm {pal}}. \) If \(u = p_1 \cdots p_k\), where every \(p_i\) is a palindrome, then \(h(u) = h(p_1) \cdots h(p_k)\) and every \(h(p_i)\) is a palindrome. The claim follows.

Second, we prove that \( |u |_{\mathrm {pal}} \le |h(u) |_{\mathrm {pal}}. \) Let \(h(u) = q_1 \cdots q_k\), where every \(q_i\) is a palindrome. We are going to define a factorization \(u = p_1 \cdots p_k\) such that every \(p_i\) is a palindrome. The informal idea is to define the words \(p_i\) so that, for a letter c in u, if the centermost letter in the image h(c) is inside \(q_j\), then c will be inside \(p_j\). This means that either \(|p_j| \le 1\) or \(q_j = x h(p_j) y\), where x is either a suffix of \(a^2 b^i a\) or the inverse of a prefix of \(a b^i a^2\) for some i, and y is either a prefix of \(a b^i a^2\) or the inverse of a suffix of \(a^2 b^i a\) for some i. If \(p_j = a_{j_0} \cdots a_{j_m}\), where \(m \ge 1\) and \(j_i \in \{1, \dots , n\}\) for all i, then

$$\begin{aligned} q_j = x' a^3 b^{j_0} a \bigg ( \prod _{i = 1}^{m - 1} a b^{j_i} a^5 b^{j_i} a \bigg ) a b^{j_m} a^3 y', \end{aligned}$$

where \(x', y' \in \{a, b\}^*\) do not contain \(a^3\) as a factor. Because \(q_j\) is a palindrome, it must be \(j_i = j_{m - i}\) for all i, so also \(p_j\) is a palindrome. The claim follows.

Third, we prove that

$$\begin{aligned} |\mathrm {Fact}(w) |_{\mathrm {pal}} \le |\mathrm {Fact}(h(w)) |_{\mathrm {pal}} \end{aligned}$$

If v is a factor of w of palindromic length k, then h(v) is a factor of h(w) of palindromic length k. The claim follows.

Finally, we prove that

$$\begin{aligned} |\mathrm {Fact}(h(w)) |_{\mathrm {pal}} \le |\mathrm {Fact}(w) |_{\mathrm {pal}} + 6. \end{aligned}$$

Every factor of h(w) is of the form xh(v)y, where v is a factor of w, x is a suffix of \(a b^i a^5 b^i a\) for some i, and y is a prefix of \(a b^i a^5 b^i a\) for some i. Then

$$\begin{aligned} |x h(v) y |_{\mathrm {pal}} \le |x |_{\mathrm {pal}} + |h(v) |_{\mathrm {pal}} + |y |_{\mathrm {pal}} \le |v |_{\mathrm {pal}} + 6. \end{aligned}$$

The claim follows.

The inequalities about the sets of prefixes can be proved in a similar way.    \(\square \)

Example 11

If w is the word of Example 9 and h is the morphism of Lemma 10, then the palindromic lengths of all prefixes of the binary infinite word h(w) are at most \(n + 3\), but h(w) has a factor of palindromic length \(2n - 1\).

5 Palindromic Jumps

In this section, we are going to prove a generalization of Lemma 6, which might be useful when studying palindromic lengths of factors. Let \(w = a_0 a_1 a_2 \cdots \) (w could also be a finite word). In the following, it is convenient to think that the positions between the letters of w are labeled so that the position before \(a_0\) is 0, the position between \(a_0\) and \(a_1\) is 1, and so on. We say that (ij) is a palindromic jump in w if either \(i \le j\) and \(a_i \cdots a_{j - 1}\) is a palindrome or \(j \le i\) and \(a_j \cdots a_{i - 1}\) is a palindrome. If \(i \le j\), then (ij) is a forward palindromic jump, and if \(j \le i\), then (ij) is a backward palindromic jump.

If we can get from position i to position j with n forward palindromic jumps, then the factor between positions i and j is a product of n palindromes. The inequality \( |y |_{\mathrm {pal}} \le |x |_{\mathrm {pal}} + |xy |_{\mathrm {pal}} \) in Lemma 6 means that if we can get from position |x| in the word xy to position 0 with m backward palindromic jumps, and we can get from position 0 to position |xy| with n forward palindromic jumps, then we can get from position |x| to position |xy| with \(m + n\) forward palindromic jumps. It follows that any sequence of m backward palindromic jumps followed by n forward palindromic jumps can be converted into a sequence of \(m + n\) forward palindromic jumps. In the following theorem, we will generalize this by proving that any sequence of n palindromic jumps can be converted into a sequence of n forward palindromic jumps. So if we can get from position i to position j with n palindromic jumps, then the factor between positions i and j has palindromic length at most n.

Theorem 12

Let \(w = a_0 a_1 a_2 \cdots \). Let \(k_0, \dots , k_n \ge 0\) and \(k_0 \le k_n\). If \((k_{i - 1}, k_i)\) is a palindromic jump in w for all \(i \in \{1, \dots , n\}\), then \(a_{k_0} \cdots a_{k_n - 1}\) is a product of n palindromes.

Proof

We can assume that \(k_{i - 1} \ne k_i\) for all \(i \in \{1, \dots , n\}\). The proof is by induction on \( L = |k_0 - k_1| + \dots + |k_{n - 1} - k_n|. \) If \(L = k_n - k_0\), then the sequence \(k_0, \dots , k_n\) is increasing and the claim is clear. Let us assume that \(L > k_n - k_0\) and that the claim is true for all values smaller than L. There is a number j such that either \(k_j < k_{j - 1}, k_{j + 1}\) or \(k_j > k_{j - 1}, k_{j + 1}\). By Lemma 5, there is a number k such that \((k_{j - 1}, k), (k, k_{j + 1})\) are palindromic jumps in w and either \(k_{j - 1} \le k \le k_{j + 1}\) or \(k_{j + 1} \le k \le k_{j - 1}\). Let \(k_j' = k\) and \(k_i' = k_i\) for all \(i \ne j\). Then \( |k_0' - k_1'| + \dots + |k_{n - 1}' - k_n'| < L \) and every \((k_{i - 1}', k_i')\) is a palindromic jump in w, so \(a_{k_0} \cdots a_{k_n}\) is a product of n palindromes by the induction hypothesis.    \(\square \)

Example 13

Consider the word abaca. Then (0, 3) is a forward palindromic jump, because aba is a palindrome, (3, 2) is a backward palindromic jump, because a is a palindrome, and (2, 5) is a forward palindromic jump, because aca is a palindrome. By Theorem 12, abaca is a product of three palindromes, which is of course very easy to see directly as well. The proof of Theorem 12 would convert the sequence (0, 3), (3, 2), (2, 5) of palindromic jumps either into the sequence (0, 1), (1, 2), (2, 5), which corresponds to the factorization \(a \cdot b \cdot aca\), or to the sequence (0, 3), (3, 4), (4, 5), which corresponds to the factorization \(aba \cdot c \cdot a\).

6 Palindromes and Inverses of Palindromes

From now on, we view the word monoid \(\varSigma ^*\) as a subset of the free group \((\varSigma ^{\pm 1})^*\). If \(x, y \in \varSigma ^*\), then \(y = x^{-1} xy\), so the inequality \( |y |_{\mathrm {pal}} \le |x |_{\mathrm {pal}} + |xy |_{\mathrm {pal}} \) of Lemma 6 can be formulated as follows: If \( y = p_1 \cdots p_m q_1 \cdots q_n, \) where every \(p_i\) is the inverse of a palindrome and every \(q_i\) is a palindrome, then y is a product of \(m + n\) palindromes. This raises the following questions:

  • If a word is a product of n elements of \((\varSigma ^*)^{\pm 1}\) that are palindromes or inverses of palindromes, is the word necessarily a product of n palindromes?

  • If a word is a product of n FG-palindromes, is the word necessarily a product of n palindromes?

The answer to both of these questions is negative, as is shown by the word

$$\begin{aligned} abca = aba \cdot a^{-2} \cdot aca, \end{aligned}$$

which was already mentioned in Example 4. However, in Theorem 14 we prove a weaker result. This is essentially a reformulation of Theorem 12. We could also have proved Theorem 14 first and then Theorem 12 as a consequence.

Theorem 14

Let \(w = p_1 \cdots p_n\), where w is a word and every \(p_i\) is either a palindrome or the inverse of a palindrome. If \(p_i \cdots p_j \in (\varSigma ^*)^{\pm 1}\) whenever \(1 \le i \le j \le n\), then w is a product of n palindromes.

Proof

For all \(i \in \{0, \dots , n\}\), let \(q_i = p_1 \cdots p_i\). Let \(R = \{q_i \mid q_i \in \varSigma ^*\}\) and \(S = \{q_i^{-1} \mid q_i^{-1} \in \varSigma ^*\}\). Let r be a longest word in R and s be a longest word in S.

First we are going to show that every \(q_i \in R\) is a prefix of r. If \(q_i = xay\) and \(q_j = xbz\), where xyz are words, ab are different letters, and \(i < j\), then

$$\begin{aligned} p_{i + 1} \cdots p_j = q_i^{-1} q_j = y^{-1} a^{-1} b z \notin (\varSigma ^*)^{\pm 1}, \end{aligned}$$

which is a contradiction. Therefore, one of \(q_i, q_j\) is a prefix of the other. This means that every \(q_i \in R\) is a prefix of r.

Then we are going to show that every \(q_i^{-1} \in S\) is a suffix of s. If \(q_i^{-1} = xaz\) and \(q_j^{-1} = ybz\), where xyz are words, ab are different letters, and \(i < j\), then

$$\begin{aligned} p_{i + 1} \cdots p_j = q_i^{-1} q_j = x a b^{-1} y^{-1} \notin (\varSigma ^*)^{\pm 1}, \end{aligned}$$

which is a contradiction. Therefore, one of \(q_i^{-1}, q_j^{-1}\) is a suffix of the other. This means that every \(q_i^{-1} \in S\) is a suffix of s.

Let \(w = sr\). Then \((|s q_{i - 1}|, |s q_i|)\) is a palindromic jump in w for all \(i \in \{1, \dots , n\}\). The claim follows from Theorem 12.    \(\square \)

7 Conjugates and Edit Distance

In this section, we will compare palindromic length and FG-palindromic length and show that they can be very different. We prove that FG-palindromic length has some nice properties that the ordinary palindromic length does not have: The FG-palindromic lengths of conjugates are almost the same, and if two elements are close to each other as measured by edit distance, then also their FG-palindromic lengths are close to each other.

Theorem 15

For every conjugacy class of a free group, there is a number k such that the FG-palindromic lengths of all elements in the conjugacy class are in \(\{2k - 1, 2k\}\).

Proof

Of all the members of a conjugacy class, let x be one with minimal FG-palindromic length. Let k be such that the FG-palindromic length of x is in \(\{2k - 1, 2k\}\). Then \(x = p_1 \cdots p_{2k}\), where every \(p_i\) is an FG-palindrome (we can add the empty palindrome if necessary). For every conjugate \(y x y^{-1}\) of x we have

$$\begin{aligned} y x y^{-1} = y (p_1 \cdots p_{2k}) y^{-1} = \prod _{i = 1}^k y p_{2i - 1} p_{2i} y^{-1} = \prod _{i = 1}^k y p_{2i - 1} y^R (y^R)^{-1} p_{2i} y^{-1}. \end{aligned}$$

Here the two elements \(y p_{2i - 1} y^R\) and \((y^R)^{-1} p_{2i} y^{-1} = (y^{-1})^R p_{2i} y^{-1}\) are FG-palindromes for all \(i \in \{1, \dots , k\}\), so \(y x y^{-1}\) is a product of 2k FG-palindromes. This proves the claim.    \(\square \)

All conjugates of a product of two palindromes are also products of two palindromes, but a conjugate of a product of three palindromes can have arbitrarily high palindromic length, as is shown in the next example. This means that Theorem 15 does not hold for palindromic length.

Example 16

Let \(\{a_1, \dots , a_n, b, c\}\) be an alphabet and let \(A = a_1 \cdots a_n\). The word

$$\begin{aligned} A^R A bc = (a_n \cdots a_1) (a_1 \cdots a_n) bc \end{aligned}$$

has palindromic length three, but its conjugate

$$\begin{aligned} A bc A^R = (a_1 \cdots a_n) bc (a_n \cdots a_1) \end{aligned}$$

has palindromic length \(2n + 2\). On the other hand, Theorem 15 guarantees that \( A bc A^R \) is a product of four FG-palindromes. In fact, it is a product of three FG-palindromes:

$$\begin{aligned} A bc A^R = A b A^R \cdot (A^R)^{-1} A^{-1} \cdot A c A^R. \end{aligned}$$

This also shows that the ratio of the palindromic length and the FG-palindromic length of a word can be arbitrarily large.

The edit distance (or Levenshtein distance) of two words can be defined as the smallest number of deletions, insertions and substitutions of letters that are required to transform the first word into the second word. A similar definition can be given for elements of a free group. Formally, we define the FG-edit distance of \(x, y \in (\varSigma ^{\pm 1})^*\) as follows:

  • If \(x = y\), the FG-edit distance is zero.

  • If \(x = uav \ne y = ubv\), where \(u, v \in (\varSigma ^{\pm 1})^*\) and \(a, b \in \varSigma ^{\pm 1} \cup \{\varepsilon \}\), the FG-edit distance is one.

  • Otherwise, the FG-edit distance is the smallest number n for which there are \(x_0, \dots , x_n \in (\varSigma ^{\pm 1})^*\) such that \(x_0 = x\), \(x_n = y\), and the edit distance of \(x_{i - 1}\) and \(x_i\) is one for all \(i \in \{1, \dots , n\}\).

The FG-edit distance of two words can be smaller than their ordinary edit distance. For example, the edit distance of \(\varepsilon \) and ab is two, but the FG-edit distance of \(\varepsilon = a a^{-1}\) and ab is one.

Next we will prove that if two elements are close to each other as measured by FG-edit distance, then also their FG-palindromic lengths are close to each other. The idea is that if we want to make a deletion, insertion or substitution in the middle of an element, we can first take a suitable conjugate, then make the deletion, insertion or substitution at the end of the element, and finally take another suitable conjugate. None of these operations can change the FG-palindromic length by much.

Theorem 17

If the FG-edit distance of x and y is d, then the difference of their FG-palindromic lengths is at most \(2d + 1\).

Proof

First, consider the case \(d = 1\). Let \(x = uav\) and \(y = ubv\), where \(u, v \in (\varSigma ^{\pm 1})^*\) and \(a, b \in \varSigma ^{\pm 1} \cup \{\varepsilon \}\). Let the FG-palindromic length of x be \(2k - l\), where \(l \in \{0, 1\}\). Then the FG-palindromic length of vua is at most 2k by Theorem 15, the FG-palindromic length of \(vub = vua \cdot a^{-1} \cdot b\) is at most \(2k + 2\), and the FG-palindromic length of ubv is at most \(2k + 2\) by Theorem 15. This proves the claim for \(d = 1\). The general case follows by iterating the above procedure.    \(\square \)

The next example shows that Theorem 17 does not hold for palindromic length.

Example 18

Consider the word \( A bc A^R \) that appeared in Example 16. It is within edit distance one of a palindrome, but its palindromic length is \(2n + 2\). On the other hand, Theorem 17 guarantees that \( A bc A^R \) is a product of four FG-palindromes. In fact, it is a product of three FG-palindromes, as we saw in Example 16.

8 Conclusion

In this article, we have studied palindromic length. In free monoids, we have compared the maximal palindromic lengths of factors and prefixes, proved the equivalence of two well-known conjectures, and given alternative equivalent ways to define palindromic length. In free groups, we have studied the relations between palindromic length, FG-palindromic length, conjugates, and edit distance. There are many open questions:

  • Conjecture 1 remains open.

  • The fact that the FG-palindromic length of a word can be much smaller than the palindromic length suggests the following question: Does there exist an aperiodic infinite word such that the FG-palindromic lengths of its factors are bounded by a constant?

  • There are several small questions about the optimality of various results. For example, are there words such that all of their prefixes have palindromic length at most n but some of their factors have palindromic length 2n? In the binary case, can we do better than using Lemma 10?

  • We could also look at combinatorial and algorithmic questions related to FG-palindromic length. Finding an algorithm for determining the FG-palindromic length was mentioned as an open problem already in [3].