The Mathlib Handbook

The volumes of the handbook are not written yet. This site shows the map of Mathlib that they will follow, at Mathlib 4472534b60.

The areas / V33. Data structures and computation

Mathlib.Data.List.PeriodicityLemma

13 declarations. Mathlib docs · Source

Periods of words (Lists)

This file defines the notion of a period of a word (list) and proves the Periodicity Lemma.

Implementation notes

The definition of a period is given in terms of self-overlap. Equivalent characterizations in terms of indices and modular arithmetic are also provided.

Tags

periodicity lemma, Fine-Wilf theorem, period, periodicity

def List.HasPeriod E1 #

{α : Type u_1} → List α → ℕ → Prop

HasPeriod w p, means that the list w has the period p, which can be seen in two equivalent ways: · The list w starts again after the prefix of length p. That is, w overlaps with itself with offset p. · The element of w at index i is the same as the element at index i + p, for all i The definition is given in terms of the self-overlap.

theorem List.hasPeriod_iff_getElem? E1 #

∀ {α : Type u_1} {p : ℕ} {w : List α}, w.HasPeriod p ↔ ∀ i < w.length - p, w[i]? = w[i + p]?

This is the equivalent definition of HasPeriod w p by indices.

theorem List.hasPeriod_zero E0 #

∀ {α : Type u_1} (w : List α), w.HasPeriod 0

theorem List.hasPeriod_of_length_le E0 #

∀ {α : Type u_1} (w : List α) (p : ℕ), w.length ≤ p → w.HasPeriod p

theorem List.hasPeriod_empty E1 #

∀ {α : Type u_1} (p : ℕ), [].HasPeriod p

theorem List.HasPeriod.getElem?_mod E1 #

∀ {α : Type u_1} (p i : ℕ) (w : List α), w.HasPeriod p → i < w.length → w[i % p]? = w[i]?

theorem List.hasPeriod_iff_forall_getElem?_mod E1 #

∀ {α : Type u_1} {p : ℕ} {w : List α}, w.HasPeriod p ↔ ∀ i < w.length, w[i]? = w[i % p]?

An equivalent definition of HasPeriod w p by modular equivalence on indices.

theorem List.HasPeriod.factor E1 #

∀ {α : Type u_1} {u v w : List α} {p : ℕ}, (u ++ v ++ w).HasPeriod p → v.HasPeriod p

If w has a period p, then any of its factors has a period p as well.

theorem List.HasPeriod.infix E1 #

∀ {α : Type u_1} {u w : List α} {p : ℕ}, w.HasPeriod p → u <:+: w → u.HasPeriod p

theorem List.HasPeriod.drop_prefix E1 #

∀ {α : Type u_1} {w : List α} (p : ℕ), w.HasPeriod p → List.drop p w <+: w

theorem List.HasPeriod.take_append E1 #

∀ {α : Type u_1} (p n : ℕ) (w : List α), p ∣ n → n ≤ w.length → w.HasPeriod p → (List.take n w ++ w).HasPeriod p

If w has a period p, and we extend it to the left by its prefix whose length divides p, then the resulting word also has a period p.

theorem List.HasPeriod.drop_of_hasPeriod_add E1 #

∀ {α : Type u_1} {q k : ℕ} {w : List α}, w.HasPeriod q → w.HasPeriod (k + q) → (List.drop q w).HasPeriod k

Induction step for the periodicity_lemma

theorem List.HasPeriod.gcd E2 #

∀ {α : Type u_1} {w : List α} {p q : ℕ},
  w.HasPeriod p → w.HasPeriod q → p + q - p.gcd q ≤ w.length → w.HasPeriod (p.gcd q)

The Periodicity Lemma, also known as the Fine and Wilf theorem, shows that if word w of length at least p + q - gcd p q has two periods p and q, then it has a period gcd p q. The proof is similar to the Euclidean algorithm for computing gcd.