The type List.Vector
represents lists with fixed length.
TODO: The API of List.Vector
is quite incomplete relative to Vector
,
and in particular does not use x[i]
(that is GetElem
notation) as the preferred accessor.
Any combination of reducing the use of List.Vector
in Mathlib, or modernising its API,
would be welcome.
List.Vector α n
is the type of lists of length n
with elements of type α
.
Note that there is also Vector α n
in the root namespace,
which is the type of arrays of length n
with elements of type α
.
Typically, if you are doing programming or verification, you will primarily use Vector α n
,
and if you are doing mathematics, you may want to use List.Vector α n
instead.
Equations
- List.Vector α n = { l : List α // l.length = n }
Instances For
Equations
- List.Vector.instDecidableEq = inferInstanceAs (DecidableEq { l : List α // l.length = n })
The empty vector with elements of type α
Equations
- List.Vector.nil = ⟨[], ⋯⟩
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
- List.Vector.cons x✝ ⟨v, h⟩ = ⟨x✝ :: v, ⋯⟩
Instances For
The first element of a vector with length at least 1
.
Equations
- List.Vector.head ⟨a :: tail, 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
- List.Vector.tail ⟨[], h⟩ = ⟨[], ⋯⟩
- List.Vector.tail ⟨head :: v, h⟩ = ⟨v, ⋯⟩
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.
nth element of a vector, indexed by a Fin
type.
Instances For
Appending a vector to another.
Equations
- List.Vector.append ⟨l₁, h₁⟩ ⟨l₂, h₂⟩ = ⟨l₁ ++ l₂, ⋯⟩
Instances For
Elimination rule for Vector
.
Equations
- List.Vector.elim H ⟨l, ⋯⟩ = H l
Instances For
Map a vector under a function.
Equations
- List.Vector.map f ⟨l, h⟩ = ⟨List.map f l, ⋯⟩
Instances For
Map a vector under a partial function.
Equations
- List.Vector.pmap f ⟨l, h⟩ hp = ⟨List.pmap f l hp, ⋯⟩
Instances For
Mapping two vectors under a curried function of two variables.
Equations
- List.Vector.map₂ f ⟨x_2, property⟩ ⟨y, property_1⟩ = ⟨List.zipWith f x_2 y, ⋯⟩
Instances For
Vector obtained by repeating an element.
Equations
- List.Vector.replicate n a = ⟨List.replicate n a, ⋯⟩
Instances For
Drop i
elements from a vector of length n
; we can have i > n
.
Equations
- List.Vector.drop i ⟨l, h⟩ = ⟨List.drop i l, ⋯⟩
Instances For
Take i
elements from a vector of length n
; we can have i > n
.
Equations
- List.Vector.take i ⟨l, h⟩ = ⟨List.take i l, ⋯⟩
Instances For
Remove the element at position i
from a vector of length n
.
Equations
- List.Vector.eraseIdx i ⟨l, h⟩ = ⟨l.eraseIdx ↑i, ⋯⟩
Instances For
Alias of List.Vector.eraseIdx
.
Remove the element at position i
from a vector of length n
.
Equations
Instances For
Vector of length n
from a function on Fin n
.
Equations
- List.Vector.ofFn x_2 = List.Vector.nil
- List.Vector.ofFn f = List.Vector.cons (f 0) (List.Vector.ofFn fun (i : Fin n) => f i.succ)
Instances For
Create a vector from another with a provably equal length.
Equations
- List.Vector.congr h ⟨l, h_1⟩ = ⟨l, ⋯⟩
Instances For
Runs a function over a vector returning the intermediate results and a final result.
Equations
- List.Vector.mapAccumr f ⟨x_2, px⟩ x✝ = ((List.mapAccumr f x_2 x✝).fst, ⟨(List.mapAccumr f x_2 x✝).snd, ⋯⟩)
Instances For
Runs a function over a pair of vectors returning the intermediate results and a final result.
Equations
- List.Vector.mapAccumr₂ f ⟨x_3, px⟩ ⟨y, py⟩ x✝ = ((List.mapAccumr₂ f x_3 y x✝).fst, ⟨(List.mapAccumr₂ f x_3 y x✝).snd, ⋯⟩)
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
- v.shiftLeftFill i fill = List.Vector.congr ⋯ ((List.Vector.drop i v).append (List.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
- v.shiftRightFill i fill = List.Vector.congr ⋯ ((List.Vector.replicate (min n i) fill).append (List.Vector.take (n - i) v))
Instances For
Basic Theorems #
Vector is determined by the underlying list.
A vector of length 0
is a nil
vector.
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.
Equations
- List.Vector.instGetElemNatLt = { getElem := fun (x : List.Vector α n) (i : ℕ) (h : i < n) => x.get ⟨i, h⟩ }