Documentation

Std.Data.Array.Lemmas

@[simp]
theorem getElem_fin {Cont : Type u_1} {Elem : Type u_2} {Dom : ContNatProp} {n : Nat} [GetElem Cont Nat Elem Dom] (a : Cont) (i : Fin n) (h : Dom a i.val) :
a[i] = a[i.val]
@[simp]
theorem getElem?_fin {Cont : Type u_1} {Elem : Type u_2} {Dom : ContNatProp} {n : Nat} [GetElem Cont Nat Elem Dom] (a : Cont) (i : Fin n) [Decidable (Dom a i.val)] :
a[i]? = a[i.val]?
@[simp]
theorem getElem!_fin {Cont : Type u_1} {Elem : Type u_2} {Dom : ContNatProp} {n : Nat} [GetElem Cont Nat Elem Dom] (a : Cont) (i : Fin n) [Decidable (Dom a i.val)] [Inhabited Elem] :
a[i]! = a[i.val]!
theorem getElem?_pos {Cont : Type u_1} {Idx : Type u_2} {Elem : Type u_3} {Dom : ContIdxProp} [GetElem Cont Idx Elem Dom] (a : Cont) (i : Idx) (h : Dom a i) [Decidable (Dom a i)] :
a[i]? = some a[i]
theorem getElem?_neg {Cont : Type u_1} {Idx : Type u_2} {Elem : Type u_3} {Dom : ContIdxProp} [GetElem Cont Idx Elem Dom] (a : Cont) (i : Idx) (h : ¬Dom a i) [Decidable (Dom a i)] :
a[i]? = none
@[simp]
theorem mkArray_data {α : Type u_1} (n : Nat) (v : α) :
(mkArray n v).data = List.replicate n v
@[simp]
theorem Array.singleton_def {α : Type u_1} (v : α) :
@[simp]
theorem Array.toArray_data {α : Type u_1} (a : Array α) :
List.toArray a.data = a
@[simp]
theorem Array.get_eq_getElem {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) :
Array.get a i = a[i.val]
@[simp]
theorem Array.get?_eq_getElem? {α : Type u_1} (a : Array α) (i : Nat) :
Array.get? a i = a[i]?
theorem Array.getElem_fin_eq_data_get {α : Type u_1} (a : Array α) (i : Fin (List.length a.data)) :
a[i] = List.get a.data i
@[simp]
theorem Array.ugetElem_eq_getElem {α : Type u_1} (a : Array α) {i : USize} (h : USize.toNat i < Array.size a) :
a[i] = a[USize.toNat i]
theorem Array.getElem?_eq_getElem {α : Type u_1} (a : Array α) (i : Nat) (h : i < Array.size a) :
a[i]? = some a[i]
theorem Array.get?_len_le {α : Type u_1} (a : Array α) (i : Nat) (h : Array.size a i) :
a[i]? = none
theorem Array.getElem_mem_data {α : Type u_1} {i : Nat} (a : Array α) (h : i < Array.size a) :
a[i] a.data
theorem Array.getElem?_eq_data_get? {α : Type u_1} (a : Array α) (i : Nat) :
a[i]? = List.get? a.data i
theorem Array.get?_eq_data_get? {α : Type u_1} (a : Array α) (i : Nat) :
Array.get? a i = List.get? a.data i
@[simp]
theorem Array.getD_eq_get? {α : Type u_1} (a : Array α) (n : Nat) (d : α) :
theorem Array.get!_eq_getD {α : Type u_1} {n : Nat} [Inhabited α] (a : Array α) :
Array.get! a n = Array.getD a n default
@[simp]
theorem Array.get!_eq_get? {α : Type u_1} {n : Nat} [Inhabited α] (a : Array α) :
@[simp]
theorem Array.back_eq_back? {α : Type u_1} [Inhabited α] (a : Array α) :
@[simp]
theorem Array.back?_push {α : Type u_1} {x : α} (a : Array α) :
theorem Array.back_push {α : Type u_1} {x : α} [Inhabited α] (a : Array α) :
theorem Array.get?_push_lt {α : Type u_1} (a : Array α) (x : α) (i : Nat) (h : i < Array.size a) :
(Array.push a x)[i]? = some a[i]
theorem Array.get?_push_eq {α : Type u_1} (a : Array α) (x : α) :
@[simp]
theorem Array.data_set {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (v : α) :
(Array.set a i v).data = List.set a.data i.val v
@[simp]
theorem Array.get_set_eq {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (v : α) :
(Array.set a i v)[i.val] = v
@[simp]
theorem Array.get_set_ne {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) {j : Nat} (v : α) (hj : j < Array.size a) (h : i.val j) :
(Array.set a i v)[j] = a[j]
@[simp]
theorem Array.get?_set_eq {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (v : α) :
(Array.set a i v)[i.val]? = some v
@[simp]
theorem Array.get?_set_ne {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) {j : Nat} (v : α) (h : i.val j) :
(Array.set a i v)[j]? = a[j]?
theorem Array.get?_set {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (j : Nat) (v : α) :
(Array.set a i v)[j]? = if i.val = j then some v else a[j]?
theorem Array.get_set {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (j : Nat) (hj : j < Array.size a) (v : α) :
(Array.set a i v)[j] = if i.val = j then v else a[j]
theorem Array.set_set {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (v : α) (v' : α) :
Array.set (Array.set a i v) { val := i.val, isLt := (_ : i.val < Array.size (Array.set a i v)) } v' = Array.set a i v'
theorem Array.swap_def {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (j : Fin (Array.size a)) :
Array.swap a i j = Array.set (Array.set a i (Array.get a j)) { val := j.val, isLt := (_ : j.val < Array.size (Array.set a i a[j.val])) } (Array.get a i)
theorem Array.data_swap {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (j : Fin (Array.size a)) :
(Array.swap a i j).data = List.set (List.set a.data i.val (Array.get a j)) j.val (Array.get a i)
theorem Array.get?_swap {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (j : Fin (Array.size a)) (k : Nat) :
(Array.swap a i j)[k]? = if j.val = k then some a[i.val] else if i.val = k then some a[j.val] else a[k]?
@[simp]
theorem Array.swapAt_def {α : Type u_1} (a : Array α) (i : Fin (Array.size a)) (v : α) :
Array.swapAt a i v = (a[i.val], Array.set a i v)
theorem Array.swapAt!_def {α : Type u_1} (a : Array α) (i : Nat) (v : α) (h : i < Array.size a) :
Array.swapAt! a i v = (a[i], Array.set a { val := i, isLt := h } v)
@[simp]
theorem Array.data_pop {α : Type u_1} (a : Array α) :
(Array.pop a).data = List.dropLast a.data
@[simp]
theorem Array.pop_empty {α : Type u_1} :
Array.pop #[] = #[]
@[simp]
theorem Array.pop_push {α : Type u_1} {x : α} (a : Array α) :
theorem Array.SatisfiesM_foldrM {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_1} [Monad m] [LawfulMonad m] {as : Array α} (motive : NatβProp) {init : β} (h0 : motive (Array.size as) init) {f : αβm β} (hf : ∀ (i : Fin (Array.size as)) (b : β), motive (i.val + 1) bSatisfiesM (motive i.val) (f as[i] b)) :
SatisfiesM (motive 0) (Array.foldrM f init as (Array.size as))
theorem Array.SatisfiesM_foldrM.go {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_1} [Monad m] [LawfulMonad m] {as : Array α} (motive : NatβProp) {f : αβm β} (hf : ∀ (i : Fin (Array.size as)) (b : β), motive (i.val + 1) bSatisfiesM (motive i.val) (f as[i] b)) {i : Nat} {b : β} (hi : i Array.size as) (H : motive i b) :
SatisfiesM (motive 0) (Array.foldrM.fold f as 0 i hi b)
theorem Array.foldr_induction {α : Type u_1} {β : Type u_2} {as : Array α} (motive : NatβProp) {init : β} (h0 : motive (Array.size as) init) {f : αββ} (hf : (i : Fin (Array.size as)) → (b : β) → motive (i.val + 1) bmotive i.val (f as[i] b)) :
motive 0 (Array.foldr f init as (Array.size as))
theorem Array.mapM_eq_mapM_data {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_1} [Monad m] [LawfulMonad m] (f : αm β) (arr : Array α) :
Array.mapM f arr = do let __do_lift ← List.mapM f arr.data pure { data := __do_lift }
theorem Array.SatisfiesM_mapIdxM {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_1} [Monad m] [LawfulMonad m] (as : Array α) (f : Fin (Array.size as)αm β) (motive : NatProp) (h0 : motive 0) (p : Fin (Array.size as)βProp) (hs : ∀ (i : Fin (Array.size as)), motive i.valSatisfiesM (fun x => p i x motive (i.val + 1)) (f i as[i])) :
SatisfiesM (fun arr => motive (Array.size as) eq, (i : Nat) → (h : i < Array.size as) → p { val := i, isLt := h } arr[i]) (Array.mapIdxM as f)
theorem Array.SatisfiesM_mapIdxM.go {m : Type u_1 → Type u_2} {α : Type u_3} {β : Type u_1} [Monad m] [LawfulMonad m] (as : Array α) (f : Fin (Array.size as)αm β) (motive : NatProp) (p : Fin (Array.size as)βProp) (hs : ∀ (i : Fin (Array.size as)), motive i.valSatisfiesM (fun x => p i x motive (i.val + 1)) (f i as[i])) {bs : Array β} {i : Nat} {j : Nat} {h : i + j = Array.size as} (h₁ : j = Array.size bs) (h₂ : (i : Nat) → (h : i < Array.size as) → (h' : i < Array.size bs) → p { val := i, isLt := h } bs[i]) (hm : motive j) :
SatisfiesM (fun arr => motive (Array.size as) eq, (i : Nat) → (h : i < Array.size as) → p { val := i, isLt := h } arr[i]) (Array.mapIdxM.map as f i j h bs)
theorem Array.mapIdx_induction {α : Type u_1} {β : Type u_2} (as : Array α) (f : Fin (Array.size as)αβ) (motive : NatProp) (h0 : motive 0) (p : Fin (Array.size as)βProp) (hs : ∀ (i : Fin (Array.size as)), motive i.valp i (f i as[i]) motive (i.val + 1)) :
motive (Array.size as) eq, (i : Nat) → (h : i < Array.size as) → p { val := i, isLt := h } (Array.mapIdx as f)[i]
theorem Array.mapIdx_induction' {α : Type u_1} {β : Type u_2} (as : Array α) (f : Fin (Array.size as)αβ) (p : Fin (Array.size as)βProp) (hs : (i : Fin (Array.size as)) → p i (f i as[i])) :
eq, (i : Nat) → (h : i < Array.size as) → p { val := i, isLt := h } (Array.mapIdx as f)[i]
@[simp]
theorem Array.size_mapIdx {α : Type u_1} {β : Type u_2} (a : Array α) (f : Fin (Array.size a)αβ) :
@[simp]
theorem Array.getElem_mapIdx {α : Type u_1} {β : Type u_2} (a : Array α) (f : Fin (Array.size a)αβ) (i : Nat) (h : i < Array.size (Array.mapIdx a f)) :
(Array.mapIdx a f)[i] = f { val := i, isLt := (_ : i < Array.size a) } a[i]
@[simp]
theorem Array.size_swap! {α : Type u_1} (a : Array α) (i : Nat) (j : Nat) (hi : i < Array.size a) (hj : j < Array.size a) :
@[simp]
theorem Array.size_reverse {α : Type u_1} (a : Array α) :
theorem Array.size_reverse.go {α : Type u_1} (as : Array α) (i : Nat) (j : Fin (Array.size as)) :
@[simp]
theorem Array.reverse_data {α : Type u_1} (a : Array α) :
(Array.reverse a).data = List.reverse a.data
theorem Array.reverse_data.go {α : Type u_1} (a : Array α) (as : Array α) (i : Nat) (j : Nat) (hj : j < Array.size as) (h : i + j + 1 = Array.size a) (h₂ : Array.size as = Array.size a) (H : ∀ (k : Nat), List.get? as.data k = if i k k j then List.get? a.data k else List.get? (List.reverse a.data) k) (k : Nat) :
List.get? (Array.reverse.loop as i { val := j, isLt := hj }).data k = List.get? (List.reverse a.data) k
@[simp]
theorem Array.size_ofFn_go {α : Type u_1} {n : Nat} (f : Fin nα) (i : Nat) (acc : Array α) :
Array.size (Array.ofFn.go f i acc) = Array.size acc + (n - i)
@[simp]
theorem Array.size_ofFn {n : Nat} {α : Type u_1} (f : Fin nα) :
theorem Array.getElem_ofFn_go {n : Nat} {α : Type u_1} (f : Fin nα) (i : Nat) {acc : Array α} {k : Nat} (hki : k < n) (hin : i n) (hi : i = Array.size acc) (hacc : ∀ (j : Nat) (hj : j < Array.size acc), acc[j] = f { val := j, isLt := (_ : j < n) }) :
(Array.ofFn.go f i acc)[k] = f { val := k, isLt := hki }
@[simp]
theorem Array.getElem_ofFn {n : Nat} {α : Type u_1} (f : Fin nα) (i : Nat) (h : i < Array.size (Array.ofFn f)) :
(Array.ofFn f)[i] = f { val := i, isLt := (_ : i < n) }