Additional theorems and definitions about the Vector
type #
This file introduces the infix notation ::ᵥ
for Vector.cons
.
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.«term_::ᵥ_» = Lean.ParserDescr.trailingNode `Vector.term_::ᵥ_ 67 68 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ::ᵥ ") (Lean.ParserDescr.cat `term 67))
Instances For
Equations
- Vector.instInhabitedVector = { default := Vector.ofFn default }
Two v w : Vector α n
are equal iff they are equal at every single index.
The empty Vector
is a Subsingleton
.
The tail
of a nil
vector is nil
.
The tail
of a vector made up of one element is nil
.
The list that makes up a Vector
made up of a single element,
retrieved via toList
, is equal to the list of that single element.
Mapping under id
does not change a vector.
Reverse a vector.
Equations
- Vector.reverse v = { val := List.reverse (Vector.toList v), property := (_ : List.length (List.reverse (Vector.toList v)) = n) }
Instances For
The List
of a vector after a reverse
, retrieved by toList
is equal
to the List.reverse
after retrieving a vector's toList
.
Accessing the nth element of a vector made up
of one element x : α
is x
itself.
The last element of a Vector
, given that the vector is at least one element.
Equations
- Vector.last v = Vector.get v (Fin.last n)
Instances For
The last element of a Vector
, given that the vector is at least one element.
Construct a Vector β (n + 1)
from a Vector α n
by scanning f : β → α → β
from the "left", that is, from 0 to Fin.last n
, using b : β
as the starting value.
Equations
- Vector.scanl f b v = { val := List.scanl f b (Vector.toList v), property := (_ : List.length (List.scanl f b (Vector.toList v)) = n + 1) }
Instances For
Providing an empty vector to scanl
gives the starting value b : β
.
The recursive step of scanl
splits a vector x ::ᵥ v : Vector α (n + 1)
into the provided starting value b : β
and the recursed scanl
f b x : β
as the starting value.
This lemma is the cons
version of scanl_get
.
The underlying List
of a Vector
after a scanl
is the List.scanl
of the underlying List
of the original Vector
.
The toList
of a Vector
after a scanl
is the List.scanl
of the toList
of the original Vector
.
The recursive step of scanl
splits a vector made up of a single element
x ::ᵥ nil : Vector α 1
into a Vector
of the provided starting value b : β
and the mapped f b x : β
as the last value.
The first element of scanl
of a vector v : Vector α n
,
retrieved via head
, is the starting value b : β
.
For an index i : Fin n
, the nth element of scanl
of a
vector v : Vector α n
at i.succ
, is equal to the application
function f : β → α → β
of the castSucc i
element of
scanl f b v
and get v i
.
This lemma is the get
version of scanl_cons
.
Monadic analog of Vector.ofFn
.
Given a monadic function on Fin n
, return a Vector α n
inside the monad.
Equations
- Vector.mOfFn x_2 = pure Vector.nil
- Vector.mOfFn f = do let a ← f 0 let v ← Vector.mOfFn fun i => f (Fin.succ i) pure (a ::ᵥ v)
Instances For
Apply a monadic function to each component of a vector, returning a vector inside the monad.
Equations
- Vector.mmap f x_2 = pure Vector.nil
- Vector.mmap f xs = do let h' ← f (Vector.head xs) let t' ← Vector.mmap f (Vector.tail xs) pure (h' ::ᵥ t')
Instances For
Define C v
by induction on v : Vector α n
.
This function has two arguments: h_nil
handles the base case on C nil
,
and h_cons
defines the inductive step using ∀ x : α, C w → C (x ::ᵥ w)
.
This can be used as induction v using Vector.inductionOn
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Define C v w
by induction on a pair of vectors v : Vector α n
and w : Vector β n
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Define C u v w
by induction on a triplet of vectors
u : Vector α n
, v : Vector β n
, and w : Vector γ b
.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Define motive v
by case-analysis on v : Vector α n
Equations
- Vector.casesOn v nil cons = Vector.inductionOn v nil fun x hd tl x_1 => cons x hd tl
Instances For
Define motive v₁ v₂
by case-analysis on v₁ : Vector α n
and v₂ : Vector β n
Equations
- Vector.casesOn₂ v₁ v₂ nil cons = Vector.inductionOn₂ v₁ v₂ nil fun x x_1 y xs ys x_2 => cons x x_1 y xs ys
Instances For
Define motive v₁ v₂ v₃
by case-analysis on v₁ : Vector α n
, v₂ : Vector β n
, and
v₃ : Vector γ n
Equations
- Vector.casesOn₃ v₁ v₂ v₃ nil cons = Vector.inductionOn₃ v₁ v₂ v₃ nil fun x x_1 y z xs ys zs x_2 => cons x x_1 y z xs ys zs
Instances For
Cast a vector to an array.
Equations
- Vector.toArray x = match x with | { val := xs, property := property } => cast (_ : Array α = Array α) (List.toArray xs)
Instances For
v.insertNth a i
inserts a
into the vector v
at position i
(and shifting later components to the right).
Equations
- Vector.insertNth a i v = { val := List.insertNth (↑i) a ↑v, property := (_ : List.length (List.insertNth (↑i) a ↑v) = n + 1) }
Instances For
set v n a
replaces the n
th element of v
with a
Equations
- Vector.set v i a = { val := List.set (↑v) (↑i) a, property := (_ : List.length (List.set (↑v) (↑i) a) = n) }
Instances For
Apply an applicative function to each component of a vector.
Equations
- Vector.traverse f x = match x with | { val := v, property := Hv } => cast (_ : F (Vector β (List.length v)) = F (Vector β n)) (Vector.traverseAux f v)
Instances For
Equations
- Vector.instTraversableFlipTypeNatVector = Traversable.mk (@Vector.traverse n)