The type Vector
represents lists with fixed length.
Equations
- Vector.instDecidableEqVector = inferInstanceAs (DecidableEq { l : List α // List.length l = n })
The empty vector with elements of type α
Equations
- Vector.nil = { val := [], property := ⋯ }
Instances For
If a : α
and l : Vector α n
, then cons a l
, is the vector of length n + 1
whose first element is a and with l as the rest of the list.
Equations
- Vector.cons x✝ x = match x✝, x with | a, { val := v, property := h } => { val := a :: v, property := ⋯ }
Instances For
The first element of a vector with length at least 1
.
Equations
- Vector.head x = match x with | { val := a :: tail, property := property } => a
Instances For
The head of a vector obtained by prepending is the element prepended.
The tail of a vector, with an empty vector having empty tail.
Equations
- Vector.tail x = match x with | { val := [], property := h } => { val := [], property := ⋯ } | { val := head :: v, property := h } => { val := v, property := ⋯ }
Instances For
The tail of a vector obtained by prepending is the vector prepended. to
Prepending the head of a vector to its tail gives the vector.
Elimination rule for Vector
.
Equations
- Vector.elim H x = match x with | { val := l, property := h } => match n, h with | .(List.length l), ⋯ => H l
Instances For
Map a vector under a function.
Equations
- Vector.map f x = match x with | { val := l, property := h } => { val := List.map f l, property := ⋯ }
Instances For
Mapping two vectors under a curried function of two variables.
Equations
- Vector.map₂ f x✝ x = match x✝, x with | { val := x, property := property }, { val := y, property := property_1 } => { val := List.zipWith f x y, property := ⋯ }
Instances For
Vector obtained by repeating an element.
Equations
- Vector.replicate n a = { val := List.replicate n a, property := ⋯ }
Instances For
Remove the element at position i
from a vector of length n
.
Equations
- Vector.removeNth i x = match x with | { val := l, property := p } => { val := List.removeNth l ↑i, property := ⋯ }
Instances For
Vector of length n
from a function on Fin n
.
Equations
- Vector.ofFn x_2 = Vector.nil
- Vector.ofFn f = Vector.cons (f 0) (Vector.ofFn fun (i : Fin n) => f (Fin.succ i))
Instances For
Create a vector from another with a provably equal length.
Equations
- Vector.congr h x = match x with | { val := x, property := p } => { val := x, property := ⋯ }
Instances For
Runs a function over a vector returning the intermediate results and a final result.
Equations
- Vector.mapAccumr f x✝ x = match x✝, x with | { val := x, property := px }, c => let res := List.mapAccumr f x c; (res.1, { val := res.2, property := ⋯ })
Instances For
Shift Primitives #
shiftLeftFill v i
is the vector obtained by left-shifting v
i
times and padding with the
fill
argument. If v.length < i
then this will return replicate n fill
.
Equations
- Vector.shiftLeftFill v i fill = Vector.congr ⋯ (Vector.append (Vector.drop i v) (Vector.replicate (min n i) fill))
Instances For
shiftRightFill v i
is the vector obtained by right-shifting v
i
times and padding with the
fill
argument. If v.length < i
then this will return replicate n fill
.
Equations
- Vector.shiftRightFill v i fill = Vector.congr ⋯ (Vector.append (Vector.replicate (min n i) fill) (Vector.take (n - i) v))
Instances For
Basic Theorems #
Vector is determined by the underlying list.
Vector of length from a list v
with witness that v
has length n
maps to v
under toList
.
A nil vector maps to a nil list.
The length of the list to which a vector of length n
maps is n
.
toList
of cons
of a vector and an element is
the cons
of the list obtained by toList
and the element
Appending of vectors corresponds under toList
to appending of lists.