Square-Free Words and Thue's Theorem #
A finite word w : List A over an alphabet A is square-free (Cslib.Word.IsSquareFree) if
it contains no nonempty factor of the form u ++ u. Repeating a single letter adjacently
([x, x]) produces a square of length 2, so square-free words have no equal consecutive letters.
Over a two-letter alphabet every word of length at least 4 contains a square, whereas Axel Thue
[Thu06] proved that arbitrarily long square-free words exist over a three-letter alphabet.
Following John Leech [Lee57], we construct arbitrarily long ternary square-free words under
standard Lean axioms by iterating a 13-uniform cyclic morphism
leechBlock : Fin 3 → List (Fin 3).
Main definitions #
Cslib.Word.IsSquareFree: predicate asserting thatw : List Ahas no nonempty square factoru ++ u <:+: w.Cslib.Word.leechBlock: Leech's13-uniform cyclic ternary morphism block onFin 3.Cslib.Word.leechWord: iterated Leech word of length13 ^ koverFin 3.
Main results #
Cslib.Word.IsSquareFree.of_infix: factors of square-free words are square-free.Cslib.Word.IsSquareFree.map: injective alphabet maps preserve square-freeness.Cslib.Word.IsSquareFree.flatMap_leechBlock: Leech's13-uniform morphism preserves square-freeness onFin 3.Cslib.Word.isSquareFree_leechWord: every iterated Leech wordleechWord kis square-free.Cslib.Word.exists_isSquareFree_length: Thue's Theorem — for everyn : ℕ, there exists a square-free word overFin 3of lengthn.Cslib.Word.infinite_setOf_isSquareFree: the set of square-free words overFin 3is infinite.
Unfolded characterization of IsSquareFree.
The empty word is square-free.
Every single-letter word is square-free.
Every factor (infix) of a square-free word is square-free.
Every prefix of a square-free word is square-free.
Every suffix of a square-free word is square-free.
Taking any prefix w.take n preserves square-freeness.
Dropping any prefix w.drop n preserves square-freeness.
Square-freeness is preserved under injective letter maps.
Indexing characterization of IsSquareFree: no nonempty slice of length k repeats
immediately at i and i + k.
Length of every leechBlock a is 13.
Leech's 13-uniform morphism preserves square-freeness on Fin 3.
Recursive unfolding leechWord (k + 1) = (leechWord k).flatMap leechBlock.
Every iterated Leech word leechWord k is square-free.