Matrices #
This file defines basic properties of matrices up to the module structure.
Matrices with rows indexed by m
, columns indexed by n
, and entries of type α
are represented
with Matrix m n α
. For the typical approach of counting rows and columns,
Matrix (Fin m) (Fin n) α
can be used.
Main definitions #
Matrix.transpose
: transpose of a matrix, turning rows into columns and vice versaMatrix.submatrix
: take a submatrix by reindexing rows and columnsMatrix.module
: matrices are a module over the ring of entries
Notation #
The locale Matrix
gives the following notation:
ᵀ
forMatrix.transpose
See Mathlib/Data/Matrix/ConjTranspose.lean
for
ᴴ
forMatrix.conjTranspose
Implementation notes #
For convenience, Matrix m n α
is defined as m → n → α
, as this allows elements of the matrix
to be accessed with A i j
. However, it is not advisable to construct matrices using terms of the
form fun i j ↦ _
or even (fun i j ↦ _ : Matrix m n α)
, as these are not recognized by Lean
as having the right type. Instead, Matrix.of
should be used.
Cast a function into a matrix.
The two sides of the equivalence are definitionally equal types. We want to use an explicit cast
to distinguish the types because Matrix
has different instances to pi types (such as Pi.mul
,
which performs elementwise multiplication, vs Matrix.mul
).
If you are defining a matrix, in terms of its entries, use of (fun i j ↦ _)
. The
purpose of this approach is to ensure that terms of the form (fun i j ↦ _) * (fun i j ↦ _)
do not
appear, as the type of *
can be misleading.
Equations
- Matrix.of = Equiv.refl (m → n → α)
Instances For
M.map f
is the matrix obtained by applying f
to each entry of the matrix M
.
This is available in bundled forms as:
AddMonoidHom.mapMatrix
LinearMap.mapMatrix
RingHom.mapMatrix
AlgHom.mapMatrix
Equiv.mapMatrix
AddEquiv.mapMatrix
LinearEquiv.mapMatrix
RingEquiv.mapMatrix
AlgEquiv.mapMatrix
Instances For
The transpose of a matrix.
Equations
- Matrix.«term_ᵀ» = Lean.ParserDescr.trailingNode `Matrix.«term_ᵀ» 1024 1024 (Lean.ParserDescr.symbol "ᵀ")
Instances For
Equations
- Matrix.inhabited = inferInstanceAs (Inhabited (m → n → α))
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
- Matrix.module = Pi.module m (fun (a : m) => n → α) R
simp-normal form pulls of
to the outside.
The scalar action via mul.toOppositeSMul
is transformed by the same map as the
elements of the matrix, when f
preserves multiplication.
Given maps (r_reindex : l → m)
and (c_reindex : o → n)
reindexing the rows and columns of
a matrix M : Matrix m n α
, the matrix M.submatrix r_reindex c_reindex : Matrix l o α
is defined
by (M.submatrix r_reindex c_reindex) i j = M (r_reindex i) (c_reindex j)
for (i,j) : l × o
.
Note that the total number of row and columns does not have to be preserved.
Equations
Instances For
For an m × n
α
-matrix A
, A.row i
is the i
th row of A
as a vector in n → α
.
A.row
is defeq to A
, but explicitly refers to the 'row functionof
Awhile avoiding defeq abuse and noisy eta-expansions, such as in expressions like
Set.Injective A.rowand
Set.range A.row. (Note 2025-04-07 : the identifier
Matrix.rowused to refer to a matrix with all rows equal; this is now called
Matrix.replicateRow`)
Instances For
For an m × n
α
-matrix A
, A.col j
is the j
th column of A
as a vector in m → α
.
A.col
is defeq to Aᵀ
, but refers to the 'column function' of A
while avoiding defeq abuse and noisy eta-expansions
(and without the simplifier unfolding transposes) in expressions like Set.Injective A.col
and Set.range A.col
.
(Note 2025-04-07 : the identifier Matrix.col
used to refer to a matrix with all columns equal;
this is now called Matrix.replicateCol
)
Instances For
A partially applied version of Matrix.row_apply
A partially applied version of Matrix.col_apply