The areas / V33. Data structures and computation
Mathlib.Data.Vector.Defs
42 declarations. Mathlib docs · Source
The type List.Vector
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.
Shift Primitives
Basic Theorems
def List.Vector E1 #
Type u → ℕ → Type (max 0 u)
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.
instance List.Vector.instDecidableEq E0 #
{α : Type u_1} → {n : ℕ} → [DecidableEq α] → DecidableEq (List.Vector α n)
def List.Vector.nil E1 #
{α : Type u_1} → List.Vector α 0
The empty vector with elements of type α
def List.Vector.cons E1 #
{α : Type u_1} → {n : ℕ} → α → List.Vector α n → List.Vector α n.succ
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.
def List.Vector.length E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n → ℕ
The length of a vector.
def List.Vector.head E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n.succ → α
The first element of a vector with length at least 1.
theorem List.Vector.head_cons E0 #
∀ {α : Type u_1} {n : ℕ} (a : α) (v : List.Vector α n), (a ::ᵥ v).head = a
The head of a vector obtained by prepending is the element prepended.
def List.Vector.tail E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n → List.Vector α (n - 1)
The tail of a vector, with an empty vector having empty tail.
theorem List.Vector.tail_cons E0 #
∀ {α : Type u_1} {n : ℕ} (a : α) (v : List.Vector α n), (a ::ᵥ v).tail = v
The tail of a vector obtained by prepending is the vector prepended. to
theorem List.Vector.cons_head_tail E0 #
∀ {α : Type u_1} {n : ℕ} (v : List.Vector α n.succ), v.head ::ᵥ v.tail = v
Prepending the head of a vector to its tail gives the vector.
def List.Vector.toList E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n → List α
The list obtained from a vector.
def List.Vector.get E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n → Fin n → α
nth element of a vector, indexed by a Fin type.
instance List.Vector.instHAppendHAddNat E0 #
{α : Type u_1} → {n m : ℕ} → HAppend (List.Vector α n) (List.Vector α m) (List.Vector α (n + m))
theorem List.Vector.append_def E0 #
∀ {α : Type u_1} {n m : ℕ},
HAppend.hAppend = fun x x_1 ↦
match x, x_1 with
| ⟨l₁, h₁⟩, ⟨l₂, h₂⟩ => ⟨l₁ ++ l₂, ⋯⟩
def List.Vector.elim E1 #
{α : Type u_5} →
{C : {n : ℕ} → List.Vector α n → Sort u} → ((l : List α) → C ⟨l, ⋯⟩) → {n : ℕ} → (v : List.Vector α n) → C v
Elimination rule for Vector.
def List.Vector.map E1 #
{α : Type u_1} → {β : Type u_2} → {n : ℕ} → (α → β) → List.Vector α n → List.Vector β n
Map a vector under a function.
theorem List.Vector.map_nil E0 #
∀ {α : Type u_1} {β : Type u_2} (f : α → β), List.Vector.map f List.Vector.nil = List.Vector.nil
A nil vector maps to a nil vector.
theorem List.Vector.map_cons E0 #
∀ {α : Type u_1} {β : Type u_2} {n : ℕ} (f : α → β) (a : α) (v : List.Vector α n),
List.Vector.map f (a ::ᵥ v) = f a ::ᵥ List.Vector.map f v
map is natural with respect to cons.
def List.Vector.pmap E1 #
{α : Type u_1} →
{β : Type u_2} →
{n : ℕ} → {p : α → Prop} → ((a : α) → p a → β) → (v : List.Vector α n) → (∀ x ∈ v.toList, p x) → List.Vector β n
Map a vector under a partial function.
theorem List.Vector.pmap_nil E0 #
∀ {α : Type u_1} {β : Type u_2} {p : α → Prop} (f : (a : α) → p a → β) (hp : ∀ x ∈ List.Vector.nil.toList, p x),
List.Vector.pmap f List.Vector.nil hp = List.Vector.nil
def List.Vector.map₂ E1 #
{α : Type u_1} →
{β : Type u_2} → {φ : Type u_4} → {n : ℕ} → (α → β → φ) → List.Vector α n → List.Vector β n → List.Vector φ n
Mapping two vectors under a curried function of two variables.
def List.Vector.replicate E1 #
{α : Type u_1} → (n : ℕ) → α → List.Vector α n
Vector obtained by repeating an element.
def List.Vector.drop E1 #
{α : Type u_1} → {n : ℕ} → (i : ℕ) → List.Vector α n → List.Vector α (n - i)
Drop i elements from a vector of length n; we can have i > n.
def List.Vector.take E1 #
{α : Type u_1} → {n : ℕ} → (i : ℕ) → List.Vector α n → List.Vector α (min i n)
Take i elements from a vector of length n; we can have i > n.
def List.Vector.eraseIdx E1 #
{α : Type u_1} → {n : ℕ} → Fin n → List.Vector α n → List.Vector α (n - 1)
Remove the element at position i from a vector of length n.
def List.Vector.ofFn E1 #
{α : Type u_1} → {n : ℕ} → (Fin n → α) → List.Vector α n
Vector of length n from a function on Fin n.
def List.Vector.congr E1 #
{α : Type u_1} → {n m : ℕ} → n = m → List.Vector α n → List.Vector α m
Create a vector from another with a provably equal length.
def List.Vector.mapAccumr E1 #
{α : Type u_1} → {β : Type u_2} → {σ : Type u_3} → {n : ℕ} → (α → σ → σ × β) → List.Vector α n → σ → σ × List.Vector β n
Runs a function over a vector returning the intermediate results and a final result.
def List.Vector.mapAccumr₂ E1 #
{α : Type u_1} →
{β : Type u_2} →
{σ : Type u_3} →
{φ : Type u_4} → {n : ℕ} → (α → β → σ → σ × φ) → List.Vector α n → List.Vector β n → σ → σ × List.Vector φ n
Runs a function over a pair of vectors returning the intermediate results and a final result.
def List.Vector.shiftLeftFill E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n → ℕ → α → List.Vector α n
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.
def List.Vector.shiftRightFill E1 #
{α : Type u_1} → {n : ℕ} → List.Vector α n → ℕ → α → List.Vector α n
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.
theorem List.Vector.eq E1 #
∀ {α : Type u_1} {n : ℕ} (a1 a2 : List.Vector α n), a1.toList = a2.toList → a1 = a2
Vector is determined by the underlying list.
theorem List.Vector.toList_mk E0 #
∀ {α : Type u_1} {n : ℕ} (v : List α) (P : v.length = n), List.Vector.toList ⟨v, P⟩ = v
Vector of length from a list v
with witness that v has length n maps to v under toList.
theorem List.Vector.toList_nil E0 #
∀ {α : Type u_1}, List.Vector.nil.toList = []
A nil vector maps to a nil list.
theorem List.Vector.toList_length E0 #
∀ {α : Type u_1} {n : ℕ} (v : List.Vector α n), v.toList.length = n
The length of the list to which a vector of length n maps is n.
theorem List.Vector.toList_cons E0 #
∀ {α : Type u_1} {n : ℕ} (a : α) (v : List.Vector α n), (a ::ᵥ v).toList = a :: v.toList
toList of cons of a vector and an element is
the cons of the list obtained by toList and the element
theorem List.Vector.toList_append E0 #
∀ {α : Type u_1} {n m : ℕ} (v : List.Vector α n) (w : List.Vector α m), (v ++ w).toList = v.toList ++ w.toList
Appending of vectors corresponds under toList to appending of lists.
theorem List.Vector.toList_drop E0 #
∀ {α : Type u_1} {n m : ℕ} (v : List.Vector α m), (List.Vector.drop n v).toList = List.drop n v.toList
drop of vectors corresponds under toList to drop of lists.
theorem List.Vector.toList_take E0 #
∀ {α : Type u_1} {n m : ℕ} (v : List.Vector α m), (List.Vector.take n v).toList = List.take n v.toList
take of vectors corresponds under toList to take of lists.
instance List.Vector.instGetElemNatLt E0 #
{α : Type u_1} → {n : ℕ} → GetElem (List.Vector α n) ℕ α fun x i ↦ i < n
theorem List.Vector.getElem_def E0 #
∀ {α : Type u_1} {n : ℕ} (v : List.Vector α n) (i : ℕ) {hi : i < n}, v[i] = v.toList[i]
theorem List.Vector.toList_getElem E1 #
∀ {α : Type u_1} {n : ℕ} (v : List.Vector α n) (i : ℕ) {hi : i < v.toList.length}, v.toList[i] = v[i]