Preliminaries #
toList #
empty #
size #
push #
mkArray #
@[simp]
theorem
Array.toList_mkArray
{n : Nat}
{α✝ : Type u_1}
{a : α✝}
:
(mkArray n a).toList = List.replicate n a
L[i] and L[i]? #
@[simp]
mem #
isEmpty #
@[simp]
Decidability of bounded quantifiers #
instance
Array.instDecidableForallForallMemOfDecidablePred
{α : Type u_1}
{xs : Array α}
{p : α → Prop}
[DecidablePred p]
:
Equations
- Array.instDecidableForallForallMemOfDecidablePred = decidable_of_iff (∀ (i : Nat) (h : i < xs.size), p xs[i]) ⋯
instance
Array.instDecidableExistsAndMemOfDecidablePred
{α : Type u_1}
{xs : Array α}
{p : α → Prop}
[DecidablePred p]
:
Equations
- Array.instDecidableExistsAndMemOfDecidablePred = decidable_of_iff (∃ (i : Nat), ∃ (h : i < xs.size), p xs[i]) ⋯
any / all #
@[simp]
theorem
List.anyM_toArray'
{m : Type → Type u_1}
{α : Type u_2}
{stop : Nat}
[Monad m]
[LawfulMonad m]
(p : α → m Bool)
(l : List α)
(h : stop = l.toArray.size)
:
Array.anyM p l.toArray 0 stop = anyM p l
Variant of anyM_toArray
with a side condition on stop
.
@[simp]
theorem
List.any_toArray'
{α : Type u_1}
{stop : Nat}
(p : α → Bool)
(l : List α)
(h : stop = l.toArray.size)
:
l.toArray.any p 0 stop = l.any p
Variant of any_toArray
with a side condition on stop
.
@[simp]
theorem
List.allM_toArray'
{m : Type → Type u_1}
{α : Type u_2}
{stop : Nat}
[Monad m]
[LawfulMonad m]
(p : α → m Bool)
(l : List α)
(h : stop = l.toArray.size)
:
Array.allM p l.toArray 0 stop = allM p l
Variant of allM_toArray
with a side condition on stop
.
@[simp]
theorem
List.all_toArray'
{α : Type u_1}
{stop : Nat}
(p : α → Bool)
(l : List α)
(h : stop = l.toArray.size)
:
l.toArray.all p 0 stop = l.all p
Variant of all_toArray
with a side condition on stop
.
theorem
List.anyM_toArray
{m : Type → Type u_1}
{α : Type u_2}
[Monad m]
[LawfulMonad m]
(p : α → m Bool)
(l : List α)
:
Array.anyM p l.toArray = anyM p l
theorem
List.allM_toArray
{m : Type → Type u_1}
{α : Type u_2}
[Monad m]
[LawfulMonad m]
(p : α → m Bool)
(l : List α)
:
Array.allM p l.toArray = allM p l
theorem
List.elem_toArray
{α : Type u_1}
[BEq α]
{l : List α}
{a : α}
:
Array.elem a l.toArray = elem a l
Variant of any_beq
with ==
reversed.
Variant of all_bne
with !=
reversed.
@[reducible, inline, deprecated Array.mem_of_contains_eq_true (since := "2024-12-12")]
Instances For
instance
Array.instDecidableMemOfLawfulBEq
{α : Type u_1}
[BEq α]
[LawfulBEq α]
(a : α)
(as : Array α)
:
Equations
set #
@[reducible, inline, deprecated Array.getElem?_set_self (since := "2024-12-11")]
Instances For
setIfInBounds #
@[reducible, inline, deprecated Array.set!_eq_setIfInBounds (since := "2024-12-12")]
Instances For
@[reducible, inline, deprecated Array.getElem?_setIfInBounds_self (since := "2024-12-11")]
Instances For
BEq #
isEqv #
@[simp]
Content below this point has not yet been aligned with List
.
@[deprecated Array.size_toArray (since := "2024-12-11")]
@[simp]
theorem
Array.foldr_push'
{α : Type u_1}
{β : Type u_2}
(f : α → β → β)
(init : β)
(arr : Array α)
(a : α)
{start : Nat}
(h : start = arr.size + 1)
:
Variant of foldr_push
with the h : start = arr.size + 1
rather than (arr.push a).size
as the argument.
@[inline]
A more efficient version of arr.toList.reverse
.
Equations
- arr.toListRev = Array.foldl (fun (l : List α) (t : α) => t :: l) [] arr
Instances For
@[simp]
uset #
get #
@[reducible, inline, deprecated Array.getD_getElem? (since := "2024-12-11")]
Equations
Instances For
ofFn #
mem #
get lemmas #
@[reducible, inline, deprecated Array.getElem?_size_le (since := "2024-10-21")]
Equations
Instances For
@[reducible, inline, deprecated Array.getElem?_push_lt (since := "2024-10-21")]
Equations
Instances For
@[reducible, inline, deprecated Array.getElem?_push_eq (since := "2024-10-21")]
Equations
Instances For
@[reducible, inline, deprecated Array.getElem?_push (since := "2024-10-21")]
Equations
Instances For
@[reducible, inline, deprecated Array.getElem?_size (since := "2024-10-21")]
Equations
Instances For
@[simp]
@[reducible, inline, deprecated Array.size_swapIfInBounds (since := "2024-11-24")]
abbrev
Array.size_swap!
{α : Type u_1}
(a : Array α)
(i j : Nat)
:
(a.swapIfInBounds i j).size = a.size
Equations
Instances For
@[irreducible]
theorem
Array.size_reverse.go
{α : Type u_1}
(as : Array α)
(i : Nat)
(j : Fin as.size)
:
(reverse.loop as i j).size = as.size
@[simp]
@[irreducible]
theorem
Array.toList_reverse.go
{α : Type u_1}
(a as : Array α)
(i j : Nat)
(hj : j < as.size)
(h : i + j + 1 = a.size)
(h₂ : as.size = a.size)
(H : ∀ (k : Nat), as.toList[k]? = if i ≤ k ∧ k ≤ j then a.toList[k]? else a.toList.reverse[k]?)
(k : Nat)
:
(reverse.loop as i ⟨j, hj⟩).toList[k]? = a.toList.reverse[k]?
take #
forIn #
foldl / foldr #
@[irreducible]
theorem
Array.foldl_induction.go
{α : Type u_1}
{β : Type u_2}
{as : Array α}
(motive : Nat → β → Prop)
{f : β → α → β}
(hf : ∀ (i : Fin as.size) (b : β), motive (↑i) b → motive (↑i + 1) (f b as[i]))
{i j : Nat}
{b : β}
(h₁ : j ≤ as.size)
(h₂ : as.size ≤ i + j)
(H : motive j b)
:
motive as.size (foldlM.loop f as as.size ⋯ i j b)
@[irreducible]
map #
theorem
Array.mapM_eq_mapM_toList
{m : Type u_1 → Type u_2}
{α : Type u_3}
{β : Type u_1}
[Monad m]
[LawfulMonad m]
(f : α → m β)
(arr : Array α)
:
mapM f arr = List.toArray <$> List.mapM f arr.toList
@[simp]
theorem
Array.getElem?_map
{α : Type u_1}
{β : Type u_2}
(f : α → β)
(as : Array α)
(i : Nat)
:
(map f as)[i]? = Option.map f as[i]?
modify #
@[simp]
theorem
Array.toList_modify
{α : Type u_1}
{x : Nat}
(as : Array α)
(f : α → α)
:
(as.modify x f).toList = List.modify f x as.toList
theorem
Array.getElem?_modify
{α : Type u_1}
{as : Array α}
{i : Nat}
{f : α → α}
{j : Nat}
:
(as.modify i f)[j]? = if i = j then Option.map f as[j]? else as[j]?
filter #
@[simp]
theorem
Array.toList_filter
{α : Type u_1}
(p : α → Bool)
(l : Array α)
:
(filter p l).toList = List.filter p l.toList
filterMap #
@[simp]
theorem
Array.toList_filterMap
{α : Type u_1}
{β : Type u_2}
(f : α → Option β)
(l : Array α)
:
(filterMap f l).toList = List.filterMap f l.toList
empty #
append #
flatten #
extract #
theorem
Array.extract_loop_zero
{α : Type u_1}
(as bs : Array α)
(start : Nat)
:
extract.loop as 0 start bs = bs
theorem
Array.extract_loop_succ
{α : Type u_1}
(as bs : Array α)
(size start : Nat)
(h : start < as.size)
:
extract.loop as (size + 1) start bs = extract.loop as size (start + 1) (bs.push as[start])
theorem
Array.extract_loop_of_ge
{α : Type u_1}
(as bs : Array α)
(size start : Nat)
(h : start ≥ as.size)
:
extract.loop as size start bs = bs
theorem
Array.extract_loop_eq_aux
{α : Type u_1}
(as bs : Array α)
(size start : Nat)
:
extract.loop as size start bs = bs ++ extract.loop as size start #[]
theorem
Array.size_extract_loop
{α : Type u_1}
(as bs : Array α)
(size start : Nat)
:
(extract.loop as size start bs).size = bs.size + min size (as.size - start)
theorem
Array.getElem_extract_loop_lt_aux
{α : Type u_1}
{i : Nat}
(as bs : Array α)
(size start : Nat)
(hlt : i < bs.size)
:
i < (extract.loop as size start bs).size
theorem
Array.getElem_extract_loop_lt
{α : Type u_1}
{i : Nat}
(as bs : Array α)
(size start : Nat)
(hlt : i < bs.size)
(h : i < (extract.loop as size start bs).size := ⋯)
:
(extract.loop as size start bs)[i] = bs[i]
@[simp]
contains #
instance
Array.instDecidableMemOfDecidableEq
{α : Type u_1}
[DecidableEq α]
(a : α)
(as : Array α)
:
Equations
- Array.instDecidableMemOfDecidableEq a as = decidable_of_iff (as.contains a = true) ⋯
swap #
eraseIdx #
isPrefixOf #
zipWith #
@[simp]
theorem
Array.toList_zipWith
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(f : α → β → γ)
(as : Array α)
(bs : Array β)
:
(as.zipWith bs f).toList = List.zipWith f as.toList bs.toList
findSomeM?, findM?, findSome?, find? #
@[simp]
theorem
Array.findSomeM?_toList
{m : Type u_1 → Type u_2}
{α : Type u_3}
{β : Type u_1}
[Monad m]
[LawfulMonad m]
(p : α → m (Option β))
(as : Array α)
:
List.findSomeM? p as.toList = findSomeM? p as
@[simp]
theorem
Array.findM?_toList
{m : Type → Type}
{α : Type}
[Monad m]
[LawfulMonad m]
(p : α → m Bool)
(as : Array α)
:
List.findM? p as.toList = findM? p as
@[simp]
theorem
Array.findSome?_toList
{α : Type u_1}
{β : Type u_2}
(p : α → Option β)
(as : Array α)
:
List.findSome? p as.toList = findSome? p as
@[simp]
theorem
Array.find?_toList
{α : Type u_1}
(p : α → Bool)
(as : Array α)
:
List.find? p as.toList = find? p as
More theorems about List.toArray
, followed by an Array
operation. #
Our goal is to have simp
"pull List.toArray
outwards" as much as possible.
@[simp]
theorem
List.mapM_toArray
{m : Type u_1 → Type u_2}
{α : Type u_3}
{β : Type u_1}
[Monad m]
[LawfulMonad m]
(f : α → m β)
(l : List α)
:
Array.mapM f l.toArray = toArray <$> mapM f l
@[simp]
@[simp]
theorem
List.filter_toArray'
{α : Type u_1}
{stop : Nat}
(p : α → Bool)
(l : List α)
(h : stop = l.toArray.size)
:
Array.filter p l.toArray 0 stop = (filter p l).toArray
theorem
List.filter_toArray
{α : Type u_1}
(p : α → Bool)
(l : List α)
:
Array.filter p l.toArray = (filter p l).toArray
theorem
List.filterMap_toArray
{α : Type u_1}
{β : Type u_2}
(f : α → Option β)
(l : List α)
:
Array.filterMap f l.toArray = (filterMap f l).toArray
@[simp]
@[simp]
theorem
Array.toList_takeWhile
{α : Type u_1}
(p : α → Bool)
(as : Array α)
:
(takeWhile p as).toList = List.takeWhile p as.toList
map #
@[simp]
map_id_fun'
differs from map_id_fun
by representing the identity function as a lambda, rather than id
.
theorem
Array.foldr_map'
{α : Type u_1}
{β : Type u_2}
(g : α → β)
(f : α → α → α)
(f' : β → β → β)
(a : α)
(l : List α)
(h : ∀ (x y : α), f' (g x) (g y) = g (f x y))
:
List.foldr f' (g a) (List.map g l) = g (List.foldr f a l)
flatten #
@[simp]
theorem
Array.flatten_toArray_map_toArray
{α : Type u_1}
(xss : List (List α))
:
(List.map List.toArray xss).toArray.flatten = xss.flatten.toArray
reverse #
findSomeRevM?, findRevM?, findSomeRev?, findRev? #
@[simp]
theorem
Array.findSomeRevM?_eq_findSomeM?_reverse
{m : Type u_1 → Type u_2}
{α : Type u_3}
{β : Type u_1}
[Monad m]
[LawfulMonad m]
(f : α → m (Option β))
(as : Array α)
:
findSomeRevM? f as = findSomeM? f as.reverse
@[simp]
theorem
Array.findSomeRev?_eq_findSome?_reverse
{α : Type u_1}
{β : Type u_2}
(f : α → Option β)
(as : Array α)
:
findSomeRev? f as = findSome? f as.reverse
unzip #
take #
Deprecations #
@[reducible, inline, deprecated List.back!_toArray (since := "2024-10-31")]
Equations
Instances For
@[reducible, inline, deprecated List.setIfInBounds_toArray (since := "2024-11-24")]
abbrev
List.setD_toArray
{α : Type u_1}
(l : List α)
(i : Nat)
(a : α)
:
l.toArray.setIfInBounds i a = (l.set i a).toArray
Instances For
@[reducible, inline, deprecated Array.foldl_toList_eq_flatMap (since := "2024-10-16")]
abbrev
Array.foldl_toList_eq_bind
{α : Type u_1}
{β : Type u_2}
(l : List α)
(acc : Array β)
(F : Array β → α → Array β)
(G : α → List β)
(H : ∀ (acc : Array β) (a : α), (F acc a).toList = acc.toList ++ G a)
:
(List.foldl F acc l).toList = acc.toList ++ l.flatMap G
Instances For
@[reducible, inline, deprecated Array.foldl_toList_eq_flatMap (since := "2024-10-16")]
abbrev
Array.foldl_data_eq_bind
{α : Type u_1}
{β : Type u_2}
(l : List α)
(acc : Array β)
(F : Array β → α → Array β)
(G : α → List β)
(H : ∀ (acc : Array β) (a : α), (F acc a).toList = acc.toList ++ G a)
:
(List.foldl F acc l).toList = acc.toList ++ l.flatMap G
Instances For
@[reducible, inline, deprecated Array.getElem_mem (since := "2024-10-17")]
Equations
Instances For
@[reducible, inline, deprecated Array.getElem_fin_eq_getElem_toList (since := "2024-10-17")]
abbrev
Array.getElem_fin_eq_toList_get
{α : Type u_1}
(a : Array α)
(i : Fin a.size)
:
a[i] = a.toList[i]
Instances For
@[reducible, inline, deprecated "Use reverse direction of `getElem?_toList`" (since := "2024-10-17")]
abbrev
Array.getElem?_eq_toList_getElem?
{α : Type u_1}
{a : Array α}
{i : Nat}
:
a.toList[i]? = a[i]?
Instances For
@[reducible, inline, deprecated Array.get?_eq_get?_toList (since := "2024-10-17")]
Instances For
@[reducible, inline, deprecated Array.getElem_push (since := "2024-10-21")]
Equations
Instances For
@[reducible, inline, deprecated Array.getElem_push_eq (since := "2024-10-21")]
Equations
Instances For
@[reducible, inline, deprecated Array.back!_eq_back? (since := "2024-10-31")]
Equations
Instances For
@[reducible, inline, deprecated Array.back!_push (since := "2024-10-31")]
Equations
Instances For
@[reducible, inline, deprecated Array.set!_is_setIfInBounds (since := "2024-11-24")]
Instances For
@[reducible, inline, deprecated Array.size_setIfInBounds (since := "2024-11-24")]
abbrev
Array.size_setD
{α : Type u_1}
(as : Array α)
(index : Nat)
(val : α)
:
(as.setIfInBounds index val).size = as.size
Equations
Instances For
@[reducible, inline, deprecated Array.getElem?_setIfInBounds_eq (since := "2024-11-24")]
Instances For
@[reducible, inline, deprecated Array.getD_get?_setIfInBounds (since := "2024-11-24")]