ofFn f
with f : Fin n → α
returns the list whose ith element is f i
.
ofFn f = #[f 0, f 1, ... , f(n - 1)]
Equations
- Array.ofFn f = Array.ofFn.go f 0 (Array.mkEmpty n)
Instances For
Auxiliary for ofFn
. ofFn.go f i acc = acc ++ #[f i, ..., f(n - 1)]
Equations
- Array.ofFn.go f i acc = if h : i < n then Array.ofFn.go f (i + 1) (Array.push acc (f { val := i, isLt := h })) else acc
Instances For
The array #[0, 1, ..., n - 1]
.
Equations
- Array.range n = Nat.fold (flip Array.push) n (Array.mkEmpty n)
Instances For
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 := ⋯; 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
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) ⋯ 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
Equations
- Array.foldlMUnsafe.fold f as i stop b = if (i == stop) = true then pure b else do let __do_lift ← f b (Array.uget as i ⋯) Array.foldlMUnsafe.fold f as (i + 1) stop __do_lift
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
Equations
- Array.foldrMUnsafe.fold f as i stop b = if (i == stop) = true then pure b else do let __do_lift ← f (Array.uget as (i - 1) ⋯) b Array.foldrMUnsafe.fold f as (i - 1) stop __do_lift
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.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.anyM p as start stop = let any := fun (stop : Nat) (h : stop ≤ Array.size as) => Array.anyM.loop p as stop h start; if h : stop ≤ Array.size as then any stop h else any (Array.size as) ⋯
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) ⋯
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
Turns #[a, b]
into #[(a, 0), (b, 1)]
.
Equations
- Array.zipWithIndex arr = Array.mapIdx arr fun (i : Fin (Array.size arr)) (a : α) => (a, ↑i)
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
Prepends an Array α
onto the front of a list. Equivalent to as.toList ++ l
.
Equations
- Array.toListAppend as l = Array.foldr List.cons l 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
Joins array of array into a single array.
flatten #[#[a₁, a₂, ⋯], #[b₁, b₂, ⋯], ⋯]
= #[a₁, a₂, ⋯, b₁, b₂, ⋯]
Equations
- Array.flatten as = Array.foldl (fun (r a : Array α) => r ++ 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 := ⋯; 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
- Array.reverse as = if h : Array.size as ≤ 1 then as else Array.reverse.loop as 0 { val := Array.size as - 1, isLt := ⋯ }
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Array.popWhile p as = if h : Array.size as > 0 then if p (Array.get as { val := Array.size as - 1, isLt := ⋯ }) = true then Array.popWhile p (Array.pop as) else as else as
Instances For
Equations
- Array.takeWhile p as = Array.takeWhile.go p as 0 #[]
Instances For
Equations
- Array.feraseIdx a i = Array.eraseIdxAux (↑i + 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 + 1) 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 := ⋯ }
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 ⋯ (Array.getLit a i hsz ⋯ :: x)
Instances For
Equations
- Array.toArrayLit a n hsz = List.toArray (Array.toListLitAux a n hsz n ⋯ [])
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 #[]