Documentation

CslibFrontier.Foundations.Data.List.ConsecutivePairs

Consecutive pairs in lists #

This module relates List.consecutivePairs to List.IsChain and describes its endpoints, length, distinctness, and interaction with flatMap.

@[simp]
theorem List.consecutivePairs_cons_cons {α : Type u_1} (a b : α) (l : List α) :
@[simp]
theorem List.isChain_iff_forall_mem_consecutivePairs {α : Type u_1} {r : α → α → Prop} {l : List α} :
IsChain r l ↔ ∀ e ∈ l.consecutivePairs, r e.1 e.2

A list is an r-chain exactly when each consecutive pair satisfies r.

theorem List.fst_mem_of_mem_consecutivePairs {α : Type u_1} {l : List α} {e : α × α} (he : e ∈ l.consecutivePairs) :
e.1 ∈ l
theorem List.snd_mem_of_mem_consecutivePairs {α : Type u_1} {l : List α} {e : α × α} (he : e ∈ l.consecutivePairs) :
e.2 ∈ l
theorem List.consecutivePairs_ne_nil_of_head?_ne_getLast? {α : Type u_1} {l : List α} {a b : α} (hab : a ≠ b) (ha : l.head? = some a) (hb : l.getLast? = some b) :
theorem List.ne_of_mem_consecutivePairs {α : Type u_1} {l : List α} (hl : l.Nodup) {a b : α} (he : (a, b) ∈ l.consecutivePairs) :
a ≠ b
theorem List.Nodup.consecutivePairs {α : Type u_1} {l : List α} (hl : l.Nodup) :
theorem List.not_swap_mem_consecutivePairs {α : Type u_1} {l : List α} (hl : l.Nodup) {a b : α} (he : (a, b) ∈ l.consecutivePairs) :
theorem List.exists_mem_consecutivePairs_boundary {α : Type u_1} (S : α → Prop) {l : List α} {a b : α} :
l.head? = some a → l.getLast? = some b → S a → ¬S b → ∃ e ∈ l.consecutivePairs, S e.1 ∧ ¬S e.2

A list starting inside S and ending outside it has a consecutive pair leaving S.

theorem List.exists_mem_consecutivePairs_snd_eq {α : Type u_1} {l : List α} {b : α} (hb : b ∈ l) (hh : l.head? ≠ some b) :
∃ (a : α), (a, b) ∈ l.consecutivePairs

Every list member distinct from the head is the second entry of a consecutive pair.

theorem List.consecutivePairs_append {α : Type u_1} {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []) :
(l₁ ++ l₂).consecutivePairs = l₁.consecutivePairs ++ (l₁.getLast h₁, l₂.head h₂) :: l₂.consecutivePairs
theorem List.consecutivePairs_append_singleton {α : Type u_1} {l : List α} {a b : α} (hl : l ≠ []) (ha : l.getLast? = some a) :
theorem List.flatMap_ne_nil {α : Type u_1} {β : Type u_2} {L : List β} (hL : L ≠ []) {f : β → List α} (hf : ∀ b ∈ L, f b ≠ []) :
theorem List.head_flatMap {α : Type u_1} {β : Type u_2} {L : List β} (hL : L ≠ []) {f : β → List α} (hf : ∀ b ∈ L, f b ≠ []) :
(flatMap f L).head ⋯ = (f (L.head hL)).head ⋯
theorem List.getLast_flatMap {α : Type u_1} {β : Type u_2} {L : List β} (hL : L ≠ []) {f : β → List α} (hf : ∀ b ∈ L, f b ≠ []) :
(flatMap f L).getLast ⋯ = (f (L.getLast hL)).getLast ⋯
theorem List.mem_consecutivePairs_flatMap {α : Type u_1} {β : Type u_2} {L : List β} (hL : L ≠ []) {f : β → List α} (hf : ∀ (b : β), f b ≠ []) {x y : α} :
(x, y) ∈ (flatMap f L).consecutivePairs ↔ (∃ b ∈ L, (x, y) ∈ (f b).consecutivePairs) ∨ ∃ p ∈ L.consecutivePairs, x = (f p.1).getLast ⋯ ∧ y = (f p.2).head ⋯
theorem List.getElem_mem_consecutivePairs {α : Type u_1} (l : List α) (i : ℕ) (hi : i + 1 < l.length) :
theorem List.mem_consecutivePairs_iff_exists_getElem {α : Type u_1} {l : List α} {x y : α} :
(x, y) ∈ l.consecutivePairs ↔ ∃ (i : ℕ) (hi : i + 1 < l.length), l[i] = x ∧ l[i + 1] = y
theorem List.step_mem_cyclicPairs {α : Type u_1} (l : List α) [NeZero l.length] (hl : l ≠ []) (i : Fin l.length) (h2 : 2 ≤ l.length) :
(l[↑i], l[↑(i + 1)]) ∈ (l.getLast hl, l.head hl) :: l.consecutivePairs
theorem List.cyclicPairs_mem_iff {α : Type u_1} (l : List α) [NeZero l.length] (hl : l ≠ []) (h2 : 2 ≤ l.length) {x y : α} :
(∃ (i : Fin l.length), l[↑i] = x ∧ l[↑(i + 1)] = y) ↔ (x, y) ∈ (l.getLast hl, l.head hl) :: l.consecutivePairs