Matrix and vector notation #
THIS FILE IS SYNCHRONIZED WITH MATHLIB4. Any changes to this file require a corresponding PR to mathlib4.
This file defines notation for vectors and matrices. Given a b c d : α
,
the notation allows us to write ![a, b, c, d] : fin 4 → α
.
Nesting vectors gives coefficients of a matrix, so ![![a, b], ![c, d]] : fin 2 → fin 2 → α
.
In later files we introduce !![a, b; c, d]
as notation for matrix.of ![![a, b], ![c, d]]
.
Main definitions #
vec_empty
is the empty vector (or0
byn
matrix)![]
vec_cons
prepends an entry to a vector, so![a, b]
isvec_cons a (vec_cons b vec_empty)
Implementation notes #
The simp
lemmas require that one of the arguments is of the form vec_cons _ _
.
This ensures simp
works with entries only when (some) entries are already given.
In other words, this notation will only appear in the output of simp
if it
already appears in the input.
Notations #
The main new notation is ![a, b]
, which gets expanded to vec_cons a (vec_cons b vec_empty)
.
Examples #
Examples of usage can be found in the test/matrix.lean
file.
![]
is the vector with no entries.
Equations
vec_head v
gives the first entry of the vector v
Equations
- matrix.vec_head v = v 0
Use ![...]
notation for displaying a vector fin n → α
, for example:
#eval ![1, 2] + ![3, 4] -- ![4, 6]
Equations
- pi_fin.has_repr = {repr := λ (f : fin n → α), "![" ++ ", ".intercalate (list.map (λ (n : fin n), repr (f n)) (list.fin_range n)) ++ "]"}
![a, b, ...] 1
is equal to b
.
The simplifier needs a special lemma for length ≥ 2
, in addition to
cons_val_succ
, because 1 : fin 1 = 0 : fin 1
.
Numeral (bit0
and bit1
) indices #
The following definitions and simp
lemmas are to allow any
numeral-indexed element of a vector given with matrix notation to
be extracted by simp
(even when the numeral is larger than the
number of elements in the vector, which is taken modulo that number
of elements by virtue of the semantics of bit0
and bit1
and of
addition on fin n
).
vec_append ho u v
appends two vectors of lengths m
and n
to produce
one of length o = m + n
. This is a variant of fin.append
with an additional ho
argument,
which provides control of definitional equality for the vector length.
This turns out to be helpful when providing simp lemmas to reduce ![a, b, c] n
, and also means
that vec_append ho u v 0
is valid. fin.append u v 0
is not valid in this case because there is
no has_zero (fin (m + n))
instance.
Equations
- matrix.vec_append ho u v = fin.append u v ∘ ⇑(fin.cast ho)