Matrix multiplication #
This file defines vector and matrix multiplication
Main definitions #
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:
⬝ᵥfordotProduct*ᵥ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
Instances For
Alias of dotProduct.
dotProduct v w is the sum of the entrywise products v i * w i
Equations
Instances For
dotProduct v w is the sum of the entrywise products v i * w i
Equations
- «term_⬝ᵥ_» = Lean.ParserDescr.trailingNode `«term_⬝ᵥ_» 72 72 (Lean.ParserDescr.binary `andthen (Lean.ParserDescr.symbol " ⬝ᵥ ") (Lean.ParserDescr.cat `term 73))
Instances For
Alias of dotProduct_assoc.
Alias of dotProduct_comm.
Alias of dotProduct_pUnit.
Alias of dotProduct_one.
Alias of one_dotProduct.
Alias of dotProduct_zero.
Alias of dotProduct_zero'.
Alias of zero_dotProduct.
Alias of zero_dotProduct'.
Alias of add_dotProduct.
Alias of dotProduct_add.
Alias of sum_elim_dotProduct_sum_elim.
Alias of comp_equiv_symm_dotProduct.
Permuting a vector on the left of a dot product can be transferred to the right.
Alias of dotProduct_comp_equiv_symm.
Permuting a vector on the right of a dot product can be transferred to the left.
Alias of comp_equiv_dotProduct_comp_equiv.
Permuting vectors on both sides of a dot product is a no-op.
Alias of diagonal_dotProduct.
Alias of dotProduct_diagonal.
Alias of dotProduct_diagonal'.
Alias of single_dotProduct.
Alias of dotProduct_single.
Alias of one_dotProduct_one.
Alias of dotProduct_single_one.
Alias of single_one_dotProduct.
Alias of neg_dotProduct.
Alias of dotProduct_neg.
Alias of neg_dotProduct_neg.
Alias of sub_dotProduct.
Alias of dotProduct_sub.
Alias of smul_dotProduct.
Alias of dotProduct_smul.
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.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.
This instance enables use with mul_smul_comm.
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 dotProduct,
so that A *ᵥ v ⬝ᵥ B *ᵥ w is parsed as (A *ᵥ v) ⬝ᵥ (B *ᵥ w).
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 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 dotProduct,
so that v ᵥ* A ⬝ᵥ w ᵥ* B is parsed as (v ᵥ* A) ⬝ᵥ (w ᵥ* B).
Equations
- Matrix.vecMul v M x✝ = 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 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.