Palindromic factors of lists #
Index characterizations of Mathlib's List.Palindrome, for whole lists
(List.Palindrome.iff_getElem?) and for factors l.extract a b (List.palindrome_extract_iff),
and the three facts about palindromic factors that center-based palindrome algorithms use:
shrinking a palindromic factor symmetrically keeps it a palindrome
(List.Palindrome.extract_of_le), a palindromic factor extends by one letter on each side iff those
two letters agree (List.palindrome_extract_sub_one_add_one_iff), and palindromic factors inside a
palindromic factor reflect to palindromic factors (List.Palindrome.extract_reflect).
List.palindromicFactors collects distinct palindromic words occurring as contiguous factors,
including the empty word. Prepending a letter introduces at most one new palindrome.
Main results #
List.Palindrome.iff_getElem?:lis a palindrome iffl[i]? = l[l.length - 1 - i]?for everyi < l.length.List.palindrome_extract_iff: forb ≤ l.length, the factorl.extract a bis a palindrome iffl[i]? = l[a + b - 1 - i]?for everya ≤ i < b.List.Palindrome.extract_of_le: shrinking a palindromic factor symmetrically about its center keeps it a palindrome.List.palindrome_extract_sub_one_add_one_iff:l.extract (a - 1) (b + 1)is a palindrome iffl.extract a bis andl[a - 1]? = l[b]?.List.Palindrome.extract_reflect: ifl.extract L Randl.extract a bare palindromes withL ≤ a ≤ b ≤ R, then so is the mirror imagel.extract (L + R - b) (L + R - a).List.card_palindromicFactors_le: a word of lengthnhas at mostn + 1distinct palindromic factors Glen, Justin, Widmer and Zamboni, Proposition 2.1.
Shrinking a palindromic factor symmetrically about its center keeps it a palindrome.
Palindromes reflect inside a palindrome: if l.extract L R is a palindrome and
L ≤ a ≤ b ≤ R, then the factor l.extract a b is a palindrome iff its mirror image
l.extract (L + R - b) (L + R - a) is; this is the forward direction.
Counting distinct palindromic factors #
The distinct palindromic factors of a finite word, including the empty word.
Prepending a letter introduces at most one distinct palindrome. Any new factor is a prefix. If two palindromic prefixes have different lengths, reflection in the longer one places the shorter one in the old word.
A word of length n has at most n + 1 distinct palindromic factors, including the empty
word. This is the Droubay–Justin–Pirillo bound as restated in Glen, Justin, Widmer and
Zamboni, Proposition 2.1. The alphabet need not be finite.