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 := (_ : List.length [] = List.length []) }
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 := (_ : Nat.succ (List.length v) = Nat.succ n) }
Instances For
The first element of a vector with length at least 1
.
Equations
- Vector.head x = match x with | { val := [], property := h } => Nat.noConfusion h | { 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 obtained by prepending is the vector prepended. to
Prepending the head of a vector to its tail gives the vector.
nth element of a vector, indexed by a Fin
type.
Equations
- Vector.get x✝ x = match x✝, x with | { val := l, property := h }, i => List.nthLe l ↑i (_ : ↑i < List.length l)
Instances For
Appending a vector to another.
Equations
- Vector.append x✝ x = match x✝, x with | { val := l₁, property := h₁ }, { val := l₂, property := h₂ } => { val := l₁ ++ l₂, property := (_ : List.length (l₁ ++ l₂) = n + m) }
Instances For
Elimination rule for Vector
.
Equations
- Vector.elim H x = match x with | { val := l, property := h } => match n, h with | .(List.length l), (_ : List.length l = 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 := (_ : List.length (List.map f l) = n) }
Instances For
Vector obtained by repeating an element.
Equations
- Vector.replicate n a = { val := List.replicate n a, property := (_ : List.length (List.replicate n a) = n) }
Instances For
Drop i
elements from a vector of length n
; we can have i > n
.
Equations
- Vector.drop i x = match x with | { val := l, property := p } => { val := List.drop i l, property := (_ : List.length (List.drop i l) = n - i) }
Instances For
Take i
elements from a vector of length n
; we can have i > n
.
Equations
- Vector.take i x = match x with | { val := l, property := p } => { val := List.take i l, property := (_ : List.length (List.take i l) = min i n) }
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 := (_ : List.length (List.removeNth l ↑i) = n - 1) }
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 := (_ : List.length x = m) }
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 (_ : n - i + min n i = n) (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 (_ : min n i + min (n - i) n = n) (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.