Matrices #
This file defines basic properties of matrices.
Notation #
The locale matrix
gives the following notation:
⬝ᵥ
formatrix.dot_product
⬝
formatrix.mul
ᵀ
formatrix.transpose
ᴴ
formatrix.conj_transpose
TODO #
Under various conditions, multiplication of infinite matrices makes sense. These have not yet been implemented.
M.map f
is the matrix obtained by applying f
to each entry of the matrix M
.
This is available in bundled forms as:
matrix.col u
is the column matrix whose entries are given by u
.
Equations
- matrix.col w x y = w x
matrix.row u
is the row matrix whose entries are given by u
.
Equations
- matrix.row v x y = v y
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
Equations
- matrix.module = pi.module m (λ (ᾰ : m), n → α) R
The scalar action via has_mul.to_has_scalar
is transformed by the same map as the elements
of the matrix, when f
preserves multiplication.
The scalar action via has_mul.to_has_opposite_scalar
is transformed by the same map as the
elements of the matrix, when f
preserves multiplication.
diagonal d
is the square matrix such that (diagonal d) i i = d i
and (diagonal d) i j = 0
if i ≠ j
.
Note that bundled versions exist as:
matrix.diagonal_add_monoid_hom
matrix.diagonal_linear_map
matrix.diagonal_ring_hom
matrix.diagonal_alg_hom
Equations
- matrix.diagonal d i j = ite (i = j) (d i) 0
matrix.diagonal
as an add_monoid_hom
.
Equations
- matrix.diagonal_add_monoid_hom n α = {to_fun := matrix.diagonal (add_zero_class.to_has_zero α), map_zero' := _, map_add' := _}
matrix.diagonal
as a linear_map
.
Equations
- matrix.diagonal_linear_map n R α = {to_fun := (matrix.diagonal_add_monoid_hom n α).to_fun, map_add' := _, map_smul' := _}
Equations
- matrix.has_one = {one := matrix.diagonal (λ (_x : n), 1)}
dot_product v w
is the sum of the entrywise products v i * w i
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.has_mul = {mul := matrix.mul _inst_3}
Equations
- matrix.non_unital_non_assoc_semiring = {add := has_add.add matrix.has_add, add_assoc := _, zero := 0, zero_add := _, add_zero := _, nsmul := add_comm_monoid.nsmul matrix.add_comm_monoid, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, mul := has_mul.mul matrix.has_mul, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _}
Left multiplication by a matrix, as an add_monoid_hom
from matrices to matrices.
Right multiplication by a matrix, as an add_monoid_hom
from matrices to matrices.
Equations
- matrix.non_assoc_semiring = {add := non_unital_non_assoc_semiring.add matrix.non_unital_non_assoc_semiring, add_assoc := _, zero := non_unital_non_assoc_semiring.zero matrix.non_unital_non_assoc_semiring, zero_add := _, add_zero := _, nsmul := non_unital_non_assoc_semiring.nsmul matrix.non_unital_non_assoc_semiring, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, mul := non_unital_non_assoc_semiring.mul matrix.non_unital_non_assoc_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, one := 1, one_mul := _, mul_one := _}
matrix.diagonal
as a ring_hom
.
Equations
- matrix.diagonal_ring_hom n α = {to_fun := matrix.diagonal (mul_zero_class.to_has_zero α), map_one' := _, map_mul' := _, map_zero' := _, map_add' := _}
Equations
- matrix.non_unital_semiring = {add := non_unital_non_assoc_semiring.add matrix.non_unital_non_assoc_semiring, add_assoc := _, zero := non_unital_non_assoc_semiring.zero matrix.non_unital_non_assoc_semiring, zero_add := _, add_zero := _, nsmul := non_unital_non_assoc_semiring.nsmul matrix.non_unital_non_assoc_semiring, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, mul := non_unital_non_assoc_semiring.mul matrix.non_unital_non_assoc_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, mul_assoc := _}
Equations
- matrix.semiring = {add := non_unital_semiring.add matrix.non_unital_semiring, add_assoc := _, zero := non_unital_semiring.zero matrix.non_unital_semiring, zero_add := _, add_zero := _, nsmul := non_unital_semiring.nsmul matrix.non_unital_semiring, nsmul_zero' := _, nsmul_succ' := _, add_comm := _, mul := non_unital_semiring.mul matrix.non_unital_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, mul_assoc := _, one := non_assoc_semiring.one matrix.non_assoc_semiring, one_mul := _, mul_one := _, npow := monoid_with_zero.npow._default non_assoc_semiring.one non_unital_semiring.mul matrix.semiring._proof_14 matrix.semiring._proof_15, npow_zero' := _, npow_succ' := _}
Equations
- matrix.non_unital_non_assoc_ring = {add := non_unital_non_assoc_semiring.add matrix.non_unital_non_assoc_semiring, add_assoc := _, zero := non_unital_non_assoc_semiring.zero matrix.non_unital_non_assoc_semiring, zero_add := _, add_zero := _, nsmul := non_unital_non_assoc_semiring.nsmul matrix.non_unital_non_assoc_semiring, nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg matrix.add_comm_group, sub := add_comm_group.sub matrix.add_comm_group, sub_eq_add_neg := _, zsmul := add_comm_group.zsmul matrix.add_comm_group, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, mul := non_unital_non_assoc_semiring.mul matrix.non_unital_non_assoc_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _}
Equations
- matrix.non_unital_ring = {add := non_unital_semiring.add matrix.non_unital_semiring, add_assoc := _, zero := non_unital_semiring.zero matrix.non_unital_semiring, zero_add := _, add_zero := _, nsmul := non_unital_semiring.nsmul matrix.non_unital_semiring, nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg matrix.add_comm_group, sub := add_comm_group.sub matrix.add_comm_group, sub_eq_add_neg := _, zsmul := add_comm_group.zsmul matrix.add_comm_group, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, mul := non_unital_semiring.mul matrix.non_unital_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, mul_assoc := _}
Equations
- matrix.non_assoc_ring = {add := non_assoc_semiring.add matrix.non_assoc_semiring, add_assoc := _, zero := non_assoc_semiring.zero matrix.non_assoc_semiring, zero_add := _, add_zero := _, nsmul := non_assoc_semiring.nsmul matrix.non_assoc_semiring, nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg matrix.add_comm_group, sub := add_comm_group.sub matrix.add_comm_group, sub_eq_add_neg := _, zsmul := add_comm_group.zsmul matrix.add_comm_group, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, mul := non_assoc_semiring.mul matrix.non_assoc_semiring, left_distrib := _, right_distrib := _, zero_mul := _, mul_zero := _, one := non_assoc_semiring.one matrix.non_assoc_semiring, one_mul := _, mul_one := _}
Equations
- matrix.ring = {add := semiring.add matrix.semiring, add_assoc := _, zero := semiring.zero matrix.semiring, zero_add := _, add_zero := _, nsmul := semiring.nsmul matrix.semiring, nsmul_zero' := _, nsmul_succ' := _, neg := add_comm_group.neg matrix.add_comm_group, sub := add_comm_group.sub matrix.add_comm_group, sub_eq_add_neg := _, zsmul := add_comm_group.zsmul matrix.add_comm_group, zsmul_zero' := _, zsmul_succ' := _, zsmul_neg' := _, add_left_neg := _, add_comm := _, mul := semiring.mul matrix.semiring, mul_assoc := _, one := semiring.one matrix.semiring, one_mul := _, mul_one := _, npow := semiring.npow matrix.semiring, npow_zero' := _, npow_succ' := _, left_distrib := _, right_distrib := _}
This instance enables use with smul_mul_assoc
.
This instance enables use with mul_smul_comm
.
The ring homomorphism α →+* matrix n n α
sending a
to the diagonal matrix with a
on the diagonal.
Equations
- matrix.algebra = {to_has_scalar := matrix.has_scalar smul_with_zero.to_has_scalar, to_ring_hom := {to_fun := ((matrix.scalar n).comp (algebra_map R α)).to_fun, map_one' := _, map_mul' := _, map_zero' := _, map_add' := _}, commutes' := _, smul_def' := _}
matrix.diagonal
as an alg_hom
.
Equations
- matrix.diagonal_alg_hom R = {to_fun := matrix.diagonal (mul_zero_class.to_has_zero α), map_one' := _, map_mul' := _, map_zero' := _, map_add' := _, commutes' := _}
Bundled versions of matrix.map
#
The equiv
between spaces of matrices induced by an equiv
between their
coefficients. This is matrix.map
as an equiv
.
The add_monoid_hom
between spaces of matrices induced by an add_monoid_hom
between their
coefficients. This is matrix.map
as an add_monoid_hom
.
The add_equiv
between spaces of matrices induced by an add_equiv
between their
coefficients. This is matrix.map
as an add_equiv
.
The linear_map
between spaces of matrices induced by a linear_map
between their
coefficients. This is matrix.map
as a linear_map
.
The linear_equiv
between spaces of matrices induced by an linear_equiv
between their
coefficients. This is matrix.map
as an linear_equiv
.
The ring_hom
between spaces of square matrices induced by a ring_hom
between their
coefficients. This is matrix.map
as a ring_hom
.
The ring_equiv
between spaces of square matrices induced by a ring_equiv
between their
coefficients. This is matrix.map
as a ring_equiv
.
The alg_hom
between spaces of square matrices induced by a alg_hom
between their
coefficients. This is matrix.map
as a alg_hom
.
The alg_equiv
between spaces of square matrices induced by a alg_equiv
between their
coefficients. This is matrix.map
as a alg_equiv
.
For two vectors w
and v
, vec_mul_vec w v i j
is defined to be w i * v j
.
Put another way, vec_mul_vec w v
is exactly col w ⬝ row v
.
Equations
- matrix.vec_mul_vec w v x y = (w x) * v y
mul_vec M v
is the matrix-vector product of M
and v
, where v
is seen as a column matrix.
Put another way, mul_vec M v
is the vector whose entries
are those of M ⬝ col v
(see col_mul_vec
).
vec_mul v M
is the vector-matrix product of v
and M
, where v
is seen as a row matrix.
Put another way, vec_mul v M
is the vector whose entries
are those of row v ⬝ M
(see row_vec_mul
).
Equations
- matrix.vec_mul v M j = v ⬝ᵥ λ (i : m), M i j
Left multiplication by a matrix, as an add_monoid_hom
from vectors to vectors.
Associate the dot product of mul_vec
to the left.
matrix.transpose
as an add_equiv
Equations
- matrix.transpose_add_equiv = {to_fun := matrix.transpose α, inv_fun := matrix.transpose α, left_inv := _, right_inv := _, map_add' := _}
matrix.transpose
as a ring_equiv
to the opposite ring
matrix.conj_transpose
as an add_equiv
Equations
matrix.conj_transpose
as a ring_equiv
to the opposite ring
When α
has a star operation, square matrices matrix n n α
have a star
operation equal to matrix.conj_transpose
.
Equations
- matrix.has_star = {star := matrix.conj_transpose _inst_1}
Equations
When α
is a *
-additive monoid, matrix.has_star
is also a *
-additive monoid.
When α
is a *
-(semi)ring, matrix.has_star
is also a *
-(semi)ring.
Equations
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.minor r_reindex c_reindex : matrix l o α
is defined
by (M.minor 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.
Given a (m × m)
diagonal matrix defined by a map d : m → α
, if the reindexing map e
is
injective, then the resulting matrix is again diagonal.
simp
lemmas for matrix.minor
s interaction with matrix.diagonal
, 1
, and matrix.mul
for
when the mappings are bundled.
The natural map that reindexes a matrix's rows and columns with equivalent types is an equivalence.
row_col
section #
Simplification lemmas for matrix.row
and matrix.col
.
Update, i.e. replace the i
th row of matrix A
with the values in b
.
Equations
- M.update_row i b = function.update M i b
Update, i.e. replace the j
th column of matrix A
with the values in b
.
Equations
- M.update_column j b = λ (i : m), function.update (M i) j (b i)