Documentation

CslibFrontier.Foundations.Combinatorics.Words.SquareFree

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 #

Main results #

def Cslib.Word.IsSquareFree {A : Type u_1} (w : List A) :

A word w : List A is square-free if no nonempty word u appears twice consecutively as a contiguous factor u ++ u <:+: w.

theorem Cslib.Word.isSquareFree_iff {A : Type u_1} {w : List A} :
IsSquareFree w ↔ ∀ (u : List A), u ≠ [] → ¬u ++ u <:+: w

Unfolded characterization of IsSquareFree.

@[simp]

The empty word is square-free.

@[simp]

Every single-letter word is square-free.

theorem Cslib.Word.IsSquareFree.of_infix {A : Type u_1} {v w : List A} (hw : IsSquareFree w) (hvw : v <:+: w) :

Every factor (infix) of a square-free word is square-free.

theorem Cslib.Word.IsSquareFree.of_prefix {A : Type u_1} {v w : List A} (hw : IsSquareFree w) (hvw : v <+: w) :

Every prefix of a square-free word is square-free.

theorem Cslib.Word.IsSquareFree.of_suffix {A : Type u_1} {v w : List A} (hw : IsSquareFree w) (hvw : v <:+ w) :

Every suffix of a square-free word is square-free.

theorem Cslib.Word.IsSquareFree.take {A : Type u_1} {w : List A} (hw : IsSquareFree w) (n : ℕ) :

Taking any prefix w.take n preserves square-freeness.

theorem Cslib.Word.IsSquareFree.drop {A : Type u_1} {w : List A} (hw : IsSquareFree w) (n : ℕ) :

Dropping any prefix w.drop n preserves square-freeness.

theorem Cslib.Word.not_isSquareFree_of_pair_infix {A : Type u_1} {w : List A} {x : A} (hx : [x, x] <:+: w) :

No square-free word contains two equal adjacent letters [x, x].

theorem Cslib.Word.pair_getElem_infix {A : Type u_1} {w : List A} {i : ℕ} (hi : i + 1 < w.length) :
[w[i], w[i + 1]] <:+: w

Any two consecutive entries [w[i], w[i + 1]] form a contiguous 2-factor of w.

theorem Cslib.Word.IsSquareFree.getElem_ne_succ {A : Type u_1} {w : List A} (hw : IsSquareFree w) {i : ℕ} (hi : i + 1 < w.length) :
w[i] ≠ w[i + 1]

Adjacent letters in a square-free word are distinct.

theorem Cslib.Word.IsSquareFree.map {A : Type u_1} {B : Type u_2} {f : A → B} (hf : Function.Injective f) {w : List A} (hw : IsSquareFree w) :

Square-freeness is preserved under injective letter maps.

theorem Cslib.Word.isSquareFree_iff_forall_slice {A : Type u_1} {w : List A} :
IsSquareFree w ↔ ∀ (i k : ℕ), 0 < k → ∀ (hik : i + 2 * k ≤ w.length), ∃ (j : ℕ) (hj : j < k), w[i + j] ≠ w[i + k + j]

Indexing characterization of IsSquareFree: no nonempty slice of length k repeats immediately at i and i + k.

Leech's 13-uniform cyclic morphism block Fin 3 → List (Fin 3), obtained by cyclically shifting 0, 1, 2 by a in [0, 1, 2, 1, 0, 2, 1, 2, 0, 1, 2, 1, 0].

@[simp]

Length of every leechBlock a is 13.

Leech's 13-uniform morphism preserves square-freeness on Fin 3.

Iterated Leech ternary word leechWord k : List (Fin 3) of length 13 ^ k.

@[simp]

The 0-th iterated Leech word is [0].

Recursive unfolding leechWord (k + 1) = (leechWord k).flatMap leechBlock.

@[simp]

Every leechWord k has length 13 ^ k.

Every iterated Leech word leechWord k is square-free.

Thue's Square-Free Word Theorem ([Thu06]; constructed via Leech's 13-uniform morphism [Lee57]): for every length n : ℕ, there exists a square-free word over Fin 3 of length n.

The set of square-free words over Fin 3 is infinite.