Matrix and vector notation #
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 #
vecEmptyis the empty vector (or0bynmatrix)![]vecConsprepends an entry to a vector, so![a, b]isvecCons a (vecCons b vecEmpty)
Implementation notes #
The simp lemmas require that one of the arguments is of the form vecCons _ _.
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.
Notation #
The main new notation is ![a, b], which gets expanded to vecCons a (vecCons b vecEmpty).
Examples #
Examples of usage can be found in the MathlibTest/matrix.lean file.
![...] notation is used to construct a vector Fin n → α using Matrix.vecEmpty and
Matrix.vecCons.
For instance, ![a, b, c] : Fin 3 is syntax for vecCons a (vecCons b (vecCons c vecEmpty)).
Note that this should not be used as syntax for Matrix as it generates a term with the wrong type.
The !![a, b; c, d] syntax (provided by Matrix.matrixNotation) should be used instead.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Unexpander for the ![x, y, ...] notation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Unexpander for the ![] notation.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Parses a chain of Matrix.vecCons calls into elements, leaving everything else in the tail.
let ⟨xs, tailn, tail⟩ ← matchVecConsPrefix n e decomposes e : Fin n → _ in the form
vecCons x₀ <| ... <| vecCons xₙ <| tail where tail : Fin tailn → _.
A simproc that handles terms of the form Matrix.vecCons a f i where i is a numeric literal.
In practice, this is most effective at handling ![a, b, c] i-style terms.
Equations
- One or more equations did not get rendered due to their size.
Instances For
mkVecLiteralQ ![x, y, z] produces the term q(![$x, $y, $z]).
Equations
- PiFin.mkLiteralQ elems = PiFin.mkLiteralQ.loop elems 0 q(![])
Instances For
The core logic of loop is that loop 0 ![] = ![a 0, a 1, a 2] = loop 1 ![a 2], where
recursion starts from the end. In this example, on the right-hand side, the variable rest := 1
tracks the length of the current generated notation ![a 2], and the last used index is
n - rest (= 3 - 1 = 2).
Equations
- PiFin.mkLiteralQ.loop elems i rest = if h : i < n then PiFin.mkLiteralQ.loop elems (i + 1) (have a := elems ⟨i, h⟩.rev; q(Matrix.vecCons «$a» «$rest»)) else rest
Instances For
bit0 and bit1 indices #
The following definitions and simp lemmas are used to allow
numeral-indexed element of a vector given with matrix notation to
be extracted by simp in Lean 3 (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).
vecAppend 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 vecAppend ho u v 0 is valid. Fin.append u v 0 is not valid in this case because there is
no Zero (Fin (m + n)) instance.
Equations
- Matrix.vecAppend ho u v = Fin.append u v ∘ Fin.cast ho