Cycles of a list #
Lists have an equivalence relation of whether they are rotational permutations of one another.
This relation is defined as IsRotated
.
Based on this, we define the quotient of lists by the rotation relation, called Cycle
.
We also define a representation of concrete cycles, available when viewing them in a goal state or
via #eval
, when over representable types. For example, the cycle (2 1 4 3)
will be shown
as c[2, 1, 4, 3]
. Two equal cycles may be printed differently if their internal representation
is different.
Return the z
such that x :: z :: _
appears in xs
, or default
if there is no such z
.
Equations
Instances For
nextOr
does not depend on the default value, if the next value appears.
Given an element x : α
of l : List α
such that x ∈ l
, get the next
element of l
. This works from head to tail, (including a check for last element)
so it will match on first hit, ignoring later duplicates.
For example:
next [1, 2, 3] 2 _ = 3
next [1, 2, 3] 3 _ = 1
next [1, 2, 3, 2, 4] 2 _ = 3
next [1, 2, 3, 2] 2 _ = 3
next [1, 1, 2, 3, 2] 1 _ = 1
Equations
- l.next x h = l.nextOr x (l.get ⟨0, ⋯⟩)
Instances For
Given an element x : α
of l : List α
such that x ∈ l
, get the previous
element of l
. This works from head to tail, (including a check for last element)
so it will match on first hit, ignoring later duplicates.
prev [1, 2, 3] 2 _ = 1
prev [1, 2, 3] 1 _ = 3
prev [1, 2, 3, 2, 4] 2 _ = 1
prev [1, 2, 3, 4, 2] 2 _ = 1
prev [1, 1, 2] 1 _ = 2
Equations
Instances For
The coercion from List α
to Cycle α
Equations
- Cycle.ofList = Quot.mk ⇑(List.IsRotated.setoid α)
Instances For
For consistency with EmptyCollection (List α)
.
Equations
- Cycle.instEmptyCollection = { emptyCollection := Cycle.nil }
Equations
- Cycle.instMembership = { mem := Cycle.Mem }
Equations
- s₁.instDecidableEq s₂ = Quotient.recOnSubsingleton₂' s₁ s₂ fun (x x_1 : List α) => decidable_of_iff' ((List.IsRotated.setoid α) x x_1) ⋯
Equations
- Cycle.instDecidableMemOfDecidableEq x s = Quotient.recOnSubsingleton' s fun (l : List α) => let_fun this := inferInstance; this
The length of the s : Cycle α
, which is the number of elements, counting duplicates.
Equations
- s.length = Quot.liftOn s List.length ⋯
Instances For
The s : Cycle α
as a Multiset α
.
Equations
- s.toMultiset = Quotient.liftOn' s Multiset.ofList ⋯
Instances For
The Multiset
of lists that can make the cycle.
Equations
- s.lists = Quotient.liftOn' s (fun (l : List α) => ↑l.cyclicPermutations) ⋯
Instances For
Auxiliary decidability algorithm for lists that contain at least two unique elements.
Equations
- Cycle.decidableNontrivialCoe [] = isFalse ⋯
- Cycle.decidableNontrivialCoe [x_1] = isFalse ⋯
- Cycle.decidableNontrivialCoe (x_1 :: y :: l) = if h : x_1 = y then decidable_of_iff' (↑(x_1 :: l)).Nontrivial ⋯ else isTrue ⋯
Instances For
Equations
- Cycle.instDecidableNontrivial = Quot.recOnSubsingleton s Cycle.decidableNontrivialCoe
Equations
- Cycle.instDecidableNodup = Quot.recOnSubsingleton s List.nodupDecidable
Equations
- Cycle.fintypeNodupCycle = Fintype.ofSurjective (fun (l : { l : List α // l.Nodup }) => ⟨↑↑l, ⋯⟩) ⋯
Equations
- Cycle.fintypeNodupNontrivialCycle = Fintype.subtype (Finset.filter Cycle.Nontrivial (Finset.map (Function.Embedding.subtype fun (s : Cycle α) => s.Nodup) Finset.univ)) ⋯
Given a s : Cycle α
such that Nodup s
, retrieve the next element after x ∈ s
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Given a s : Cycle α
such that Nodup s
, retrieve the previous element before x ∈ s
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
We define a representation of concrete cycles, available when viewing them in a goal state or
via #eval
, when over representable types. For example, the cycle (2 1 4 3)
will be shown
as c[2, 1, 4, 3]
. Two equal cycles may be printed differently if their internal representation
is different.
Equations
- One or more equations did not get rendered due to their size.
chain R s
means that R
holds between adjacent elements of s
.
chain R ([a, b, c] : Cycle α) ↔ R a b ∧ R b c ∧ R c a
Equations
- Cycle.Chain r c = Quotient.liftOn' c (fun (l : List α) => match l with | [] => True | a :: m => List.Chain r a (m ++ [a])) ⋯
Instances For
As a function from a relation to a predicate, chain
is monotonic.