Documentation

Init.Data.Array.Find

Lemmas about Array.findSome?, Array.find?. #

findSome? #

@[simp]
theorem Array.findSomeRev?_push_of_isSome {α : Type u_1} {α✝ : Type u_2} {f : αOption α✝} {a : α} (l : Array α) (h : (f a).isSome = true) :
Array.findSomeRev? f (l.push a) = f a
@[simp]
theorem Array.findSomeRev?_push_of_isNone {α : Type u_1} {α✝ : Type u_2} {f : αOption α✝} {a : α} (l : Array α) (h : (f a).isNone = true) :
theorem Array.exists_of_findSome?_eq_some {α : Type u_1} {β : Type u_2} {b : β} {f : αOption β} {l : Array α} (w : Array.findSome? f l = some b) :
∃ (a : α), a l f a = some b
@[simp]
theorem Array.findSome?_eq_none_iff {α✝ : Type u_1} {α✝¹ : Type u_2} {p : α✝Option α✝¹} {l : Array α✝} :
Array.findSome? p l = none ∀ (x : α✝), x lp x = none
@[simp]
theorem Array.findSome?_isSome_iff {α : Type u_1} {β : Type u_2} {f : αOption β} {l : Array α} :
(Array.findSome? f l).isSome = true ∃ (x : α), x l (f x).isSome = true
theorem Array.findSome?_eq_some_iff {α : Type u_1} {β : Type u_2} {f : αOption β} {l : Array α} {b : β} :
Array.findSome? f l = some b ∃ (l₁ : Array α), ∃ (a : α), ∃ (l₂ : Array α), l = l₁.push a ++ l₂ f a = some b ∀ (x : α), x l₁f x = none
@[simp]
theorem Array.findSome?_guard {α : Type u_1} {p : αBool} (l : Array α) :
Array.findSome? (Option.guard fun (x : α) => p x = true) l = Array.find? p l
@[simp]
theorem Array.getElem?_zero_filterMap {α : Type u_1} {β : Type u_2} (f : αOption β) (l : Array α) :
@[simp]
theorem Array.getElem_zero_filterMap {α : Type u_1} {β : Type u_2} (f : αOption β) (l : Array α) (h : 0 < (Array.filterMap f l).size) :
(Array.filterMap f l)[0] = (Array.findSome? f l).get
@[simp]
theorem Array.back?_filterMap {α : Type u_1} {β : Type u_2} (f : αOption β) (l : Array α) :
@[simp]
theorem Array.back!_filterMap {β : Type u_1} {α : Type u_2} [Inhabited β] (f : αOption β) (l : Array α) :
@[simp]
theorem Array.map_findSome? {α : Type u_1} {β : Type u_2} {γ : Type u_3} (f : αOption β) (g : βγ) (l : Array α) :
theorem Array.findSome?_map {β : Type u_1} {γ : Type u_2} {α✝ : Type u_3} {p : γOption α✝} (f : βγ) (l : Array β) :
theorem Array.findSome?_append {α : Type u_1} {α✝ : Type u_2} {f : αOption α✝} {l₁ l₂ : Array α} :
Array.findSome? f (l₁ ++ l₂) = (Array.findSome? f l₁).or (Array.findSome? f l₂)
theorem Array.getElem?_zero_flatten {α : Type u_1} (L : Array (Array α)) :
L.flatten[0]? = Array.findSome? (fun (l : Array α) => l[0]?) L
theorem Array.getElem_zero_flatten.proof {α : Type u_1} {L : Array (Array α)} (h : 0 < L.flatten.size) :
(Array.findSome? (fun (l : Array α) => l[0]?) L).isSome = true
theorem Array.getElem_zero_flatten {α : Type u_1} {L : Array (Array α)} (h : 0 < L.flatten.size) :
L.flatten[0] = (Array.findSome? (fun (l : Array α) => l[0]?) L).get
theorem Array.back?_flatten {α : Type u_1} {L : Array (Array α)} :
L.flatten.back? = Array.findSomeRev? (fun (l : Array α) => l.back?) L
theorem Array.findSome?_mkArray {α✝ : Type u_1} {α✝¹ : Type u_2} {f : α✝Option α✝¹} {n : Nat} {a : α✝} :
Array.findSome? f (mkArray n a) = if n = 0 then none else f a
@[simp]
theorem Array.findSome?_mkArray_of_pos {n : Nat} {α✝ : Type u_1} {α✝¹ : Type u_2} {f : α✝Option α✝¹} {a : α✝} (h : 0 < n) :
@[simp]
theorem Array.findSome?_mkArray_of_isSome {α✝ : Type u_1} {α✝¹ : Type u_2} {f : α✝Option α✝¹} {n : Nat} {a : α✝} :
(f a).isSome = trueArray.findSome? f (mkArray n a) = if n = 0 then none else f a
@[simp]
theorem Array.findSome?_mkArray_of_isNone {α✝ : Type u_1} {α✝¹ : Type u_2} {f : α✝Option α✝¹} {n : Nat} {a : α✝} (h : (f a).isNone = true) :

find? #

@[simp]
theorem Array.find?_singleton {α : Type u_1} (a : α) (p : αBool) :
Array.find? p #[a] = if p a = true then some a else none
@[simp]
theorem Array.findRev?_push_of_pos {α : Type} {p : αBool} {a : α} (l : Array α) (h : p a = true) :
Array.findRev? p (l.push a) = some a
@[simp]
theorem Array.findRev?_cons_of_neg {α : Type} {p : αBool} {a : α} (l : Array α) (h : ¬p a = true) :
@[simp]
theorem Array.find?_eq_none {α✝ : Type u_1} {p : α✝Bool} {l : Array α✝} :
Array.find? p l = none ∀ (x : α✝), x l¬p x = true
theorem Array.find?_eq_some_iff_append {α : Type u_1} {p : αBool} {b : α} {xs : Array α} :
Array.find? p xs = some b p b = true ∃ (as : Array α), ∃ (bs : Array α), xs = as.push b ++ bs ∀ (a : α), a as(!p a) = true
@[simp]
theorem Array.find?_push_eq_some {α : Type u_1} {a : α} {p : αBool} {b : α} {xs : Array α} :
Array.find? p (xs.push a) = some b Array.find? p xs = some b Array.find? p xs = none p a = true a = b
@[simp]
theorem Array.find?_isSome {α : Type u_1} {xs : Array α} {p : αBool} :
(Array.find? p xs).isSome = true ∃ (x : α), x xs p x = true
theorem Array.find?_some {α : Type u_1} {p : αBool} {a : α} {xs : Array α} (h : Array.find? p xs = some a) :
p a = true
theorem Array.mem_of_find?_eq_some {α : Type u_1} {p : αBool} {a : α} {xs : Array α} (h : Array.find? p xs = some a) :
a xs
theorem Array.get_find?_mem {α : Type u_1} {p : αBool} {xs : Array α} (h : (Array.find? p xs).isSome = true) :
(Array.find? p xs).get h xs
@[simp]
theorem Array.find?_filter {α : Type u_1} {xs : Array α} (p q : αBool) :
Array.find? q (Array.filter p xs) = Array.find? (fun (a : α) => decide (p a = true q a = true)) xs
@[simp]
theorem Array.getElem?_zero_filter {α : Type u_1} (p : αBool) (l : Array α) :
(Array.filter p l)[0]? = Array.find? p l
@[simp]
theorem Array.getElem_zero_filter {α : Type u_1} (p : αBool) (l : Array α) (h : 0 < (Array.filter p l).size) :
(Array.filter p l)[0] = (Array.find? p l).get
@[simp]
theorem Array.back?_filter {α : Type} (p : αBool) (l : Array α) :
(Array.filter p l).back? = Array.findRev? p l
@[simp]
theorem Array.back!_filter {α : Type} [Inhabited α] (p : αBool) (l : Array α) :
(Array.filter p l).back! = (Array.findRev? p l).get!
@[simp]
theorem Array.find?_filterMap {α : Type u_1} {β : Type u_2} (xs : Array α) (f : αOption β) (p : βBool) :
Array.find? p (Array.filterMap f xs) = (Array.find? (fun (a : α) => Option.any p (f a)) xs).bind f
@[simp]
theorem Array.find?_map {β : Type u_1} {α : Type u_2} {p : αBool} (f : βα) (xs : Array β) :
@[simp]
theorem Array.find?_append {α : Type u_1} {p : αBool} {l₁ l₂ : Array α} :
Array.find? p (l₁ ++ l₂) = (Array.find? p l₁).or (Array.find? p l₂)
@[simp]
theorem Array.find?_flatten {α : Type u_1} (xs : Array (Array α)) (p : αBool) :
Array.find? p xs.flatten = Array.findSome? (fun (x : Array α) => Array.find? p x) xs
theorem Array.find?_flatten_eq_none {α : Type u_1} {xs : Array (Array α)} {p : αBool} :
Array.find? p xs.flatten = none ∀ (ys : Array α), ys xs∀ (x : α), x ys(!p x) = true
theorem Array.find?_flatten_eq_some {α : Type u_1} {xs : Array (Array α)} {p : αBool} {a : α} :
Array.find? p xs.flatten = some a p a = true ∃ (as : Array (Array α)), ∃ (ys : Array α), ∃ (zs : Array α), ∃ (bs : Array (Array α)), xs = as.push (ys.push a ++ zs) ++ bs (∀ (a : Array α), a as∀ (x : α), x a(!p x) = true) ∀ (x : α), x ys(!p x) = true

If find? p returns some a from xs.flatten, then p a holds, and some array in xs contains a, and no earlier element of that array satisfies p. Moreover, no earlier array in xs has an element satisfying p.

@[simp]
theorem Array.find?_flatMap {α : Type u_1} {β : Type u_2} (xs : Array α) (f : αArray β) (p : βBool) :
Array.find? p (Array.flatMap f xs) = Array.findSome? (fun (x : α) => Array.find? p (f x)) xs
theorem Array.find?_flatMap_eq_none {α : Type u_1} {β : Type u_2} {xs : Array α} {f : αArray β} {p : βBool} :
Array.find? p (Array.flatMap f xs) = none ∀ (x : α), x xs∀ (y : β), y f x(!p y) = true
theorem Array.find?_mkArray {α✝ : Type u_1} {p : α✝Bool} {n : Nat} {a : α✝} :
Array.find? p (mkArray n a) = if n = 0 then none else if p a = true then some a else none
@[simp]
theorem Array.find?_mkArray_of_length_pos {n : Nat} {α✝ : Type u_1} {p : α✝Bool} {a : α✝} (h : 0 < n) :
Array.find? p (mkArray n a) = if p a = true then some a else none
@[simp]
theorem Array.find?_mkArray_of_pos {α✝ : Type u_1} {p : α✝Bool} {n : Nat} {a : α✝} (h : p a = true) :
Array.find? p (mkArray n a) = if n = 0 then none else some a
@[simp]
theorem Array.find?_mkArray_of_neg {α✝ : Type u_1} {p : α✝Bool} {n : Nat} {a : α✝} (h : ¬p a = true) :
theorem Array.find?_mkArray_eq_none {α : Type u_1} {n : Nat} {a : α} {p : αBool} :
Array.find? p (mkArray n a) = none n = 0 (!p a) = true
@[simp]
theorem Array.find?_mkArray_eq_some {α : Type u_1} {n : Nat} {a b : α} {p : αBool} :
Array.find? p (mkArray n a) = some b n 0 p a = true a = b
@[simp]
theorem Array.get_find?_mkArray {α : Type u_1} (n : Nat) (a : α) (p : αBool) (h : (Array.find? p (mkArray n a)).isSome = true) :
(Array.find? p (mkArray n a)).get h = a
theorem Array.find?_pmap {α : Type u_1} {β : Type u_2} {P : αProp} (f : (a : α) → P aβ) (xs : Array α) (H : ∀ (a : α), a xsP a) (p : βBool) :
Array.find? p (Array.pmap f xs H) = Option.map (fun (x : { x : α // x xs }) => match x with | a, m => f a ) (Array.find? (fun (x : { x : α // x xs }) => match x with | a, m => p (f a )) xs.attach)