List rotation #
This file proves basic results about list.rotate
, the list rotation.
Main declarations #
is_rotated l₁ l₂
: States thatl₁
is a rotated version ofl₂
.cyclic_permutations l
: The list of all cyclic permutants ofl
, up to the length ofl
.
Tags #
rotated, rotation, permutation, cycle
theorem
list.zip_with_rotate_distrib
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(f : α → β → γ)
(l : list α)
(l' : list β)
(n : ℕ)
(h : l.length = l'.length) :
(list.zip_with f l l').rotate n = list.zip_with f (l.rotate n) (l'.rotate n)
@[simp]
theorem
list.zip_with_rotate_one
{α : Type u}
{β : Type u_1}
(f : α → α → β)
(x y : α)
(l : list α) :
theorem
list.rotate_injective
{α : Type u}
(n : ℕ) :
function.injective (λ (l : list α), l.rotate n)
The relation list.is_rotated l l'
forms a setoid
of cycles.
Equations
- list.is_rotated.setoid α = {r := list.is_rotated α, iseqv := _}
List of all cyclic permutations of l
.
The cyclic_permutations
of a nonempty list l
will always contain list.length l
elements.
This implies that under certain conditions, there are duplicates in list.cyclic_permutations l
.
The n
th entry is equal to l.rotate n
, proven in list.nth_le_cyclic_permutations
.
The proof that every cyclic permutant of l
is in the list is list.mem_cyclic_permutations_iff
.
cyclic_permutations [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]]
Equations
- (_x :: _x_1).cyclic_permutations = (list.zip_with append (_x :: _x_1).tails (_x :: _x_1).inits).init
- list.nil.cyclic_permutations = [list.nil]
@[simp]
theorem
list.cyclic_permutations_cons
{α : Type u}
(x : α)
(l : list α) :
(x :: l).cyclic_permutations = (list.zip_with append (x :: l).tails (x :: l).inits).init
theorem
list.cyclic_permutations_of_ne_nil
{α : Type u}
(l : list α)
(h : l ≠ list.nil) :
l.cyclic_permutations = (list.zip_with append l.tails l.inits).init
@[simp]
@[simp]
theorem
list.nth_le_cyclic_permutations
{α : Type u}
(l : list α)
(n : ℕ)
(hn : n < l.cyclic_permutations.length) :
l.cyclic_permutations.nth_le n hn = l.rotate n
theorem
list.length_mem_cyclic_permutations
{α : Type u}
{l' : list α}
(l : list α)
(h : l' ∈ l.cyclic_permutations) :
@[simp]
theorem
list.mem_cyclic_permutations_iff
{α : Type u}
{l l' : list α} :
l ∈ l'.cyclic_permutations ↔ l ~r l'
@[simp]
@[simp]
theorem
list.cyclic_permutations_eq_singleton_iff
{α : Type u}
{l : list α}
{x : α} :
l.cyclic_permutations = [[x]] ↔ l = [x]
If a l : list α
is nodup l
, then all of its cyclic permutants are distinct.
@[simp]
theorem
list.cyclic_permutations_rotate
{α : Type u}
(l : list α)
(k : ℕ) :
(l.rotate k).cyclic_permutations = l.cyclic_permutations.rotate k
@[simp]
theorem
list.is_rotated_cyclic_permutations_iff
{α : Type u}
{l l' : list α} :
l.cyclic_permutations ~r l'.cyclic_permutations ↔ l ~r l'
@[protected, instance]
Equations
- l.is_rotated_decidable l' = decidable_of_iff' (l' ∈ list.map l.rotate (list.range (l.length + 1))) list.is_rotated_iff_mem_map_range
@[protected, instance]