The areas / V33. Data structures and computation
Mathlib.Data.List.Basic
229 declarations and 1 deprecated aliases. Mathlib docs · Source
Basic properties of lists
mem
length
set-theoretic notation of lists
bounded quantifiers over lists
list subset
append
replicate
pure
bind
concat
reverse
getLast
getLast?
head(!?) and tail
sublists
indexOf
nth element
map
foldl, foldr
foldlM, foldrM, mapM
filter
filterMap
filter
eraseP
erase
diff
Forall
Miscellaneous lemmas
theorem List.getLastI.match_1.congr_eq_2 E1 #
∀ {α : Type u_1} (motive : List α → Sort u_2) (x : List α) (h_1 : Unit → motive []) (h_2 : (a : α) → motive [a])
(h_3 : (head b : α) → motive [head, b]) (h_4 : (head head_1 : α) → (l : List α) → motive (head :: head_1 :: l))
(a : α),
x = [a] →
(match x with
| [] => h_1 ()
| [a] => h_2 a
| [head, b] => h_3 head b
| head :: head_1 :: l => h_4 head head_1 l) ≍
h_2 a
theorem List.getLastI.match_1.congr_eq_1 E1 #
∀ {α : Type u_1} (motive : List α → Sort u_2) (x : List α) (h_1 : Unit → motive []) (h_2 : (a : α) → motive [a])
(h_3 : (head b : α) → motive [head, b]) (h_4 : (head head_1 : α) → (l : List α) → motive (head :: head_1 :: l)),
x = [] →
(match x with
| [] => h_1 ()
| [a] => h_2 a
| [head, b] => h_3 head b
| head :: head_1 :: l => h_4 head head_1 l) ≍
h_1 ()
theorem List.head.hcongr_3 E1 #
∀ (α α' : Type u),
α = α' → ∀ (as : List α) (as' : List α'), as ≍ as' → ∀ (a : as ≠ []) (a' : as' ≠ []), a ≍ a' → as.head a ≍ as'.head a'
theorem List.getLastI.match_1.congr_eq_3 E1 #
∀ {α : Type u_1} (motive : List α → Sort u_2) (x : List α) (h_1 : Unit → motive []) (h_2 : (a : α) → motive [a])
(h_3 : (head b : α) → motive [head, b]) (h_4 : (head head_1 : α) → (l : List α) → motive (head :: head_1 :: l))
(head b : α),
x = [head, b] →
(match x with
| [] => h_1 ()
| [a] => h_2 a
| [head, b] => h_3 head b
| head :: head_1 :: l => h_4 head head_1 l) ≍
h_3 head b
theorem Fin.mk.hinj E1 #
∀ {n val : ℕ} {isLt : val < n} {n_1 val_1 : ℕ} {isLt_1 : val_1 < n_1},
n = n_1 → ⟨val, isLt⟩ ≍ ⟨val_1, isLt_1⟩ → n = n_1 ∧ val = val_1
theorem List.getLastI.match_1.congr_eq_4 E1 #
∀ {α : Type u_1} (motive : List α → Sort u_2) (x : List α) (h_1 : Unit → motive []) (h_2 : (a : α) → motive [a])
(h_3 : (head b : α) → motive [head, b]) (h_4 : (head head_1 : α) → (l : List α) → motive (head :: head_1 :: l))
(head head_1 : α) (l : List α),
x = head :: head_1 :: l →
(l = [] → False) →
(match x with
| [] => h_1 ()
| [a] => h_2 a
| [head, b] => h_3 head b
| head :: head_2 :: l => h_4 head head_2 l) ≍
h_4 head head_1 l
instance List.uniqueOfIsEmpty E0 #
{α : Type u} → [IsEmpty α] → Unique (List α)
There is only one list of an empty type
instance List.instLawfulIdentityAppendNil_mathlib E0 #
∀ {α : Type u}, Std.LawfulIdentity Append.append []
instance List.instAssociativeAppend_mathlib E0 #
∀ {α : Type u}, Std.Associative Append.append
theorem List.cons_injective E0 #
∀ {α : Type u} {a : α}, Function.Injective (List.cons a)
theorem List.singleton_injective E1 #
∀ {α : Type u}, Function.Injective fun a ↦ [a]
theorem List.setOfPred_mem_cons E1 #
∀ {α : Type u} (l : List α) (a : α), {x | x ∈ a :: l} = insert a {x | x ∈ l}
theorem List.mem_pair E0 #
∀ {α : Type u} {a b c : α}, a ∈ [b, c] ↔ a = b ∨ a = c
theorem List.mem_map_of_injective E0 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Injective f → ∀ {a : α} {l : List α}, f a ∈ List.map f l ↔ a ∈ l
theorem Function.Involutive.exists_mem_and_apply_eq_iff E0 #
∀ {α : Type u} {f : α → α}, Function.Involutive f → ∀ (x : α) (l : List α), (∃ y ∈ l, f y = x) ↔ f x ∈ l
theorem List.mem_map_of_involutive E0 #
∀ {α : Type u} {f : α → α}, Function.Involutive f → ∀ {a : α} {l : List α}, a ∈ List.map f l ↔ f a ∈ l
theorem List.length_pos_of_ne_nil E1 #
∀ {α : Type u_1} {l : List α}, l ≠ [] → 0 < l.length
Alias of the reverse direction of List.length_pos_iff.
theorem List.length_pos_iff_ne_nil E1 #
∀ {α : Type u} {l : List α}, 0 < l.length ↔ l ≠ []
theorem List.exists_of_length_succ E1 #
∀ {α : Type u} {n : ℕ} (l : List α), l.length = n + 1 → ∃ h t, l = h :: t
theorem List.length_eq_succ_iff E0 #
∀ {α : Type u} {n : ℕ} {l : List α}, l.length = n + 1 ↔ ∃ h t, h :: t = l ∧ t.length = n
theorem List.length_injective_iff E0 #
∀ {α : Type u}, Function.Injective List.length ↔ Subsingleton α
theorem List.length_injective E0 #
∀ {α : Type u} [Subsingleton α], Function.Injective List.length
theorem List.length_eq_two E1 #
∀ {α : Type u} {l : List α}, l.length = 2 ↔ ∃ a b, l = [a, b]
theorem List.length_eq_two' E1 #
∀ {α : Type u} {l : List α} (h : l ≠ []), l.length = 2 ↔ l = [l.head h, l.getLast h]
theorem List.length_eq_three E1 #
∀ {α : Type u} {l : List α}, l.length = 3 ↔ ∃ a b c, l = [a, b, c]
theorem List.length_eq_four E1 #
∀ {α : Type u} {l : List α}, l.length = 4 ↔ ∃ a b c d, l = [a, b, c, d]
instance List.instSingletonList E0 #
{α : Type u} → Singleton α (List α)
instance List.instInsertOfDecidableEq_mathlib E0 #
{α : Type u} → [DecidableEq α] → Insert α (List α)
instance List.instLawfulSingleton_mathlib E0 #
∀ {α : Type u} [inst : DecidableEq α], LawfulSingleton α (List α)
theorem List.singleton_eq E0 #
∀ {α : Type u} (x : α), {x} = [x]
theorem List.insert_neg E1 #
∀ {α : Type u} [inst : DecidableEq α] {x : α} {l : List α}, x ∉ l → insert x l = x :: l
theorem List.insert_pos E1 #
∀ {α : Type u} [inst : DecidableEq α] {x : α} {l : List α}, x ∈ l → insert x l = l
theorem List.doubleton_eq E0 #
∀ {α : Type u} [inst : DecidableEq α] {x y : α}, x ≠ y → {x, y} = [x, y]
theorem List.forall_mem_of_forall_mem_cons E1 #
∀ {α : Type u} {p : α → Prop} {a : α} {l : List α}, (∀ x ∈ a :: l, p x) → ∀ x ∈ l, p x
theorem List.exists_mem_cons_of E1 #
∀ {α : Type u} {p : α → Prop} {a : α} (l : List α), p a → ∃ x ∈ a :: l, p x
theorem List.exists_mem_cons_of_exists E1 #
∀ {α : Type u} {p : α → Prop} {a : α} {l : List α}, (∃ x ∈ l, p x) → ∃ x ∈ a :: l, p x
theorem List.or_exists_of_exists_mem_cons E1 #
∀ {α : Type u} {p : α → Prop} {a : α} {l : List α}, (∃ x ∈ a :: l, p x) → p a ∨ ∃ x ∈ l, p x
theorem List.exists_mem_cons_iff E0 #
∀ {α : Type u} (p : α → Prop) (a : α) (l : List α), (∃ x ∈ a :: l, p x) ↔ p a ∨ ∃ x ∈ l, p x
instance List.instIsPreorderSubset E0 #
∀ {α : Type u}, IsPreorder (List α) fun x1 x2 ↦ x1 ⊆ x2
theorem List.cons_subset_of_subset_of_mem E1 #
∀ {α : Type u} {a : α} {l m : List α}, a ∈ m → l ⊆ m → a :: l ⊆ m
theorem List.append_subset_of_subset_of_subset E1 #
∀ {α : Type u} {l₁ l₂ l : List α}, l₁ ⊆ l → l₂ ⊆ l → l₁ ++ l₂ ⊆ l
theorem List.map_subset_iff E0 #
∀ {α : Type u} {β : Type v} {l₁ l₂ : List α} (f : α → β),
Function.Injective f → (List.map f l₁ ⊆ List.map f l₂ ↔ l₁ ⊆ l₂)
theorem List.notMem_of_subset E1 #
∀ {α : Type u} {l l₁ : List α}, l ⊆ l₁ → ∀ {a : α}, a ∉ l₁ → a ∉ l
theorem List.append_eq_has_append E1 #
∀ {α : Type u} {L₁ L₂ : List α}, L₁.append L₂ = L₁ ++ L₂
theorem List.append_right_injective E1 #
∀ {α : Type u} (s : List α), Function.Injective fun t ↦ s ++ t
theorem List.append_left_injective E1 #
∀ {α : Type u} (t : List α), Function.Injective fun s ↦ s ++ t
theorem List.replicate_add E1 #
∀ {α : Type u} (m n : ℕ) (a : α), List.replicate (m + n) a = List.replicate m a ++ List.replicate n a
theorem List.replicate_subset_singleton E1 #
∀ {α : Type u} (n : ℕ) (a : α), List.replicate n a ⊆ [a]
theorem List.subset_singleton_iff E0 #
∀ {α : Type u} {a : α} {L : List α}, L ⊆ [a] ↔ ∃ n, L = List.replicate n a
theorem List.replicate_right_injective E1 #
∀ {α : Type u} {n : ℕ}, n ≠ 0 → Function.Injective (List.replicate n)
theorem List.replicate_right_inj E1 #
∀ {α : Type u} {a b : α} {n : ℕ}, n ≠ 0 → (List.replicate n a = List.replicate n b ↔ a = b)
theorem List.replicate_right_inj' E1 #
∀ {α : Type u} {a b : α} {n : ℕ}, List.replicate n a = List.replicate n b ↔ n = 0 ∨ a = b
theorem List.replicate_left_injective E1 #
∀ {α : Type u} (a : α), Function.Injective fun x ↦ List.replicate x a
theorem List.replicate_left_inj E1 #
∀ {α : Type u} {a : α} {n m : ℕ}, List.replicate n a = List.replicate m a ↔ n = m
theorem List.head?_flatten_replicate E0 #
∀ {α : Type u} {n : ℕ}, n ≠ 0 → ∀ (l : List α), (List.replicate n l).flatten.head? = l.head?
theorem List.getLast?_flatten_replicate E0 #
∀ {α : Type u} {n : ℕ}, n ≠ 0 → ∀ (l : List α), (List.replicate n l).flatten.getLast? = l.getLast?
theorem List.mem_pure E0 #
∀ {α : Type u} (x y : α), x ∈ pure y ↔ x = y
theorem List.bind_eq_flatMap E0 #
∀ {α β : Type u_2} (f : α → List β) (l : List α), l >>= f = List.flatMap f l
theorem List.reverse_cons' E1 #
∀ {α : Type u} (a : α) (l : List α), (a :: l).reverse = l.reverse.concat a
theorem List.reverse_concat' E1 #
∀ {α : Type u} (l : List α) (a : α), (l ++ [a]).reverse = a :: l.reverse
theorem List.reverse_involutive E0 #
∀ {α : Type u}, Function.Involutive List.reverse
theorem List.reverse_injective E0 #
∀ {α : Type u}, Function.Injective List.reverse
theorem List.reverse_surjective E1 #
∀ {α : Type u}, Function.Surjective List.reverse
theorem List.reverse_bijective E1 #
∀ {α : Type u}, Function.Bijective List.reverse
theorem List.concat_eq_reverse_cons E1 #
∀ {α : Type u} (a : α) (l : List α), l.concat a = (a :: l.reverse).reverse
theorem List.map_reverseAux E0 #
∀ {α : Type u} {β : Type v} (f : α → β) (l₁ l₂ : List α),
List.map f (l₁.reverseAux l₂) = (List.map f l₁).reverseAux (List.map f l₂)
theorem List.reverse_perm' E0 #
∀ {α : Type u} {l₁ l₂ : List α}, l₁.reverse.Perm l₂ ↔ l₁.Perm l₂
theorem List.perm_reverse E0 #
∀ {α : Type u} {l₁ l₂ : List α}, l₁.Perm l₂.reverse ↔ l₁.Perm l₂
theorem List.getLast_append_singleton E1 #
∀ {α : Type u} {a : α} (l : List α), (l ++ [a]).getLast ⋯ = a
theorem List.getLast_append_of_right_ne_nil E1 #
∀ {α : Type u} (l₁ l₂ : List α) (h : l₂ ≠ []), (l₁ ++ l₂).getLast ⋯ = l₂.getLast h
theorem List.getLast_concat' E1 #
∀ {α : Type u} {a : α} (l : List α), (l.concat a).getLast ⋯ = a
theorem List.getLast_singleton' E0 #
∀ {α : Type u} (a : α), [a].getLast ⋯ = a
theorem List.dropLast_append_getLast E1 #
∀ {α : Type u} {l : List α} (h : l ≠ []), l.dropLast ++ [l.getLast h] = l
theorem List.getLast_congr E1 #
∀ {α : Type u} {l₁ l₂ : List α} (h₁ : l₁ ≠ []) (h₂ : l₂ ≠ []), l₁ = l₂ → l₁.getLast h₁ = l₂.getLast h₂
theorem List.getLast_replicate_succ E1 #
∀ {α : Type u} (m : ℕ) (a : α), (List.replicate (m + 1) a).getLast ⋯ = a
theorem List.mem_getLast?_eq_getLast E0 #
∀ {α : Type u} {l : List α} {x : α}, x ∈ l.getLast? → ∃ (h : l ≠ []), x = l.getLast h
theorem List.getLast?_eq_getLast_of_ne_nil E1 #
∀ {α : Type u} {l : List α} (h : l ≠ []), l.getLast? = some (l.getLast h)
theorem List.mem_getLast?_cons E0 #
∀ {α : Type u} {x y : α} {l : List α}, x ∈ l.getLast? → x ∈ (y :: l).getLast?
theorem List.dropLast_append_getLast? E1 #
∀ {α : Type u} {l : List α}, ∀ a ∈ l.getLast?, l.dropLast ++ [a] = l
theorem List.getLastI_eq_getLast?_getD E1 #
∀ {α : Type u} [inst : Inhabited α] (l : List α), l.getLastI = l.getLast?.getD default
theorem List.getLast?_append_cons E1 #
∀ {α : Type u} (l₁ : List α) (a : α) (l₂ : List α), (l₁ ++ a :: l₂).getLast? = (a :: l₂).getLast?
theorem List.getLast?_append_of_ne_nil E1 #
∀ {α : Type u} (l₁ : List α) {l₂ : List α}, l₂ ≠ [] → (l₁ ++ l₂).getLast? = l₂.getLast?
theorem List.mem_getLast?_append_of_mem_getLast? E0 #
∀ {α : Type u} {l₁ l₂ : List α} {x : α}, x ∈ l₂.getLast? → x ∈ (l₁ ++ l₂).getLast?
theorem List.mem_dropLast_of_mem_of_ne_getLast E0 #
∀ {α : Type u} {l : List α} {a : α} (ha : a ∈ l), a ≠ l.getLast ⋯ → a ∈ l.dropLast
theorem List.mem_dropLast_of_mem_of_ne_getLastD E0 #
∀ {α : Type u} {l : List α} {a d : α}, a ∈ l → a ≠ l.getLastD d → a ∈ l.dropLast
theorem List.mem_dropLast_of_mem_of_ne_getLast? E0 #
∀ {α : Type u} {l : List α} {a : α}, a ∈ l → some a ≠ l.getLast? → a ∈ l.dropLast
theorem List.head!_nil E0 #
∀ {α : Type u} [inst : Inhabited α], [].head! = default
theorem List.head_eq_getElem_zero E1 #
∀ {α : Type u} {l : List α} (hl : l ≠ []), l.head hl = l[0]
theorem List.head!_eq_head?_getD E1 #
∀ {α : Type u} [inst : Inhabited α] (l : List α), l.head! = l.head?.getD default
theorem List.surjective_head! E1 #
∀ {α : Type u} [inst : Inhabited α], Function.Surjective List.head!
theorem List.surjective_head? E1 #
∀ {α : Type u}, Function.Surjective List.head?
theorem List.surjective_tail E1 #
∀ {α : Type u}, Function.Surjective List.tail
theorem List.head!_cons E0 #
∀ {α : Type u} [inst : Inhabited α] (a : α) (l : List α), (a :: l).head! = a
theorem List.head!_append E0 #
∀ {α : Type u} [inst : Inhabited α] (t : List α) {s : List α}, s ≠ [] → (s ++ t).head! = s.head!
theorem List.mem_head?_append_of_mem_head? E0 #
∀ {α : Type u} {s t : List α} {x : α}, x ∈ s.head? → x ∈ (s ++ t).head?
theorem List.head?_append_of_ne_nil E1 #
∀ {α : Type u} (l₁ : List α) {l₂ : List α}, l₁ ≠ [] → (l₁ ++ l₂).head? = l₁.head?
theorem List.tail_append_singleton_of_ne_nil E1 #
∀ {α : Type u} {a : α} {l : List α}, l ≠ [] → (l ++ [a]).tail = l.tail ++ [a]
theorem List.cons_head?_tail E1 #
∀ {α : Type u} {l : List α} {a : α}, a ∈ l.head? → a :: l.tail = l
theorem List.head!_mem_head? E1 #
∀ {α : Type u} [inst : Inhabited α] {l : List α}, l ≠ [] → l.head! ∈ l.head?
theorem List.cons_head!_tail E1 #
∀ {α : Type u} [inst : Inhabited α] {l : List α}, l ≠ [] → l.head! :: l.tail = l
theorem List.head!_mem_self E1 #
∀ {α : Type u} [inst : Inhabited α] {l : List α}, l ≠ [] → l.head! ∈ l
theorem List.get_eq_getElem? E1 #
∀ {α : Type u} (l : List α) (i : Fin l.length), l.get i = l[i]?.get ⋯
theorem List.exists_mem_iff_getElem E1 #
∀ {α : Type u} {l : List α} {p : α → Prop}, (∃ x ∈ l, p x) ↔ ∃ i, ∃ (x : i < l.length), p l[i]
theorem List.exists_mem_iff_get E1 #
∀ {α : Type u} {l : List α} {p : α → Prop}, (∃ x ∈ l, p x) ↔ ∃ i, p (l.get i)
theorem List.forall_mem_iff_getElem E1 #
∀ {α : Type u} {l : List α} {p : α → Prop}, (∀ x ∈ l, p x) ↔ ∀ (i : ℕ) (x : i < l.length), p l[i]
theorem List.forall_mem_iff_get E1 #
∀ {α : Type u} {l : List α} {p : α → Prop}, (∀ x ∈ l, p x) ↔ ∀ (i : Fin l.length), p (l.get i)
theorem List.get_surjective_iff E0 #
∀ {α : Type u} {l : List α}, Function.Surjective l.get ↔ ∀ (x : α), x ∈ l
theorem List.getElem_fin_surjective_iff E0 #
∀ {α : Type u} {l : List α}, (Function.Surjective fun n ↦ l[↑n]) ↔ ∀ (x : α), x ∈ l
theorem List.getElem?_surjective_iff E0 #
∀ {α : Type u} {l : List α}, (Function.Surjective fun n ↦ l[n]?) ↔ ∀ (x : α), x ∈ l
theorem List.get_tail E1 #
∀ {α : Type u} (l : List α) (i : ℕ) (h : i < l.tail.length) (h' : optParam (i + 1 < l.length) ⋯),
l.tail.get ⟨i, h⟩ = l.get ⟨i + 1, h'⟩
theorem List.getElem_mem_tail E1 #
∀ {α : Type u} {k : ℕ} (l : List α), k ≠ 0 → ∀ (hk : k < l.length), l[k] ∈ l.tail
theorem List.tail_eq_nil_iff E0 #
∀ {α : Type u} {l : List α}, l.tail = [] ↔ l.length ≤ 1
theorem List.dropLast_eq_nil_iff E0 #
∀ {α : Type u} {l : List α}, l.dropLast = [] ↔ l.length ≤ 1
theorem List.cons_sublist_cons' E1 #
∀ {α : Type u} {l₁ l₂ : List α} {a b : α}, (a :: l₁).Sublist (b :: l₂) ↔ (a :: l₁).Sublist l₂ ∨ a = b ∧ l₁.Sublist l₂
theorem List.sublist_cons_of_sublist E1 #
∀ {α : Type u} {l₁ l₂ : List α} (a : α), l₁.Sublist l₂ → l₁.Sublist (a :: l₂)
theorem List.sublist_singleton E0 #
∀ {α : Type u} {l : List α} {a : α}, l.Sublist [a] ↔ l = [] ∨ l = [a]
theorem List.Sublist.antisymm E1 #
∀ {α : Type u} {l₁ l₂ : List α}, l₁.Sublist l₂ → l₂.Sublist l₁ → l₁ = l₂
instance List.instIsPartialOrderSublist E0 #
∀ {α : Type u}, IsPartialOrder (List α) List.Sublist
theorem List.Sublist.of_cons_of_ne E1 #
∀ {α : Type u} {l₁ l₂ : List α} {a b : α}, a ≠ b → (a :: l₁).Sublist (b :: l₂) → (a :: l₁).Sublist l₂
If the first element of two lists are different, then a sublist relation can be reduced.
theorem List.idxOf_cons_eq E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a b : α} (l : List α), b = a → List.idxOf a (b :: l) = 0
theorem List.idxOf_cons_ne E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a b : α} (l : List α),
b ≠ a → List.idxOf a (b :: l) = (List.idxOf a l).succ
theorem List.idxOf_eq_length_iff E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a : α} {l : List α}, List.idxOf a l = l.length ↔ a ∉ l
theorem List.idxOf_of_notMem E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} {a : α}, a ∉ l → List.idxOf a l = l.length
theorem List.idxOf_eq_zero_iff_eq_nil_or_head_eq E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} (a : α), List.idxOf a l = 0 ↔ l = [] ∨ l.head? = some a
theorem List.idxOf_eq_zero_iff_head_eq E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} (hl : l ≠ []) {a : α}, List.idxOf a l = 0 ↔ l.head hl = a
theorem List.idxOf_append_of_mem E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α] {a : α}, a ∈ l₁ → List.idxOf a (l₁ ++ l₂) = List.idxOf a l₁
theorem List.idxOf_append_of_notMem E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α] {a : α},
a ∉ l₁ → List.idxOf a (l₁ ++ l₂) = l₁.length + List.idxOf a l₂
theorem List.IsPrefix.idxOf_le E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α], l₁ <+: l₂ → ∀ (a : α), List.idxOf a l₁ ≤ List.idxOf a l₂
theorem List.IsPrefix.idxOf_eq_of_mem E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α],
l₁ <+: l₂ → ∀ {a : α}, a ∈ l₁ → List.idxOf a l₁ = List.idxOf a l₂
theorem List.IsPrefix.mem_iff_idxOf_lt_length E0 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α],
l₁ <+: l₂ → ∀ (a : α), a ∈ l₁ ↔ List.idxOf a l₂ < l₁.length
theorem List.IsSuffix.idxOf_le E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α],
l₁ <:+ l₂ → ∀ (a : α), List.idxOf a l₂ ≤ l₂.length - l₁.length + List.idxOf a l₁
theorem List.IsSuffix.idxOf_add_length_le E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : BEq α] [LawfulBEq α],
l₁ <:+ l₂ → ∀ (a : α), List.idxOf a l₂ + l₁.length ≤ List.idxOf a l₁ + l₂.length
theorem List.mem_take_iff_idxOf_lt E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a : α} {n : ℕ} {l : List α},
a ∈ l → (a ∈ List.take n l ↔ List.idxOf a l < n)
theorem List.mem_dropLast_iff_idxOf_lt E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} {a : α},
a ∈ l → (a ∈ l.dropLast ↔ List.idxOf a l < l.length - 1)
theorem List.succ_idxOf_lt_length_of_mem_dropLast E1 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} {a : α}, a ∈ l.dropLast → List.idxOf a l + 1 < l.length
theorem List.idxOf_getLast E1 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} (hl : l ≠ []),
l.getLast hl ∉ l.dropLast → List.idxOf (l.getLast hl) l = l.length - 1
theorem List.idxOf_tail_of_head_ne E1 #
∀ {α : Type u} {l : List α} [inst : BEq α] [LawfulBEq α] {a : α} (hl : l ≠ []),
l.head hl ≠ a → List.idxOf a l.tail = List.idxOf a l - 1
theorem List.getElem?_length E1 #
∀ {α : Type u} (l : List α), l[l.length]? = none
theorem List.getElem_map_rev E1 #
∀ {α : Type u} {β : Type v} (f : α → β) {l : List α} {n : ℕ} {h : n < l.length}, f l[n] = (List.map f l)[n]
A version of getElem_map that can be used for rewriting.
theorem List.get_length_sub_one E1 #
∀ {α : Type u} {l : List α} (h : l.length - 1 < l.length), l.get ⟨l.length - 1, h⟩ = l.getLast ⋯
theorem List.ext_getElem?' E1 #
∀ {α : Type u} {l₁ l₂ : List α}, (∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?) → l₁ = l₂
theorem List.ext_get_iff E0 #
∀ {α : Type u} {l₁ l₂ : List α},
l₁ = l₂ ↔ l₁.length = l₂.length ∧ ∀ (n : ℕ) (h₁ : n < l₁.length) (h₂ : n < l₂.length), l₁.get ⟨n, h₁⟩ = l₂.get ⟨n, h₂⟩
theorem List.ext_getElem?_iff' E1 #
∀ {α : Type u} {l₁ l₂ : List α}, l₁ = l₂ ↔ ∀ n < max l₁.length l₂.length, l₁[n]? = l₂[n]?
theorem List.ext_getElem! E1 #
∀ {α : Type u} {l₁ l₂ : List α} [inst : Inhabited α], l₁.length = l₂.length → (∀ (n : ℕ), l₁[n]! = l₂[n]!) → l₁ = l₂
If two lists l₁ and l₂ are the same length and l₁[n]! = l₂[n]! for all n,
then the lists are equal.
theorem List.idxOf_get E1 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a : α} {l : List α} (h : List.idxOf a l < l.length),
l.get ⟨List.idxOf a l, h⟩ = a
theorem List.getElem?_idxOf E0 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a : α} {l : List α}, a ∈ l → l[List.idxOf a l]? = some a
theorem List.idxOf_inj E1 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {l : List α} {x y : α}, x ∈ l → (List.idxOf x l = List.idxOf y l ↔ x = y)
theorem List.get_reverse' E1 #
∀ {α : Type u} (l : List α) (n : Fin l.reverse.length) (hn' : l.length - 1 - ↑n < l.length),
l.reverse.get n = l.get ⟨l.length - 1 - ↑n, hn'⟩
theorem List.getElem_set_of_ne E1 #
∀ {α : Type u} {l : List α} {i j : ℕ}, i ≠ j → ∀ (a : α) (hj : j < (l.set i a).length), (l.set i a)[j] = l[j]
theorem List.flatMap_pure_eq_map E1 #
∀ {α : Type u} {β : Type v} (f : α → β) (l : List α), List.flatMap (pure ∘ f) l = List.map f l
theorem List.flatMap_congr E1 #
∀ {α : Type u} {β : Type v} {l : List α} {f g : α → List β}, (∀ x ∈ l, f x = g x) → List.flatMap f l = List.flatMap g l
theorem List.infix_flatMap_of_mem E1 #
∀ {α : Type u} {a : α} {as : List α}, a ∈ as → ∀ (f : α → List α), f a <:+: List.flatMap f as
theorem List.map_eq_map E0 #
∀ {α β : Type u_2} (f : α → β) (l : List α), f <$> l = List.map f l
theorem List.comp_map E1 #
∀ {α : Type u} {β : Type v} {γ : Type w} (h : β → γ) (g : α → β) (l : List α),
List.map (h ∘ g) l = List.map h (List.map g l)
A single List.map of a composition of functions is equal to
composing a List.map with another List.map, fully applied.
This is the reverse direction of List.map_map.
theorem List.map_comp_map E0 #
∀ {α : Type u} {β : Type v} {γ : Type w} (g : β → γ) (f : α → β), List.map g ∘ List.map f = List.map (g ∘ f)
Composing a List.map with another List.map is equal to
a single List.map of composed functions.
theorem Function.LeftInverse.list_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β} {g : β → α},
Function.LeftInverse f g → Function.LeftInverse (List.map f) (List.map g)
theorem Function.RightInverse.list_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β} {g : β → α},
Function.RightInverse f g → Function.RightInverse (List.map f) (List.map g)
theorem Function.Involutive.list_map E1 #
∀ {α : Type u} {f : α → α}, Function.Involutive f → Function.Involutive (List.map f)
theorem List.map_leftInverse_iff E0 #
∀ {α : Type u} {β : Type v} {f : α → β} {g : β → α},
Function.LeftInverse (List.map f) (List.map g) ↔ Function.LeftInverse f g
theorem List.map_rightInverse_iff E0 #
∀ {α : Type u} {β : Type v} {f : α → β} {g : β → α},
Function.RightInverse (List.map f) (List.map g) ↔ Function.RightInverse f g
theorem List.map_involutive_iff E0 #
∀ {α : Type u} {f : α → α}, Function.Involutive (List.map f) ↔ Function.Involutive f
theorem Function.Injective.list_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Injective f → Function.Injective (List.map f)
theorem List.map_injective_iff E0 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Injective (List.map f) ↔ Function.Injective f
theorem Function.Surjective.list_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Surjective f → Function.Surjective (List.map f)
theorem List.map_surjective_iff E0 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Surjective (List.map f) ↔ Function.Surjective f
theorem Function.Bijective.list_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Bijective f → Function.Bijective (List.map f)
theorem List.map_bijective_iff E0 #
∀ {α : Type u} {β : Type v} {f : α → β}, Function.Bijective (List.map f) ↔ Function.Bijective f
theorem List.foldl_ext E1 #
∀ {α : Type u} {β : Type v} (f g : α → β → α) (a : α) {l : List β},
(∀ (a : α), ∀ b ∈ l, f a b = g a b) → List.foldl f a l = List.foldl g a l
theorem List.foldr_ext E1 #
∀ {α : Type u} {β : Type v} (f g : α → β → β) (b : β) {l : List α},
(∀ a ∈ l, ∀ (b : β), f a b = g a b) → List.foldr f b l = List.foldr g b l
theorem List.foldl_concat E1 #
∀ {α : Type u} {β : Type v} (f : β → α → β) (b : β) (x : α) (xs : List α),
List.foldl f b (xs ++ [x]) = f (List.foldl f b xs) x
theorem List.foldr_concat E1 #
∀ {α : Type u} {β : Type v} (f : α → β → β) (b : β) (x : α) (xs : List α),
List.foldr f b (xs ++ [x]) = List.foldr f (f x b) xs
theorem List.foldl_fixed' E1 #
∀ {α : Type u} {β : Type v} {f : α → β → α} {a : α}, (∀ (b : β), f a b = a) → ∀ (l : List β), List.foldl f a l = a
theorem List.foldr_fixed' E1 #
∀ {α : Type u} {β : Type v} {f : α → β → β} {b : β}, (∀ (a : α), f a b = b) → ∀ (l : List α), List.foldr f b l = b
theorem List.foldl_fixed E0 #
∀ {α : Type u} {β : Type v} {a : α} (l : List β), List.foldl (fun a x ↦ a) a l = a
theorem List.foldr_fixed E0 #
∀ {α : Type u} {β : Type v} {b : β} (l : List α), List.foldr (fun x b ↦ b) b l = b
theorem List.reverse_foldl E1 #
∀ {α : Type u} {l : List α}, (List.foldl (fun t h ↦ h :: t) [] l).reverse = l
theorem List.foldl_hom₂ E1 #
∀ {ι : Type u_1} {α : Type u} {β : Type v} {γ : Type w} (l : List ι) (f : α → β → γ) (op₁ : α → ι → α) (op₂ : β → ι → β)
(op₃ : γ → ι → γ) (a : α) (b : β),
(∀ (a : α) (b : β) (i : ι), f (op₁ a i) (op₂ b i) = op₃ (f a b) i) →
List.foldl op₃ (f a b) l = f (List.foldl op₁ a l) (List.foldl op₂ b l)
theorem List.foldr_hom₂ E1 #
∀ {ι : Type u_1} {α : Type u} {β : Type v} {γ : Type w} (l : List ι) (f : α → β → γ) (op₁ : ι → α → α) (op₂ : ι → β → β)
(op₃ : ι → γ → γ) (a : α) (b : β),
(∀ (a : α) (b : β) (i : ι), f (op₁ i a) (op₂ i b) = op₃ i (f a b)) →
List.foldr op₃ (f a b) l = f (List.foldr op₁ a l) (List.foldr op₂ b l)
theorem List.injective_foldl_comp E1 #
∀ {α : Type u} {l : List (α → α)} {f : α → α},
(∀ f ∈ l, Function.Injective f) → Function.Injective f → Function.Injective (List.foldl Function.comp f l)
theorem List.append_cons_inj_of_notMem E1 #
∀ {α : Type u} {x₁ x₂ z₁ z₂ : List α} {a₁ a₂ : α},
a₂ ∉ x₁ → a₂ ∉ z₁ → (x₁ ++ a₁ :: z₁ = x₂ ++ a₂ :: z₂ ↔ x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂)
Consider two lists l₁ and l₂ with designated elements a₁ and a₂ somewhere in them:
l₁ = x₁ ++ [a₁] ++ z₁ and l₂ = x₂ ++ [a₂] ++ z₂.
Assume the designated element a₂ is present in neither x₁ nor z₁.
We conclude that the lists are equal (l₁ = l₂) if and only if their respective parts are equal
(x₁ = x₂ ∧ a₁ = a₂ ∧ z₁ = z₂).
theorem List.foldrM_eq_foldr E1 #
∀ {α : Type u} {β : Type v} {m : Type v → Type w} [inst : Monad m] [LawfulMonad m] (f : α → β → m β) (b : β)
(l : List α), List.foldrM f b l = List.foldr (fun a mb ↦ mb >>= f a) (pure b) l
theorem List.foldlM_eq_foldl E1 #
∀ {α : Type u} {β : Type v} {m : Type v → Type w} [inst : Monad m] [LawfulMonad m] (f : β → α → m β) (b : β)
(l : List α),
List.foldlM f b l =
List.foldl
(fun mb a ↦ do
let b ← mb
f b a)
(pure b) l
theorem List.length_eq_length_filter_add E1 #
∀ {α : Type u} {l : List α} (f : α → Bool), l.length = (List.filter f l).length + (List.filter (fun x ↦ !f x) l).length
theorem List.filterMap_eq_flatMap_toList E1 #
∀ {α : Type u} {β : Type v} (f : α → Option β) (l : List α), List.filterMap f l = List.flatMap (fun a ↦ (f a).toList) l
theorem List.filterMap_congr E1 #
∀ {α : Type u} {β : Type v} {f g : α → Option β} {l l' : List α},
l = l' → (∀ x ∈ l, f x = g x) → List.filterMap f l = List.filterMap g l'
theorem List.filterMap_eq_map_iff_forall_eq_some E1 #
∀ {α : Type u} {β : Type v} {f : α → Option β} {g : α → β} {l : List α},
List.filterMap f l = List.map g l ↔ ∀ x ∈ l, f x = some (g x)
theorem List.filterMap_none E0 #
∀ {α : Type u} {β : Type v} (l : List α), List.filterMap (fun x ↦ none) l = []
theorem List.filter_singleton E1 #
∀ {α : Type u} {p : α → Bool} {a : α}, List.filter p [a] = bif p a then [a] else []
theorem List.filter_eq_foldr E1 #
∀ {α : Type u} (p : α → Bool) (l : List α),
List.filter p l = List.foldr (fun a out ↦ bif p a then a :: out else out) [] l
theorem List.filter_subset_self E0 #
∀ {α : Type u} {p : α → Bool} (l : List α), List.filter p l ⊆ l
theorem List.of_mem_filter E1 #
∀ {α : Type u} {p : α → Bool} {a : α} {l : List α}, a ∈ List.filter p l → p a = true
theorem List.mem_of_mem_filter E0 #
∀ {α : Type u} {p : α → Bool} {a : α} {l : List α}, a ∈ List.filter p l → a ∈ l
theorem List.mem_filter_of_mem E0 #
∀ {α : Type u} {p : α → Bool} {a : α} {l : List α}, a ∈ l → p a = true → a ∈ List.filter p l
theorem List.monotone_filter_right E1 #
∀ {α : Type u} (l : List α) ⦃p q : α → Bool⦄,
(∀ (a : α), p a = true → q a = true) → (List.filter p l).Sublist (List.filter q l)
theorem List.map_filter E0 #
∀ {α : Type u} {β : Type v} (p : α → Bool) {f : α → β},
Function.Injective f →
∀ (l : List α) [inst : DecidablePred fun b ↦ ∃ a, p a = true ∧ f a = b],
List.map f (List.filter p l) = List.filter (fun b ↦ decide (∃ a, p a = true ∧ f a = b)) (List.map f l)
theorem List.filter_attach' E1 #
∀ {α : Type u} (l : List α) (p : { a // a ∈ l } → Bool) [inst : DecidableEq α],
List.filter p l.attach =
List.map (Subtype.map id ⋯) (List.filter (fun x ↦ decide (∃ (h : x ∈ l), p ⟨x, h⟩ = true)) l).attach
theorem List.filter_attach E1 #
∀ {α : Type u} (l : List α) (p : α → Bool),
List.filter (fun x ↦ p ↑x) l.attach = List.map (Subtype.map id ⋯) (List.filter p l).attach
theorem List.filter_comm E1 #
∀ {α : Type u} (p q : α → Bool) (l : List α), List.filter p (List.filter q l) = List.filter q (List.filter p l)
theorem List.filter_true E0 #
∀ {α : Type u} (l : List α), List.filter (fun x ↦ true) l = l
theorem List.filter_false E0 #
∀ {α : Type u} (l : List α), List.filter (fun x ↦ false) l = []
theorem List.length_eraseP_add_one E1 #
∀ {α : Type u} {p : α → Bool} {l : List α} {a : α}, a ∈ l → p a = true → (List.eraseP p l).length + 1 = l.length
theorem List.length_erase_add_one E1 #
∀ {α : Type u} [inst : BEq α] [LawfulBEq α] {a : α} {l : List α}, a ∈ l → (l.erase a).length + 1 = l.length
theorem List.map_erase E0 #
∀ {α : Type u} {β : Type v} [inst : BEq α] [LawfulBEq α] [inst_2 : BEq β] [LawfulBEq β] {f : α → β},
Function.Injective f → ∀ {a : α} (l : List α), List.map f (l.erase a) = (List.map f l).erase (f a)
theorem List.map_foldl_erase E0 #
∀ {α : Type u} {β : Type v} [inst : BEq α] [LawfulBEq α] [inst_2 : BEq β] [LawfulBEq β] {f : α → β},
Function.Injective f →
∀ {l₁ l₂ : List α},
List.map f (List.foldl List.erase l₁ l₂) = List.foldl (fun l a ↦ l.erase (f a)) (List.map f l₁) l₂
theorem List.erase_getElem E1 #
∀ {ι : Type u_1} [inst : BEq ι] [LawfulBEq ι] {l : List ι} {i : ℕ} (hi : i < l.length),
(l.erase l[i]).Perm (l.eraseIdx i)
theorem List.length_eraseIdx_add_one E1 #
∀ {ι : Type u_1} {l : List ι} {i : ℕ}, i < l.length → (l.eraseIdx i).length + 1 = l.length
theorem List.map_diff E0 #
∀ {α : Type u} {β : Type v} [inst : BEq α] [LawfulBEq α] [inst_2 : BEq β] [LawfulBEq β] {f : α → β},
Function.Injective f → ∀ {l₁ l₂ : List α}, List.map f (l₁.diff l₂) = (List.map f l₁).diff (List.map f l₂)
theorem List.choose_spec E1 #
∀ {α : Type u} (p : α → Prop) [inst : DecidablePred p] (l : List α) (hp : ∃ a ∈ l, p a),
List.choose p l hp ∈ l ∧ p (List.choose p l hp)
theorem List.choose_mem E1 #
∀ {α : Type u} (p : α → Prop) [inst : DecidablePred p] (l : List α) (hp : ∃ a ∈ l, p a), List.choose p l hp ∈ l
theorem List.choose_property E1 #
∀ {α : Type u} (p : α → Prop) [inst : DecidablePred p] (l : List α) (hp : ∃ a ∈ l, p a), p (List.choose p l hp)
theorem List.forall_cons E0 #
∀ {α : Type u} (p : α → Prop) (x : α) (l : List α), List.Forall p (x :: l) ↔ p x ∧ List.Forall p l
theorem List.forall_append E0 #
∀ {α : Type u} {p : α → Prop} {xs ys : List α}, List.Forall p (xs ++ ys) ↔ List.Forall p xs ∧ List.Forall p ys
theorem List.forall_iff_forall_mem E1 #
∀ {α : Type u} {p : α → Prop} {l : List α}, List.Forall p l ↔ ∀ x ∈ l, p x
theorem List.Forall.imp E1 #
∀ {α : Type u} {p q : α → Prop}, (∀ (x : α), p x → q x) → ∀ {l : List α}, List.Forall p l → List.Forall q l
theorem List.forall_map_iff E0 #
∀ {α : Type u} {β : Type v} {l : List α} {p : β → Prop} (f : α → β),
List.Forall p (List.map f l) ↔ List.Forall (p ∘ f) l
instance List.instDecidablePredForall E0 #
{α : Type u} → (p : α → Prop) → [DecidablePred p] → DecidablePred (List.Forall p)
theorem List.get_attach E1 #
∀ {α : Type u} (l : List α) (i : Fin l.attach.length), ↑(l.attach.get i) = l.get ⟨↑i, ⋯⟩
theorem List.disjoint_pmap E1 #
∀ {α : Type u} {β : Type v} {p : α → Prop} {f : (a : α) → p a → β} {s t : List α} (hs : ∀ a ∈ s, p a)
(ht : ∀ a ∈ t, p a),
(∀ (a a' : α) (ha : p a) (ha' : p a'), f a ha = f a' ha' → a = a') →
s.Disjoint t → (List.pmap f s hs).Disjoint (List.pmap f t ht)
The images of disjoint lists under a partially defined map are disjoint
theorem List.disjoint_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β} {s t : List α},
Function.Injective f → s.Disjoint t → (List.map f s).Disjoint (List.map f t)
The images of disjoint lists under an injective map are disjoint
theorem List.Disjoint.map E1 #
∀ {α : Type u} {β : Type v} {f : α → β} {s t : List α},
Function.Injective f → s.Disjoint t → (List.map f s).Disjoint (List.map f t)
Alias of List.disjoint_map.
The images of disjoint lists under an injective map are disjoint
theorem List.Disjoint.of_map E1 #
∀ {α : Type u} {β : Type v} {f : α → β} {s t : List α}, (List.map f s).Disjoint (List.map f t) → s.Disjoint t
theorem List.Disjoint.map_iff E0 #
∀ {α : Type u} {β : Type v} {f : α → β} {s t : List α},
Function.Injective f → ((List.map f s).Disjoint (List.map f t) ↔ s.Disjoint t)
theorem List.Perm.disjoint_left E1 #
∀ {α : Type u} {l₁ l₂ l : List α}, l₁.Perm l₂ → (l₁.Disjoint l ↔ l₂.Disjoint l)
theorem List.Perm.disjoint_right E1 #
∀ {α : Type u} {l₁ l₂ l : List α}, l₁.Perm l₂ → (l.Disjoint l₁ ↔ l.Disjoint l₂)
theorem List.disjoint_reverse_left E0 #
∀ {α : Type u} {l₁ l₂ : List α}, l₁.reverse.Disjoint l₂ ↔ l₁.Disjoint l₂
theorem List.disjoint_reverse_right E0 #
∀ {α : Type u} {l₁ l₂ : List α}, l₁.Disjoint l₂.reverse ↔ l₁.Disjoint l₂
theorem List.lookup_graph E1 #
∀ {α : Type u} {β : Type v} [inst : BEq α] [LawfulBEq α] (f : α → β) {a : α} {as : List α},
a ∈ as → List.lookup a (List.map (fun x ↦ (x, f x)) as) = some (f a)
theorem List.range'_0 E0 #
∀ (a b : ℕ), List.range' a b 0 = List.replicate b a
theorem List.left_le_of_mem_range' E1 #
∀ {a b s x : ℕ}, x ∈ List.range' a b s → a ≤ x
Deprecated aliases
| Name | New name | Since |
|---|---|---|
List.set_of_mem_cons | List.setOfPred_mem_cons | 2026-07-13 |