@[extern lean_mk_array]
Equations
- mkArray n v = { data := List.replicate n v }
@[simp]
Equations
- Array.instEmptyCollectionArray = { emptyCollection := Array.empty }
Equations
- Array.instInhabitedArray = { default := Array.empty }
Equations
- Array.isEmpty a = decide (Array.size a = 0)
@[extern lean_array_uget]
Equations
- Array.uget a i h = Array.get a { val := USize.toNat i, isLt := h }
Equations
- Array.back a = Array.get! a (Array.size a - 1)
Equations
- Array.get? a i = if h : i < Array.size a then some (Array.get a { val := i, isLt := h }) else none
Equations
- Array.back? a = Array.get? a (Array.size a - 1)
@[inline]
abbrev
Array.getLit
{α : Type u}
{n : Nat}
(a : Array α)
(i : Nat)
(h₁ : Array.size a = n)
(h₂ : i < n)
:
α
Equations
- Array.getLit a i h₁ h₂ = Array.get a { val := i, isLt := (_ : i < Array.size a) }
@[simp]
theorem
Array.size_set
{α : Type u}
(a : Array α)
(i : Fin (Array.size a))
(v : α)
:
Array.size (Array.set a i v) = Array.size a
@[simp]
theorem
Array.size_push
{α : Type u}
(a : Array α)
(v : α)
:
Array.size (Array.push a v) = Array.size a + 1
@[extern lean_array_uset]
def
Array.uset
{α : Type u}
(a : Array α)
(i : USize)
(v : α)
(h : USize.toNat i < Array.size a)
:
Array α
Equations
- Array.uset a i v h = Array.set a { val := USize.toNat i, isLt := h } v
@[extern lean_array_fswap]
def
Array.swap
{α : Type u}
(a : Array α)
(i : Fin (Array.size a))
(j : Fin (Array.size a))
:
Array α
Equations
- Array.swap a i j = let v₁ := Array.get a i; let v₂ := Array.get a j; let a' := Array.set a i v₂; Array.set a' ((_ : Array.size a = Array.size (Array.set a i (Array.get a j))) ▸ j) v₁
@[inline]
Equations
- Array.swapAt a i v = let e := Array.get a i; let a := Array.set a i v; (e, a)
Equations
- Array.shrink a n = Array.shrink.loop (Array.size a - n) a
Equations
- Array.shrink.loop 0 _fun_discr = _fun_discr
- Array.shrink.loop (Nat.succ n) _fun_discr = Array.shrink.loop n (Array.pop _fun_discr)
@[implementedBy Array.modifyMUnsafe]
def
Array.modifyM
{α : Type u}
{m : Type u → Type u_1}
[inst : Monad m]
(a : Array α)
(i : Nat)
(f : α → m α)
:
m (Array α)
Equations
- Array.modifyM a i f = if h : i < Array.size a then let idx := { val := i, isLt := h }; let v := Array.get a idx; do let v ← f v pure (Array.set a idx v) else pure a
@[inline]
Equations
- Array.modify a i f = Id.run (Array.modifyM a i f)
@[inline]
Equations
- Array.modifyOp self idx f = Array.modify self idx f
@[inline]
unsafe def
Array.forInUnsafe
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(b : β)
(f : α → β → m (ForInStep β))
:
m β
Equations
- Array.forInUnsafe as b f = let sz := USize.ofNat (Array.size as); Array.forInUnsafe.loop as f sz 0 b
@[implementedBy Array.forInUnsafe]
def
Array.forIn
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(b : β)
(f : α → β → m (ForInStep β))
:
m β
Equations
- Array.forIn as b f = Array.forIn.loop as f (Array.size as) (_ : Array.size as ≤ Array.size as) b
def
Array.forIn.loop
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(f : α → β → m (ForInStep β))
(i : Nat)
(h : i ≤ Array.size as)
(b : β)
:
m β
Equations
- One or more equations did not get rendered due to their size.
- Array.forIn.loop as f 0 x b = pure b
@[inline]
unsafe def
Array.foldlMUnsafe
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : β → α → m β)
(init : β)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m β
Equations
- One or more equations did not get rendered due to their size.
@[implementedBy Array.foldlMUnsafe]
def
Array.foldlM
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : β → α → m β)
(init : β)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m β
Equations
- One or more equations did not get rendered due to their size.
def
Array.foldlM.loop
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : β → α → m β)
(as : Array α)
(stop : Nat)
(h : stop ≤ Array.size as)
(i : Nat)
(j : Nat)
(b : β)
:
m β
Equations
- One or more equations did not get rendered due to their size.
@[inline]
unsafe def
Array.foldrMUnsafe
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → β → m β)
(init : β)
(as : Array α)
(start : optParam Nat (Array.size as))
(stop : optParam Nat 0)
:
m β
Equations
- One or more equations did not get rendered due to their size.
@[implementedBy Array.foldrMUnsafe]
def
Array.foldrM
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → β → m β)
(init : β)
(as : Array α)
(start : optParam Nat (Array.size as))
(stop : optParam Nat 0)
:
m β
Equations
- One or more equations did not get rendered due to their size.
def
Array.foldrM.fold
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → β → m β)
(as : Array α)
(stop : optParam Nat 0)
(i : Nat)
(h : i ≤ Array.size as)
(b : β)
:
m β
@[inline]
unsafe def
Array.mapMUnsafe
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → m β)
(as : Array α)
:
m (Array β)
Equations
- Array.mapMUnsafe f as = let sz := USize.ofNat (Array.size as); unsafeCast (Array.mapMUnsafe.map f sz 0 (unsafeCast as))
@[specialize]
unsafe def
Array.mapMUnsafe.map
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → m β)
(sz : USize)
(i : USize)
(r : Array NonScalar)
:
m (Array PNonScalar)
Equations
- One or more equations did not get rendered due to their size.
@[implementedBy Array.mapMUnsafe]
def
Array.mapM
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(f : α → m β)
(as : Array α)
:
m (Array β)
Equations
- Array.mapM f as = Array.foldlM (fun bs a => do let b ← f a pure (Array.push bs b)) (Array.mkEmpty (Array.size as)) as 0 (Array.size as)
@[inline]
def
Array.mapIdxM
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(f : Fin (Array.size as) → α → m β)
:
m (Array β)
Equations
- Array.mapIdxM as f = Array.mapIdxM.map as f (Array.size as) 0 (_ : Array.size as + 0 = Array.size as + 0) (Array.mkEmpty (Array.size as))
@[specialize]
def
Array.mapIdxM.map
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(f : Fin (Array.size as) → α → m β)
(i : Nat)
(j : Nat)
(inv : i + j = Array.size as)
(bs : Array β)
:
m (Array β)
Equations
- One or more equations did not get rendered due to their size.
- Array.mapIdxM.map as f 0 j x bs = pure bs
@[inline]
unsafe def
Array.anyMUnsafe
{α : Type u}
{m : Type → Type w}
[inst : Monad m]
(p : α → m Bool)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m Bool
Equations
- Array.anyMUnsafe p as start stop = if start < stop then if stop ≤ Array.size as then Array.anyMUnsafe.any p as (USize.ofNat start) (USize.ofNat stop) else pure false else pure false
@[implementedBy Array.anyMUnsafe]
def
Array.anyM
{α : Type u}
{m : Type → Type w}
[inst : Monad m]
(p : α → m Bool)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m Bool
Equations
- Array.anyM p as start stop = let any := fun stop h => Array.anyM.loop p as stop h start; if h : stop ≤ Array.size as then any stop h else any (Array.size as) (_ : Array.size as ≤ Array.size as)
def
Array.anyM.loop
{α : Type u}
{m : Type → Type w}
[inst : Monad m]
(p : α → m Bool)
(as : Array α)
(stop : Nat)
(h : stop ≤ Array.size as)
(j : Nat)
:
m Bool
Equations
- One or more equations did not get rendered due to their size.
@[inline]
def
Array.allM
{α : Type u}
{m : Type → Type w}
[inst : Monad m]
(p : α → m Bool)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m Bool
Equations
- Array.allM p as start stop = do let a ← Array.anyM (fun v => do let a ← p v pure !a) as start stop pure !a
@[inline]
def
Array.findSomeRevM?
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(f : α → m (Option β))
:
m (Option β)
Equations
- Array.findSomeRevM? as f = Array.findSomeRevM?.find as f (Array.size as) (_ : Array.size as ≤ Array.size as)
@[specialize]
def
Array.findSomeRevM?.find
{α : Type u}
{β : Type v}
{m : Type v → Type w}
[inst : Monad m]
(as : Array α)
(f : α → m (Option β))
:
(x : Nat) → x ≤ Array.size as → m (Option β)
Equations
- One or more equations did not get rendered due to their size.
- Array.findSomeRevM?.find as f 0 x = pure none
@[inline]
def
Array.findRevM?
{α : Type}
{m : Type → Type w}
[inst : Monad m]
(as : Array α)
(p : α → m Bool)
:
m (Option α)
Equations
- Array.findRevM? as p = Array.findSomeRevM? as fun a => do let a_1 ← p a pure (if a_1 = true then some a else none)
@[inline]
def
Array.forM
{α : Type u}
{m : Type v → Type w}
[inst : Monad m]
(f : α → m PUnit)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m PUnit
Equations
- Array.forM f as start stop = Array.foldlM (fun x => f) PUnit.unit as start stop
@[inline]
def
Array.forRevM
{α : Type u}
{m : Type v → Type w}
[inst : Monad m]
(f : α → m PUnit)
(as : Array α)
(start : optParam Nat (Array.size as))
(stop : optParam Nat 0)
:
m PUnit
Equations
- Array.forRevM f as start stop = Array.foldrM (fun a x => f a) PUnit.unit as start stop
@[inline]
def
Array.foldl
{α : Type u}
{β : Type v}
(f : β → α → β)
(init : β)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
β
Equations
- Array.foldl f init as start stop = Id.run (Array.foldlM f init as start stop)
@[inline]
def
Array.foldr
{α : Type u}
{β : Type v}
(f : α → β → β)
(init : β)
(as : Array α)
(start : optParam Nat (Array.size as))
(stop : optParam Nat 0)
:
β
Equations
- Array.foldr f init as start stop = Id.run (Array.foldrM f init as start stop)
@[inline]
def
Array.mapIdx
{α : Type u}
{β : Type v}
(as : Array α)
(f : Fin (Array.size as) → α → β)
:
Array β
Equations
- Array.mapIdx as f = Id.run (Array.mapIdxM as f)
@[inline]
Equations
- Array.find? as p = Id.run (Array.findM? as p)
@[inline]
Equations
- Array.findSome? as f = Id.run (Array.findSomeM? as f)
@[inline]
def
Array.findSome!
{α : Type u}
{β : Type v}
[inst : Inhabited β]
(a : Array α)
(f : α → Option β)
:
β
Equations
- One or more equations did not get rendered due to their size.
@[inline]
Equations
- Array.findSomeRev? as f = Id.run (Array.findSomeRevM? as f)
@[inline]
Equations
- Array.findRev? as p = Id.run (Array.findRevM? as p)
@[inline]
Equations
- Array.findIdx? as p = Array.findIdx?.loop as p (Array.size as) 0 (_ : Array.size as + 0 = Array.size as + 0)
Equations
- Array.getIdx? a v = Array.findIdx? a fun a => a == v
Equations
- Array.contains as a = Array.any as (fun b => a == b) 0 (Array.size as)
Equations
- Array.elem a as = Array.contains as a
Equations
- Array.reverse as = let n := Array.size as; let mid := n / 2; Array.reverse.rev n mid as 0
Equations
- Array.reverse.rev n mid as i = if h : i < mid then Array.reverse.rev n mid (Array.swap! as i (n - i - 1)) (i + 1) else as
@[inline]
Equations
- One or more equations did not get rendered due to their size.
@[export lean_array_to_list]
Equations
- Array.toList as = Array.foldr List.cons [] as (Array.size as)
Equations
- One or more equations did not get rendered due to their size.
Equations
- Array.instToStringArray = { toString := fun a => "#" ++ toString (Array.toList a) }
Equations
- Array.append as bs = Array.foldl (fun r v => Array.push r v) as bs 0 (Array.size bs)
Equations
- Array.instAppendArray = { append := Array.append }
Equations
- Array.appendList as bs = List.foldl (fun r v => Array.push r v) as bs
@[inline]
def
Array.concatMapM
{α : Type u}
{m : Type u_1 → Type u_2}
{β : Type u_1}
[inst : Monad m]
(f : α → m (Array β))
(as : Array α)
:
m (Array β)
Equations
- Array.concatMapM f as = Array.foldlM (fun bs a => do let a ← f a pure (bs ++ a)) Array.empty as 0 (Array.size as)
@[inline]
Equations
- Array.concatMap f as = Array.foldl (fun bs a => bs ++ f a) Array.empty as 0 (Array.size as)
Equations
- One or more equations did not get rendered due to their size.
@[specialize]
def
Array.isEqvAux
{α : Type u_1}
(a : Array α)
(b : Array α)
(hsz : Array.size a = Array.size b)
(p : α → α → Bool)
(i : Nat)
:
Equations
- One or more equations did not get rendered due to their size.
@[inline]
Equations
- Array.isEqv a b p = if h : Array.size a = Array.size b then Array.isEqvAux a b h p 0 else false
Equations
- Array.instBEqArray = { beq := fun a b => Array.isEqv a b BEq.beq }
@[inline]
def
Array.filter
{α : Type u_1}
(p : α → Bool)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
Array α
Equations
- Array.filter p as start stop = Array.foldl (fun r a => if p a = true then Array.push r a else r) #[] as start stop
@[inline]
def
Array.filterM
{m : Type → Type u_1}
{α : Type}
[inst : Monad m]
(p : α → m Bool)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
m (Array α)
Equations
- Array.filterM p as start stop = Array.foldlM (fun r a => do let a_1 ← p a if a_1 = true then pure (Array.push r a) else pure r) #[] as start stop
@[inline]
def
Array.filterMap
{α : Type u_1}
{β : Type u_2}
(f : α → Option β)
(as : Array α)
(start : optParam Nat 0)
(stop : optParam Nat (Array.size as))
:
Array β
Equations
- Array.filterMap f as start stop = Id.run (Array.filterMapM f as start stop)
@[specialize]
Equations
- One or more equations did not get rendered due to their size.
theorem
Array.ext
{α : Type u_1}
(a : Array α)
(b : Array α)
(h₁ : Array.size a = Array.size b)
(h₂ : ∀ (i : Nat) (hi₁ : i < Array.size a) (hi₂ : i < Array.size b),
Array.get a { val := i, isLt := hi₁ } = Array.get b { val := i, isLt := hi₂ })
:
a = b
theorem
Array.ext.extAux
{α : Type u_1}
(a : List α)
(b : List α)
(h₁ : List.length a = List.length b)
(h₂ : ∀ (i : Nat) (hi₁ : i < List.length a) (hi₂ : i < List.length b),
List.get a { val := i, isLt := hi₁ } = List.get b { val := i, isLt := hi₂ })
:
a = b
theorem
Array.extLit
{α : Type u_1}
{n : Nat}
(a : Array α)
(b : Array α)
(hsz₁ : Array.size a = n)
(hsz₂ : Array.size b = n)
(h : ∀ (i : Nat) (hi : i < n), Array.getLit a i hsz₁ hi = Array.getLit b i hsz₂ hi)
:
a = b
def
Array.indexOfAux
{α : Type u_1}
[inst : BEq α]
(a : Array α)
(v : α)
(i : Nat)
:
Option (Fin (Array.size a))
Equations
- Array.indexOfAux a v i = if h : i < Array.size a then let idx := { val := i, isLt := h }; if (Array.get a idx == v) = true then some idx else Array.indexOfAux a v (i + 1) else none
Equations
- Array.indexOf? a v = Array.indexOfAux a v 0
@[simp]
theorem
Array.size_swap
{α : Type u_1}
(a : Array α)
(i : Fin (Array.size a))
(j : Fin (Array.size a))
:
Array.size (Array.swap a i j) = Array.size a
@[simp]
Equations
- One or more equations did not get rendered due to their size.
Equations
- Array.takeWhile p as = Array.takeWhile.go p as 0 #[]
Equations
- One or more equations did not get rendered due to their size.
Equations
- Array.feraseIdx a i = Array.eraseIdxAux (i.val + 1) a
Equations
- Array.eraseIdx a i = if i < Array.size a then Array.eraseIdxAux (i + 1) a else a
Equations
- Array.erase as a = match Array.indexOf? as a with | none => as | some i => Array.feraseIdx as i
Equations
- Array.insertAtAux i as j = if h : i < j then let as := Array.swap! as (j - 1) j; Array.insertAtAux i as (j - 1) else as
Insert element a
at position i
.
Pre: i < as.size
Equations
- One or more equations did not get rendered due to their size.
def
Array.toListLitAux
{α : Type u_1}
(a : Array α)
(n : Nat)
(hsz : Array.size a = n)
(i : Nat)
:
i ≤ Array.size a → List α → List α
Equations
- Array.toListLitAux a n hsz 0 x _fun_discr = _fun_discr
- Array.toListLitAux a n hsz (Nat.succ i) hi _fun_discr = Array.toListLitAux a n hsz i (_ : i ≤ Array.size a) (Array.getLit a i hsz (_ : i < n) :: _fun_discr)
Equations
- Array.toArrayLit a n hsz = List.toArray (Array.toListLitAux a n hsz n (_ : n ≤ Array.size a) [])
theorem
Array.toArrayLit_eq
{α : Type u_1}
(a : Array α)
(n : Nat)
(hsz : Array.size a = n)
:
a = Array.toArrayLit a n hsz
def
Array.isPrefixOfAux
{α : Type u_1}
[inst : BEq α]
(as : Array α)
(bs : Array α)
(hle : Array.size as ≤ Array.size bs)
(i : Nat)
:
Equations
- One or more equations did not get rendered due to their size.
Return true iff as
is a prefix of bs
.
That is, bs = as ++ t
for some t : List α
.
Equations
- Array.isPrefixOf as bs = if h : Array.size as ≤ Array.size bs then Array.isPrefixOfAux as bs h 0 else false
Equations
- Array.allDiff as = Array.allDiffAux as 0
@[inline]
def
Array.zipWith
{α : Type u_1}
{β : Type u_2}
{γ : Type u_3}
(as : Array α)
(bs : Array β)
(f : α → β → γ)
:
Array γ
Equations
- Array.zipWith as bs f = Array.zipWithAux f as bs 0 #[]
Equations
- Array.split as p = Array.foldl (fun x a => match x with | (as, bs) => if p a = true then (Array.push as a, bs) else (as, Array.push bs a)) (#[], #[]) as 0 (Array.size as)