The areas / V33. Data structures and computation
Mathlib.Data.List.GetD
24 declarations. Mathlib docs · Source
getD and getI
This file provides theorems for working with the getD and getI functions. These are used to
access an element of a list by numerical index, with a default value as a fallback when the index
is out of range.
theorem List.getD_eq_getElem E1 #
∀ {α : Type u} (l : List α) (d : α) {n : ℕ} (hn : n < l.length), l.getD n d = l[n]
theorem List.getD_eq_getElem? E1 #
∀ {α : Type u} (l : List α) (d : α) (i : Fin l.length), l.getD (↑i) d = l[i]?.get ⋯
theorem List.getD_eq_get E1 #
∀ {α : Type u} (l : List α) (d : α) (i : Fin l.length), l.getD (↑i) d = l.get i
theorem List.getD_map E1 #
∀ {α : Type u} {β : Type v} (l : List α) (d : α) {n : ℕ} (f : α → β), (List.map f l).getD n (f d) = f (l.getD n d)
theorem List.getD_eq_default E1 #
∀ {α : Type u} (l : List α) (d : α) {n : ℕ}, l.length ≤ n → l.getD n d = d
theorem List.getD_reverse E1 #
∀ {α : Type u} {l : List α}, ∀ i < l.length, l.reverse.getD i = l.getD (l.length - 1 - i)
def List.decidableGetDNilNe E1 #
{α : Type u} → (a : α) → DecidablePred fun i ↦ [].getD i a ≠ a
An empty list can always be decidably checked for the presence of an element.
Not an instance because it would clash with DecidableEq α.
theorem List.getElem?_getD_singleton_default_eq E0 #
∀ {α : Type u} (d : α) (n : ℕ), [d][n]?.getD d = d
theorem List.getElem?_getD_replicate_default_eq E0 #
∀ {α : Type u} (d : α) (r n : ℕ), (List.replicate r d)[n]?.getD d = d
theorem List.getD_replicate E1 #
∀ {α : Type u} (x : α) {y : α} {i n : ℕ}, i < n → (List.replicate n x).getD i y = x
theorem List.getD_append E1 #
∀ {α : Type u} (l l' : List α) (d : α), ∀ n < l.length, (l ++ l').getD n d = l.getD n d
theorem List.getD_append_right E1 #
∀ {α : Type u} (l l' : List α) (d : α) (n : ℕ), l.length ≤ n → (l ++ l').getD n d = l'.getD (n - l.length) d
theorem List.getD_surjective_iff E0 #
∀ {α : Type u} {l : List α} {d : α}, (Function.Surjective fun x ↦ l.getD x d) ↔ ∀ (x : α), x = d ∨ x ∈ l
theorem List.getD_surjective E1 #
∀ {α : Type u} {l : List α}, (∀ (x : α), x ∈ l) → ∀ (d : α), Function.Surjective fun x ↦ l.getD x d
theorem List.getI_nil E0 #
∀ {α : Type u} (n : ℕ) [inst : Inhabited α], [].getI n = default
theorem List.getI_cons_zero E0 #
∀ {α : Type u} (x : α) (xs : List α) [inst : Inhabited α], (x :: xs).getI 0 = x
theorem List.getI_cons_succ E0 #
∀ {α : Type u} (x : α) (xs : List α) (n : ℕ) [inst : Inhabited α], (x :: xs).getI (n + 1) = xs.getI n
theorem List.getI_eq_getElem E1 #
∀ {α : Type u} (l : List α) [inst : Inhabited α] {n : ℕ} (hn : n < l.length), l.getI n = l[n]
theorem List.getI_eq_default E1 #
∀ {α : Type u} (l : List α) [inst : Inhabited α] {n : ℕ}, l.length ≤ n → l.getI n = default
theorem List.getD_default_eq_getI E1 #
∀ {α : Type u} (l : List α) [inst : Inhabited α] {n : ℕ}, l.getD n default = l.getI n
theorem List.getI_append E1 #
∀ {α : Type u} [inst : Inhabited α] (l l' : List α), ∀ n < l.length, (l ++ l').getI n = l.getI n
theorem List.getI_append_right E1 #
∀ {α : Type u} [inst : Inhabited α] (l l' : List α) (n : ℕ), l.length ≤ n → (l ++ l').getI n = l'.getI (n - l.length)
theorem List.getI_eq_getElem?_getD E1 #
∀ {α : Type u} (l : List α) [inst : Inhabited α] (n : ℕ), l.getI n = l[n]?.getD default
theorem List.getI_zero_eq_headI E1 #
∀ {α : Type u} (l : List α) [inst : Inhabited α], l.getI 0 = l.headI