Matrix multiplication #
This file defines matrix multiplication
Main definitions #
Matrix.dotProduct: the dot product between two vectorsMatrix.mul: multiplication of two matricesMatrix.mulVec: multiplication of a matrix with a vectorMatrix.vecMul: multiplication of a vector with a matrixMatrix.vecMulVec: multiplication of a vector with a vector to get a matrixMatrix.instRing: square matrices form a ring
Notation #
The locale Matrix gives the following notation:
⬝ᵥforMatrix.dotProduct*ᵥforMatrix.mulVecᵥ*forMatrix.vecMul
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.
TODO #
Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented.
dotProduct v w is the sum of the entrywise products v i * w i
Equations
- Matrix.dotProduct v w = ∑ i : m, v i * w i
Instances For
dotProduct v w is the sum of the entrywise products v i * w i
Equations
- Matrix.«term_⬝ᵥ_» = Lean.ParserDescr.trailingNode `Matrix.«term_⬝ᵥ_» 72 72 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⬝ᵥ ") (Lean.ParserDescr.cat `term 73))
Instances For
Permuting a vector on the left of a dot product can be transferred to the right.
Permuting a vector on the right of a dot product can be transferred to the left.
Permuting vectors on both sides of a dot product is a no-op.
M * N is the usual product of matrices M and N, i.e. we have that
(M * N) i k is the dot product of the i-th row of M by the k-th column of N.
This is currently only defined when m is finite.
Equations
- Matrix.instHMulOfFintypeOfMulOfAddCommMonoid = { hMul := fun (M : Matrix l m α) (N : Matrix m n α) (i : l) (k : n) => Matrix.dotProduct (fun (j : m) => M i j) fun (j : m) => N j k }
Equations
- Matrix.nonUnitalNonAssocSemiring = NonUnitalNonAssocSemiring.mk ⋯ ⋯ ⋯ ⋯
Left multiplication by a matrix, as an AddMonoidHom from matrices to matrices.
Equations
Instances For
Right multiplication by a matrix, as an AddMonoidHom from matrices to matrices.
Equations
Instances For
This instance enables use with smul_mul_assoc.
Equations
- ⋯ = ⋯
This instance enables use with mul_smul_comm.
Equations
- ⋯ = ⋯
Equations
- Matrix.nonAssocSemiring = NonAssocSemiring.mk ⋯ ⋯ ⋯ ⋯
Equations
- Matrix.nonUnitalSemiring = NonUnitalSemiring.mk ⋯
Equations
- Matrix.semiring = Semiring.mk ⋯ ⋯ ⋯ ⋯ npowRecAuto ⋯ ⋯
Equations
- Matrix.nonUnitalNonAssocRing = NonUnitalNonAssocRing.mk ⋯ ⋯ ⋯ ⋯
Equations
- Matrix.instNonUnitalRing = NonUnitalRing.mk ⋯
Equations
- Matrix.instNonAssocRing = NonAssocRing.mk ⋯ ⋯ ⋯ ⋯ ⋯ ⋯
For two vectors w and v, vecMulVec w v i j is defined to be w i * v j.
Put another way, vecMulVec w v is exactly col w * row v.
Equations
- Matrix.vecMulVec w v = Matrix.of fun (x : m) (y : n) => w x * v y
Instances For
M *ᵥ v (notation for mulVec M v) is the matrix-vector product of matrix M and vector v,
where v is seen as a column vector.
Put another way, M *ᵥ v is the vector whose entries are those of M * col v (see col_mulVec).
The notation has precedence 73, which comes immediately before ⬝ᵥ for Matrix.dotProduct,
so that A *ᵥ v ⬝ᵥ B *ᵥ w is parsed as (A *ᵥ v) ⬝ᵥ (B *ᵥ w).
Equations
- M.mulVec v x = Matrix.dotProduct (fun (j : n) => M x j) v
Instances For
M *ᵥ v (notation for mulVec M v) is the matrix-vector product of matrix M and vector v,
where v is seen as a column vector.
Put another way, M *ᵥ v is the vector whose entries are those of M * col v (see col_mulVec).
The notation has precedence 73, which comes immediately before ⬝ᵥ for Matrix.dotProduct,
so that A *ᵥ v ⬝ᵥ B *ᵥ w is parsed as (A *ᵥ v) ⬝ᵥ (B *ᵥ w).
Equations
- Matrix.«term_*ᵥ_» = Lean.ParserDescr.trailingNode `Matrix.«term_*ᵥ_» 73 74 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " *ᵥ ") (Lean.ParserDescr.cat `term 73))
Instances For
v ᵥ* M (notation for vecMul v M) is the vector-matrix product of vector v and matrix M,
where v is seen as a row vector.
Put another way, v ᵥ* M is the vector whose entries are those of row v * M (see row_vecMul).
The notation has precedence 73, which comes immediately before ⬝ᵥ for Matrix.dotProduct,
so that v ᵥ* A ⬝ᵥ w ᵥ* B is parsed as (v ᵥ* A) ⬝ᵥ (w ᵥ* B).
Equations
- Matrix.vecMul v M x = Matrix.dotProduct v fun (i : m) => M i x
Instances For
v ᵥ* M (notation for vecMul v M) is the vector-matrix product of vector v and matrix M,
where v is seen as a row vector.
Put another way, v ᵥ* M is the vector whose entries are those of row v * M (see row_vecMul).
The notation has precedence 73, which comes immediately before ⬝ᵥ for Matrix.dotProduct,
so that v ᵥ* A ⬝ᵥ w ᵥ* B is parsed as (v ᵥ* A) ⬝ᵥ (w ᵥ* B).
Equations
- Matrix.«term_ᵥ*_» = Lean.ParserDescr.trailingNode `Matrix.«term_ᵥ*_» 73 73 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ᵥ* ") (Lean.ParserDescr.cat `term 74))
Instances For
Left multiplication by a matrix, as an AddMonoidHom from vectors to vectors.
Equations
- Matrix.mulVec.addMonoidHomLeft v = { toFun := fun (M : Matrix m n α) => M.mulVec v, map_zero' := ⋯, map_add' := ⋯ }
Instances For
The ith row of the multiplication is the same as the vecMul with the ith row of A.
Associate the dot product of mulVec to the left.
simp lemmas for Matrix.submatrixs interaction with Matrix.diagonal, 1, and Matrix.mul
for when the mappings are bundled.