The areas / V33. Data structures and computation
Mathlib.Data.List.SplitBy
17 declarations. Mathlib docs · Source
Split a list into contiguous runs of elements which pairwise satisfy a relation.
This file provides the basic API for List.splitBy which is defined in Core.
The main results are the following:
List.flatten_splitBy: the lists inList.splitByjoin to the original list.List.nil_notMem_splitBy: the empty list is not contained inList.splitBy.List.isChain_of_mem_splitBy: any two adjacent elements in a list inList.splitByare related by the specified relation.List.isChain_getLast_head_splitBy: the last element of each list inList.splitByis not related to the first element of the next list.
theorem List.splitBy.loop.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : List α → α → List α → List (List α) → Sort u_2) (x : List α) (x_1 : α) (x_2 : List α)
(x_3 : List (List α))
(h_1 : (a : α) → (as : List α) → (b : α) → (r : List α) → (acc : List (List α)) → motive (a :: as) b r acc)
(h_2 : (ag : α) → (r : List α) → (acc : List (List α)) → motive [] ag r acc) (a : α) (as : List α) (b : α)
(r : List α) (acc : List (List α)),
x = a :: as →
x_1 = b →
x_2 = r →
x_3 = acc →
(match x, x_1, x_2, x_3 with
| a :: as, b, r, acc => h_1 a as b r acc
| [], ag, r, acc => h_2 ag r acc) ≍
h_1 a as b r acc
theorem List.splitBy.loop.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : List α → α → List α → List (List α) → Sort u_2) (x : List α) (x_1 : α) (x_2 : List α)
(x_3 : List (List α))
(h_1 : (a : α) → (as : List α) → (b : α) → (r : List α) → (acc : List (List α)) → motive (a :: as) b r acc)
(h_2 : (ag : α) → (r : List α) → (acc : List (List α)) → motive [] ag r acc) (ag : α) (r : List α)
(acc : List (List α)),
x = [] →
x_1 = ag →
x_2 = r →
x_3 = acc →
(match x, x_1, x_2, x_3 with
| a :: as, b, r, acc => h_1 a as b r acc
| [], ag, r, acc => h_2 ag r acc) ≍
h_2 ag r acc
theorem List.splitBy_nil E0 #
∀ {α : Type u_1} (r : α → α → Bool), List.splitBy r [] = []
theorem List.flatten_splitBy E0 #
∀ {α : Type u_1} (r : α → α → Bool) (l : List α), (List.splitBy r l).flatten = l
theorem List.splitBy_eq_nil E0 #
∀ {α : Type u_1} {r : α → α → Bool} {l : List α}, List.splitBy r l = [] ↔ l = []
theorem List.splitBy_ne_nil E1 #
∀ {α : Type u_1} {r : α → α → Bool} {l : List α}, List.splitBy r l ≠ [] ↔ l ≠ []
theorem List.nil_notMem_splitBy E0 #
∀ {α : Type u_1} (r : α → α → Bool) (l : List α), [] ∉ List.splitBy r l
theorem List.ne_nil_of_mem_splitBy E1 #
∀ {α : Type u_1} {m : List α} {r : α → α → Bool} {l : List α}, m ∈ List.splitBy r l → m ≠ []
theorem List.head_head_splitBy E1 #
∀ {α : Type u_1} (r : α → α → Bool) {l : List α} (hn : l ≠ []), ((List.splitBy r l).head ⋯).head ⋯ = l.head hn
theorem List.getLast_getLast_splitBy E1 #
∀ {α : Type u_1} (r : α → α → Bool) {l : List α} (hn : l ≠ []), ((List.splitBy r l).getLast ⋯).getLast ⋯ = l.getLast hn
theorem List.isChain_of_mem_splitBy E1 #
∀ {α : Type u_1} {m : List α} {r : α → α → Bool} {l : List α},
m ∈ List.splitBy r l → List.IsChain (fun x y ↦ r x y = true) m
theorem List.isChain_getLast_head_splitBy E1 #
∀ {α : Type u_1} (r : α → α → Bool) (l : List α),
List.IsChain (fun a b ↦ ∃ (ha : a ≠ []) (hb : b ≠ []), r (a.getLast ha) (b.head hb) = false) (List.splitBy r l)
theorem List.splitBy_of_isChain E1 #
∀ {α : Type u_1} {r : α → α → Bool} {l : List α},
l ≠ [] → List.IsChain (fun x y ↦ r x y = true) l → List.splitBy r l = [l]
theorem List.splitBy_flatten E1 #
∀ {α : Type u_1} {r : α → α → Bool} {l : List (List α)},
[] ∉ l →
(∀ m ∈ l, List.IsChain (fun x y ↦ r x y = true) m) →
List.IsChain (fun a b ↦ ∃ (ha : a ≠ []) (hb : b ≠ []), r (a.getLast ha) (b.head hb) = false) l →
List.splitBy r l.flatten = l
theorem List.splitBy_eq_iff E0 #
∀ {α : Type u_1} {m : List α} {r : α → α → Bool} {l : List (List α)},
List.splitBy r m = l ↔
m = l.flatten ∧
[] ∉ l ∧
(∀ m ∈ l, List.IsChain (fun x y ↦ r x y = true) m) ∧
List.IsChain (fun a b ↦ ∃ (ha : a ≠ []) (hb : b ≠ []), r (a.getLast ha) (b.head hb) = false) l
A characterization of splitBy m r as the unique list l such that:
- The lists of
ljoin tom. - It does not contain the empty list.
- Every list in
lisIsChainofr. - The last element of each list in
lis not related byrto the head of the next.
theorem List.splitBy_append E1 #
∀ {α : Type u_1} {r : α → α → Bool} {l m : List α},
(∀ x ∈ l.getLast?, ∀ y ∈ m.head?, r x y = false) → List.splitBy r (l ++ m) = List.splitBy r l ++ List.splitBy r m
theorem List.splitBy_append_cons E1 #
∀ {α : Type u_1} {r : α → α → Bool} {l : List α} {a : α} (m : List α),
(∀ x ∈ l.getLast?, r x a = false) → List.splitBy r (l ++ a :: m) = List.splitBy r l ++ List.splitBy r (a :: m)