List rotation #
This file proves basic results about List.rotate, the list rotation.
Main declarations #
List.IsRotated l₁ l₂: States thatl₁is a rotated version ofl₂.List.cyclicPermutations l: The list of all cyclic permutants ofl, up to the length ofl.
Tags #
rotated, rotation, permutation, cycle
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.
A variant of List.nthLe_rotate useful for rewrites from right to left.
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'.
Equations
- List.«term_~r_» = Lean.ParserDescr.trailingNode `List.term_~r_ 1000 1001 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ~r ") (Lean.ParserDescr.cat `term 1000))
Instances For
The relation List.IsRotated l l' forms a Setoid of cycles.
Equations
- List.IsRotated.setoid α = { r := List.IsRotated, iseqv := (_ : Equivalence List.IsRotated) }
Instances For
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.nthLe_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]]
Equations
- List.cyclicPermutations x = match x with | [] => [[]] | l@h:(head :: tail) => List.dropLast (List.zipWith (fun x x_1 => x ++ x_1) (List.tails l) (List.inits l))
Instances For
If a l : List α is Nodup l, then all of its cyclic permutants are distinct.
Equations
- List.isRotatedDecidable l l' = decidable_of_iff' (l' ∈ List.map (List.rotate l) (List.range (List.length l + 1))) (_ : l ~r l' ↔ l' ∈ List.map (List.rotate l) (List.range (List.length l + 1)))
Equations
- List.instDecidableRListSetoid = List.isRotatedDecidable l l'