Equations
- Array.instEmptyCollectionArray = { emptyCollection := #[] }
Equations
- Array.isEmpty a = decide (Array.size a = 0)
Instances For
Equations
- Array.singleton v = mkArray 1 v
Instances For
Low-level version of fget
which is as fast as a C array read.
Fin
values are represented as tag pointers in the Lean runtime. Thus,
fget
may be slightly slower than uget
.
Equations
- Array.uget a i h = a[USize.toNat i]
Instances For
Equations
- Array.instGetElemArrayUSizeLtNatInstLTNatToNatSize = { getElem := fun (xs : Array α) (i : USize) (h : USize.toNat i < Array.size xs) => Array.uget xs i h }
Equations
- Array.back a = Array.get! a (Array.size a - 1)
Instances For
Equations
- Array.get? a i = if h : i < Array.size a then some a[i] else none
Instances For
Equations
- Array.back? a = Array.get? a (Array.size a - 1)
Instances For
Equations
- Array.getLit a i h₁ h₂ = let_fun this := (_ : i < Array.size a); a[i]
Instances For
Low-level version of fset
which is as fast as a C array fset.
Fin
values are represented as tag pointers in the Lean runtime. Thus,
fset
may be slightly slower than uset
.
Equations
- Array.uset a i v h = Array.set a { val := USize.toNat i, isLt := h } v
Instances For
Swaps two entries in an array.
This will perform the update destructively provided that a
has a reference
count of 1 when called.
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₁
Instances For
Swaps two entries in an array, or panics if either index is out of bounds.
This will perform the update destructively provided that a
has a reference
count of 1 when called.
Equations
- Array.swap! a i j = if h₁ : i < Array.size a then if h₂ : j < Array.size a then Array.swap a { val := i, isLt := h₁ } { val := j, isLt := h₂ } else a else a
Instances For
Equations
- Array.swapAt a i v = let e := Array.get a i; let a := Array.set a i v; (e, a)
Instances For
Equations
- Array.shrink a n = Array.shrink.loop (Array.size a - n) a
Instances For
Equations
- Array.shrink.loop 0 x = x
- Array.shrink.loop (Nat.succ n) x = Array.shrink.loop n (Array.pop x)
Instances For
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
Instances For
We claim this unsafe implementation is correct because an array cannot have more than usizeSz
elements in our runtime.
This kind of low level trick can be removed with a little bit of compiler support. For example, if the compiler simplifies as.size < usizeSz
to true.
Equations
- Array.forInUnsafe as b f = let sz := USize.ofNat (Array.size as); Array.forInUnsafe.loop as f sz 0 b
Instances For
Reference implementation for forIn
Equations
- Array.forIn as b f = Array.forIn.loop as f (Array.size as) (_ : Array.size as ≤ Array.size as) b
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Array.forIn.loop as f 0 x b = pure b
Instances For
See comment at forInUnsafe
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reference implementation for foldlM
Equations
- One or more equations did not get rendered due to their size.
Instances For
See comment at forInUnsafe
Equations
- One or more equations did not get rendered due to their size.
Instances For
Reference implementation for foldrM
Equations
- One or more equations did not get rendered due to their size.
Instances For
See comment at forInUnsafe
Equations
- Array.mapMUnsafe f as = let sz := USize.ofNat (Array.size as); unsafeCast (Array.mapMUnsafe.map f sz 0 (unsafeCast as))
Instances For
Reference implementation for mapM
Equations
- Array.mapM f as = Array.mapM.map f as 0 (Array.mkEmpty (Array.size as))
Instances For
Equations
- Array.mapM.map f as i r = if hlt : i < Array.size as then do let __do_lift ← f as[i] Array.mapM.map f as (i + 1) (Array.push r __do_lift) else pure r
Instances For
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))
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Array.mapIdxM.map as f 0 j x bs = pure bs
Instances For
Equations
- Array.allM p as start stop = do let __do_lift ← Array.anyM (fun (v : α) => do let __do_lift ← p v pure !__do_lift) as start stop pure !__do_lift
Instances For
Equations
- Array.findSomeRevM? as f = Array.findSomeRevM?.find as f (Array.size as) (_ : Array.size as ≤ Array.size as)
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Array.findSomeRevM?.find as f 0 x = pure none
Instances For
Equations
- Array.forM f as start stop = Array.foldlM (fun (x : PUnit) => f) PUnit.unit as start stop
Instances For
Equations
- Array.forRevM f as start stop = Array.foldrM (fun (a : α) (x : PUnit) => f a) PUnit.unit as start stop
Instances For
Equations
- Array.foldl f init as start stop = Id.run (Array.foldlM f init as start stop)
Instances For
Equations
- Array.foldr f init as start stop = Id.run (Array.foldrM f init as start stop)
Instances For
Equations
- Array.mapIdx as f = Id.run (Array.mapIdxM as f)
Instances For
Equations
- Array.findIdx? as p = Array.findIdx?.loop as p (Array.size as) 0 (_ : Array.size as + 0 = Array.size as + 0)
Instances For
Equations
- Array.getIdx? a v = Array.findIdx? a fun (a : α) => a == v
Instances For
Equations
- Array.contains as a = Array.any as (fun (b : α) => a == b) 0
Instances For
Equations
- Array.elem a as = Array.contains as a
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Convert a Array α
into an List α
. This is O(n) in the size of the array.
Equations
- Array.toList as = Array.foldr List.cons [] as (Array.size as)
Instances For
Equations
- Array.append as bs = Array.foldl (fun (r : Array α) (v : α) => Array.push r v) as bs 0
Instances For
Equations
- Array.appendList as bs = List.foldl (fun (r : Array α) (v : α) => Array.push r v) as bs
Instances For
Equations
- Array.concatMap f as = Array.foldl (fun (bs : Array β) (a : α) => bs ++ f a) #[] as 0
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Array.isEqvAux a b hsz p i = if h : i < Array.size a then let_fun this := (_ : i < Array.size b); p a[i] b[i] && Array.isEqvAux a b hsz p (i + 1) else true
Instances For
Equations
- Array.isEqv a b p = if h : Array.size a = Array.size b then Array.isEqvAux a b h p 0 else false
Instances For
Equations
- Array.instBEqArray = { beq := fun (a b : Array α) => Array.isEqv a b BEq.beq }
Equations
- Array.filter p as start stop = Array.foldl (fun (r : Array α) (a : α) => if p a = true then Array.push r a else r) #[] as start stop
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Array.filterMap f as start stop = Id.run (Array.filterMapM f as start stop)
Instances For
Equations
- Array.getMax? as lt = if h : 0 < Array.size as then let a0 := as[0]; some (Array.foldl (fun (best a : α) => if lt best a = true then a else best) a0 as 1) else none
Instances For
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
Instances For
Equations
- Array.indexOf? a v = Array.indexOfAux a v 0
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Array.takeWhile p as = Array.takeWhile.go p as 0 #[]
Instances For
Equations
- Array.feraseIdx a i = Array.eraseIdxAux (i.val + 1) a
Instances For
Equations
- Array.eraseIdx a i = if i < Array.size a then Array.eraseIdxAux (i + 1) a else a
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Array.eraseIdx' a i = Array.eraseIdxSzAux a (i.val + 1) a (_ : Array.size a = Array.size a)
Instances For
Equations
- Array.erase as a = match Array.indexOf? as a with | none => as | some i => Array.feraseIdx as i
Instances For
Insert element a
at position i
.
Equations
- Array.insertAt as i a = let j := Array.size as; let as_1 := Array.push as a; Array.insertAt.loop as i as_1 { val := j, isLt := (_ : Array.size as < Array.size (Array.push as a)) }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Array.toListLitAux a n hsz 0 x_3 x = x
- Array.toListLitAux a n hsz (Nat.succ i) hi x = Array.toListLitAux a n hsz i (_ : i ≤ Array.size a) (Array.getLit a i hsz (_ : i < n) :: x)
Instances For
Equations
- Array.toArrayLit a n hsz = List.toArray (Array.toListLitAux a n hsz n (_ : n ≤ Array.size a) [])
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
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
Instances For
Equations
- Array.allDiff as = Array.allDiffAux as 0
Instances For
Equations
- Array.zipWith as bs f = Array.zipWithAux f as bs 0 #[]