Additional theorems about the vector
type #
This file introduces the infix notation ::ᵥ
for vector.cons
.
Equations
- vector.inhabited = {default := vector.of_fn (λ (_x : fin n), default α)}
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
.
Mapping under id
does not change a vector.
Accessing the nth
element of a vector made up
of one element x : α
is x
itself.
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 = ⟨list.scanl f b v.to_list, _⟩
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_nth
.
The underlying list
of a vector
after a scanl
is the list.scanl
of the underlying list
of the original vector
.
The to_list
of a vector
after a scanl
is the list.scanl
of the to_list
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 i.cast_succ
element of
scanl f b v
and nth v i
.
This lemma is the nth
version of scanl_cons
.
Equations
- vector.m_of_fn f = f 0 >>= λ (a : α), vector.m_of_fn (λ (i : fin n), f i.succ) >>= λ (v : vector α n), pure (a::ᵥv)
- vector.m_of_fn f = pure vector.nil
Equations
- vector.mmap f xs = f xs.head >>= λ (h' : β), vector.mmap f xs.tail >>= λ (t' : vector β n), pure (h'::ᵥt')
- vector.mmap f xs = pure vector.nil
Define C v
by induction on v : vector α (n + 1)
, a vector of
at least one element.
This function has two arguments: h0
handles the base case on C nil
,
and hs
defines the inductive step using ∀ x : α, C v → C (x ::ᵥ v)
.
Equations
- vector.to_array ⟨xs, h⟩ = cast _ xs.to_array
Equations
- vector.insert_nth a i v = ⟨list.insert_nth ↑i a v.val, _⟩
update_nth v n a
replaces the n
th element of v
with a
Equations
- v.update_nth i a = ⟨v.val.update_nth i.val a, _⟩
Equations
- vector.traverse f ⟨v, Hv⟩ = cast _ (traverse_aux f v)
Equations
- vector.flip.traversable = {to_functor := {map := λ (α β : Type u), vector.map, map_const := λ (α β : Type u), vector.map ∘ function.const β}, traverse := vector.traverse n}
Equations
- vector.flip.is_lawful_traversable = {to_is_lawful_functor := _, id_traverse := _, comp_traverse := _, traverse_eq_map_id := _, naturality := _}