List rotation #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
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
is_rotated 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'
.
Instances for list.is_rotated
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 has_append.append (_x :: _x_1).tails (_x :: _x_1).inits).init
- list.nil.cyclic_permutations = [list.nil]
If a l : list α
is nodup l
, then all of its cyclic permutants are distinct.
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