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.Rotate

102 declarations and 1 deprecated aliases. Mathlib docs · Source

List rotation

This file proves basic results about List.rotate, the list rotation.

Main declarations

  • List.IsRotated l₁ l₂: States that l₁ is a rotated version of l₂.
  • List.cyclicPermutations l: The list of all cyclic permutants of l, up to the length of l.

Tags

rotated, rotation, permutation, cycle

theorem List.rotate_mod E0 #

∀ {α : Type u} (l : List α) (n : ℕ), l.rotate (n % l.length) = l.rotate n

theorem List.rotate_nil E0 #

∀ {α : Type u} (n : ℕ), [].rotate n = []

theorem List.rotate_zero E0 #

∀ {α : Type u} (l : List α), l.rotate 0 = l

theorem List.rotate'_nil E1 #

∀ {α : Type u} (n : ℕ), [].rotate' n = []

theorem List.rotate'_zero E0 #

∀ {α : Type u} (l : List α), l.rotate' 0 = l

theorem List.rotate'_cons_succ E1 #

∀ {α : Type u} (l : List α) (a : α) (n : ℕ), (a :: l).rotate' n.succ = (l ++ [a]).rotate' n

theorem List.length_rotate' E0 #

∀ {α : Type u} (l : List α) (n : ℕ), (l.rotate' n).length = l.length

theorem List.rotate'_eq_drop_append_take E1 #

∀ {α : Type u} {l : List α} {n : ℕ}, n ≤ l.length → l.rotate' n = List.drop n l ++ List.take n l

theorem List.rotate'_rotate' E0 #

∀ {α : Type u} (l : List α) (n m : ℕ), (l.rotate' n).rotate' m = l.rotate' (n + m)

theorem List.rotate'_length E0 #

∀ {α : Type u} (l : List α), l.rotate' l.length = l

theorem List.rotate'_length_mul E0 #

∀ {α : Type u} (l : List α) (n : ℕ), l.rotate' (l.length * n) = l

theorem List.rotate'_mod E0 #

∀ {α : Type u} (l : List α) (n : ℕ), l.rotate' (n % l.length) = l.rotate' n

theorem List.rotate_eq_rotate' E1 #

∀ {α : Type u} (l : List α) (n : ℕ), l.rotate n = l.rotate' n

theorem List.rotate_cons_succ E0 #

∀ {α : Type u} (l : List α) (a : α) (n : ℕ), (a :: l).rotate (n + 1) = (l ++ [a]).rotate n

theorem List.mem_rotate E0 #

∀ {α : Type u} {l : List α} {a : α} {n : ℕ}, a ∈ l.rotate n ↔ a ∈ l

theorem List.length_rotate E0 #

∀ {α : Type u} (l : List α) (n : ℕ), (l.rotate n).length = l.length

theorem List.rotate_replicate E0 #

∀ {α : Type u} (a : α) (n k : ℕ), (List.replicate n a).rotate k = List.replicate n a

theorem List.rotate_eq_drop_append_take E1 #

∀ {α : Type u} {l : List α} {n : ℕ}, n ≤ l.length → l.rotate n = List.drop n l ++ List.take n l

theorem List.rotate_eq_drop_append_take_mod E1 #

∀ {α : Type u} {l : List α} {n : ℕ}, l.rotate n = List.drop (n % l.length) l ++ List.take (n % l.length) l

theorem List.rotate_append_length_eq E0 #

∀ {α : Type u} (l l' : List α), (l ++ l').rotate l.length = l' ++ l

theorem List.rotate_rotate E0 #

∀ {α : Type u} (l : List α) (n m : ℕ), (l.rotate n).rotate m = l.rotate (n + m)

theorem List.rotate_length E0 #

∀ {α : Type u} (l : List α), l.rotate l.length = l

theorem List.rotate_length_mul E0 #

∀ {α : Type u} (l : List α) (n : ℕ), l.rotate (l.length * n) = l

theorem List.rotate_perm E1 #

∀ {α : Type u} (l : List α) (n : ℕ), (l.rotate n).Perm l

theorem List.nodup_rotate E0 #

∀ {α : Type u} {l : List α} {n : ℕ}, (l.rotate n).Nodup ↔ l.Nodup

theorem List.rotate_eq_nil_iff E0 #

∀ {α : Type u} {l : List α} {n : ℕ}, l.rotate n = [] ↔ l = []

theorem List.nil_eq_rotate_iff E0 #

∀ {α : Type u} {l : List α} {n : ℕ}, [] = l.rotate n ↔ [] = l

theorem List.rotate_singleton E0 #

∀ {α : Type u} (x : α) (n : ℕ), [x].rotate n = [x]

theorem List.zipWith_rotate_distrib E1 #

∀ {α : Type u} {β : Type u_1} {γ : Type u_2} (f : α → β → γ) (l : List α) (l' : List β) (n : ℕ),
  l.length = l'.length → (List.zipWith f l l').rotate n = List.zipWith f (l.rotate n) (l'.rotate n)

theorem List.zipWith_rotate_one E1 #

∀ {α : Type u} {β : Type u_1} (f : α → α → β) (x y : α) (l : List α),
  List.zipWith f (x :: y :: l) ((x :: y :: l).rotate 1) = f x y :: List.zipWith f (y :: l) (l ++ [x])

theorem List.getElem?_rotate E1 #

∀ {α : Type u} {l : List α} {n m : ℕ}, m < l.length → (l.rotate n)[m]? = l[(m + n) % l.length]?

theorem List.getElem_rotate E0 #

∀ {α : Type u} (l : List α) (n k : ℕ) (h : k < (l.rotate n).length), (l.rotate n)[k] = l[(k + n) % l.length]

theorem List.get_rotate E1 #

∀ {α : Type u} (l : List α) (n : ℕ) (k : Fin (l.rotate n).length), (l.rotate n).get k = l.get ⟨(↑k + n) % l.length, ⋯⟩

theorem List.head?_rotate E0 #

∀ {α : Type u} {l : List α} {n : ℕ}, n < l.length → (l.rotate n).head? = l[n]?

theorem List.get_rotate_one E1 #

∀ {α : Type u} (l : List α) (k : Fin (l.rotate 1).length), (l.rotate 1).get k = l.get ⟨(↑k + 1) % l.length, ⋯⟩

theorem List.getElem_eq_getElem_rotate E1 #

∀ {α : Type u} (l : List α) (n k : ℕ) (hk : k < l.length), l[k] = (l.rotate n)[(l.length - n % l.length + k) % l.length]

A version of List.getElem_rotate that represents l[k] in terms of (List.rotate l n)[⋯], not vice versa. Can be used instead of rewriting List.getElem_rotate from right to left.

theorem List.get_eq_get_rotate E1 #

∀ {α : Type u} (l : List α) (n : ℕ) (k : Fin l.length),
  l.get k = (l.rotate n).get ⟨(l.length - n % l.length + ↑k) % l.length, ⋯⟩

A version of List.get_rotate that represents List.get l in terms of List.get (List.rotate l n), not vice versa. Can be used instead of rewriting List.get_rotate from right to left.

theorem List.rotate_eq_self_iff_eq_replicate E1 #

∀ {α : Type u} [hα : Nonempty α] {l : List α}, (∀ (n : ℕ), l.rotate n = l) ↔ ∃ a, l = List.replicate l.length a

theorem List.rotate_one_eq_self_iff_eq_replicate E1 #

∀ {α : Type u} [Nonempty α] {l : List α}, l.rotate 1 = l ↔ ∃ a, l = List.replicate l.length a

theorem List.rotate_injective E1 #

∀ {α : Type u} (n : ℕ), Function.Injective fun l ↦ l.rotate n

theorem List.rotate_eq_rotate E0 #

∀ {α : Type u} {l l' : List α} {n : ℕ}, l.rotate n = l'.rotate n ↔ l = l'

theorem List.rotate_eq_iff E0 #

∀ {α : Type u} {l l' : List α} {n : ℕ}, l.rotate n = l' ↔ l = l'.rotate (l'.length - n % l'.length)

theorem List.rotate_eq_singleton_iff E0 #

∀ {α : Type u} {l : List α} {n : ℕ} {x : α}, l.rotate n = [x] ↔ l = [x]

theorem List.singleton_eq_rotate_iff E0 #

∀ {α : Type u} {l : List α} {n : ℕ} {x : α}, [x] = l.rotate n ↔ [x] = l

theorem List.reverse_rotate E1 #

∀ {α : Type u} (l : List α) (n : ℕ), (l.rotate n).reverse = l.reverse.rotate (l.length - n % l.length)

theorem List.rotate_reverse E1 #

∀ {α : Type u} (l : List α) (n : ℕ), l.reverse.rotate n = (l.rotate (l.length - n % l.length)).reverse

theorem List.map_rotate E0 #

∀ {α : Type u} {β : Type u_1} (f : α → β) (l : List α) (n : ℕ), List.map f (l.rotate n) = (List.map f l).rotate n

theorem List.Nodup.rotate_congr E1 #

∀ {α : Type u} {l : List α}, l.Nodup → l ≠ [] → ∀ (i j : ℕ), l.rotate i = l.rotate j → i % l.length = j % l.length

theorem List.Nodup.rotate_congr_iff E0 #

∀ {α : Type u} {l : List α}, l.Nodup → ∀ {i j : ℕ}, l.rotate i = l.rotate j ↔ i % l.length = j % l.length ∨ l = []

theorem List.Nodup.rotate_eq_self_iff E0 #

∀ {α : Type u} {l : List α}, l.Nodup → ∀ {n : ℕ}, l.rotate n = l ↔ n % l.length = 0 ∨ l = []

def List.IsRotated E1 #

{α : Type u} → List α → List α → Prop

IsRotated l₁ l₂ or l₁ ~r l₂ asserts that l₁ and l₂ are cyclic permutations of each other. This is defined by claiming that ∃ n, l.rotate n = l'.

def List.«term_~r_» E1 #

Lean.TrailingParserDescr

IsRotated l₁ l₂ or l₁ ~r l₂ asserts that l₁ and l₂ are cyclic permutations of each other. This is defined by claiming that ∃ n, l.rotate n = l'.

theorem List.IsRotated.refl E1 #

∀ {α : Type u} (l : List α), l ~r l

theorem List.IsRotated.symm E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' → l' ~r l

theorem List.isRotated_comm E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' ↔ l' ~r l

theorem List.IsRotated.forall E0 #

∀ {α : Type u} (l : List α) (n : ℕ), l.rotate n ~r l

theorem List.IsRotated.trans E1 #

∀ {α : Type u} {l l' l'' : List α}, l ~r l' → l' ~r l'' → l ~r l''

instance List.instIsEquivIsRotated E0 #

∀ {α : Type u}, IsEquiv (List α) List.IsRotated

def List.IsRotated.setoid E1 #

(α : Type u_1) → Setoid (List α)

The relation List.IsRotated l l' forms a Setoid of cycles.

theorem List.IsRotated.perm E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' → l.Perm l'

theorem List.IsRotated.nodup_iff E0 #

∀ {α : Type u} {l l' : List α}, l ~r l' → (l.Nodup ↔ l'.Nodup)

theorem List.IsRotated.mem_iff E0 #

∀ {α : Type u} {l l' : List α}, l ~r l' → ∀ {a : α}, a ∈ l ↔ a ∈ l'

theorem List.isRotated_nil_iff E0 #

∀ {α : Type u} {l : List α}, l ~r [] ↔ l = []

theorem List.isRotated_nil_iff' E0 #

∀ {α : Type u} {l : List α}, [] ~r l ↔ [] = l

theorem List.isRotated_singleton_iff E0 #

∀ {α : Type u} {l : List α} {x : α}, l ~r [x] ↔ l = [x]

theorem List.isRotated_singleton_iff' E0 #

∀ {α : Type u} {l : List α} {x : α}, [x] ~r l ↔ [x] = l

theorem List.isRotated_concat E1 #

∀ {α : Type u} (hd : α) (tl : List α), tl ++ [hd] ~r hd :: tl

theorem List.isRotated_append E1 #

∀ {α : Type u} {l l' : List α}, l ++ l' ~r l' ++ l

theorem List.IsRotated.reverse E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' → l.reverse ~r l'.reverse

theorem List.isRotated_reverse_comm_iff E0 #

∀ {α : Type u} {l l' : List α}, l.reverse ~r l' ↔ l ~r l'.reverse

theorem List.isRotated_reverse_iff E0 #

∀ {α : Type u} {l l' : List α}, l.reverse ~r l'.reverse ↔ l ~r l'

theorem List.isRotated_iff_mod E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' ↔ ∃ n ≤ l.length, l.rotate n = l'

theorem List.isRotated_iff_mem_map_range E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' ↔ l' ∈ List.map l.rotate (List.range (l.length + 1))

theorem List.IsRotated.map E1 #

∀ {α : Type u} {β : Type u_1} {l₁ l₂ : List α}, l₁ ~r l₂ → ∀ (f : α → β), List.map f l₁ ~r List.map f l₂

theorem List.IsRotated.cons_append_singleton E1 #

∀ {α : Type u} {l : List α} {a : α}, a :: l ~r l ++ [a]

theorem List.IsRotated.cons_getLast_dropLast E1 #

∀ {α : Type u} (L : List α) (hL : L ≠ []), L.getLast hL :: L.dropLast ~r L

theorem List.IsRotated.dropLast_tail E1 #

∀ {α : Type u_1} {L : List α} (hL : L ≠ []), L.head hL = L.getLast hL → L.dropLast ~r L.tail

theorem List.comp_isRotated_sublist E1 #

∀ {α : Type u}, Relation.Comp List.IsRotated List.Sublist = Relation.Comp List.Sublist List.IsRotated

def List.cyclicPermutations E1 #

{α : Type u} → List α → List (List α)

List of all cyclic permutations of l. The cyclicPermutations of a nonempty list l will always contain List.length l elements. This implies that under certain conditions, there are duplicates in List.cyclicPermutations l. The nth entry is equal to l.rotate n, proven in List.get_cyclicPermutations. The proof that every cyclic permutant of l is in the list is List.mem_cyclicPermutations_iff.

     cyclicPermutations [1, 2, 3, 2, 4] =
       [[1, 2, 3, 2, 4], [2, 3, 2, 4, 1], [3, 2, 4, 1, 2],
        [2, 4, 1, 2, 3], [4, 1, 2, 3, 2]]

theorem List.cyclicPermutations_nil E0 #

∀ {α : Type u}, [].cyclicPermutations = [[]]

theorem List.cyclicPermutations_cons E1 #

∀ {α : Type u} (x : α) (l : List α),
  (x :: l).cyclicPermutations = (List.zipWith (fun x1 x2 ↦ x1 ++ x2) (x :: l).tails (x :: l).inits).dropLast

theorem List.cyclicPermutations_of_ne_nil E1 #

∀ {α : Type u} (l : List α),
  l ≠ [] → l.cyclicPermutations = (List.zipWith (fun x1 x2 ↦ x1 ++ x2) l.tails l.inits).dropLast

theorem List.length_cyclicPermutations_cons E1 #

∀ {α : Type u} (x : α) (l : List α), (x :: l).cyclicPermutations.length = l.length + 1

theorem List.length_cyclicPermutations_of_ne_nil E0 #

∀ {α : Type u} (l : List α), l ≠ [] → l.cyclicPermutations.length = l.length

theorem List.cyclicPermutations_ne_nil E0 #

∀ {α : Type u} (l : List α), l.cyclicPermutations ≠ []

theorem List.getElem_cyclicPermutations E0 #

∀ {α : Type u} (l : List α) (n : ℕ) (h : n < l.cyclicPermutations.length), l.cyclicPermutations[n] = l.rotate n

theorem List.get_cyclicPermutations E1 #

∀ {α : Type u} (l : List α) (n : Fin l.cyclicPermutations.length), l.cyclicPermutations.get n = l.rotate ↑n

theorem List.head_cyclicPermutations E0 #

∀ {α : Type u} (l : List α), l.cyclicPermutations.head ⋯ = l

theorem List.head?_cyclicPermutations E0 #

∀ {α : Type u} (l : List α), l.cyclicPermutations.head? = some l

theorem List.cyclicPermutations_injective E1 #

∀ {α : Type u}, Function.Injective List.cyclicPermutations

theorem List.cyclicPermutations_inj E0 #

∀ {α : Type u} {l l' : List α}, l.cyclicPermutations = l'.cyclicPermutations ↔ l = l'

theorem List.length_mem_cyclicPermutations E1 #

∀ {α : Type u} {l' : List α} (l : List α), l' ∈ l.cyclicPermutations → l'.length = l.length

theorem List.mem_cyclicPermutations_self E0 #

∀ {α : Type u} (l : List α), l ∈ l.cyclicPermutations

theorem List.cyclicPermutations_rotate E0 #

∀ {α : Type u} (l : List α) (k : ℕ), (l.rotate k).cyclicPermutations = l.cyclicPermutations.rotate k

theorem List.mem_cyclicPermutations_iff E0 #

∀ {α : Type u} {l l' : List α}, l ∈ l'.cyclicPermutations ↔ l ~r l'

theorem List.cyclicPermutations_eq_nil_iff E0 #

∀ {α : Type u} {l : List α}, l.cyclicPermutations = [[]] ↔ l = []

theorem List.cyclicPermutations_eq_singleton_iff E0 #

∀ {α : Type u} {l : List α} {x : α}, l.cyclicPermutations = [[x]] ↔ l = [x]

theorem List.Nodup.cyclicPermutations E1 #

∀ {α : Type u} {l : List α}, l.Nodup → l.cyclicPermutations.Nodup

If a l : List α is Nodup l, then all of its cyclic permutants are distinct.

theorem List.IsRotated.cyclicPermutations E1 #

∀ {α : Type u} {l l' : List α}, l ~r l' → l.cyclicPermutations ~r l'.cyclicPermutations

theorem List.isRotated_cyclicPermutations_iff E0 #

∀ {α : Type u} {l l' : List α}, l.cyclicPermutations ~r l'.cyclicPermutations ↔ l ~r l'

instance List.isRotatedDecidable E0 #

{α : Type u} → [DecidableEq α] → (l l' : List α) → Decidable (l ~r l')

instance List.instDecidableR_mathlib E0 #

{α : Type u} → [DecidableEq α] → {l l' : List α} → Decidable ((List.IsRotated.setoid α) l l')

Deprecated aliases

NameNew nameSince
List.IsRotated.eqvEquivalence.of_isEquiv2026-09-09