Array literal syntax #
Instances For
Preliminary theorems #
Equations
- Array.instMembership = { mem := Array.Mem }
Equations
Instances For
Instances For
Externs #
Low-level version of size
that directly queries the C array object cached size.
While this is not provable, usize
always returns the exact size of the array since
the implementation only supports arrays of size less than USize.size
.
Equations
- a.usize = a.size.toUSize
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
- a.swap i j hi hj = (a.set i a[j] hi).set j a[i] ⋯
Instances For
Swaps two entries in an array, or returns the array unchanged 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
Instances For
Equations
Instances For
Definitions #
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) (acc.push (f ⟨i, h⟩)) else acc
Instances For
The array #[0, 1, ..., n - 1]
.
Equations
- Array.range n = Array.ofFn fun (i : Fin n) => ↑i
Instances For
Equations
- Array.singleton v = mkArray 1 v
Instances For
Instances For
take a n
returns the first n
elements of a
.
Equations
- a.take n = Array.take.loop (a.size - n) a
Instances For
Equations
- Array.take.loop 0 x = x
- Array.take.loop n.succ x = Array.take.loop n x.pop
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.
Instances For
Equations
- One or more equations did not get rendered due to their size.
- Array.forIn'.loop as f 0 x_2 b = pure b
Instances For
Reference implementation for foldlM
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 forIn'Unsafe
Instances For
Reference implementation for mapM
Equations
- Array.mapM f as = Array.mapM.map f as 0 (Array.mkEmpty as.size)
Instances For
Equations
- Array.mapM.map f as i r = if hlt : i < as.size then do let __do_lift ← f as[i] Array.mapM.map f as (i + 1) (r.push __do_lift) else pure r
Instances For
Variant of mapIdxM
which receives the index as a Fin as.size
.
Equations
- as.mapFinIdxM f = Array.mapFinIdxM.map as f as.size 0 ⋯ (Array.mkEmpty as.size)
Instances For
Equations
- Array.mapFinIdxM.map as f 0 j x bs = pure bs
- Array.mapFinIdxM.map as f i_2.succ j inv_2 bs = do let __do_lift ← f ⟨j, ⋯⟩ (as.get j ⋯) Array.mapFinIdxM.map as f i_2 (j + 1) ⋯ (bs.push __do_lift)
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? f as = Array.findSomeRevM?.find f as as.size ⋯
Instances For
Equations
- Array.findSomeRevM?.find f as 0 x_2 = pure none
- Array.findSomeRevM?.find f as i.succ h = do let r ← f as[i] match r with | some val => pure r | none => let_fun this := ⋯; Array.findSomeRevM?.find f as i this
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 = (Array.foldlM f init as start stop).run
Instances For
Equations
- Array.foldr f init as start stop = (Array.foldrM f init as start stop).run
Instances For
Turns #[a, b]
into #[(a, 0), (b, 1)]
.
Equations
- arr.zipWithIndex = Array.mapIdx (fun (i : Nat) (a : α) => (a, i)) arr
Instances For
Equations
- Array.findSome! f a = match Array.findSome? f a with | some b => b | none => panicWithPosWithDecl "Init.Data.Array.Basic" "Array.findSome!" 599 14 "failed to find element"
Instances For
Equations
- Array.elem a as = as.contains a
Instances For
Convert a Array α
into an List α
. This is O(n) in the size of the array.
Equations
- as.toListImpl = Array.foldr List.cons [] as
Instances For
Prepends an Array α
onto the front of a list. Equivalent to as.toList ++ l
.
Equations
- as.toListAppend l = Array.foldr List.cons l as
Instances For
Equations
- Array.flatMap f as = Array.foldl (fun (bs : Array β) (a : α) => bs ++ f a) #[] as
Instances For
Equations
- Array.filter p as start stop = Array.foldl (fun (r : Array α) (a : α) => if p a = true then r.push a else r) #[] as start stop
Instances For
Equations
- as.reverse = if h : as.size ≤ 1 then as else Array.reverse.loop as 0 ⟨as.size - 1, ⋯⟩
Instances For
Equations
- Array.reverse.loop as i j = if h : i < ↑j then let_fun this := ⋯; let as_1 := as.swap i ↑j ⋯ ⋯; let_fun this := ⋯; Array.reverse.loop as_1 (i + 1) ⟨↑j - 1, this⟩ else as
Instances For
Equations
- Array.popWhile p as = if h : as.size > 0 then if p as[as.size - 1] = true then Array.popWhile p as.pop else as else as
Instances For
Equations
- Array.takeWhile p as = Array.takeWhile.go p as 0 #[]
Instances For
Equations
- Array.takeWhile.go p as i r = if h : i < as.size then let a := as[i]; if p a = true then Array.takeWhile.go p as (i + 1) (r.push a) else r else r
Instances For
Remove the element at a given index from an array without a runtime bounds checks,
using a Nat
index and a tactic-provided bound.
This function takes worst case O(n) time because
it has to backshift all elements at positions greater than i
.
Equations
Instances For
Remove the element at a given index from an array, or do nothing if the index is out of bounds.
This function takes worst case O(n) time because
it has to backshift all elements at positions greater than i
.
Instances For
Equations
- Array.insertIdx.loop i as j = if i < ↑j then let j' := ⟨↑j - 1, ⋯⟩; let as_1 := as.swap ↑j' ↑j ⋯ ⋯; Array.insertIdx.loop i as_1 ⟨↑j', ⋯⟩ else as
Instances For
Equations
Instances For
Equations
- Array.zipWithAll.go f as bs i cs = if i < max as.size bs.size then let a := as[i]?; let b := bs[i]?; Array.zipWithAll.go f as bs (i + 1) (cs.push (f a b)) else cs
Instances For
Auxiliary functions used in metaprogramming. #
We do not currently intend to provide verification theorems for these functions.
Drop none
s from a Array, and replace each remaining some a
with a
.
Equations
- as.reduceOption = Array.filterMap id as