Definitions on Arrays #
This file contains various definitions on Array
. It does not contain
proofs about these definitions, those are contained in other files in Std.Data.Array
.
Drop none
s from a Array, and replace each remaining some a
with a
.
Equations
- Array.reduceOption l = Array.filterMap id l 0
Instances For
Check whether xs
and ys
are equal as sets, i.e. they contain the same
elements when disregarding order and duplicates. O(n*m)
! If your element type
has an Ord
instance, it is asymptotically more efficient to sort the two
arrays, remove duplicates and then compare them elementwise.
Equations
- Array.equalSet xs ys = (Array.all xs (fun (x : α) => Array.contains ys x) 0 && Array.all ys (fun (x : α) => Array.contains xs x) 0)
Instances For
Sort an array using compare
to compare elements.
Equations
- Array.qsortOrd xs = Array.qsort xs (fun (x y : α) => Ordering.isLT (compare x y)) 0
Instances For
Returns the first minimal element among d
and elements of the array.
If start
and stop
are given, only the subarray xs[start:stop]
is
considered (in addition to d
).
Equations
- Array.minWith xs d start stop = Array.foldl (fun (min x : α) => if Ordering.isLT (compare x min) = true then x else min) d xs start stop
Instances For
Find the first minimal element of an array. If the array is empty, d
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
- Array.minD xs d start stop = if h : start < Array.size xs ∧ start < stop then Array.minWith xs (Array.get xs { val := start, isLt := ⋯ }) (start + 1) stop else d
Instances For
Find the first minimal element of an array. If the array is empty, none
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
- Array.min? xs start stop = if h : start < Array.size xs ∧ start < stop then some (Array.minD xs (Array.get xs { val := start, isLt := ⋯ }) start stop) else none
Instances For
Find the first minimal element of an array. If the array is empty, default
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
- Array.minI xs start stop = Array.minD xs default start stop
Instances For
Returns the first maximal element among d
and elements of the array.
If start
and stop
are given, only the subarray xs[start:stop]
is
considered (in addition to d
).
Equations
- Array.maxWith xs d start stop = Array.minWith xs d start stop
Instances For
Find the first maximal element of an array. If the array is empty, d
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
- Array.maxD xs d start stop = Array.minD xs d start stop
Instances For
Find the first maximal element of an array. If the array is empty, none
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
- Array.max? xs start stop = Array.min? xs start stop
Instances For
Find the first maximal element of an array. If the array is empty, default
is
returned. If start
and stop
are given, only the subarray xs[start:stop]
is
considered.
Equations
- Array.maxI xs start stop = Array.minI xs start stop
Instances For
"Attach" the proof that the elements of xs
are in xs
to produce a new list
with the same elements but in the type {x // x ∈ xs}
.
Equations
- Array.attach xs = { data := List.pmap Subtype.mk xs.data ⋯ }
Instances For
O(|join L|)
. join L
concatenates all the arrays in L
into one array.
join #[#[a], #[], #[b, c], #[d, e, f]] = #[a, b, c, d, e, f]
Equations
- Array.join l = Array.foldl (fun (x x_1 : Array α) => x ++ x_1) #[] l 0
Instances For
The empty subarray.
Equations
- Subarray.empty = { as := #[], start := 0, stop := 0, h₁ := Subarray.empty.proof_1, h₂ := Subarray.empty.proof_1 }
Instances For
Equations
- Subarray.instEmptyCollectionSubarray = { emptyCollection := Subarray.empty }
Check whether a subarray is empty.
Equations
- Subarray.isEmpty as = (as.start == as.stop)
Instances For
Check whether a subarray contains an element.
Equations
- Subarray.contains as a = Subarray.any (fun (x : α) => x == a) as